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:gov.nih.nci.cacisweb.util.CaCISUtil.java

/**
 * /* ww w .java  2s.  co m*/
 * @param propertyFileLocation
 * @param keyStoreLocation
 * @param keyStoreType
 * @param keyStorePassword
 * @return
 * @throws PropFileAndKeystoreOutOfSyncException
 */
public boolean isPropertyFileAndKeystoreInSync(String propertyFileLocation, String keyStoreLocation,
        String keyStoreType, String keyStorePassword) throws PropFileAndKeystoreOutOfSyncException {
    boolean isInSync = false;
    try {
        Properties configFile = new Properties();
        InputStream is = new FileInputStream(propertyFileLocation);
        configFile.load(is);
        is.close();
        KeyStore keystore = getKeystore(keyStoreLocation, keyStoreType, keyStorePassword);
        // Enumeration<String> keystoreEnumeration = keystore.aliases();
        // while (keystoreEnumeration.hasMoreElements()) {
        // String alias = (String) keystoreEnumeration.nextElement();
        // if (!configFile.containsKey(alias)) {
        // isInSync = false;
        // throw new PropFileAndKeystoreOutOfSyncException(String.format(
        // "Alias [%s] entry in key/trust store [%s] does not exist in the properties file [%s]. "
        // + "It is recommended that you manually correct this before proceeding", alias,
        // keyStoreLocation, propertyFileLocation));
        // }
        // }

        Enumeration<Object> propertyEnumeration = configFile.keys();
        while (propertyEnumeration.hasMoreElements()) {
            String property = (String) propertyEnumeration.nextElement();
            if (!keystore.containsAlias(property)) {
                isInSync = false;
                throw new PropFileAndKeystoreOutOfSyncException(String.format(
                        "Property [%s] entry in properties file [%s] does not exist in the key/trust store [%s]. "
                                + "It is recommended that you manually correct this before proceeding",
                        property, propertyFileLocation, keyStoreLocation));
            }
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new PropFileAndKeystoreOutOfSyncException(
                String.format("File [%] not found", propertyFileLocation));
    } catch (IOException e) {
        e.printStackTrace();
        throw new PropFileAndKeystoreOutOfSyncException(
                String.format("File [%] cannot be loaded.", propertyFileLocation));
    } catch (KeyStoreException e) {
        e.printStackTrace();
        throw new PropFileAndKeystoreOutOfSyncException(String
                .format("Error verifying the contents inside the key/trust store [%].", keyStoreLocation));
    } catch (KeystoreInstantiationException e) {
        e.printStackTrace();
        throw new PropFileAndKeystoreOutOfSyncException(e.getMessage());
    }
    return isInSync;
}

From source file:dk.defxws.fedoragsearch.server.Config.java

private void convertProperties(Properties props) {
    Enumeration<Object> it = props.keys();
    while (it.hasMoreElements()) {
        String propName = (String) it.nextElement();
        props.setProperty(propName, insertSystemProperties(props.getProperty(propName)));
    }/* ww w .  ja va 2 s. c  o m*/
}

From source file:org.alfresco.reporting.action.executer.ReportContainerExecutor.java

/**
 * Execute the single report/*from   w w  w  .j ava2 s  .c o m*/
 * 
 * @param reportRef the actual report
 * @param targetDocumentRef the new documnt to store the report into
 * @param outputType the type of report to generate (pdf or Excel)
 */
private void executeReportExecuter(final ReportTemplate report, final NodeRef targetDocumentRef,
        final Properties keyValues) {
    logger.debug("enter executeReportExecuter");
    logger.debug("  reportRef        : " + report.getNodeRef());
    logger.debug("  reportName       : " + report.getName());
    logger.debug("  targetDocumentRef: " + targetDocumentRef);
    logger.debug("  outputType       : " + report.getOutputFormat());
    logger.debug("  parameters       : " + keyValues);

    Action action = actionService.createAction(ReportExecuter.NAME);
    action.setParameterValue(ReportExecuter.OUTPUT_TYPE, report.getOutputFormat());
    action.setParameterValue(ReportExecuter.TARGET_DOCUMENT, targetDocumentRef);

    if (keyValues.size() > 0) {
        action.setParameterValue(ReportExecuter.SEPARATOR, Constants.SEPARATOR);

        Enumeration keys = keyValues.keys();

        //Properties namespaces = reportingHelper.getNameSpacesShortToLong();
        /*
        Collection<String> nameSpaceKeys = namespaceService.getURIs();
        for (String myKey:nameSpaceKeys){
           String myValue = namespaceService.getNamespaceURI(myKey);
           logger.debug("Found value: "+ myValue+"  namespacekey: " + myKey);
        }
        */

        int i = 0;
        while (keys.hasMoreElements()) {
            i++;
            String key = (String) keys.nextElement();

            String pushString = key + Constants.SEPARATOR + keyValues.getProperty(key, "");

            logger.debug("Setting report parameter " + key + " = " + keyValues.getProperty(key, ""));

            if (i == 1)
                action.setParameterValue(ReportExecuter.PARAM_1, pushString);
            if (i == 2)
                action.setParameterValue(ReportExecuter.PARAM_2, pushString);
            if (i == 3)
                action.setParameterValue(ReportExecuter.PARAM_3, pushString);
            if (i == 4)
                action.setParameterValue(ReportExecuter.PARAM_4, pushString);

        } // end while key.hasMoreElements
    }

    actionService.executeAction(action, report.getNodeRef());
    logger.debug("Exit executeReportExecuter");
}

From source file:br.org.indt.ndg.client.Service.java

public Collection<PreferenceVO> listPreferences() throws NDGServerException {
    try {/*from   www.  j  ava  2s . com*/
        MSMBusinessDelegate msmBD = new MSMBusinessDelegate();
        Properties p = msmBD.getSettings();

        //Get Hashtable Enumeration to get key and value
        Enumeration keyEnum = p.keys();

        ArrayList<PreferenceVO> list = new ArrayList<PreferenceVO>();
        while (keyEnum.hasMoreElements()) {
            //nextElement is used to get key of hashtable
            String key = (String) keyEnum.nextElement();

            //get is used to get value of key in hashtable
            String value = (String) p.get(key);
            PreferenceVO bean = new PreferenceVO();
            bean.setPreference(key);
            bean.setValue(value);
            list.add(bean);
        }
        return list;
    } catch (MSMApplicationException e) {
        e.printStackTrace();
        throw new NDGServerException(e.getErrorCode());
    }
}

From source file:org.rhq.bundle.ant.AntMain.java

/**
 * Start Ant// w  w  w .  j a  va2  s  .c om
 * @param args command line args
 * @param additionalUserProperties properties to set beyond those that
 *        may be specified on the args list
 * @param coreLoader - not used
 *
 * @since Ant 1.6
 */
public void startAnt(String[] args, Properties additionalUserProperties, ClassLoader coreLoader) {
    try {
        Diagnostics.validateVersion();
        processArgs(args);
    } catch (Throwable exc) {
        handleLogfile();
        printMessage(exc);
        exit(1);
        return;
    }

    if (additionalUserProperties != null) {
        for (Enumeration e = additionalUserProperties.keys(); e.hasMoreElements();) {
            String key = (String) e.nextElement();
            String property = additionalUserProperties.getProperty(key);
            definedProps.put(key, property);
        }
    }

    // expect the worst
    int exitCode = 1;
    try {
        try {
            runBuild(coreLoader);
            exitCode = 0;
        } catch (ExitStatusException ese) {
            exitCode = ese.getStatus();
            if (exitCode != 0) {
                throw ese;
            }
        }
    } catch (BuildException be) {
        if (err != System.err) {
            printMessage(be);
        }
    } catch (Throwable exc) {
        exc.printStackTrace();
        printMessage(exc);
    } finally {
        handleLogfile();
    }
    exit(exitCode);
}

From source file:nl.imvertor.common.Configurator.java

/**
 * Read property file used to represent cli parameters, and put these in the work configuration.
 * Do not override existing property values.
 * //w ww.j  ava 2  s .co  m
 * Property file may also have an arguments property, set to a comma-separated list of relative paths to other property files to be included, in that order.
 * 
 * The file is located relative to the property file holding the include statement. 
 * If not available, it is assume it is available in the props folder of the managed input folder.
 * If not found there, an exception is raised. 
 * 
 * @param filePath
 * @throws Exception 
 */
private void loadFromPropertyFile(String filePath) throws Exception {
    File f = getFile(filePath);
    runner.debug(logger, "Reading property file " + f.getCanonicalPath());
    Properties properties = new Properties();
    FileInputStream s = new FileInputStream(f);
    BufferedReader in = new BufferedReader(new InputStreamReader(s, "UTF-8"));
    properties.load(in);
    s.close();

    // read arguments first
    String arguments = properties.getProperty("arguments");
    if (arguments != null)
        loadFromPropertyFiles(f, arguments);

    // then process the arguments
    Enumeration<Object> e = properties.keys();
    while (e.hasMoreElements()) {
        String optionName = e.nextElement().toString();
        String value = properties.getProperty(optionName);
        // process file properties in context of the current file
        if (optionName.equals("umlfile") | optionName.equals("zipfile") | optionName.equals("hisfile")) {
            File parent = (new File(filePath)).getParentFile();
            if (AnyFile.isAbsolutePath(value))
                value = (new File(value)).getCanonicalPath();
            else
                value = (new File(parent, value)).getCanonicalPath();
        }
        setParm(workConfiguration, "cli", optionName, value, true);
        setOptionIsReady(optionName, true);

    }
}

From source file:dk.defxws.fedoragsearch.server.Config.java

private void checkPropNames(String propsFileName, Properties props, String[] propNames) {
    //      Check for unknown properties, indicating typos or wrong property names
    Enumeration it = props.keys();
    while (it.hasMoreElements()) {
        String propName = (String) it.nextElement();
        //MIH: replace system-property-names
        props.setProperty(propName, insertSystemProperty(props.getProperty(propName)));
        for (int i = 0; i < propNames.length; i++) {
            if (propNames[i].equals(propName)) {
                propName = null;//from  ww  w  . j av  a  2 s . com
            }
        }
        if (propName != null) {
            errors.append("\n*** unknown config property in " + propsFileName + ": " + propName);
        }
    }
}

From source file:com.aliyun.odps.conf.Configuration.java

/**
 * ?? {@link OutputStream}//from w  w w.j av  a2  s.  c om
 *
 * @param out
 *     {@link OutputStream}
 */
@SuppressWarnings("rawtypes")
public void writeXml(OutputStream out) throws IOException {
    Properties properties = getProps();
    try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element conf = doc.createElement("configuration");
        doc.appendChild(conf);
        conf.appendChild(doc.createTextNode("\n"));
        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            Object object = properties.get(name);
            String value = null;
            if (object instanceof String) {
                value = (String) object;
            } else {
                continue;
            }
            Element propNode = doc.createElement("property");
            conf.appendChild(propNode);

            Element nameNode = doc.createElement("name");
            nameNode.appendChild(doc.createTextNode(name));
            propNode.appendChild(nameNode);

            Element valueNode = doc.createElement("value");
            valueNode.appendChild(doc.createTextNode(value));
            propNode.appendChild(valueNode);

            conf.appendChild(doc.createTextNode("\n"));
        }

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(out);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.alfresco.reporting.action.executer.ReportContainerExecuter.java

/**
 * Execute the single report/*from ww  w . j ava2 s . c  om*/
 * 
 * @param reportRef
 *            the actual report
 * @param targetDocumentRef
 *            the new documnt to store the report into
 * @param outputType
 *            the type of report to generate (pdf or Excel)
 */
private void executeReportExecuter(final ReportTemplate report, final NodeRef targetDocumentRef,
        final Properties keyValues) {
    if (logger.isDebugEnabled()) {
        logger.debug("enter executeReportExecuter");
        logger.debug("  reportRef        : " + report.getNodeRef());
        logger.debug("  reportName       : " + report.getName());
        logger.debug("  targetDocumentRef: " + targetDocumentRef);
        logger.debug("  outputType       : " + report.getOutputFormat());
        logger.debug("  parameters       : " + keyValues);
    }

    Action action = actionService.createAction(ReportExecuter.NAME);
    action.setParameterValue(ReportExecuter.OUTPUT_TYPE, report.getOutputFormat());
    action.setParameterValue(ReportExecuter.TARGET_DOCUMENT, targetDocumentRef);

    if (keyValues.size() > 0) {
        action.setParameterValue(ReportExecuter.SEPARATOR, Constants.SEPARATOR);

        Enumeration keys = keyValues.keys();

        // Properties namespaces =
        // reportingHelper.getNameSpacesShortToLong();
        /*
         * Collection<String> nameSpaceKeys = namespaceService.getURIs();
         * for (String myKey:nameSpaceKeys){ String myValue =
         * namespaceService.getNamespaceURI(myKey); logger.debug(
         * "Found value: "+ myValue+"  namespacekey: " + myKey); }
         */

        int i = 0;
        while (keys.hasMoreElements()) {
            i++;
            String key = (String) keys.nextElement();

            String pushString = key + Constants.SEPARATOR + keyValues.getProperty(key, "");

            if (logger.isDebugEnabled())
                logger.debug("Setting report parameter " + key + " = " + keyValues.getProperty(key, ""));

            if (i == 1)
                action.setParameterValue(ReportExecuter.PARAM_1, pushString);
            if (i == 2)
                action.setParameterValue(ReportExecuter.PARAM_2, pushString);
            if (i == 3)
                action.setParameterValue(ReportExecuter.PARAM_3, pushString);
            if (i == 4)
                action.setParameterValue(ReportExecuter.PARAM_4, pushString);

        } // end while key.hasMoreElements
    }

    actionService.executeAction(action, report.getNodeRef());
    if (logger.isDebugEnabled())
        logger.debug("Exit executeReportExecuter");
}

From source file:org.webdavaccess.LocalFileSystemStorage.java

private void saveCustomProperties(Properties newProperties, String resourceUri) {
    if (newProperties == null || newProperties.size() == 0)
        return;//from ww w  .ja v a2 s .c om

    resourceUri = normalize(resourceUri);
    File file = getPropertiesFile(resourceUri);
    if (file == null)
        return;
    Properties persisted = new Properties();
    // Properties file exists, load it so we can add new properties
    if (file.exists()) {
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            persisted.loadFromXML(in);
        } catch (Exception e) {
            log.warn("Failed to get properties from cache for " + resourceUri);
            return;
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (Exception e) {
                }
        }
    }
    // Add new properties with key format of: resourceUri + "|" + key
    Enumeration en = newProperties.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        persisted.setProperty(getResourcePropertyKey(resourceUri, key), newProperties.getProperty(key));
    }
    // Store the updates properties
    OutputStream os = null;
    try {
        os = new FileOutputStream(file);
        persisted.storeToXML(os, "");
    } catch (Exception e) {
        log.warn("Failed to store properties for " + resourceUri);
    } finally {
        if (os != null)
            try {
                os.close();
            } catch (Exception e) {
            }
    }
}