• 读取properties文件


    package com.pcitc.hrs.zcps.util;

    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;

    import com.pcitc.hrs.common.model.ApplicationConstant;
    import com.pcitc.simpletemplate.StringUtils;

    public class ParameterUtil {

    private static Properties paramProps = null ;

    static {
    paramProps = new Properties() ;
    InputStream is = null ;
    try {
    is = ParameterUtil.class.getResourceAsStream("/config/parameter.properties") ;
    paramProps.load(is) ;
    } catch (IOException e) {
    }
    finally {
    try {
    if (is!=null) {
    is.close() ;
    is = null ;
    }
    } catch (Exception e) {
    }
    }
    }

    public static String getExportDir() {
    String str = paramProps.getProperty("export.dir") ;
    str = StringUtils.isNull(str) ? "" : str ;
    return str ;
    }

    public static String getTodoMachineId() {
    String str = paramProps.getProperty("todo.machine.id") ;
    str = StringUtils.isNull(str) ? "localhost" : str ;
    return str ;
    }

    public static int getTodoFailResetMinutes() {
    String str = paramProps.getProperty("todo.fail.reset.minute") ;
    if (StringUtils.isNull(str))
    return 120 ;
    try {
    int n = Integer.parseInt(str) ;
    n = n<=0 ? 120 : n ;
    return n ;
    } catch (Exception e) {
    return 120 ;
    }
    }

    public static boolean isProductDeploy() {
    String str = paramProps.getProperty("deploy.production") ;
    if (str!=null && str.equalsIgnoreCase("N"))
    return false ;
    return true ;
    }

    public static String getDefaultLang() {
    String str = paramProps.getProperty("lang.default") ;
    return str==null ? ApplicationConstant._DEFAULT_LANG : str ;
    }

    public static String[] getSupportLangs() {
    String str = paramProps.getProperty("lang.support") ;
    if (StringUtils.isNull(str)) return new String[0] ;
    return str.split(",",-1) ;
    }

    public static String getSupportLang(String lang) {
    String defaultLang = getDefaultLang() ;
    String[] arr = getSupportLangs() ;
    int len = arr==null ? 0 : arr.length ;
    for (int i=0; i<len; i++) {
    String str = arr[i] ;
    if (str!=null && str.equalsIgnoreCase(lang)) return lang ;
    }
    return defaultLang ;
    }

    public static boolean isCasLogin() {
    String str = paramProps.getProperty("cas.login.flag") ;
    if (str!=null && str.equalsIgnoreCase("Y"))
    return true ;
    return false ;
    }

    public static String getCasLoginUrl() {
    String str = paramProps.getProperty("cas.login.url") ;
    return str==null ? "" : str ;
    }

    public static boolean isCasLogout() {
    String str = paramProps.getProperty("cas.logout.flag") ;
    if (str!=null && str.equalsIgnoreCase("Y"))
    return true ;
    return false ;
    }

    public static String getCasLogoutUrl() {
    String str = paramProps.getProperty("cas.logout.url") ;
    return str==null ? "" : str ;
    }

    public static String getLocalFileRootDir(){
    String str = paramProps.getProperty("file.local.rootdir");
    return str==null ? "" : str ;
    }

    public static String getPhotoNotFound(){
    String str = paramProps.getProperty("file.notFound.photo");
    return str==null ? "" : str ;
    }


    public static String getAttachPath(){
    String str = paramProps.getProperty("attach.path") ;
    str = str==null ? "" : str ;
    return str ;
    }

    public static String getAttachFileName(){
    String str = paramProps.getProperty("attach.file.name") ;
    str = str==null ? "" : str ;
    return str ;
    }

    public static String getDataTemplatePath(){
    String str = paramProps.getProperty("ssp.data.template.dir");
    str = str==null ? "" : str ;
    return str ;
    }

    public static String getCacheSystemPrefix() {
    String str = paramProps.getProperty("cache.system.prefix") ;
    return str ;
    }

    public static int getSqCacheTTL(){
    String ttl = paramProps.getProperty("cache.redis.sqcache.ttl");
    if(StringUtils.isNull(ttl)){
    return 1728000 ;
    }
    try {
    return Integer.parseInt(ttl);
    } catch (Exception e) {
    return 1728000 ;
    }
    }

    public static String getSapWebServiceUrl() {
    return paramProps.getProperty("sap.webservice.url") ;
    }

    public static String getSapWebServiceCallbackUrl() {
    return paramProps.getProperty("sap.webservice.callback.url") ;
    }

    public static String getSapWebServiceUser() {
    return paramProps.getProperty("sap.webservice.user") ;
    }

    public static String getSapWebServicePassword() {
    return paramProps.getProperty("sap.webservice.password") ;
    }

    public static boolean isSapWebServiceSendImmediate() {
    String str = paramProps.getProperty("sap.webservice.send.immediate") ;
    if (str!=null && str.equalsIgnoreCase("Y"))
    return true ;
    return false ;
    }

    public static String getEmpImageUrl(){
    return paramProps.getProperty("image.server.url") ;
    }

    public static String getImageServerUrl() {
    return paramProps.getProperty("server.image.url") ;
    }

    public static String getImageAttachServerUrl() {
    return paramProps.getProperty("server.ims.attach.url") ;
    }

    public static String getImageServerHost() {
    return paramProps.getProperty("server.image.host") ;
    }

    public static int getImageServerPort() {
    String str = paramProps.getProperty("server.image.port") ;
    if (StringUtils.isNull(str))
    return 80 ;
    try {
    return Integer.parseInt(str) ;
    } catch (Exception e) {
    return 80 ;
    }
    }

    public static String getImageServerUser() {
    return paramProps.getProperty("server.image.user") ;
    }

    public static String getImageServerPassword() {
    return paramProps.getProperty("server.image.password") ;
    }

    public static String getImageSystemUploadUrl() {
    String str = paramProps.getProperty("server.image.url.upload") ;
    return str ;
    }

    public static String getImageSystemLookUrl() {
    String str = paramProps.getProperty("server.image.ws.ImsLookUrlService") ;
    return str ;
    }

    public static String getImageSystemFileOperationUrl() {
    String str = paramProps.getProperty("server.image.ws.FileOperationService") ;
    return str ;
    }

    public static String getImageRemoteServiceUrl() {
    String str = paramProps.getProperty("server.image.ws.ImageRemoteService") ;
    return str ;
    }

    public static String getImageSystemFileQueryUrl() {
    String str = paramProps.getProperty("server.image.ws.FileQueryService") ;
    return str ;
    }

    public static String getSmsAppId(){
    return paramProps.getProperty("sms.appid");
    }

    public static String getSmsWebServiceUrl(){
    return paramProps.getProperty("sms.webservice.url");
    }

    public static String getAppUrl4Image() {
    return paramProps.getProperty("app.url.image") ;
    }

    public static String getEmpDefaultAvtar(){
    return paramProps.getProperty("emp_default_avtar");
    }

    public static int getMainHomeNewsCount(){
    String str = paramProps.getProperty("ess.mainhome.news.count");
    return StringUtils.isNull(str) ? 5 : Integer.parseInt(str);
    }

    public static String getAvtarPhyPath(){
    return paramProps.getProperty("image.server.avtar.phy");
    }

    public static String[] getUpperNum(){
    String upperNum = paramProps.getProperty("income.upper.number");
    return(upperNum.split(","));
    }

    public static String[] getUpperMonetrayUnit(){
    String upperNum = paramProps.getProperty("income.upper.monetrayUnit");
    return(upperNum.split(","));
    }

    public static String getUpperFull(){
    return paramProps.getProperty("income.upper.Full");
    }

    public static String getUpperNegative(){
    return paramProps.getProperty("income.upper.negative");
    }

    public static int getMoneyPrecision(){
    return Integer.parseInt(paramProps.getProperty("income.upper.moneyPrecision"));
    }

    public static String getUpperZeroFull(){
    return paramProps.getProperty("income.upper.zeroFull");
    }

    public static String getServerOwner(){
    return paramProps.getProperty("server.owner");
    }

    public static String getImportRootPath(){
    return paramProps.getProperty("import.root.dir");
    }

    public static String getImportNormPath(){
    return paramProps.getProperty("import.norm.dir");
    }

    public static String getIdapLogoutPath(){
    return paramProps.getProperty("idap.loginout.path");
    }

    public static String getAdAccountStuffix() {
    String suffix = paramProps.getProperty("ad.account.suffix") ;
    if (StringUtils.isNull(suffix))
    return "" ;
    return suffix.toUpperCase();
    }

    public static String getSspSSOLoginUrl(){
    return paramProps.getProperty("ssp.webservice.url");
    }

    public static String getEncodingConvert(){
    return paramProps.getProperty("ssp.encoding.convert");
    }

    public static String getFTPServiceUrl(){
    return paramProps.getProperty("ftp.serverurl.wsproxy");
    }

    public static String getSignServiceUrl(){
    String str = paramProps.getProperty("sign.serverurl.wsproxy") ;
    str = str==null ? "" : str ;
    return str ;
    }

    public static String getOSSEndpoint() {
    return paramProps.getProperty("zcps.ali.oss.endpoint") ;
    }

    public static String getOSSAccessId() {
    return paramProps.getProperty("zcps.ali.oss.Id") ;
    }
    public static String getOSSAccessSecret() {
    return paramProps.getProperty("zcps.ali.oss.Secret") ;
    }
    public static String getOSSBucketName() {
    return paramProps.getProperty("zcps.ali.oss.bucketName") ;
    }

    public static String getFileStorageType() {
    return paramProps.getProperty("zcps.storage.type") ;
    }

    public static String getAuthnUserUrl() {
    return paramProps.getProperty("authn.user.url") ;
    }
    }

    package com.hm.common.util;

    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;

    public class PropertiesUtil {
    final static String fileName = "/conf/common.properties";

    // 获取key所对应的值
    public static String getProperties(String key) {
    Properties prop = new Properties();
    InputStream is = null;
    try {
    // properties文件放在src目录的下边
    is = PropertiesUtil.class.getResourceAsStream(fileName);
    if (is == null)
    is = new FileInputStream(fileName);
    prop.load(is);
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (is != null) {
    try {
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    return prop.getProperty(key);
    }

    public static void main(String[] args) {
    System.out.println( PropertiesUtil.getProperties("a.vn.salt"));
    }

    }

    package com.la.util;

    import java.util.PropertyResourceBundle;
    import java.util.ResourceBundle;
    import java.util.logging.Logger;

    public class configResponse {

    // protected static Logger logger = Logger.getLogger(configResponse.class);
    protected static ResourceBundle configResponse;

    protected static final String config_response_file="config/configResponse.properties";

    static {

    try {
    configResponse = PropertyResourceBundle.getBundle(config_response_file);

    } catch (Exception e) {
    // TODO: handle exception
    }
    }

    public static int getIntegerCode(String key) {
    try {
    if (configResponse.getString(key) != null) {
    return Integer.parseInt(configResponse.getString(key));
    }
    } catch (Exception e) {
    // logger.error("RESPONSE CODE FROM STRING TO INT THEN ERROR." , e) ;
    }
    return 0 ;
    }
    /**
    * update by Brain
    * @param key
    * @return
    */
    public static String getStringCode(String key){
    return configResponse.getString(key)!=null?configResponse.getString(key):"";
    }

    public static int getIntegerCode(String key , int value ) {
    try {
    if (configResponse.getString(key) != null) {
    return Integer.parseInt(configResponse.getString(key));
    }
    } catch (Exception e) {
    // logger.error("RESPONSE CODE FROM STRING TO INT THEN ERROR." , e) ;
    }
    return value ;
    }

    public static String get(String key) {
    return configResponse.getString(key);
    }

    public static String get(String key , String value) {
    return configResponse.getString(key)==null?value:configResponse.getString(key) ;
    }


    }

  • 相关阅读:
    我来了
    学习笔记-数据仓库和数据挖掘
    React及JSX常见问题
    JavaScript笔记,不定期更新
    比strlen执行速度更快的处理字符串长度的函数
    LESS笔记/注意手册(更新中)
    鼠标移到图片变化的三种写法(可移植性强、代码少)
    信息安全技术作业5--散列函数的应用及其安全性
    结对作业(web)
    读《构建之法》第4、17章
  • 原文地址:https://www.cnblogs.com/lovelanglangyou/p/7418531.html
Copyright © 2020-2023  润新知