Example usage for java.util Properties keys

List of usage examples for java.util Properties keys

Introduction

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

Prototype

@Override
    public Enumeration<Object> keys() 

Source Link

Usage

From source file:org.usapi.PropertyHelper.java

/**
 * Load a properties file from the classpath and make its properties
 * available in the environment, unless overridden by -D arg to JVM
 *//*from w w  w  .  ja  va2  s  . c om*/
private static void loadTestProperties() {
    //Properties sysProps = System.getProperties();
    Properties testProps = new Properties();

    // load defaults
    testProps.put(SERVER_HOST, "");
    testProps.put(SERVER_PORT, "");
    testProps.put(CHROMEDRIVER_HOST, "127.0.0.1");
    testProps.put(CHROMEDRIVER_PORT, "9515");
    testProps.put(CHROMEDRIVER_EXECUTABLE, getChromeDriverFilename());
    testProps.put(BROWSER_CMD, "*firefox");
    testProps.put(BROWSER_URL, "http://localhost");
    testProps.put(EXECUTION_SPEED, "0");
    testProps.put(FAILURECAPTURE_DIR, failureCaptureDir);
    testProps.put(ENABLE_JAVASCRIPT, "true");
    testProps.put(ENABLE_NATIVE_EVENTS, "false"); // if we leave native events on, FF on Windoze can start acting up
    testProps.put(JQUERY_WAIT_FOR_AJAX, "false");

    String properties = System.getProperty(SELENIUM_PROPERTIES);
    properties = properties == null ? SELENIUM_PROPERTIES : properties;
    log.info("Using properties file " + properties);

    URL url = ClassLoader.getSystemResource(properties);
    try {
        testProps.load(url.openStream());
    } catch (Exception e) {
        log.info("Unable to load default properties file from classpath: " + properties);
    }

    Enumeration keys = testProps.keys();
    String key, value = null;
    while (keys.hasMoreElements()) {
        key = (String) keys.nextElement();
        value = testProps.getProperty(key);
        // property might already be set at invocation/from the cmd line
        // so we do not want to override it here
        // values loaded at this point should be override-able from the
        // cmd line
        String existingProp = System.getProperty(key);
        log.info("Using system property " + key + ", value: " + (existingProp == null ? value : existingProp));
        if (existingProp == null) {
            System.setProperty(key, value);
        }
    }
}

From source file:org.apache.nutch.analysis.lang.LanguageIdentifier.java

/**
 * Constructs a new Language Identifier.
 *///www  .  j a v  a  2  s  . com
public LanguageIdentifier(Configuration conf) {

    // Gets ngram sizes to take into account from the Nutch Config
    minLength = conf.getInt("lang.ngram.min.length", NGramProfile.DEFAULT_MIN_NGRAM_LENGTH);
    maxLength = conf.getInt("lang.ngram.max.length", NGramProfile.DEFAULT_MAX_NGRAM_LENGTH);
    // Ensure the min and max values are in an acceptale range
    // (ie min >= DEFAULT_MIN_NGRAM_LENGTH and max <= DEFAULT_MAX_NGRAM_LENGTH)
    maxLength = Math.min(maxLength, NGramProfile.ABSOLUTE_MAX_NGRAM_LENGTH);
    maxLength = Math.max(maxLength, NGramProfile.ABSOLUTE_MIN_NGRAM_LENGTH);
    minLength = Math.max(minLength, NGramProfile.ABSOLUTE_MIN_NGRAM_LENGTH);
    minLength = Math.min(minLength, maxLength);

    // Gets the value of the maximum size of data to analyze
    analyzeLength = conf.getInt("lang.analyze.max.length", DEFAULT_ANALYSIS_LENGTH);

    Properties p = new Properties();
    try {
        p.load(this.getClass().getResourceAsStream("langmappings.properties"));

        Enumeration alllanguages = p.keys();

        if (LOG.isInfoEnabled()) {
            LOG.info(new StringBuffer().append("Language identifier configuration [").append(minLength)
                    .append("-").append(maxLength).append("/").append(analyzeLength).append("]").toString());
        }

        StringBuffer list = new StringBuffer("Language identifier plugin supports:");
        HashMap<NGramEntry, List<NGramEntry>> tmpIdx = new HashMap<NGramEntry, List<NGramEntry>>();
        while (alllanguages.hasMoreElements()) {
            String lang = (String) (alllanguages.nextElement());

            InputStream is = this.getClass().getClassLoader().getResourceAsStream(
                    "org/apache/nutch/analysis/lang/" + lang + "." + NGramProfile.FILE_EXTENSION);

            if (is != null) {
                NGramProfile profile = new NGramProfile(lang, minLength, maxLength);
                try {
                    profile.load(is);
                    languages.add(profile);
                    supportedLanguages.add(lang);
                    List<NGramEntry> ngrams = profile.getSorted();
                    for (int i = 0; i < ngrams.size(); i++) {
                        NGramEntry entry = ngrams.get(i);
                        List<NGramEntry> registered = tmpIdx.get(entry);
                        if (registered == null) {
                            registered = new ArrayList<NGramEntry>();
                            tmpIdx.put(entry, registered);
                        }
                        registered.add(entry);
                        entry.setProfile(profile);
                    }
                    list.append(" " + lang + "(" + ngrams.size() + ")");
                    is.close();
                } catch (IOException e1) {
                    if (LOG.isFatalEnabled()) {
                        LOG.fatal(e1.toString());
                    }
                }
            }
        }
        // transform all ngrams lists to arrays for performances
        Iterator<NGramEntry> keys = tmpIdx.keySet().iterator();
        while (keys.hasNext()) {
            NGramEntry entry = keys.next();
            List<NGramEntry> l = tmpIdx.get(entry);
            if (l != null) {
                NGramEntry[] array = l.toArray(new NGramEntry[l.size()]);
                ngramsIdx.put(entry.getSeq(), array);
            }
        }
        if (LOG.isInfoEnabled()) {
            LOG.info(list.toString());
        }
        // Create the suspect profile
        suspect = new NGramProfile("suspect", minLength, maxLength);
    } catch (Exception e) {
        if (LOG.isFatalEnabled()) {
            LOG.fatal(e.toString());
        }
    }
}

