Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

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

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:com.enioka.jqm.api.HibernateClient.java

HibernateClient(Properties p) {
    this.p = p;/*w  ww.  ja  va2  s  . c om*/
    if (p.containsKey("emf")) {
        jqmlogger.trace("emf present in properties");
        emf = (EntityManagerFactory) p.get("emf");
    }
}

From source file:org.alfresco.reporting.processor.PersonProcessor.java

/**
 * //from   w w  w  . j av a 2 s  .c om
 * @param definition
 * @param nodeRef   Current nodeRef to put all related and relevant property 
 * values into the reporting database
 * @param defBacklist the Blacklist String
 * @return
 */

public Properties processPropertyDefinitions(Properties definition, NodeRef nodeRef, String defBacklist) {
    if (logger.isDebugEnabled()) {
        logger.debug("enter processPropertyDefinitions def  : " + definition);
        logger.debug("enter processPropertyDefinitions node : " + nodeRef);
        logger.debug("enter processPropertyDefinitions black: " + defBacklist);
    }

    try {
        Map<QName, Serializable> map = getNodeService().getProperties(nodeRef);
        Iterator<QName> keys = map.keySet().iterator();
        Properties classToColumnType = getClassToColumnType();
        Properties replacementDataType = getReplacementDataType();
        while (keys.hasNext()) {
            String key = "";
            String type = "";
            try {
                QName qname = keys.next();
                //Serializable s = map.get(qname);
                if (qname != null) {
                    key = qname.toString();
                    key = replaceNameSpaces(key);
                    //logger.debug("processPropertyDefinitions: Processing key " + key);
                    if (!key.startsWith("{urn:schemas_microsoft_com:}") && !definition.containsKey(key)) {
                        type = "";
                        if (replacementDataType.containsKey(key)) {
                            type = replacementDataType.getProperty(key, "-").trim();
                        } else {
                            type = "-";
                            try {
                                type = getDictionaryService().getProperty(qname).getDataType().toString()
                                        .trim();
                                type = type.substring(type.indexOf("}") + 1, type.length());
                                type = classToColumnType.getProperty(type, "-");
                            } catch (NullPointerException npe) {
                                // ignore. cm_source and a few others have issues in their datatype??
                                //logger.fatal("Silent drop of NullPointerException against " + key);
                            }
                            // if the key is not in the BlackList, add it to the prop object that 
                            // will update the table definition
                        }
                        if ((type != null) && !type.equals("-") && !type.equals("") && (key != null)
                                && (!key.equals("")) && (!defBacklist.contains("," + key + ","))) {
                            definition.setProperty(key, type);
                            //if (logger.isDebugEnabled())
                            //   logger.debug("processPropertyDefinitions: Adding column "+ key + "=" + type);
                        } else {
                            //if (logger.isDebugEnabled())
                            //   logger.debug("Ignoring column "+ key + "=" + type);
                        }
                    } // end if containsKey
                } //end if key!=null
            } catch (Exception e) {
                logger.error("processPropertyDefinitions: Property not found! Property below...");
                logger.error("processPropertyDefinitions: type=" + type + ", key=" + key);
                e.printStackTrace();
            }
        } // end while
    } catch (Exception e) {
        e.printStackTrace();
    }
    //logger.debug("Exit processPropertyDefinitions");
    return definition;
}

From source file:com.google.api.ads.adwords.awreporting.server.appengine.processors.ReportProcessorAppEngine.java

/**
 * Generate all the mapped reports to the given account IDs.
 * // w  ww . j a  v  a  2s .  c o m
 * @param dateRangeType the date range type.
 * @param dateStart the starting date in YYYYMMDD format
 * @param dateEnd the ending date in YYYYMMDD format
 * @param accountIdsSet the account IDs.
 * @param properties the properties file
 * 
 * @reportType
 * @reportFieldsToInclude
 * 
 * @throws Exception error reaching the API.
 */
