Example usage for java.util Properties entrySet

List of usage examples for java.util Properties entrySet

Introduction

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

Prototype

@Override
    public Set<Map.Entry<Object, Object>> entrySet() 

Source Link

Usage

From source file:any.Linker.java

/** 
 * initialise with properties/*from   ww w.ja  v a2s . co m*/
 * 
 * @param properties
 */
public Linker(Properties properties) {
    this.properties = properties;

    final LoopConnection loop = new LoopConnection(this);
    //      namedCon.put("host", loop);
    namedCon.put("loop", loop); // FIXME

    // setup services from properties file
    ClassLoader cl;
    cl = Linker.class.getClassLoader();
    try {

        for (Map.Entry<Object, Object> p : properties.entrySet()) {

            String key = p.getKey().toString();

            if (key.startsWith("serve.")) {

                String name = key.substring(6);
                String classstr = p.getValue().toString();

                if (logger.isDebugEnabled())
                    logger.debug("setup servable with name: " + name + " and " + classstr);

                Servable s = (Servable) cl.loadClass(classstr).newInstance();
                servableMap.put(name, s);
                s.init(properties, loop.getOutQueue(), this);
            }
        }

    } catch (InstantiationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ClassNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    ConfigServable configServable = new ConfigServable();
    servableMap.put("config", configServable);
    configServable.init(properties, null, null);

}

From source file:net.minecraftforge.fml.common.FMLCommonHandler.java

/**
 * Loads a lang file, first searching for a marker to enable the 'extended' format {escape charaters}
 * If the marker is not found it simply returns and let the vanilla code load things.
 * The Marker is 'PARSE_ESCAPES' by itself on a line starting with '#' as such:
 * #PARSE_ESCAPES/*  w ww  .  j  av a 2 s  .com*/
 *
 * @param table The Map to load each key/value pair into.
 * @param inputstream Input stream containing the lang file.
 * @return A new InputStream that vanilla uses to load normal Lang files, Null if this is a 'enhanced' file and loading is done.
 */
public InputStream loadLanguage(Map<String, String> table, InputStream inputstream) throws IOException {
    byte[] data = IOUtils.toByteArray(inputstream);

    boolean isEnhanced = false;
    for (String line : IOUtils.readLines(new ByteArrayInputStream(data), Charsets.UTF_8)) {
        if (!line.isEmpty() && line.charAt(0) == '#') {
            line = line.substring(1).trim();
            if (line.equals("PARSE_ESCAPES")) {
                isEnhanced = true;
                break;
            }
        }
    }

    if (!isEnhanced)
        return new ByteArrayInputStream(data);

    Properties props = new Properties();
    props.load(new InputStreamReader(new ByteArrayInputStream(data), Charsets.UTF_8));
    for (Entry e : props.entrySet()) {
        table.put((String) e.getKey(), (String) e.getValue());
    }
    props.clear();
    return null;
}

From source file:org.apache.ode.utils.HierarchicalProperties.java

private void processProperties(Properties props, File file) throws IOException {

    validatePropertyNames(props, file);//  w  w  w . jav  a 2 s. c o  m

    Map<String, String> nsByAlias = collectAliases(props, file);

    // #4. process each property

    for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
        Map.Entry e = (Map.Entry) it.next();
        String key = (String) e.getKey();
        String value = (String) e.getValue();

        // parse the property name
        String[] info = parseProperty(key);
        String nsalias = info[0];
        String service = info[1];
        String port = info[2];
        String targetedProperty = info[3];

        QName qname = null;
        if (nsalias != null) {
            qname = new QName(nsByAlias.get(nsalias) != null ? nsByAlias.get(nsalias) : nsalias, service);
        }
        // get the map associated to this port
        ChainedMap p = (ChainedMap) hierarchicalMap.get(qname, port);
        if (p == null) {
            // create it if necessary
            // get the associated service map
            ChainedMap s = (ChainedMap) hierarchicalMap.get(qname, null);
            if (s == null) {
                // create the service map if necessary, the parent is the root map.
                s = new ChainedMap(getRootMap());
                // put it in the multi-map
                hierarchicalMap.put(qname, null, s);
            }

            // create the map itself and link it to the service map
            p = new ChainedMap(s);
            // put it in the multi-map
            hierarchicalMap.put(qname, port, p);
        }

        if (targetedProperty.endsWith(".file") || targetedProperty.endsWith(".path")) {
            String absolutePath = file.toURI().resolve(value).getPath();
            if (log.isDebugEnabled())
                log.debug("path: " + value + " resolved into: " + absolutePath);
            value = absolutePath;
        }

        // save the key/value in its chained map
        if (log.isDebugEnabled())
            log.debug("New property: " + targetedProperty + " -> " + value);
        p.put(targetedProperty, value);
    }
}