From source file:org.hyperic.hq.product.RtPlugin.java

protected ParsedFile[] generateFileList(Properties alreadyParsedFiles, String logdir, String logmask)
        throws IOException {
    FilenameFilter filter = new GlobFilenameFilter(logmask.trim());
    ArrayList removedFiles = new ArrayList();
    Enumeration en = alreadyParsedFiles.keys();

    while (en.hasMoreElements()) {
        String file = (String) en.nextElement();
        File temp = new File(file);

        if (filter.accept(temp.getParentFile(), temp.getName())) {
            removedFiles.add(file);/*from w  w w. j  av  a2  s .  co m*/
        }
    }

    File directory = new File(logdir);
    if (!directory.canRead()) {
        this.log.error("logDir (" + logdir + ") is not readable by the agent!");
    }
    File[] flist = directory.listFiles(filter);
    ArrayList toParse = new ArrayList();

    if (flist == null || flist.length == 0) {
        this.log.warn("No valid response time log files found.  " + "logDir='" + logdir + "', logMask='"
                + logmask + "'");
        return (ParsedFile[]) toParse.toArray(new ParsedFile[0]);
    }

    for (int i = 0; i < flist.length; i++) {
        Long len = new Long(flist[i].length());
        String canonPath = flist[i].getCanonicalPath();
        String value = alreadyParsedFiles.getProperty(canonPath);

        Long oldlen = (value == null) ? new Long(0) : Long.valueOf(value);

        // This file exists, remove it from the list of files
        // that have been removed.
        removedFiles.remove(canonPath);

        if (oldlen.compareTo(len) != 0) {
            this.log.debug("Adding " + canonPath + " to parse list " + "(offset=" + oldlen + ")");
            toParse.add(new ParsedFile(canonPath, oldlen.longValue()));
        }
    }

    // Remove the files that were removed since the last time we parsed
    // the logs.  The way this 'removed files' thing is implemented is
    // soo lame.
    Iterator it = removedFiles.iterator();
    while (it.hasNext()) {
        String toRemove = (String) it.next();
        this.log.debug("Removing " + toRemove + " from parse list");
        this.log.debug(toRemove);
        alreadyParsedFiles.remove(toRemove);
    }

    return (ParsedFile[]) toParse.toArray(new ParsedFile[0]);
}

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

/**
 * <p>//from w  w  w. j  a v  a2  s.c  o m
 * This will merge the Global Variables properties file into the
 * {@link ApplicationType} object.
 * </p>
 * 
 * @throws MojoExecutionException
 */
private void mergeGlobalVariables() throws MojoExecutionException {
    Properties propertiesGlobalVariables;
    try {
        propertiesGlobalVariables = loadPropertiesFile(deploymentGlobalVariables);
    } catch (Exception e) {
        throw new MojoExecutionException(
                PROPERTIES_GLOBAL_VARIABLES_LOAD_FAILURE + " '" + deploymentGlobalVariables + "'", e);
    }

    Enumeration<Object> e = propertiesGlobalVariables.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = propertiesGlobalVariables.getProperty(key);

        application.setGlobalVariable(key, value);
    }
}

