List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:Main.java
/** * Merge the given Properties instance into the given Map, copying all properties (key-value pairs) over. * <p>/* www. j a v a 2 s.c o m*/ * 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", "rawtypes" }) public static void mergePropertiesIntoMap(Properties props, Map map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } if (props != null) { for (final Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) { final 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); } } }
From source file:com.flozano.socialauth.AuthProviderFactory.java
/** * /* w ww . j a v a2 s . c o m*/ * @param id * the id of requested provider. It can be facebook, foursquare, * google, hotmail, linkedin,myspace, twitter, yahoo. * @param properties * properties containing key/secret for different providers and * information of custom provider. * @return AuthProvider the instance of requested provider based on given * id. If id is a URL it returns the OpenId provider. * @throws Exception */ public static AuthProvider getInstance(final String id, final Properties properties) throws Exception { for (Object key : properties.keySet()) { String str = key.toString(); if (str.startsWith("socialauth.")) { String val = str.substring("socialauth.".length()); registerProvider(val, Class.forName(properties.get(str).toString())); } } return loadProvider(id, properties); }
From source file:com.pactera.edg.am.metamanager.extractor.util.Utils.java
public static String transformName(String name) { try {//ww w. java2s.c o m Properties properties = TransformConfLoader.getProperties(); StringBuffer sb = new StringBuffer(); for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements();) { // ????? Object expression = enumer.nextElement(); Pattern regex = Pattern.compile((String) expression); Matcher regexMatcher = regex.matcher(name); // ????? String targetExpression = (String) properties.get(expression); if (regexMatcher.find()) { // ???? regexMatcher.appendReplacement(sb, targetExpression); // ? if (log.isDebugEnabled()) { log.debug(new StringBuilder("????:").append(name).append(" ????:") .append(sb).toString()); } return sb.toString(); } } } catch (Exception e) { log.warn("????!????:" + name, e); } return name; }
From source file:com.aimdek.ccm.util.CommonUtil.java
/** * Gets the property value.//from w w w. j a v a 2s . c om * * @param fileName * the file name * @param propertyName * the property name * @return the property value */ public static String getPropertyValue(String fileName, String propertyName) { Properties properties = new Properties(); InputStream inputStream = null; String value = BLANK; try { inputStream = new FileInputStream(fileName); properties.load(inputStream); value = (String) properties.get(propertyName); } catch (FileNotFoundException e) { LOGGER.error("Property file not found", e); } catch (IOException e) { LOGGER.error(e); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException e) { LOGGER.error("Error while closing FileInputstream", e); } } return value; }
From source file:edu.sampleu.common.FreemarkerUtil.java
/** * Loads properties from user defined properties file, if not available uses resource file * * writes processed template to file//from w w w.j ava 2 s.c o m * @param key * @param output * @param template * @throws IOException * @throws TemplateException */ public static File ftlWrite(String key, File output, Template template, InputStream inputStream) throws IOException, TemplateException { PropertiesUtils propUtils = new PropertiesUtils(); Properties props = propUtils.loadProperties(inputStream); props.put("baseName", output.getName().substring(0, output.getName().indexOf("ST"))); props.put("className", output.getName().substring(0, output.getName().indexOf("ST"))); // backwards compatibility if (output.getName().contains("TmplMthd")) { // Template method pattern props.put("className", output.getName().substring(0, output.getName().indexOf("TmplMthd"))); } if (props.get("test1") == null) { // backwards compatibility for Smoke Test Freemarker Generation props.put("test1", "test" + props.get("className") + "Bookmark"); props.put("test2", "test" + props.get("className") + "Nav"); } props = propUtils.systemPropertiesOverride(props, key); props = propUtils.transformNumberedPropertiesToList(props); File outputFile = writeTemplateToFile(output, template, props); return outputFile; }
From source file:Main.java
/** * Convert Properties to string//ww w .j a v a2 s . co m * * @param props * @return xml string * @throws IOException */ public static String writePropToString(Properties props) throws IOException { try { org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); org.w3c.dom.Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); for (Enumeration e = props.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object object = props.get(name); String value; if (object instanceof String) { value = (String) object; } else { continue; } org.w3c.dom.Element propNode = doc.createElement("property"); conf.appendChild(propNode); org.w3c.dom.Element nameNode = doc.createElement("name"); nameNode.appendChild(doc.createTextNode(name.trim())); propNode.appendChild(nameNode); org.w3c.dom.Element valueNode = doc.createElement("value"); valueNode.appendChild(doc.createTextNode(value.trim())); propNode.appendChild(valueNode); conf.appendChild(doc.createTextNode("\n")); } Source source = new DOMSource(doc); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (Exception e) { throw new IOException(e); } }
From source file:com.griddynamics.jagger.JaggerLauncher.java
public static void loadBootProperties(URL directory, String environmentPropertiesLocation, Properties environmentProperties) throws IOException { URL bootPropertiesFile = new URL(directory, environmentPropertiesLocation); System.setProperty(ENVIRONMENT_PROPERTIES, environmentPropertiesLocation); environmentProperties.load(bootPropertiesFile.openStream()); String defaultBootPropertiesLocation = environmentProperties.getProperty(DEFAULT_ENVIRONMENT_PROPERTIES); if (defaultBootPropertiesLocation == null) { defaultBootPropertiesLocation = DEFAULT_ENVIRONMENT_PROPERTIES_LOCATION; }/*from w ww . j av a 2 s . c o m*/ URL defaultBootPropertiesFile = new URL(directory, defaultBootPropertiesLocation); Properties defaultBootProperties = new Properties(); defaultBootProperties.load(defaultBootPropertiesFile.openStream()); for (String name : defaultBootProperties.stringPropertyNames()) { if (!environmentProperties.containsKey(name)) { environmentProperties.setProperty(name, defaultBootProperties.getProperty(name)); } } Properties properties = System.getProperties(); for (Enumeration<String> enumeration = (Enumeration<String>) properties.propertyNames(); enumeration .hasMoreElements();) { String key = enumeration.nextElement(); environmentProperties.put(key, properties.get(key)); } System.setProperty(ENVIRONMENT_PROPERTIES, environmentPropertiesLocation); System.setProperty(DEFAULT_ENVIRONMENT_PROPERTIES, defaultBootPropertiesLocation); }
From source file:com.sap.dirigible.ide.workspace.wizard.project.create.ProjectTemplateType.java
public static ProjectTemplateType createTemplateType(IRepository repository, String location) throws IOException { ICollection projectTemplateRoot = repository.getCollection(location); if (!projectTemplateRoot.exists()) { throw new IOException(String.format(PROJECT_TEMPLATE_LOCATION_S_IS_NOT_VALID, location)); }/*from w w w. j av a 2 s . c om*/ IResource projectMetadataResource = projectTemplateRoot.getResource("project.properties"); //$NON-NLS-1$ if (!projectMetadataResource.exists()) { throw new IOException(String.format(PROJECT_TEMPLATE_METADATA_DOES_NOT_EXIST_AT_S, location)); } Properties projectMetadata = new Properties(); ByteArrayInputStream byteArrayInputStream = null; try { byteArrayInputStream = new ByteArrayInputStream(projectMetadataResource.getContent()); projectMetadata.load(byteArrayInputStream); String name = (String) projectMetadata.get(PARAM_NAME); //$NON-NLS-1$ String description = (String) projectMetadata.get(PARAM_DESCRIPTION); //$NON-NLS-1$ String imageName = (String) projectMetadata.get(PARAM_IMAGE); //$NON-NLS-1$ String imagePreviewName = (String) projectMetadata.get(PARAM_IMAGE_PREVIEW); //$NON-NLS-1$ String contentName = (String) projectMetadata.get(PARAM_CONTENT); //$NON-NLS-1$ Image image = createImageFromResource(projectTemplateRoot, imageName); Image imagePreview = createImageFromResource(projectTemplateRoot, imagePreviewName); IResource contentResource = projectTemplateRoot.getResource(contentName); if (!contentResource.exists()) { throw new IOException(String.format(PROJECT_TEMPLATE_CONTENT_DOES_NOT_EXIST_AT_S, contentName)); } ProjectTemplateType templateType = new ProjectTemplateType(name, description, location, image, imagePreview, contentResource.getPath(), "template"); return templateType; } finally { if (byteArrayInputStream != null) { byteArrayInputStream.close(); } } }
From source file:edu.samplu.common.FreemarkerUtil.java
/** * Loads properties from user defined properties file, if not available uses resource file * * writes processed template to file/*from w ww. j av a 2 s . c o m*/ * @param key * @param output * @param template * @throws IOException * @throws TemplateException */ public static File ftlWrite(String key, File output, Template template, InputStream inputStream) throws IOException, TemplateException { Properties props = PropertiesUtils.loadProperties(inputStream); props.put("baseName", output.getName().substring(0, output.getName().indexOf("ST"))); props.put("className", output.getName().substring(0, output.getName().indexOf("ST"))); // backwards compatibility if (output.getName().contains("TmplMthd")) { // Template method pattern props.put("className", output.getName().substring(0, output.getName().indexOf("TmplMthd"))); } if (props.get("test1") == null) { // backwards compatibility for Smoke Test Freemarker Generation props.put("test1", "test" + props.get("className") + "Bookmark"); props.put("test2", "test" + props.get("className") + "Nav"); } PropertiesUtils.systemPropertiesOverride(props, key); PropertiesUtils.transformNumberedPropertiesToList(props); File outputFile = writeTemplateToFile(output, template, props); return outputFile; }
From source file:de.hypoport.ep2.support.configuration.properties.PropertiesLoader.java
private static String replacePropertyPlaceHolder(String value, Properties properties) { while (value.contains("${")) { int start = value.indexOf("${"); int end = value.indexOf("}"); if (start < end) { String propertyPlaceHolder = value.substring(start, end + 1); String propertyName = propertyPlaceHolder.substring(2, propertyPlaceHolder.length() - 1); Object propertyValue = properties.get(propertyName); if (propertyValue == null) { propertyValue = ""; }/*from w w w .ja v a 2 s . c om*/ value = value.replace(propertyPlaceHolder, (String) propertyValue); } else { value = value.replace("${", ""); LOG.warn("Cannot resolve all properties in " + value); } } return value; }