From source file:com.haulmont.cuba.gui.theme.ThemeConstantsRepository.java

public void loadThemeProperties(String fileName, Map<String, String> themeMap) {
    InputStream propertiesStream = null;
    try {/*from   w  w w  .ja v  a 2 s.  c o  m*/
        propertiesStream = resources.getResourceAsStream(fileName);
        if (propertiesStream == null) {
            throw new DevelopmentException("Unable to load theme constants for: '" + fileName + "'");
        }

        InputStreamReader propertiesReader = new InputStreamReader(propertiesStream, StandardCharsets.UTF_8);

        Properties properties = new Properties();
        try {
            properties.load(propertiesReader);
        } catch (IOException e) {
            throw new DevelopmentException("Unable to parse theme constants for: '" + fileName + "'");
        }

        Object includeValue = properties.get("@include");
        if (includeValue != null) {
            String[] themeIncludes = StringUtils.split(includeValue.toString(), " ,");

            for (String include : themeIncludes) {
                loadThemeProperties(include, themeMap);
            }
        }

        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            Object key = entry.getKey();
            Object value = entry.getValue();

            if (key != null && !"@include".equals(key) && value != null) {
                themeMap.put(key.toString(), value.toString());
            }
        }
    } finally {
        IOUtils.closeQuietly(propertiesStream);
    }
}

From source file:py.una.pol.karaku.configuration.PropertiesUtil.java

/**
 * Dado un nombre de archivo lo carga a las propiedades, si no es un path
 * del classpath, lo carga del sistema operativo.
 * /*  www . j  av a2  s  .  c  o  m*/
 * @param properties
 *            al que se le aadiran propiedades
 */
protected Properties mergeProperties(Properties main) {

    String filePath = main.getProperty(ANOTHER_KEY, "config.properties");
    Properties properties = new Properties();
    try {
        if (filePath.startsWith("/")) {
            FileInputStream fis = new FileInputStream(filePath);
            properties.load(fis);
            fis.close();
        } else {
            properties.load(new ClassPathResource(filePath).getInputStream());
        }
    } catch (FileNotFoundException e) {
        throw new KarakuWrongConfigurationFileException(filePath, e);
    } catch (IOException e) {
        throw new KarakuWrongConfigurationFileException(filePath, e);
    }

    for (Entry<Object, Object> entry : properties.entrySet()) {
        Object value = entry.getValue();
        value = ((String) value).trim();
        main.put(entry.getKey(), value);
    }
    return main;
}

From source file:net.hasor.maven.ExecMojo.java