From source file:org.apache.hive.hcatalog.pig.HCatLoader.java

private void restoreLoaderSpecificStateFromUDFContext(Job job, Properties udfProps) throws IOException {
    for (Enumeration<Object> emr = udfProps.keys(); emr.hasMoreElements();) {
        PigHCatUtil.getConfigFromUDFProperties(udfProps, job.getConfiguration(), emr.nextElement().toString());
    }/*from   ww w .  ja v a 2s.c  o  m*/
}

From source file:org.alfresco.reporting.ReportingHelper.java

/**
 * Given the input string, replace all namespaces where possible. 
 * @param namespace/*w  w  w  . ja  v  a 2s.co  m*/
 * @return string whith replaced full namespaces into short namespace definitions
 */

public String replaceNameSpaces(String namespace) {
    // use regular expressions to do a global replace of the full namespace into the short version.
    Properties p = getNameSpaces();
    Enumeration<Object> keys = p.keys();
    while (keys.hasMoreElements()) {
        String into = (String) keys.nextElement();
        String from = p.getProperty(into);
        namespace = namespace.replace(from, into);
    }
    namespace = namespace.replace("-", "_");

    return namespace;
}

From source file:org.pepstock.jem.node.StartUpSystem.java

/**
 * //  ww  w  . j av  a  2s . c o m
 * @param conf
 * @param substituter
 * @throws ConfigurationException
 */
private static void loadNode() throws ConfigurationException {
    // load node class, checking if they are configured.
    Node node = JEM_ENV_CONFIG.getNode();
    // load all factories for affinity factory
    // for all factories checking which have the right className. If
    // not,
    // exception occurs, otherwise it's loaded
    if (node != null && node.getClassName() != null) {
        String className = node.getClassName();
        try {
            // load by Class.forName of loader
            Object objectNode = Class.forName(className).newInstance();

            // check if it's a AffinityLoader. if not, exception occurs.
            if (objectNode instanceof NodeInfo) {
                Main.setNode((NodeInfo) objectNode);

                // gets properties defined. If not empty, substitutes
                // the value of property with variables
                Properties propsOfNode = node.getProperties();
                if (!propsOfNode.isEmpty()) {
                    // scans all properties
                    for (Enumeration<Object> e = propsOfNode.keys(); e.hasMoreElements();) {
                        // gets key and value
                        String key = e.nextElement().toString();
                        String value = propsOfNode.getProperty(key);
                        // substitutes variables if present
                        // and sets new value for the key
                        propsOfNode.setProperty(key, substituteVariable(value));
                    }
                }
                // initializes the factory with properties defined
                // and puts in the list if everything went good
                Main.getNode().init(propsOfNode);
                LogAppl.getInstance().emit(NodeMessage.JEMC090I, className);
                return;
            }
            LogAppl.getInstance().emit(NodeMessage.JEMC091E);
            throw new ConfigurationException(NodeMessage.JEMC091E.toMessage().getFormattedMessage(className));
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
        // in this case the class name is null so ignore, emitting a
        // warning
    }
    Main.setNode(new NodeInfo());
    LogAppl.getInstance().emit(NodeMessage.JEMC090I, NodeInfo.class.getName());
}

From source file:com.photon.phresco.impl.DrupalApplicationProcessor.java

private void storeConfigObj(List<Configuration> configs, File featureManifestXmlFile, File featureSqlDir,
        String environmentName) throws PhrescoException {
    try {/*  www . j av  a 2s.  c  o m*/
        if (!featureManifestXmlFile.isFile()) {
            throw new PhrescoException("manifest file is not available");
        }

        // Document
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(featureManifestXmlFile);
        doc.getDocumentElement().normalize();

        // xpath
        XPathFactory factory = XPathFactory.newInstance();
        XPath xPathInstance = factory.newXPath();

        for (Configuration configuration : configs) {
            Properties properties = configuration.getProperties();
            Enumeration em = properties.keys();
            while (em.hasMoreElements()) {
                String insertQuery = "";
                String insertFieldQuery = "";

                String deleteQuery = "";
                String deleteFieldQuery = "";

                String tableName = "";
                String variableName = "";
                String defaultValue = "";

                String constructedQuery = "";
                String key = (String) em.nextElement();
                Object object = properties.get(key);

                // get config object for this key
                String xPathQuery = CONFIG_XPATH + key + CONFIG_XPATH_END_TAG;
                XPathExpression xPathExpression = xPathInstance.compile(xPathQuery);
                //evalute the xpath query in the entire xml document and define the return type
                Object results = xPathExpression.evaluate(doc, XPathConstants.NODESET);
                NodeList nList = (NodeList) results;

                // config objects
                for (int i = 0; i < nList.getLength(); i++) {
                    Node nNode = nList.item(i);
                    // get config object values
                    if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                        // getting child nodes to construct query
                        NodeList childNodes = nNode.getChildNodes();
                        for (int temp1 = 0; temp1 < childNodes.getLength(); temp1++) {
                            Node childNode = childNodes.item(temp1);
                            if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                                if (TABLE_NAME.equals(childNode.getNodeName())) {
                                    tableName = childNode.getTextContent();
                                    if (!VARIABLE_FIELD.equals(tableName)) {
                                        return;
                                    }
                                    deleteQuery = deleteQuery + DELETE_FROM + childNode.getTextContent() + WHERE
                                            + NAME_FIELD + EQUAL;
                                    insertQuery = insertQuery + INSERT_INTO + childNode.getTextContent()
                                            + VARIABLE_START_TAG + NAME_FIELD + SQL_VARIABLE_SEP + VALUE_FIELD
                                            + VARIABLE_END_TAG + VALUES_START_TAG;
                                } else if (VARIABLE_NAME.equals(childNode.getNodeName())) {
                                    variableName = childNode.getTextContent();
                                    deleteFieldQuery = SINGLE_QUOTE + childNode.getTextContent() + SINGLE_QUOTE
                                            + SEMI_COLON + LINE_BREAK;
                                } else if (CURRENT_VALUE.equals(childNode.getNodeName())) {
                                    childNode.setTextContent(object.toString());
                                }
                                defaultValue = object.toString();
                                insertFieldQuery = variableName + SQL_VALUE_SEP + defaultValue + VALUES_END_TAG;
                            }
                        }
                    }
                }

                constructedQuery = deleteQuery + deleteFieldQuery + insertQuery + insertFieldQuery;

                List<File> sqlFolders = getSqlFolders(featureSqlDir);
                for (File sqlFolder : sqlFolders) {
                    replaceSqlBlock(sqlFolder, CONFIGURATION + environmentName + DOT_SQL, key,
                            constructedQuery);
                }
            }
        }
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.transform(new DOMSource(doc), new StreamResult(featureManifestXmlFile.getPath()));
    } catch (Exception e) {
        throw new PhrescoException(e);
    }
}

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

