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.apache.rahas.impl.SAMLTokenIssuerConfig.java

/**
 * Set crypto information using WSS4J mechanisms
 * // w  ww .  j  av a2 s .  c  o m
 * @param providerClassName
 *            Provider class - an implementation of
 *            org.apache.ws.security.components.crypto.Crypto
 * @param props Configuration properties
 */
public void setCryptoProperties(String providerClassName, Properties props) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    this.cryptoPropertiesElement = fac.createOMElement(CRYPTO_PROPERTIES);
    OMElement cryptoElem = fac.createOMElement(CRYPTO, this.cryptoPropertiesElement);
    cryptoElem.addAttribute(PROVIDER.getLocalPart(), providerClassName, null);
    Enumeration keys = props.keys();
    while (keys.hasMoreElements()) {
        String prop = (String) keys.nextElement();
        String value = (String) props.get(prop);
        OMElement propElem = fac.createOMElement(PROPERTY, cryptoElem);
        propElem.setText(value);
        propElem.addAttribute("name", prop, null);
    }
}

From source file:org.apache.pig.backend.hadoop.executionengine.MRExecutionEngine.java

/**
 * Method to apply pig properties to JobConf (replaces properties with
 * resulting jobConf values)//from ww w. j a  v  a2 s  . c om
 * 
 * @param conf
 *            JobConf with appropriate hadoop resource files
 * @param properties
 *            Pig properties that will override hadoop properties;
 *            properties might be modified
 */
@SuppressWarnings("deprecation")
protected void recomputeProperties(JobConf jobConf, Properties properties) {
    // We need to load the properties from the hadoop configuration
    // We want to override these with any existing properties we have.
    if (jobConf != null && properties != null) {
        // set user properties on the jobConf to ensure that defaults
        // and deprecation is applied correctly
        Enumeration<Object> propertiesIter = properties.keys();
        while (propertiesIter.hasMoreElements()) {
            String key = (String) propertiesIter.nextElement();
            String val = properties.getProperty(key);
            // We do not put user.name, See PIG-1419
            if (!key.equals("user.name"))
                jobConf.set(key, val);
        }
        // clear user defined properties and re-populate
        properties.clear();
        Iterator<Map.Entry<String, String>> iter = jobConf.iterator();
        while (iter.hasNext()) {
            Map.Entry<String, String> entry = iter.next();
            properties.put(entry.getKey(), entry.getValue());
        }
    }
}

From source file:org.smartfrog.avalanche.client.sf.apps.ca.InstallCA.java

public void configureCA(Properties props) throws CAException {

    File confLoc = new File(confFile);
    InputStream fis = null;/*from   ww w  .jav  a 2s. c  om*/

    try {
        log.info("Template file : " + confFileTmpl);
        fis = getClass().getResourceAsStream(confFileTmpl);
        DiskUtils.fCopy(fis, confLoc);
    } catch (FileNotFoundException fnfe) {
        log.error(fnfe);
        throw new CAException(fnfe);
    } catch (IOException ioe) {
        log.error(ioe);
        throw new CAException(ioe);
    }

    Enumeration confKeys = props.keys();
    TxtFileHelper txtEdit = new TxtFileHelper(confFile);

    try {
        while (confKeys.hasMoreElements()) {
            String key = (String) confKeys.nextElement();
            String value = props.getProperty(key);
            if (key.equals("emailAddress"))
                txtEdit.changeValueAfter("=", key, value, 3);
            else
                txtEdit.changeValueAfter("=", key, value);
        }
    } catch (FileNotFoundException fnfe) {
        log.error(fnfe);
        throw new CAException(fnfe);
    } catch (IOException ioe) {
        log.error(ioe);
        throw new CAException(ioe);
    }

    //Create the necessary dir structure for CA
    try {
        createDirStruct();
    } catch (FileNotFoundException fnfe) {
        log.error(fnfe);
        throw new CAException(fnfe);
    } catch (IOException ioe) {
        log.error(ioe);
        throw new CAException(ioe);
    }

    gridSecurityConf(props);
}

From source file:com.glaf.core.config.DBConfiguration.java