private Map<String, String> handleSystemEnvVariables() throws MojoExecutionException {
    validateEnvironmentVars();/*from  w  w w.j a v  a2  s .  c o  m*/
    Map<String, String> enviro = new HashMap<String, String>();
    try {
        Properties systemEnvVars = CommandLineUtils.getSystemEnvVars();
        for (Map.Entry<?, ?> entry : systemEnvVars.entrySet()) {
            enviro.put((String) entry.getKey(), (String) entry.getValue());
        }
    } catch (IOException x) {
        getLog().error("Could not assign default system enviroment variables.", x);
    }
    if (environmentVariables != null) {
        enviro.putAll(environmentVariables);
    }
    if (this.environmentScript != null) {
        getLog().info("Pick up external environment script: " + this.environmentScript);
        Map<String, String> envVarsFromScript = this.createEnvs(this.environmentScript);
        if (envVarsFromScript != null) {
            enviro.putAll(envVarsFromScript);
        }
    }
    if (this.getLog().isDebugEnabled()) {
        Set<String> keys = new TreeSet<String>();
        keys.addAll(enviro.keySet());
        for (String key : keys) {
            this.getLog().debug("env: " + key + "=" + enviro.get(key));
        }
    }
    return enviro;
}

From source file:ar.edu.taco.TacoConfigurator.java

public TacoConfigurator(String configurationFile, Properties overridingProperties) {
    super();/*from  w ww  .  ja  v a  2s.  c  o m*/
    try {
        super.load(configurationFile);
        for (Entry<Object, Object> entry : overridingProperties.entrySet()) {
            this.setProperty((String) entry.getKey(), entry.getValue());
        }
        TacoCustomScope tacoScope = buildTacoScope();
        this.tacoScope = tacoScope;
        instance = this;
    } catch (ConfigurationException e) {
        throw new TacoException(e);
    }
}

From source file:com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition.java

private void setBindings(GroovyShell shell, String bindings) throws IOException {
    if (bindings != null) {
        Properties p = new Properties();
        p.load(new StringReader(bindings));
        for (Map.Entry<Object, Object> entry : p.entrySet()) {
            shell.setVariable((String) entry.getKey(), entry.getValue());
        }//  w w w.ja v a  2s .c  o  m
    }
}

From source file:atg.tools.dynunit.test.AtgDustCase.java

