Java Code Examples for java.util.Properties#get()

The following examples show how to use java.util.Properties#get() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: archiva   File: ArchivaRuntimeInfo.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public ArchivaRuntimeInfo( @Named( value = "archivaRuntimeProperties" ) Properties archivaRuntimeProperties )
{
    this.version = (String) archivaRuntimeProperties.get( "archiva.version" );
    this.buildNumber = (String) archivaRuntimeProperties.get( "archiva.buildNumber" );
    String archivaTimeStamp = (String) archivaRuntimeProperties.get( "archiva.timestamp" );
    if ( NumberUtils.isNumber( archivaTimeStamp ) )
    {
        this.timestamp = NumberUtils.createLong( archivaTimeStamp );
    }
    else
    {
        this.timestamp = new Date().getTime();
    }
    this.devMode = Boolean.getBoolean( "archiva.devMode" );
}
 
Example 2
Source Project: p4ic4idea   File: RpcPropertyDefs.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method to first try to get the short form from the passed-in
 * properties, then try for the long form. Returns defaultValue if it can't
 * find a definition associated with either short or long form keys.<p>
 * 
 * Note: this method is null safe, i.e. if either or both props or nick is null,
 * it simply returns null.
 */

public static String getProperty(Properties props, String nick, String defaultValue) {
	
	if ((props != null) && (nick != null)) {
		String propStr = null;
		if (props.get(nick) != null) {
			propStr = String.valueOf(props.get(nick));
		}
		
		if (propStr == null) {
			if (props.get(RPC_PROPERTY_PREFIX + nick) != null) {
				propStr = String.valueOf(props.get(RPC_PROPERTY_PREFIX + nick));
			}
		}
		
		if (propStr != null) {
			return propStr;
		}
	}
	
	return defaultValue;
}
 
Example 3
private static synchronized void startLocalManagementAgent() {
    Properties agentProps = VMSupport.getAgentProperties();

    // start local connector if not started
    if (agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP) == null) {
        JMXConnectorServer cs = ConnectorBootstrap.startLocalConnectorServer();
        String address = cs.getAddress().toString();
        // Add the local connector address to the agent properties
        agentProps.put(LOCAL_CONNECTOR_ADDRESS_PROP, address);

        try {
            // export the address to the instrumentation buffer
            ConnectorAddressLink.export(address);
        } catch (Exception x) {
            // Connector server started but unable to export address
            // to instrumentation buffer - non-fatal error.
            warning(EXPORT_ADDRESS_FAILED, x.getMessage());
        }
    }
}
 
Example 4
/**
 * Merge the given Properties instance into the given Map,
 * copying all properties (key-value pairs) over.
 * <p>Uses <code>Properties.propertyNames()</code> to even catch
 * default properties linked into the original Properties instance.
 * @param props the Properties instance to merge (may be <code>null</code>)
 * @param map the target Map to merge the properties into
 */
@SuppressWarnings("unchecked")
public static void mergePropertiesIntoMap(Properties props, Map map) {
	if (map == null) {
		throw new IllegalArgumentException("Map must not be null");
	}
	if (props != null) {
		for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
			String key = (String) en.nextElement();
			Object value = props.getProperty(key);
			if (value == null) {
				// Potentially a non-String value...
				value = props.get(key);
			}
			map.put(key, value);
		}
	}
}
 
Example 5
private static void readInput() throws IOException {
    currencyData = new Properties();
    currencyData.load(System.in);

    // initialize other lookup strings
    formatVersion = (String) currencyData.get("formatVersion");
    dataVersion = (String) currencyData.get("dataVersion");
    validCurrencyCodes = (String) currencyData.get("all");
    for (int i = 0; i <= SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS; i++) {
        currenciesWithDefinedMinorUnitDecimals[i]
            = (String) currencyData.get("minor"+i);
    }
    currenciesWithMinorUnitsUndefined  = (String) currencyData.get("minorUndefined");
    if (formatVersion == null ||
            dataVersion == null ||
            validCurrencyCodes == null ||
            currenciesWithMinorUnitsUndefined == null) {
        throw new NullPointerException("not all required data is defined in input");
    }
}
 