public static ConnectionDefinition toConnectionDefinition(Properties props) {
    if (props != null && !props.isEmpty()) {
        ConnectionDefinition model = new ConnectionDefinition();
        model.setDatasource(props.getProperty(JDBC_DATASOURCE));
        model.setDriver(props.getProperty(JDBC_DRIVER));
        model.setUrl(props.getProperty(JDBC_URL));
        model.setName(props.getProperty(JDBC_NAME));
        model.setUser(props.getProperty(JDBC_USER));
        model.setPassword(props.getProperty(JDBC_PASSWORD));
        model.setSubject(props.getProperty(SUBJECT));
        model.setProvider(props.getProperty(JDBC_PROVIDER));
        model.setType(props.getProperty(JDBC_TYPE));
        model.setHost(props.getProperty(HOST));
        model.setDatabase(props.getProperty(DATABASE));
        if (StringUtils.isNotEmpty(props.getProperty(PORT))) {
            model.setPort(Integer.parseInt(props.getProperty(PORT)));
        }/*  w  w w  .j a v  a2  s .  co  m*/

        if (StringUtils.equals("true", props.getProperty(JDBC_AUTOCOMMIT))) {
            model.setAutoCommit(true);
        }

        Properties p = new Properties();
        Enumeration<?> e = props.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String value = props.getProperty(key);
            p.put(key, value);
        }
        model.setProperties(p);
        return model;
    }
    return null;
}

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

/**
 * <p>//  ww w . jav a2  s  . c  o  m
 * This expands wild cards properties.<br /><br />
 * Both wildcard expressions and expressions to expand are present in the
 * same properties object.<br /><br />
 * <i>Example</i>
 *  <ul>
 *     <li><b>property with wildcard</b>: /root/element[*]/key=new_value</li>
 *     <li><b>property matching</b>: /root/element[my_name]/key=old_value</li>
 *  </ul>
 *  will expand to:<br />
 *  <ul>
 *     <li><b>property after expansion</b>:
 * /root/element[my_name]/key=new_value</li>
 *  </ul>
 * </p>
 * 
 * @param properties, the properties object with wildcard expressions and
 * expressions to expand
 * @return properties with expanded expressions, but without wildcard
 * expressions
 */