public void generateReportsForMCC(String userId, String mccAccountId,
        ReportDefinitionDateRangeType dateRangeType, String dateStart, String dateEnd, Set<Long> accountIdsSet,
        Properties properties, ReportDefinitionReportType onDemandReportType,
        List<String> reportFieldsToInclude) throws Exception {

    LOGGER.info("*** Retrieving account IDs ***");

    if (accountIdsSet == null || accountIdsSet.size() == 0) {
        // Getting accounts Ids from DB
        accountIdsSet = Sets.newHashSet();
        List<Account> accounts = persister.get(Account.class, Account.TOP_ACCOUNT_ID,
                Long.valueOf(mccAccountId));
        for (Account account : accounts) {
            accountIdsSet.add(Long.valueOf(account.getId()));
        }
    }

    LOGGER.info("*** Generating Reports for " + accountIdsSet.size() + " accounts ***");

    Stopwatch stopwatch = Stopwatch.createStarted();

    // We will download/generate the reportType with reportFieldsToInclude fields
    // if null we will use the Properties file report definitions
    if (onDemandReportType != null) {

        // Skip properties file
        this.downloadAndProcess(userId, mccAccountId, onDemandReportType, dateRangeType, dateStart, dateEnd,
                accountIdsSet, properties);

    } else {

        Set<ReportDefinitionReportType> allReportTypes = this.csvReportEntitiesMapping.getDefinedReports();

        // Iterate over properties file
        for (ReportDefinitionReportType propertiesReportType : allReportTypes) {
            if (properties.containsKey(propertiesReportType.name())) {
                this.downloadAndProcess(userId, mccAccountId, propertiesReportType, dateRangeType, dateStart,
                        dateEnd, accountIdsSet, properties);
            }
        }
    }

    stopwatch.stop();
    LOGGER.info("*** Finished processing all reports in " + (stopwatch.elapsed(TimeUnit.MILLISECONDS) / 1000)
            + " seconds ***\n");
}

From source file:info.magnolia.jcr.util.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>/some/path/node.prop</code> or
 * <code>/some/path/node.@type</code>.
 *///from   www .ja v a  2  s. c o m
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;
        // explicitly enforce certain syntax
        if (!orgKey.startsWith("/")) {
            throw new IllegalArgumentException("Missing trailing '/' for key: " + orgKey);
        }
        if (StringUtils.countMatches(orgKey, ".") > 1) {
            throw new IllegalArgumentException("Key must not contain more than one '.': " + orgKey);
        }
        if (orgKey.contains("@") && !orgKey.contains(".@")) {
            throw new IllegalArgumentException("Key containing '@' must be preceded by a '.': " + orgKey);
        }
        // if this is a node definition (no property)
        String newKey = orgKey;

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.removeStart(keySuffix, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + ".@type")) {
                    cleaned.put(path + ".@type", NodeTypes.ContentNode.NAME);
                }
                continue;
            }
            throw new IllegalArgumentException(
                    "Key for a path (everything without a '.' is considered to be a path) must not contain a value ('='): "
                            + orgKey);
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:org.apache.maven.archetype.creator.FilesetArchetypeCreator.java

private void extractPropertiesFromProject(MavenProject project, Properties properties,
        Properties configurationProperties, String packageName) {
    if (!properties.containsKey(Constants.GROUP_ID)) {
        properties.setProperty(Constants.GROUP_ID, project.getGroupId());
    }/*from  www  .j  a v  a  2s. co m*/
    configurationProperties.setProperty(Constants.GROUP_ID, properties.getProperty(Constants.GROUP_ID));

    if (!properties.containsKey(Constants.ARTIFACT_ID)) {
        properties.setProperty(Constants.ARTIFACT_ID, project.getArtifactId());
    }
    configurationProperties.setProperty(Constants.ARTIFACT_ID, properties.getProperty(Constants.ARTIFACT_ID));

    if (!properties.containsKey(Constants.VERSION)) {
        properties.setProperty(Constants.VERSION, project.getVersion());
    }
    configurationProperties.setProperty(Constants.VERSION, properties.getProperty(Constants.VERSION));

    if (packageName != null) {
        properties.setProperty(Constants.PACKAGE, packageName);
    } else if (!properties.containsKey(Constants.PACKAGE)) {
        properties.setProperty(Constants.PACKAGE, project.getGroupId());
    }
    configurationProperties.setProperty(Constants.PACKAGE, properties.getProperty(Constants.PACKAGE));
}

From source file:org.apache.gobblin.metrics.GobblinMetrics.java