private void mergeServices() throws MojoExecutionException {
    Properties propertiesServices;
    try {//w ww .  ja v a 2  s .  c  o  m
        propertiesServices = loadPropertiesFile(deploymentServices);
    } catch (Exception e) {
        throw new MojoExecutionException(PROPERTIES_SERVICES_LOAD_FAILURE + " '" + deploymentServices + "'", e);
    }

    Pattern patternElements = Pattern.compile("(\\w+(\\[[\\w -\\.\\/?]*\\])?)+");

    Enumeration<Object> e = propertiesServices.keys();
    while (e.hasMoreElements()) {
        String currentPath = "";

        String key = (String) e.nextElement();
        String value = propertiesServices.getProperty(key);

        Matcher matcherElements;
        Object parent = null;
        while ((matcherElements = patternElements.matcher(key)).find()) {
            String element = matcherElements.group();
            currentPath = currentPath + FLAT_PATH_SEPARATOR + element;

            parent = application.getElement(currentPath, element, value, parent);

            if (key.equals(element)) {
                break;
            }
            key = key.substring(element.length() + 1);
        }
    }

    try {
        application.removeDefaultBindingIfNotExists(loadPropertiesFile(deploymentServices));
    } catch (Exception ex) {
        throw new MojoExecutionException(PROPERTIES_SERVICES_LOAD_FAILURE + " '" + deploymentServices + "'",
                ex);
    }
    application.removeDuplicateBinding();
}

From source file:org.cesecore.certificates.ca.catoken.CAToken.java

/**
 * Internal method just to get rid of the always present date that is part of the standard Properties.store().
 * /*  w w w .jav  a  2  s  .  c om*/
 * @param prop
 * @return String that can be loaded by Properties.load
 */
private String storeProperties(Properties caTokenProperties) {
    this.keyStrings = new PurposeMapping(caTokenProperties);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(baos);
    Enumeration<Object> e = caTokenProperties.keys();
    while (e.hasMoreElements()) {
        Object s = e.nextElement();
        if (caTokenProperties.get(s) != null) {
            writer.println(s + "=" + caTokenProperties.get(s));
        }
    }
    writer.close();
    return baos.toString();
}