protected Properties expandWildCards(Properties properties) {
    Properties propertiesWithWildCards = new Properties() { // sorted properties
        private static final long serialVersionUID = 7793482336210629858L;

        @Override
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    String key;

    // retrieve the keys with WildCards
    Enumeration<Object> e = properties.keys();
    while (e.hasMoreElements()) {
        key = (String) e.nextElement();
        if (isAWildCard(key)) {
            propertiesWithWildCards.setProperty(key, properties.getProperty(key));
            properties.remove(key);
        }
    }

    // try to replace the values of other keys matching the keys with WildCards
    Enumeration<Object> w = propertiesWithWildCards.keys();
    while (w.hasMoreElements()) {
        String keyWithWildCards = (String) w.nextElement();
        String regex = wildcardToRegex(keyWithWildCards);

        String ignoreWildcardInVariablesPattern = "(.*)variables\\\\\\[(.*)\\\\\\]\\/variable\\\\\\[(.*)\\\\\\](.*)";
        Pattern p = Pattern.compile(ignoreWildcardInVariablesPattern);
        Matcher m = p.matcher(regex);
        if (m.matches()) {
            String variables = m.group(2);
            String variable = m.group(3);
            variables = variables.replace(".*", "\\*");
            variable = variable.replace(".*", "\\*");
            regex = m.group(1) + "variables\\[" + variables + "\\]/variable\\[" + variable + "\\]" + m.group(4);
        }

        Boolean found = false;

        e = properties.keys();
        while (e.hasMoreElements()) {
            key = (String) e.nextElement();

            if (Pattern.matches(regex, key)) {
                found = true;
                String value = (String) propertiesWithWildCards.getProperty(keyWithWildCards);
                properties.setProperty(key, value);
            }
        }

        // not found, we put back the expression with wild cards in the original list (false positive)
        // this way the wildcard can still be used in a next pass and will be removed at the end by AbstractPackagingMojo.removeWildCards 
        if (!found) {
            properties.setProperty(keyWithWildCards, propertiesWithWildCards.getProperty(keyWithWildCards));
        }
    }

    return properties;
}

From source file:org.kchine.rpf.PoolUtils.java

private static void injectSystemProperties(InputStream is, boolean override) {
    if (is != null) {
        try {/*w  w w  . java 2  s.  co  m*/
            Properties props = new Properties();

            props.loadFromXML(is);

            System.out.println("Properties : " + props);

            Enumeration<Object> keys = props.keys();
            while (keys.hasMoreElements()) {
                String key = (String) keys.nextElement();
                boolean setProp = override || System.getProperty(key) == null
                        || System.getProperty(key).equals("");
                if (setProp)
                    System.setProperty(key, props.getProperty(key));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.cloudata.core.common.conf.CloudataConf.java

/** Writes non-default properties in this configuration.*/
public void write(OutputStream out) throws IOException {
    Properties properties = getProps();
    try {//w  w  w  . jav a  2 s .  c  om
        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.apache.james.fetchmail.FetchMail.java

private void logJavaMailProperties() {
    // if debugging, list the JavaMail property key/value pairs
    // for this Session
    if (logger.isDebugEnabled()) {
        logger.debug("Session properties:");
        Properties properties = getSession().getProperties();
        Enumeration<Object> e = properties.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String val = (String) properties.get(key);
            if (val.length() > 40) {
                val = val.substring(0, 37) + "...";
            }/*from ww w .j  ava  2  s  .  c o  m*/
            logger.debug(key + "=" + val);

        }
    }
}

From source file:org.wso2.carbon.utils.i18n.ResourceBundle.java

/**
 * Merge two Properties objects/* w w  w.  j  a  v a  2  s.c  o  m*/
 */
protected Properties merge(Properties p1, Properties p2) {
    if ((p1 == null) && (p2 == null)) {
        return null;
    } else if (p1 == null) {
        return p2;
    } else if (p2 == null) {
        return p1;
    }

    // Now merge. p1 takes precedence
    Enumeration enumeration = p2.keys();
    while (enumeration.hasMoreElements()) {
        String key = (String) enumeration.nextElement();
        if (p1.getProperty(key) == null) {
            p1.put(key, p2.getProperty(key));
        }
    }

    return p1;
}

From source file:com.netscape.admin.certsrv.Console.java

/**
  * main routine. It will pass the command line parameters then call the Console constructor
  * to create a console instance.// www .j av  a2s.  c om
  *
  * @param parameters list
  */

public static void mainImpl(String argv[]) throws Exception {

    Options options = new Options();

    Option option = new Option("f", true, "Capture stderr and stdout to file.");
    option.setArgName("file");
    options.addOption(option);

    option = new Option("D", true, "Debug options.");
    option.setArgName("options");
    options.addOption(option);

    option = new Option("x", true, "Extra options (javalaf, nowinpos, nologo).");
    option.setArgName("options");
    options.addOption(option);

    options.addOption("v", "verbose", false, "Run in verbose mode.");
    options.addOption("h", "help", false, "Show help message.");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, argv);

    String[] cmdArgs = cmd.getArgs();

    verbose = cmd.hasOption("verbose");

    String outFile = cmd.getOptionValue("f");
    if (outFile != null) {
        try {
            TeeStream.tee(outFile);
        } catch (Exception e) {
            System.err.println("Missing or invalid output file specification for the -f option: " + e);
            System.exit(1);
        }
    }

    if (cmd.hasOption("D")) {
        Debug.setApplicationStartTime(_t0);
        String extraParam = cmd.getOptionValue("D");
        if (!extraParam.isEmpty()) {
            if (extraParam.equals("?") || !Debug.setTraceMode(extraParam)) {
                System.out.println(Debug.getUsage());
                waitForKeyPress(); // allow the user to read the msg on Win NT
                System.exit(0);
            }
        } else {
            Debug.setTraceMode(null);
        }

        // Show all system proprties if debug level is 9
        if (Debug.getTraceLevel() == 9) {
            try {
                Properties props = System.getProperties();
                for (Enumeration<Object> e = props.keys(); e.hasMoreElements();) {
                    String key = (String) e.nextElement();
                    String val = (String) props.get(key);
                    Debug.println(9, key + "=" + val);
                }
            } catch (Exception e) {
            }
        }
    }

    if (cmdArgs.length != 1 || cmd.hasOption("help")) {
        printHelp();
        waitForKeyPress(); // allow the user to read the msg on Win NT
        return;
    }

    Debug.println(0, "Management-Console/" + _resource.getString("console", "displayVersion") + " B"
            + VersionInfo.getBuildNumber());

    if (cmd.hasOption("x")) {
        String extraParam = cmd.getOptionValue("x");
        boolean supportedOption = false;

        if (extraParam.indexOf(OPTION_NOLOGO) != -1) {
            _showSplashScreen = false;
            supportedOption = true;
        }
        if (extraParam.indexOf(OPTION_NOWINPOS) != -1) {
            Framework.setEnableWinPositioning(false);
            supportedOption = true;
        }
        if (extraParam.indexOf(OPTION_JAVALAF) != -1) {
            _useJavaLookAndFeel = true;
            supportedOption = true;
        }

        if (supportedOption == false) {
            printHelp();
            waitForKeyPress(); // allow the user to read the msg on Win NT
            System.exit(0);
        }
    }

    String sAdminURL = cmdArgs[0];

    ConsoleInfo cinfo = new ConsoleInfo();
    CMSAdmin admin = new CMSAdmin();
    URL url = null;
    try {
        url = new URL(sAdminURL);
    } catch (Exception e) {
        String es = e.toString();
        String ep = "java.net.MalformedURLException:";
        if (es != null && es.startsWith(ep)) {
            es = es.substring(ep.length());
        }
        System.err.println("\nURL error: " + es + "\n");
        waitForKeyPress(); // allow the user to read the msg on Win NT
        System.exit(1);
    }
    if (url == null) {
        System.err.println("\nIncorrect URL: " + sAdminURL + "\n");
        waitForKeyPress(); // allow the user to read the msg on Win NT
        System.exit(1);
    }
    cinfo.put("cmsServerInstance", "instanceID");

    String protocol = url.getProtocol();
    String hostName = url.getHost();
    String path = url.getPath();
    /* Protocol part of URL is required only by URL class. Console assumes URL protocol. */
    if (protocol == null || protocol.length() == 0
            || ((!protocol.equalsIgnoreCase("https")) && (!protocol.equalsIgnoreCase("http")))) {
        System.err.println(
                "\nIncorrect protocol" + ((protocol != null && protocol.length() > 0) ? ": " + protocol : ".")
                        + "\nDefault supported protocol is 'https'.\n");
        waitForKeyPress(); // allow the user to read the msg on Win NT
        System.exit(1);
    }

    if (hostName == null || hostName.length() == 0) {
        System.err.println("\nMissing hostName: " + sAdminURL + "\n");
        waitForKeyPress(); // allow the user to read the msg on Win NT
        System.exit(1);
    }
    if (path == null || path.length() < 2) {
        System.err.println("\nMissing URL path: " + sAdminURL
                + "\nDefault supported URL paths are 'ca', 'kra', 'ocsp', and 'tks'.\n");
        waitForKeyPress(); // allow the user to read the msg on Win NT
        System.exit(1);
    }
    path = path.substring(1);
    if ((!path.equals("ca")) && (!path.equals("kra")) && (!path.equals("ocsp")) && (!path.equals("tks"))) {
        System.err.println("\nWarning: Potentially incorrect URL path: " + path
                + "\n         Default supported URL paths are 'ca', 'kra', 'ocsp', and 'tks'.\n");
    }
    int portNumber = url.getPort();
    if (portNumber < 0) {
        System.err.println("\nWarning: Unspecified port number: " + sAdminURL + "\n");
        /* Add warning about using non default port numbers after port separation is done.
                       "\n         Default port number is 9443.\n");
        } else if (portNumber != 9443) {
            System.err.println("\nWarning: Attempt to connect to non default port number: "+sAdminURL+
                       "\n         Default port number is 9443.\n");
        */
    }

    UtilConsoleGlobals.initJSS();

    ClientConfig config = new ClientConfig();
    config.setServerURL(protocol, hostName, portNumber);

    PKIClient client = new PKIClient(config);

    InfoClient infoClient = new InfoClient(client);
    Info info = infoClient.getInfo();
    String banner = info.getBanner();

    if (banner != null) {

        System.out.println(banner);
        System.out.println();
        System.out.print("Do you want to proceed (y/N)? ");
        System.out.flush();

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine().trim();

        if (!line.equalsIgnoreCase("Y")) {
            return;
        }
    }

    cinfo.put("cmsHost", url.getHost());
    cinfo.put("cmsPort", Integer.toString(portNumber));
    cinfo.put("cmsPath", path);
    admin.initialize(cinfo);
    admin.run(null, null);
    /*
            _console = new Console(sAdminURL, localAdminURL, sLang, host, uid, password);
    */
}