private void buildInfluxDBMetricReporter(Properties properties) {
    boolean metricsEnabled = PropertiesUtils.getPropAsBoolean(properties,
            ConfigurationKeys.METRICS_REPORTING_INFLUXDB_METRICS_ENABLED_KEY,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_INFLUXDB_METRICS_ENABLED);
    if (metricsEnabled) {
        LOGGER.info("Reporting metrics to InfluxDB");
    }/*from   ww w. j a  va  2 s  . c  o  m*/

    boolean eventsEnabled = PropertiesUtils.getPropAsBoolean(properties,
            ConfigurationKeys.METRICS_REPORTING_INFLUXDB_EVENTS_ENABLED_KEY,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_INFLUXDB_EVENTS_ENABLED);
    if (eventsEnabled) {
        LOGGER.info("Reporting events to InfluxDB");
    }

    if (!metricsEnabled && !eventsEnabled) {
        return;
    }

    try {
        Preconditions.checkArgument(
                properties.containsKey(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_DATABASE),
                "InfluxDB database name is missing.");
    } catch (IllegalArgumentException exception) {
        LOGGER.error("Not reporting to InfluxDB due to missing InfluxDB configuration(s).", exception);
        return;
    }

    String url = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_URL);
    String username = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_USER);
    String password = PasswordManager.getInstance(properties)
            .readPassword(properties.getProperty(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_PASSWORD));
    String database = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_DATABASE);

    InfluxDBConnectionType connectionType;
    String type = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_SENDING_TYPE,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_INFLUXDB_SENDING_TYPE).toUpperCase();
    try {
        connectionType = InfluxDBConnectionType.valueOf(type);
    } catch (IllegalArgumentException exception) {
        LOGGER.warn("InfluxDB Reporter connection type " + type + " not recognized. Will use TCP for sending.",
                exception);
        connectionType = InfluxDBConnectionType.TCP;
    }

    if (metricsEnabled) {
        try {
            InfluxDBReporter.Factory.newBuilder().withConnectionType(connectionType)
                    .withConnection(url, username, password, database)
                    .withMetricContextName(this.metricContext.getName()) // contains the current job id
                    .build(properties);
        } catch (IOException e) {
            LOGGER.error("Failed to create InfluxDB metrics reporter. Will not report metrics to InfluxDB.", e);
        }
    }

    if (eventsEnabled) {
        String eventsDbProp = properties
                .getProperty(ConfigurationKeys.METRICS_REPORTING_INFLUXDB_EVENTS_DATABASE);
        String eventsDatabase = (eventsDbProp == null) ? (metricsEnabled ? database : null) : eventsDbProp;
        try {
            InfluxDBEventReporter eventReporter = InfluxDBEventReporter.Factory
                    .forContext(RootMetricContext.get()).withConnectionType(connectionType)
                    .withConnection(url, username, password, eventsDatabase).build();
            this.codahaleScheduledReporters.add(this.codahaleReportersCloser.register(eventReporter));
        } catch (IOException e) {
            LOGGER.error("Failed to create InfluxDB event reporter. Will not report events to InfluxDB.", e);
        }
    }
}

From source file:org.apache.gobblin.metrics.GobblinMetrics.java