/**
 * Prepares a test against an existing database.
 *
 * @param repositoryPath/*w  ww. j a v  a2 s  .co  m*/
 *         The the repository to be tested, specified as nucleus
 *         component path.
 * @param connectionProperties
 *         A {@link Properties} instance with the following values (in
 *         this example the properties are geared towards an mysql
 *         database):
 *         <p/>
 *         <pre>
 *                                                                                                                     final
 *                                                             Properties properties = new
 *                                                                                         Properties();
 *
 *                                                             properties.put(&quot;driver&quot;,
 *                                                                                         &quot;com.mysql.jdbc.Driver&quot;);
 *
 *                                                             properties.put(&quot;url&quot;,
 *                                                                                         &quot;jdbc:mysql://localhost:3306/someDb&quot;);
 *
 *                                                             properties.put(&quot;user&quot;,
 *                                                                                         &quot;someUserName&quot;);
 *
 *                                                             properties.put(&quot;password&quot;,
 *                                                                                         &quot;somePassword&quot;);
 *                                                                                                                     </pre>
 * @param dropTables
 *         If <code>true</code> then existing tables will be dropped and
 *         re-created, if set to <code>false</code> the existing tables
 *         will be used.
 * @param createTables
 *         if set to <code>true</code> all non existing tables needed for
 *         the current test run will be created, if set to
 *         <code>false</code> this class expects all needed tables for
 *         this test run to be already created
 * @param definitionFiles
 *         One or more needed repository definition files.
 *
 * @throws IOException
 *         The moment we have some properties/configuration related
 *         error
 * @throws SQLException
 *         Whenever there is a database related error
 */
protected final void prepareRepository(final String repositoryPath, final Properties connectionProperties,
        final boolean dropTables, final boolean createTables, final String... definitionFiles)
        throws SQLException, IOException {

    final Map<String, String> connectionSettings = new HashMap<String, String>();

    for (final Entry<Object, Object> entry : connectionProperties.entrySet()) {
        connectionSettings.put((String) entry.getKey(), (String) entry.getValue());

    }
    final RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();

    repositoryConfiguration.setDebug(debug);
    repositoryConfiguration.setRoot(configurationLocation);
    repositoryConfiguration.createPropertiesByConfigurationLocation();
    repositoryConfiguration.createFakeXADataSource(connectionProperties);
    repositoryConfiguration.createRepository(repositoryPath, dropTables, createTables, definitionFiles);

    repositoryManager.initializeMinimalRepositoryConfiguration(configurationLocation, repositoryPath,
            connectionSettings, dropTables, debug, definitionFiles);
}

From source file:net.mindengine.oculus.frontend.service.runs.JdbcTestRunDAO.java

/**
 * Collecting all the conditions/*www. j  a  v  a2  s .c  o  m*/
 * 
 * @param filter
 * @return
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public SqlSearchCondition createCondition(SearchFilter filter) throws IOException {

    SqlSearchCondition condition = new SqlSearchCondition();

    // TestName
    String testName = filter.getTestCaseName();
    if (testName != null && !testName.isEmpty()) {
        testName = testName.trim();
        // checking whether it is an id of test or just a name
        if (StringUtils.isNumeric(testName)) {
            // The id of a test was provided
            condition.append(condition.createSimpleCondition(false, "t.id", testName));
        } else {
            if (testName.contains(",")) {
                condition.append(condition.createArrayCondition(testName, "t.name", "tr.name"));
            } else {
                condition.append(condition.createSimpleCondition(testName, true, "t.name", "tr.name"));
            }
        }
    }

    // TestRun Statuses
    List<String> statuses = (List<String>) filter.getTestCaseStatusList();
    if (statuses != null && statuses.size() > 0) {
        String statusColumns[] = new String[statuses.size() * 2];
        int j = 0;
        for (int i = 0; i < statuses.size(); i++) {
            j = i * 2;
            String value = statuses.get(i);
            statusColumns[j] = "tr.status";
            statusColumns[j + 1] = value;
        }
        condition.append(condition.createSimpleCondition(false, statusColumns));
    }
    // TestRun Reason
    String reason = filter.getTestRunReason();
    if (reason != null && !reason.isEmpty()) {
        reason = "*" + reason + "*";
        condition.append(condition.createSimpleCondition(reason, true, "tr.reasons"));
    }
    // Root Project Id
    {
        String parentProject = filter.getRootProject();
        if (parentProject != null && !parentProject.isEmpty()) {
            // checking whether it is an id of project or just a name
            if (StringUtils.isNumeric(parentProject)) {
                Long projectId = Long.parseLong(parentProject);
                if (projectId > 0) {
                    // The id of a project was provided
                    condition.append(condition.createSimpleCondition(false, "pp.id", parentProject));
                }
            }
        }
    }
    // Project Name
    {
        String project = filter.getProject();
        if (project != null && !project.isEmpty()) {
            // checking whether it is an id of project or just a name
            if (StringUtils.isNumeric(project)) {
                // The id of a project was provided
                condition.append(condition.createSimpleCondition(false, "p.id", project));
            } else {
                if (project.contains(",")) {
                    condition.append(condition.createArrayCondition(project, "p.name"));
                } else {
                    condition.append(condition.createSimpleCondition(project, true, "p.name"));
                }
            }
        }
    }
    // Suite Run Name
    {
        String suiteRunName = filter.getSuite();
        if (suiteRunName != null && !suiteRunName.isEmpty()) {
            if (suiteRunName.contains(",")) {
                if (StringUtils.isNumeric(suiteRunName.replace(",", ""))) {
                    condition.append(condition.createArrayCondition(suiteRunName, "sr.id"));
                } else {
                    condition.append(condition.createArrayCondition(suiteRunName, "sr.name"));
                }
            } else {
                if (StringUtils.isNumeric(suiteRunName)) {
                    condition.append(condition.createSimpleCondition(suiteRunName, true, "sr.id"));
                } else {
                    condition.append(condition.createSimpleCondition(suiteRunName, true, "sr.name"));
                }
            }
        }
    }
    // Suite Run Start Time
    {
        String dateAfter = filter.getSuiteRunTimeAfter();
        if (dateAfter != null && !dateAfter.isEmpty()) {
            if (!dateAfter.contains(":")) {
                dateAfter += " 00:00:00";
            }

            // Checking whether the string is in date format
            try {
                Timestamp.valueOf(dateAfter);
                condition.append("tr.start_time >= '" + dateAfter + "'");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        String dateBefore = filter.getSuiteRunTimeBefore();
        if (dateBefore != null && !dateBefore.isEmpty()) {
            if (!dateBefore.contains(":")) {
                dateBefore += " 00:00:00";
            }

            // Checking whether the string is in date format
            try {
                Timestamp.valueOf(dateBefore);
                condition.append("tr.start_time <= '" + dateBefore + "'");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    // Suite Run Parameters
    {
        String suiteRunParameters = filter.getSuiteRunParameters();
        if (suiteRunParameters != null && !suiteRunParameters.isEmpty()) {
            // Parsing the suiteRunParameters template;
            Properties prop = new Properties();
            prop.load(new StringReader(suiteRunParameters));
            for (Entry<Object, Object> property : prop.entrySet()) {
                condition.append(condition.createSimpleCondition(
                        "*" + property.getKey() + "<v>" + property.getValue() + "*", true, "sr.parameters"));
            }
        }
    }
    // Suite Run Agent
    {
        String suiteRunAgent = filter.getSuiteRunAgent();
        if (suiteRunAgent != null && !suiteRunAgent.isEmpty()) {
            if (suiteRunAgent.contains(",")) {
                condition.append(condition.createArrayCondition(suiteRunAgent, "sr.agent_name"));
            } else {
                condition.append(condition.createSimpleCondition(suiteRunAgent, true, "sr.agent_name"));
            }
        }
    }
    // User designer
    {
        String designer = filter.getUserDesigner();
        if (designer != null && !designer.isEmpty()) {
            if (designer.contains(",")) {
                if (StringUtils.isNumeric(designer.replace(",", ""))) {
                    condition.append(condition.createArrayCondition(designer, "ud.id"));
                } else {
                    condition.append(condition.createArrayCondition(designer, "ud.login", "ud.name"));
                }
            } else {
                // checking whether it is an id of project or just a name
                if (StringUtils.isNumeric(designer)) {
                    // The id of a project was provided
                    condition.append(condition.createSimpleCondition(false, "ud.id", designer));
                } else {
                    condition.append(condition.createSimpleCondition(designer, true, "ud.login", "ud.name"));
                }
            }
        }
    }

    // User runner
    {
        String runner = filter.getUserRunner();
        if (runner != null && !runner.isEmpty()) {
            if (runner.contains(",")) {
                if (StringUtils.isNumeric(runner.replace(",", ""))) {
                    condition.append(condition.createArrayCondition(runner, "ur.id"));
                } else {
                    condition.append(condition.createArrayCondition(runner, "ur.login", "ur.name"));
                }
            } else {
                // checking whether it is an id of project or just a name
                if (StringUtils.isNumeric(runner)) {
                    // The id of a project was provided
                    condition.append(condition.createSimpleCondition(false, "ur.id", runner));
                } else {
                    condition.append(condition.createSimpleCondition(runner, true, "ur.login", "ur.name"));
                }
            }
        }
    }
    // Issue
    String issueName = filter.getIssue();
    if (issueName != null && !issueName.isEmpty()) {
        if (issueName.contains(",")) {
            condition.append(condition.createArrayCondition(issueName, "iss.name", "iss.link"));
        } else {
            condition.append(condition.createSimpleCondition(issueName, true, "iss.name", "iss.link"));
        }
    }
    return condition;
}