Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

In this page you can find the example usage for java.util Properties get.

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:com.legstar.coxb.gen.CoxbGenModelTest.java

/**
 * Test the serialization and construction using a properties file.
 * //from  w ww.  ja va  2 s .c o  m
 * @throws Exception if test fails
 */
public void testPropertySerialization() throws Exception {
    CoxbGenModel model = new CoxbGenModel();
    Properties props = model.toProperties();
    assertEquals(null, props.get(JaxbGenModel.JAXB_XSD_LOCATION));
    assertEquals("true", props.get(JaxbGenModel.JAXB_XJB_ISGENERATEISSETMETHOD));
    assertEquals("1", props.get(JaxbGenModel.JAXB_XJB_SERIALIZABLE_ID));
    assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_ELEMENTNAME_PREFIX));
    assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_ELEMENTNAME_SUFFIX));
    assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_TYPENAME_PREFIX));
    assertEquals(null, props.get(JaxbGenModel.JAXB_XJB_TYPENAME_SUFFIX));

    assertEquals(null, props.get(CoxbGenModel.COXB_PACKAGENAME));
    assertEquals(null, props.get(CoxbGenModel.COXB_JAXB_ALTERNATIVEPACKAGENAME));
    assertEquals(null, props.get(CoxbGenModel.COXB_JAXB_ALTERNATIVEFACTORYNAME));
    assertEquals("true", props.get(CoxbGenModel.COXB_ISXMLTRANSFORMERS));
    assertEquals("false", props.get(CoxbGenModel.COXB_ISJSONTRANSFORMERS));
    assertEquals(null, props.get(CoxbGenModel.COXB_XSDFILE));
    assertEquals(null, props.get(CoxbGenModel.COXB_JAXBROOTCLASSNAMES));
    assertEquals(null, props.get(CoxbGenModel.COXB_JAXBSRCDIR));
    assertEquals(null, props.get(CoxbGenModel.COXB_JAXBBINDIR));
    assertEquals(null, props.get(CoxbGenModel.COXB_COXBSRCDIR));
    assertEquals(null, props.get(CoxbGenModel.COXB_COXBBINDIR));
    assertEquals(null, props.get(CoxbGenModel.COXB_UNMARSHAL_CHOICE_STRATEGIES));

    assertEquals("{isCompileTransformers=false," + " isXmlTransformers=true," + " serializableID=1,"
            + " internalBindings=true," + " eciCompatible=false," + " isJsonTransformers=false,"
            + " noPackageInfo=false," + " generateIsSetMethod=true}", model.toString());

    model = new CoxbGenModel(props);
    assertEquals(null, model.getJaxbPackageName());
    JaxbGenModel xjbModel = new JaxbGenModel();
    xjbModel.setXsdLocation("xsdLocation");
    xjbModel.setSerializableUid(265L);
    xjbModel.setGenerateIsSetMethod(false);
    xjbModel.setElementNamePrefix("elementNamePrefix");
    xjbModel.setElementNameSuffix("elementNameSuffix");
    xjbModel.setTypeNamePrefix("typeNamePrefix");
    xjbModel.setTypeNameSuffix("typeNameSuffix");
    props.putAll(xjbModel.toProperties());

    model = new CoxbGenModel(props);
    assertEquals("xsdLocation", model.getJaxbGenModel().getXsdLocation());
    assertEquals(265L, model.getSerializableUid());
    assertEquals(false, model.isGenerateIsSetMethod());
    assertEquals("elementNamePrefix", model.getElementNamePrefix());
    assertEquals("elementNameSuffix", model.getElementNameSuffix());
    assertEquals("typeNamePrefix", model.getTypeNamePrefix());
    assertEquals("typeNameSuffix", model.getTypeNameSuffix());

    props.put(CoxbGenModel.COXB_PACKAGENAME, "coxb.package.name");
    model = new CoxbGenModel(props);
    assertEquals("coxb.package.name", model.getCoxbPackageName());

    props.put(CoxbGenModel.COXB_JAXB_ALTERNATIVEPACKAGENAME, "jaxb.alt.package.name");
    props.put(CoxbGenModel.COXB_JAXB_ALTERNATIVEFACTORYNAME, "jaxb.alt.package.name.AltFactory");
    model = new CoxbGenModel(props);
    assertEquals("jaxb.alt.package.name", model.getAlternativePackageName());
    assertEquals("jaxb.alt.package.name.AltFactory", model.getAlternativeFactoryName());

    props.put(CoxbGenModel.COXB_ISXMLTRANSFORMERS, "true");
    props.put(CoxbGenModel.COXB_ISJSONTRANSFORMERS, "true");
    model = new CoxbGenModel(props);
    assertTrue(model.isXmlTransformers());
    assertTrue(model.isJsonTransformers());

    props.put(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_0", "FirstClass");
    props.put(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_1", "SecondClass");
    model = new CoxbGenModel(props);
    assertEquals("[FirstClass, SecondClass]", model.getJaxbRootClassNames().toString());

    props.put(CoxbGenModel.COXB_XSDFILE, "xsdfile");
    props.put(CoxbGenModel.COXB_JAXBSRCDIR, "jaxbsrcdir");
    props.put(CoxbGenModel.COXB_JAXBBINDIR, "jaxbbindir");
    props.put(CoxbGenModel.COXB_COXBSRCDIR, "coxbsrcdir");
    props.put(CoxbGenModel.COXB_COXBBINDIR, "coxbbindir");
    model = new CoxbGenModel(props);
    assertEquals("xsdfile", model.getXsdFile().getPath());
    assertEquals("jaxbsrcdir", model.getJaxbSrcDir().getPath());
    assertEquals("jaxbbindir", model.getJaxbBinDir().getPath());
    assertEquals("coxbsrcdir", model.getCoxbSrcDir().getPath());
    assertEquals("coxbbindir", model.getCoxbBinDir().getPath());
    props.put(CoxbGenModel.COXB_UNMARSHAL_CHOICE_STRATEGIES + "_0", "ITEMA:some.Strategy");
    model = new CoxbGenModel(props);
    assertEquals("ITEMA:some.Strategy", model.getUnmarshalChoiceStrategies().get(0).toString());

    props = model.toProperties();
    assertEquals("coxb.package.name", props.getProperty(CoxbGenModel.COXB_PACKAGENAME));
    assertEquals("jaxb.alt.package.name", props.getProperty(CoxbGenModel.COXB_JAXB_ALTERNATIVEPACKAGENAME));
    assertEquals("jaxb.alt.package.name.AltFactory",
            props.getProperty(CoxbGenModel.COXB_JAXB_ALTERNATIVEFACTORYNAME));
    assertEquals("true", props.getProperty(CoxbGenModel.COXB_ISXMLTRANSFORMERS));
    assertEquals("true", props.getProperty(CoxbGenModel.COXB_ISJSONTRANSFORMERS));
    assertEquals((new File("xsdfile")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_XSDFILE));
    assertEquals("FirstClass", props.getProperty(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_0"));
    assertEquals("SecondClass", props.getProperty(CoxbGenModel.COXB_JAXBROOTCLASSNAMES + "_1"));
    assertEquals((new File("jaxbsrcdir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_JAXBSRCDIR));
    assertEquals((new File("jaxbbindir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_JAXBBINDIR));
    assertEquals((new File("coxbsrcdir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_COXBSRCDIR));
    assertEquals((new File("coxbbindir")).getCanonicalPath(), props.getProperty(CoxbGenModel.COXB_COXBBINDIR));

    assertEquals("xsdLocation", props.getProperty(JaxbGenModel.JAXB_XSD_LOCATION));
    assertEquals("false", props.getProperty(JaxbGenModel.JAXB_XJB_ISGENERATEISSETMETHOD));
    assertEquals("265", props.getProperty(JaxbGenModel.JAXB_XJB_SERIALIZABLE_ID));
    assertEquals("elementNamePrefix", props.getProperty(JaxbGenModel.JAXB_XJB_ELEMENTNAME_PREFIX));
    assertEquals("elementNameSuffix", props.getProperty(JaxbGenModel.JAXB_XJB_ELEMENTNAME_SUFFIX));
    assertEquals("typeNamePrefix", props.getProperty(JaxbGenModel.JAXB_XJB_TYPENAME_PREFIX));
    assertEquals("typeNameSuffix", props.getProperty(JaxbGenModel.JAXB_XJB_TYPENAME_SUFFIX));

    assertEquals("ITEMA:some.Strategy",
            props.getProperty(CoxbGenModel.COXB_UNMARSHAL_CHOICE_STRATEGIES + "_0"));
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.BuildReportRenderer.java

/**
 * Renders a single cell of the table./* w  w w.  j a  v  a 2s .  c  om*/
 *
 * @param buildMetaDataProperties build meta data properties to access the
 *          data to be rendered.
 * @param key the key to the data to be rendered.
 */
private void renderCell(final Properties buildMetaDataProperties, final String key) {
    final Object value = buildMetaDataProperties.get(key);
    if (value != null) {
        sink.tableRow();
        sink.tableCell();
        sink.text(getLabel(key));
        sink.tableCell_();
        sink.tableCell();
        if (Constant.PROP_NAME_MAVEN_ACTIVE_PROFILES.equals(key)) {
            renderMultiTupleValue(buildMetaDataProperties, value, Constant.MAVEN_ACTIVE_PROFILE_PREFIX);
        } else if (Constant.PROP_NAME_SCM_LOCALLY_MODIFIED_FILES.equals(key)) {
            final String filesValue = Constant.prettifyFilesValue(value);
            renderMultiValue(filesValue, NoopNormalizer.INSTANCE);
        } else if (Constant.PROP_NAME_MAVEN_GOALS.equals(key)) {
            renderMultiValue(value, NoopNormalizer.INSTANCE);
        } else if (Constant.PROP_NAME_MAVEN_FILTERS.equals(key)) {
            renderMultiValue(value, filePathNormalizer);
        } else {
            renderSingleValue(value);
        }
        sink.tableCell_();
        sink.tableRow_();
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.util.ProviderProperties.java

/**
 * Merge properties with existing properties.
 *
 * @param p New properties/*from  ww w .ja va 2  s  . c om*/
 */
public void mergeProperties(Properties p) {
    //todo: consider refactoring to AbstractProperties
    Set<Object> keys = p.keySet();
    Iterator<Object> i = keys.iterator();
    Object key;

    while (i.hasNext()) {
        key = i.next();
        String value = (String) p.get(key);
        if (key != null && value != null) {
            this.props.put(key, value);
        }
    }
}

From source file:edu.vt.middleware.ldap.props.AbstractPropertyConfig.java

/** {@inheritDoc} */
public void setEnvironmentProperties(final Properties properties) {
    if (properties != null) {
        final Map<String, String> props = new HashMap<String, String>();
        final Enumeration<?> en = properties.keys();
        if (en != null) {
            while (en.hasMoreElements()) {
                final String name = (String) en.nextElement();
                final String value = (String) properties.get(name);
                if (this.hasEnvironmentProperty(name)) {
                    props.put(name, value);
                } else {
                    this.setEnvironmentProperties(name, value);
                }//from   w w  w  .  jav  a  2  s .c om
            }
            for (Map.Entry<String, String> e : props.entrySet()) {
                this.setEnvironmentProperties(e.getKey(), e.getValue());
            }
        }
    }
}

From source file:org.solmix.runtime.cm.support.SpringConfigureUnitManager.java

private Dictionary<String, ?> toDictionary(Properties properties) {
    Dictionary<String, Object> dic = new Hashtable<String, Object>();
    if (properties != null) {
        Enumeration<Object> en = properties.keys();
        while (en.hasMoreElements()) {
            Object key = en.nextElement();
            dic.put(key.toString(), properties.get(key));
        }/*from w  w  w . j av  a2s .com*/
    }
    return dic;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.source.MassMavenizerMojo.java

/**
 * /*  w w w .j  av a2 s  .  c o m*/
 * @param configuration, a list of "-D" properties
 * @return the configuration as a List<Element> used by MojoExecutor
 */
private List<Element> generateConfiguration(Properties configuration) {
    List<Element> configurations = new ArrayList<Element>();

    if (configuration != null) {
        for (Object key : configuration.keySet()) {
            String value = configuration.get(key).toString();
            getLog().debug(value);
            configurations.add(element(key.toString(), value));
        }
    }

    return configurations;
}

From source file:com.urbancode.terraform.main.Main.java

private Credentials parseCredentials(File credsFile) {
    Credentials result = null;//from www  .  j a v a  2 s. c om

    Properties credProps = loadPropertiesFromFile(credsFile);

    for (Property cmdlineProp : props) {
        if (credProps.get(cmdlineProp.getName()) == null) {
            credProps.put(cmdlineProp.getName(), cmdlineProp.getValue());
        }
    }

    result = parseCredsFromProps(credProps);

    if (result != null) {
        log.info("Restored Credentials: " + credsFile + " : " + result.getName());
    } else {
        log.info("Did not restore Credentials for " + credsFile);
    }

    return result;
}

From source file:ca.weblite.contacts.webservice.RESTServiceConfiguration.java

private static void loadRuntimeSettings() {
    Properties p = new Properties();
    Map props = new HashMap();
    try {//w  ww.  j  a v a2s. co  m
        InputStream in = RESTServiceConfiguration.class.getResourceAsStream("/runtime.properties");
        if (in != null) {
            try {
                p.load(in);
                props.putAll(p);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Throwable t) {
                    }
                }
            }
        }
        in = RESTServiceConfiguration.class.getResourceAsStream("/runtime.override.properties");
        if (in != null) {
            try {
                p.load(in);
                props.putAll(p);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Throwable t) {
                    }
                }
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    System.out.println("In LoadRuntimeSettings");
    System.out.println(p);
    if (p.containsKey("DB_URL")) {
        DB_URL = (String) p.get("DB_URL");
        DB_PASSWORD = (String) p.get("DB_PASSWORD");
        DB_USERNAME = (String) p.get("DB_USERNAME");
    }
    if (p.containsKey("GCM_SERVER_API_KEY")) {
        GCM_SERVER_API_KEY = (String) p.get("GCM_SERVER_API_KEY");
    }
    if (p.containsKey("PUSH_TOKEN")) {
        PUSH_TOKEN = (String) p.get("PUSH_TOKEN");
    }
    if (p.containsKey("IOS_PUSH_CERT_URL")) {
        IOS_PUSH_CERT_URL = (String) p.getProperty("IOS_PUSH_CERT_URL");
    }
    if (p.containsKey("IOS_PUSH_CERT_PASSWORD")) {
        IOS_PUSH_CERT_PASSWORD = (String) p.getProperty("IOS_PUSH_CERT_PASSWORD");
    }

}

From source file:com.bluexml.side.Framework.alfresco.signature.integration.SignatureHelper.java

private Map<String, Serializable> initParams(Properties props, NodeRef key, ArrayList<String> myException) {
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("exception", myException);
    params.put("private-key", key);
    params.put("key-type", (Serializable) props.get("Service.signature.key.type"));
    params.put("key-password", (Serializable) props.get("Service.signature.key.password"));
    params.put("store-password", (Serializable) props.get("Service.signature.keystore.password"));
    params.put("alias", (Serializable) props.get("Service.signature.key.alias"));
    params.put("visibility", (Serializable) props.get("Service.signature.visibility"));
    params.put("location-x", (Serializable) props.get("Service.signature.position.x"));
    params.put("location-y", (Serializable) props.get("Service.signature.position.y"));
    params.put("height", (Serializable) props.get("Service.signature.heigth"));
    params.put("width", (Serializable) props.get("Service.signature.width"));
    params.put("reason", (Serializable) props.get("Service.signature.location"));
    params.put("location", (Serializable) props.get("Service.signature.location"));
    params.put("signed-name", (Serializable) props.get("Service.signature.signed.file.name"));
    return params;
}

From source file:com.nokia.carbide.installpackages.InstallPackages.java

private String getMasterFilePath() {
    if (serverPath != null)
        return serverPath;
    Location installLocation = Platform.getInstallLocation();
    URL url = installLocation.getURL();
    IPath path = new Path(url.getPath());
    path = path.append("configuration/server.properties"); //$NON-NLS-1$
    try {// ww w. j ava  2  s  .co  m
        File file = path.toFile();
        InputStream is = new FileInputStream(file);
        Properties properties = new Properties();
        properties.load(is);
        is.close();
        String key = service.getIdentifier();
        String pathStr = (String) properties.get(key);
        if (pathStr != null)
            return serverPath = pathStr;
    } catch (IOException e) {
        RemoteConnectionsActivator.logError(e);
    }
    return ""; //$NON-NLS-1$
}