private void buildGraphiteMetricReporter(Properties properties) {
    boolean metricsEnabled = PropertiesUtils.getPropAsBoolean(properties,
            ConfigurationKeys.METRICS_REPORTING_GRAPHITE_METRICS_ENABLED_KEY,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_GRAPHITE_METRICS_ENABLED);
    if (metricsEnabled) {
        LOGGER.info("Reporting metrics to Graphite");
    }/*from  ww  w  .ja  v  a  2 s.  co m*/

    boolean eventsEnabled = PropertiesUtils.getPropAsBoolean(properties,
            ConfigurationKeys.METRICS_REPORTING_GRAPHITE_EVENTS_ENABLED_KEY,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_GRAPHITE_EVENTS_ENABLED);
    if (eventsEnabled) {
        LOGGER.info("Reporting events to Graphite");
    }

    if (!metricsEnabled && !eventsEnabled) {
        return;
    }

    try {
        Preconditions.checkArgument(
                properties.containsKey(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_HOSTNAME),
                "Graphite hostname is missing.");
    } catch (IllegalArgumentException exception) {
        LOGGER.error("Not reporting to Graphite due to missing Graphite configuration(s).", exception);
        return;
    }

    String hostname = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_HOSTNAME);
    int port = Integer.parseInt(properties.getProperty(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_PORT,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_GRAPHITE_PORT));

    GraphiteConnectionType connectionType;
    String type = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_SENDING_TYPE,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_GRAPHITE_SENDING_TYPE).toUpperCase();
    String prefix = properties.getProperty(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_PREFIX,
            ConfigurationKeys.DEFAULT_METRICS_REPORTING_GRAPHITE_PREFIX);
    try {
        connectionType = GraphiteConnectionType.valueOf(type);
    } catch (IllegalArgumentException exception) {
        LOGGER.warn("Graphite Reporter connection type " + type + " not recognized. Will use TCP for sending.",
                exception);
        connectionType = GraphiteConnectionType.TCP;
    }

    if (metricsEnabled) {
        try {
            GraphiteReporter.Factory.newBuilder().withConnectionType(connectionType)
                    .withConnection(hostname, port).withMetricContextName(this.metricContext.getName()) //contains the current job id
                    .withMetricsPrefix(prefix).build(properties);
        } catch (IOException e) {
            LOGGER.error("Failed to create Graphite metrics reporter. Will not report metrics to Graphite.", e);
        }
    }

    if (eventsEnabled) {
        boolean emitValueAsKey = PropertiesUtils.getPropAsBoolean(properties,
                ConfigurationKeys.METRICS_REPORTING_GRAPHITE_EVENTS_VALUE_AS_KEY,
                ConfigurationKeys.DEFAULT_METRICS_REPORTING_GRAPHITE_EVENTS_VALUE_AS_KEY);
        String eventsPortProp = properties
                .getProperty(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_EVENTS_PORT);
        int eventsPort = (eventsPortProp == null)
                ? (metricsEnabled ? port : Integer.parseInt(ConfigurationKeys.METRICS_REPORTING_GRAPHITE_PORT))
                : Integer.parseInt(eventsPortProp);
        try {
            GraphiteEventReporter eventReporter = GraphiteEventReporter.Factory
                    .forContext(RootMetricContext.get()).withConnectionType(connectionType)
                    .withConnection(hostname, eventsPort).withPrefix(prefix).withEmitValueAsKey(emitValueAsKey)
                    .build();
            this.codahaleScheduledReporters.add(this.codahaleReportersCloser.register(eventReporter));
        } catch (IOException e) {
            LOGGER.error("Failed to create Graphite event reporter. Will not report events to Graphite.", e);
        }
    }
}

From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.PrivateEC2CloudifyDriver.java

private String replaceProperties(final File file, final File propertiesFile) throws IOException {
    logger.fine("Properties file=" + propertiesFile.getName());
    final Properties props = new Properties();
    props.load(new FileInputStream(propertiesFile));

    String templateString = FileUtils.readFileToString(file);

    final Pattern p = Pattern.compile(PATTERN_PROPS_JSON);
    Matcher m = p.matcher(templateString);
    while (m.find()) {
        final String group = m.group();
        final String group1 = m.group(1);
        if (props.containsKey(group1)) {
            final String value = props.getProperty(group1);
            if (logger.isLoggable(Level.FINEST)) {
                logger.finest("Replacing property " + group + " by " + value);
            }//  w  w w  .j  a va  2 s  . co m
            templateString = m.replaceFirst(group.replace(group1, value));
            m = p.matcher(templateString);
        } else {
            throw new IllegalStateException("Couldn't find property: " + group1);
        }
    }
    return templateString;
}

From source file:fr.ens.biologie.genomique.eoulsan.it.IT.java

/**
 * Retrieve properties for the test, compile specific configuration with
 * global.//from   w  w  w.  ja  v a 2 s.c om
 * @param globalsConf global configuration for tests
 * @return Properties content of configuration file
 * @throws IOException if an error occurs while reading the file.
 * @throws EoulsanException if an error occurs while evaluating value property
 */
private Properties loadConfigurationFile(final Properties globalsConf) throws IOException, EoulsanException {

    final File testConfFile = new File(this.testDataDirectory, ITFactory.TEST_CONFIGURATION_FILENAME);

    checkExistingFile(testConfFile, "test configuration file");

    // Add global configuration
    final Properties props = new Properties();
    props.putAll(globalsConf);

    final BufferedReader br = newReader(testConfFile, Charsets.toCharset(Globals.DEFAULT_FILE_ENCODING));

    String line = null;

    while ((line = br.readLine()) != null) {
        // Skip commentary
        if (line.startsWith("#")) {
            continue;
        }

        final int pos = line.indexOf('=');
        if (pos == -1) {
            continue;
        }

        final String key = line.substring(0, pos).trim();

        // Evaluate value
        String value = evaluateExpressions(line.substring(pos + 1).trim(), true);

        // Key pattern : add value for test to values from
        // configuration general

        if (isKeyInCompileProperties(key) && props.containsKey(key)) {
            // Concatenate values
            value = props.getProperty(key) + SEPARATOR + value;
        }

        // Save parameter with value
        props.put(key, value);
    }
    br.close();

    return props;

}