Example 6
Source Project: dr-elephant   File: AnalyticJobTest.java    License: Apache License 2.0 6 votes vote down vote up
private void setCounterData(MapReduceCounterData counter, String filePath)
    throws IOException {
  Properties counterData = TestUtil.loadProperties(filePath);

  for (Object groupName : counterData.keySet()) {
    String counterValueString = (String) counterData.get(groupName);
    counterValueString = counterValueString.replaceAll("\\{|\\}", "");

    StringBuilder stringBuilder = new StringBuilder();

    for (String counterKeyValue : counterValueString.split(",")) {
      stringBuilder.append(counterKeyValue.trim()).append('\n');
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(stringBuilder.toString().getBytes(DEFAULT_ENCODING));
    Properties counterProperties = new Properties();
    counterProperties.load(inputStream);

    for (Object counterKey : counterProperties.keySet()) {
      long counterValue = Long.parseLong(counterProperties.get(counterKey).toString());
      counter.set(groupName.toString(), counterKey.toString(), counterValue);
    }
  }
}
 
Example 7
Source Project: hottub   File: MimeTable.java    License: GNU General Public License v2.0 6 votes vote down vote up
void parse(Properties entries) {
    // first, strip out the platform-specific temp file template
    String tempFileTemplate = (String)entries.get("temp.file.template");
    if (tempFileTemplate != null) {
        entries.remove("temp.file.template");
        MimeTable.tempFileTemplate = tempFileTemplate;
    }

    // now, parse the mime-type spec's
    Enumeration<?> types = entries.propertyNames();
    while (types.hasMoreElements()) {
        String type = (String)types.nextElement();
        String attrs = entries.getProperty(type);
        parse(type, attrs);
    }
}
 
Example 8
private static void readInput() throws IOException {
    currencyData = new Properties();
    currencyData.load(System.in);

    // initialize other lookup strings
    formatVersion = (String) currencyData.get("formatVersion");
    dataVersion = (String) currencyData.get("dataVersion");
    validCurrencyCodes = (String) currencyData.get("all");
    currenciesWith0MinorUnitDecimals  = (String) currencyData.get("minor0");
    currenciesWith1MinorUnitDecimal  = (String) currencyData.get("minor1");
    currenciesWith3MinorUnitDecimal  = (String) currencyData.get("minor3");
    currenciesWithMinorUnitsUndefined  = (String) currencyData.get("minorUndefined");
    if (formatVersion == null ||
            dataVersion == null ||
            validCurrencyCodes == null ||
            currenciesWith0MinorUnitDecimals == null ||
            currenciesWith1MinorUnitDecimal == null ||
            currenciesWith3MinorUnitDecimal == null ||
            currenciesWithMinorUnitsUndefined == null) {
        throw new NullPointerException("not all required data is defined in input");
    }
}
 
Example 9
Source Project: letv   File: AppUpgradeConstants.java    License: Apache License 2.0 5 votes vote down vote up
public static String[] getChannelInfo(Context context) {
    String[] channelInfo = new String[2];
    try {
        String pchannel = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128).metaData.getString("UMENG_CHANNEL");
        InputStream in = context.getAssets().open("channel-maps.properties");
        if (pchannel == null || in == null) {
            return channelInfo;
        }
        Properties p = new Properties();
        p.load(in);
        String value = (String) p.get(pchannel);
        if (pchannel.contains(" ")) {
            value = (String) p.get(pchannel.split(" ")[0]);
            if (!TextUtils.isEmpty(value) && value.contains(NetworkUtils.DELIMITER_COLON)) {
                value = value.substring(value.indexOf(58) + 1);
            }
        }
        if (TextUtils.isEmpty(value) || !value.contains("#")) {
            return channelInfo;
        }
        String[] data = value.split("#");
        if (data == null || data.length != 2) {
            return channelInfo;
        }
        String appeky = data[1];
        channelInfo[0] = data[0];
        channelInfo[1] = appeky;
        return channelInfo;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 10
/**
 * GET http://localhost:8080/<portal>/api/rs/en/ideaInstances?id=1
 *
 * @param properties
 * @return
 * @throws Throwable
 */
public JAXBIdeaInstance getIdeaInstanceForApi(Properties properties) throws Throwable {
    JAXBIdeaInstance jaxbIdeaInstance = null;
    try {
        String codeParam = properties.getProperty("code");
        if (StringUtils.isNotBlank(codeParam)) {
            codeParam = URLDecoder.decode(codeParam, "UTF-8");
        }

        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        //TODO CREATE ROLE
        List<Integer> ideaStateFilter = new ArrayList<Integer>();
        ideaStateFilter.add(IIdea.STATUS_APPROVED);

        if (null != user && !this.getAuthorizationManager().isAuthOnPermission(user, Permission.SUPERUSER)) {
            ideaStateFilter.clear();
        }
        IdeaInstance ideaInstance = this.getIdeaInstanceManager().getIdeaInstance(codeParam, ideaStateFilter);
        if (null == ideaInstance) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + codeParam + "' does not exist", Response.Status.CONFLICT);
        }
        if (!isAuthOnInstance(user, ideaInstance)) {
            _logger.warn("the current user is not granted to any group required by instance {}", codeParam);
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + codeParam + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbIdeaInstance = new JAXBIdeaInstance(ideaInstance);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting ideaInstance", t);
        throw new ApsSystemException("Error extracting idea instance", t);
    }
    return jaxbIdeaInstance;
}
 
Example 11
/**
 * Gets whether socket keepAlive is enabled, by consulting the
 * PerformanceTuningSettings.  (If no setting specified, defaults
 * to true.)
 * @return if socketKeepAlive is enabled
 */
protected boolean isSocketKeepAliveEnabled() {
  if (mOwner instanceof AnalysisEngine) {
    Properties settings = ((AnalysisEngine)mOwner).getPerformanceTuningSettings();
    if (settings != null) {
      String enabledStr = (String)settings.get(UIMAFramework.SOCKET_KEEPALIVE_ENABLED);
      return !"false".equalsIgnoreCase(enabledStr);
    }
  }
  return true;
}
 
Example 12
/**
 * creates a new AbstractDatabaseAdapter
 *
 * @param connInfo parameters specifying the
 * @throws DatabaseConnectionException if the connection cannot be established.
 */
public AbstractDatabaseAdapter(Properties connInfo) throws DatabaseConnectionException {
	try {
		this.connection = createConnection(connInfo);
	} catch (SQLException e) {
		throw new DatabaseConnectionException("Unable to create a connection to: "
				+ connInfo.get("jdbc_url"), e);
	}

	this.statements = new LinkedList<Statement>();
	this.resultSets = new LinkedList<ResultSet>();
}
 
Example 13
Source Project: das   File: DasClientVersion.java    License: Apache License 2.0 5 votes vote down vote up
private static String initVersion() {
    String path = "/version.prop";
    InputStream stream = DasClientVersion.class.getResourceAsStream(path);
    if (stream == null) {
        return "UNKNOWN";
    }
    Properties props = new Properties();
    try {
        props.load(stream);
        stream.close();
        return (String) props.get("version");
    } catch (IOException e) {
        return "UNKNOWN";
    }
}
 
Example 14
Source Project: datafu   File: ContextualEvalFunc.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to return the context properties for this instance of this class
 * 
 * @return instances properties
 */
protected Properties getInstanceProperties() {
  Properties contextProperties = getContextProperties();
  if (!contextProperties.containsKey(getInstanceName())) {
    contextProperties.put(getInstanceName(), new Properties());
  }
  return (Properties)contextProperties.get(getInstanceName());
}
 
Example 15
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example 16
Source Project: fabric-sdk-java   File: Orderer.java    License: Apache License 2.0 5 votes vote down vote up
String getEndpoint() {
    if (null == endPoint) {
        Properties properties = parseGrpcUrl(url);
        endPoint = properties.get("host") + ":" + properties.getProperty("port").toLowerCase().trim();
    }
    return endPoint;
}
 
Example 17
Source Project: deltaspike   File: DefaultCipherService.java    License: Apache License 2.0 5 votes vote down vote up
protected String getMasterKey(String masterSalt)
{
    File masterFile = getMasterFile();
    if (!masterFile.exists())
    {
        throw new IllegalStateException("Could not find master.hash file. Create a master password first!");
    }

    try
    {
        String saltHash = byteToHex(secureHash(masterSalt));
        String saltKey = byteToHex(secureHash(saltHash));

        Properties keys = loadProperties(masterFile.toURI().toURL());

        String encryptedMasterKey = (String) keys.get(saltKey);
        if (encryptedMasterKey == null)
        {
            throw new IllegalStateException("Could not find master key for hash " + saltKey +
                ". Create a master password first!");
        }

        return aesDecrypt(hexToByte(encryptedMasterKey), saltHash);
    }
    catch (MalformedURLException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 18
public static Object getPropertyValue(Properties p, String key) {
    return p.get(key);
}
 
Example 19
Source Project: XBatis-Code-Generator   File: Settings.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 初始化系统参数
 *
 * @return
 */
public boolean initSystemParam() {
	boolean blnRet = true;
	
	String daopath = "dao/";
	String path = ClassLoader.getSystemResource(daopath).getPath();
	logger.info("开始初始化数据库环境,路径为【" + path + "】");
	//加载DB属性文件
	List<String> files = FileUtil.getFileListWithExt(path, ".properties");
	String propertiesFilename = null;
	if(files!=null&&files.size()==1){
		propertiesFilename = files.get(0);
		logger.info("找到DB属性配置文件,文件名为【" + path + propertiesFilename + "】");
	}
	if(propertiesFilename==null){
		logger.error("OUT---[false]DB属性配置文件在["+path+"]找不到!");
		return false;
	}
	//解析属性文件
	Properties prop = PropertiesUtil.getPropertiesByResourceBundle(daopath + FileUtil.getFilenameWithoutExt(propertiesFilename));
	if (prop == null) {
		logger.error("OUT---[false]属性配置文件内容解析为空!");
		return false;
	}
	
	//设置DB类型及数据库连接信息
	String type = (String) prop.get("DB_TYPE");
	if("Mysql".equals(type)){
		dbType = Settings.DB_TYPE_MYSQL;
	}else{
		logger.error("OUT---[false]属性配置文件指定的DB_TYPE不存在!type:" + type);
		blnRet = false;
	}
	url = (String) prop.get("DB_SERVER");
	port = (String) prop.get("DB_PORT");
	dbName = (String) prop.get("DB_NAME");
	dbUser = (String) prop.get("DB_USER");
	dbPwd = (String) prop.get("DB_PWD");
	//设置生成指定表、使用模版、Java包路径、代码输出路径
	String tablestr = (String) prop.get("DB_TABLES");
	if(tablestr!=null){
		String[] ts = tablestr.split(",");
		for(int i=0;i<ts.length;i++){
			tables.add(ts[i]);
		}
		logger.info("指定生成表:" + tables.toString());
	}
	javaPackage = (String) prop.get("JAVA_PACKAGE");
	String tmpl = (String) prop.get("USE_TMPL");
	if(StringUtils.isBlank(tmpl)){
		tmplPath = daopath + "ibatisdao";
		logger.warn("DAO模版未指定,使用默认模版:" + tmplPath);
	}else{
		tmplPath = daopath + tmpl;
		logger.info("使用模版:" + tmplPath);
	}
	String gendir = (String) prop.get("GEN_PATH");
	if(StringUtils.isBlank(gendir)){
		genPath = System.getProperty("user.dir") + "/gendir/";
		logger.warn("代码生成输出路径未指定,使用默认路径:" + genPath);
	}else{
		File f = new File(gendir);
		if(!f.exists()||!f.isDirectory()){
			genPath = System.getProperty("user.dir") + "/gendir/";
			logger.warn("指定的代码生成输出路径不存在,使用默认路径:" + genPath);
		}else{
			genPath = gendir;
			logger.info("使用指定的代码生成输出路径:" + genPath);
		}
	}
	
	//打印数据库DAO代码生成环境配置信息
	Iterator<Entry<Object,Object>> it = prop.entrySet().iterator();
	logger.info("数据库DAO代码生成环境配置信息如下:");
	while (it.hasNext()) {
		Entry<Object, Object> en = it.next();
		logger.info(en.getKey() + "=" + en.getValue());
	}
	logger.info("结束初始化数据库DAO代码生成环境【" + path + propertiesFilename + "】!");
	return blnRet;
}
 
Example 20
protected static void
doHTTPProperties(
	Properties			properties )
{
	Boolean	raw = (Boolean)properties.get( ClientIDGenerator.PR_RAW_REQUEST );
	
	if ( raw != null && raw ){
		
		return;
	}
	
	String	version = Constants.AZUREUS_VERSION;
	
		// trim of any _Bnn or _CVS suffix as unfortunately some trackers can't cope with this
		// (well, apparently can't cope with B10)
		// its not a big deal anyway
	
	int	pos = version.indexOf('_');
	
	if ( pos != -1 ){
		
		version = version.substring(0,pos);
	}
	
	String	agent = Constants.AZUREUS_NAME + " " + version;
			
	if ( send_os ){
						
		agent += ";" + Constants.OSName;
	
		agent += ";Java " + Constants.JAVA_VERSION;
	}
	
	properties.put( ClientIDGenerator.PR_USER_AGENT, agent );
}