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:fr.fastconnect.factory.tibco.bw.maven.packaging.MergePropertiesMojo.java

private Properties removeEmptyBindings(Properties properties) {
    ArrayList<String> pars = new ArrayList<String>();

    Pattern pNotEmptyBinding = Pattern.compile(regexNotEmptyBinding);
    Pattern pEmptyBinding = Pattern.compile(regexEmptyBinding);
    String parName;/*from w  ww .  j a  v  a2  s  . c o  m*/

    Enumeration<Object> e = properties.keys();
    // first check if there is at least one non empty binding (non default)
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        Matcher mNotEmptyBinding = pNotEmptyBinding.matcher(key);
        if (mNotEmptyBinding.matches()) {
            parName = mNotEmptyBinding.group(1);
            if (pars.contains(parName))
                continue;
            pars.add(parName);
        }
    }
    // then delete
    e = properties.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        Matcher mEmptyBinding = pEmptyBinding.matcher(key);
        if (mEmptyBinding.matches()) {
            parName = mEmptyBinding.group(1);
            if (pars.contains(parName)) {
                properties.remove(key);
            }
        }
    }

    return properties;
}

From source file:org.sipfoundry.sipxconfig.admin.CertificateManagerImpl.java

public Properties loadCertPropertiesFile() {
    File propertiesFile = new File(m_certDirectory, PROPERTIES_FILE);
    try {/*from   w w w.  ja va 2 s  .c  o  m*/
        FileInputStream propertiesStream = new FileInputStream(propertiesFile);
        Properties properties = new Properties();
        properties.load(propertiesStream);
        Enumeration<Object> propertiesEnum = properties.keys();
        while (propertiesEnum.hasMoreElements()) {
            String key = (String) propertiesEnum.nextElement();
            String value = properties.getProperty(key);
            value = StringUtils.strip(value, DOUBLE_QUOTES);
            properties.setProperty(key, value);
        }
        return properties;
    } catch (FileNotFoundException e) {
        return null;
    } catch (IOException e) {
        throw new UserException(READ_ERROR, propertiesFile.getPath());
    }
}

From source file:com.krawler.esp.utils.ConfigReader.java

/** Writes non-default properties in this configuration. */
public void write(OutputStream out) throws IOException {
    Properties properties = getProps();
    try {/*from  w w  w  .  j  a v  a 2s  .  c o m*/
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element conf = doc.createElement("krawler-conf");
        doc.appendChild(conf);
        conf.appendChild(doc.createTextNode("\n"));
        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            String value = (String) properties.get(name);

            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:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java

private void createMiscElement(final Element docRoot) {
    final Properties nonStandardProperties = Constant.calcNonStandardProperties(buildMetaDataProperties,
            selectedProperties);//from   ww w.j  ava2  s . c  o  m
    if (!nonStandardProperties.isEmpty()) {
        final Element parent = document.createElement("misc");

        for (final Enumeration<Object> en = nonStandardProperties.keys(); en.hasMoreElements();) {
            final String key = String.valueOf(en.nextElement());
            createMetaDataElement(parent, key);
        }
        docRoot.appendChild(parent);
    }
}

From source file:org.sipfoundry.sipxconfig.admin.CertificateManagerImpl.java

public void writeCertPropertiesFile(Properties properties) {
    File propertiesFile = new File(m_certDirectory, PROPERTIES_FILE);
    try {/*from  w w w .  ja  va 2  s  .co  m*/
        Enumeration<Object> propertiesEnum = properties.keys();
        while (propertiesEnum.hasMoreElements()) {
            String key = (String) propertiesEnum.nextElement();
            String value = properties.getProperty(key);
            value = DOUBLE_QUOTES + value + DOUBLE_QUOTES;
            properties.setProperty(key, value);
        }
        FileOutputStream propertiesStream = new FileOutputStream(propertiesFile);
        properties.store(propertiesStream, null);
    } catch (IOException e) {
        throw new UserException(WRITE_ERROR, propertiesFile.getPath());
    }
}

From source file:org.apache.jmeter.JMeterReport.java

/** {@inheritDoc} */
@Override/*from   w w w. ja  v  a2 s.  c o  m*/
public String[][] getIconMappings() {
    String iconProp = JMeterUtils.getPropDefault("jmeter.icons", "org/apache/jmeter/images/icon.properties");
    Properties p = JMeterUtils.loadProperties(iconProp);
    if (p == null) {
        log.info(iconProp + " not found - using default icon set");
        return DEFAULT_ICONS;
    }
    log.info("Loaded icon properties from " + iconProp);
    String[][] iconlist = new String[p.size()][3];
    Enumeration<Object> pe = p.keys();
    int i = 0;
    while (pe.hasMoreElements()) {
        String key = (String) pe.nextElement();
        String icons[] = JOrphanUtils.split(p.getProperty(key), " ");
        iconlist[i][0] = key;
        iconlist[i][1] = icons[0];
        if (icons.length > 1) {
            iconlist[i][2] = icons[1];
        }
        i++;
    }
    return iconlist;
}

From source file:org.openmrs.web.servlet.LoginServlet.java

/**
 * Regenerates session id after each login attempt.
 * @param request//  w  w  w  .  j av a2 s. c o  m
 */
private void regenerateSession(HttpServletRequest request) {

    HttpSession oldSession = request.getSession();

    Enumeration attrNames = oldSession.getAttributeNames();
    Properties props = new Properties();

    if (attrNames != null) {
        while (attrNames.hasMoreElements()) {
            String key = (String) attrNames.nextElement();
            props.put(key, oldSession.getAttribute(key));
        }

        //Invalidating previous session
        oldSession.invalidate();
        //Generate new session
        HttpSession newSession = request.getSession(true);
        attrNames = props.keys();

        while (attrNames.hasMoreElements()) {
            String key = (String) attrNames.nextElement();
            newSession.setAttribute(key, props.get(key));
        }
    }
}

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

/**
 * Loads affintiies loaders from JEM configuration.
 *//*from   w w  w. j  a  v  a2 s  .  c o  m*/
private static void loadDynamicAffinities() throws ConfigurationException {
    // load factories, checking if they are configured. If not, exception
    // occurs
    AffinityFactory affinityFactory = JEM_NODE_CONFIG.getExecutionEnviroment().getAffinityFactory();
    if (affinityFactory != null) {

        // load all factories for affinity factory
        // for all factories checking which have the right className. If
        // not,
        // exception occurs, otherwise it's loaded
        if (affinityFactory.getClassName() != null) {
            String className = affinityFactory.getClassName();
            try {
                // load by Class.forName of loader
                Object objectFactory = Class.forName(className).newInstance();

                // check if it's a AffinityLoader. if not, exception occurs.
                if (objectFactory instanceof AffinityLoader) {
                    AffinityLoader loader = (AffinityLoader) objectFactory;

                    // gets properties defined. If not empty, substitutes
                    // the value of property with variables
                    Properties propsOfFactory = affinityFactory.getProperties();
                    if (!propsOfFactory.isEmpty()) {
                        // scans all properties
                        for (Enumeration<Object> e = propsOfFactory.keys(); e.hasMoreElements();) {
                            // gets key and value
                            String key = e.nextElement().toString();
                            String value = propsOfFactory.getProperty(key);
                            // substitutes variables if present
                            // and sets new value for the key
                            propsOfFactory.setProperty(key, substituteVariable(value));
                        }
                    }
                    LogAppl.getInstance().emit(NodeMessage.JEMC049I, className);
                    // initializes the factory with properties defined
                    // and puts in the list if everything went good
                    loader.init(propsOfFactory);
                    // locks the access to file to avoid multiple accesses

                    Result result = loader.load(new SystemInfo());
                    if (result != null) {
                        Main.EXECUTION_ENVIRONMENT.getDynamicAffinities().addAll(result.getAffinities());
                        Main.EXECUTION_ENVIRONMENT.setMemory(result.getMemory());
                        Main.EXECUTION_ENVIRONMENT.setParallelJobs(result.getParallelJobs());
                    }
                    Main.setAffinityLoader(loader);
                } else {
                    LogAppl.getInstance().emit(NodeMessage.JEMC089E, className);
                }

            } catch (Exception e) {
                LogAppl.getInstance().emit(NodeMessage.JEMC031E, e, className);
            }
            // in this case the class name is null so ignore, emitting a
            // warning
        } else {
            LogAppl.getInstance().emit(NodeMessage.JEMC038W, ConfigKeys.FACTORY_ALIAS,
                    affinityFactory.toString());
        }
    }
    LogAppl.getInstance().emit(NodeMessage.JEMC050I, Main.EXECUTION_ENVIRONMENT);
}

From source file:org.codehaus.mojo.webtest.components.AntExecutor.java

/**
 * Run an ANT script within the JVM..//from   w w  w  . jav  a 2  s. c om
 *
 * @param antFile        the ANT scripts to be executed
 * @param userProperties the properties to be set for the ANT script
 * @param mavenProject   the current maven project
 * @param artifacts      the list of dependencies
 * @param target         the ANT target to be executed
 * @throws DependencyResolutionRequiredException
 *                        not dependencies were resolved
 * @throws BuildException the build failed
 */
public AntExecutor(File antFile, Properties userProperties, MavenProject mavenProject, List artifacts,
        String target) throws BuildException, DependencyResolutionRequiredException {
    File antBaseDir = antFile.getParentFile();

    Project antProject = new Project();

    antProject.init();
    antProject.addBuildListener(this.createLogger());
    antProject.setBaseDir(antBaseDir);

    ProjectHelper2.configureProject(antProject, antFile);
    // ProjectHelper2 projectHelper = new ProjectHelper2();
    // projectHelper.parse( antProject, antFile );

    Enumeration propertyKeys = userProperties.keys();
    while (propertyKeys.hasMoreElements()) {
        String key = (String) propertyKeys.nextElement();
        String value = userProperties.getProperty(key);
        antProject.setUserProperty(key, value);
    }

    // NOTE: from maven-antrun-plugin

    Path p = new Path(antProject);
    p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator));

    /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
    antProject.addReference("maven.dependency.classpath", p);
    antProject.addReference("maven.compile.classpath", p);

    p = new Path(antProject);
    p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator));
    antProject.addReference("maven.runtime.classpath", p);

    p = new Path(antProject);
    p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator));
    antProject.addReference("maven.test.classpath", p);

    /* set maven.plugin.classpath with plugin dependencies */
    antProject.addReference("maven.plugin.classpath", getPathFromArtifacts(artifacts, antProject));

    antProject.executeTarget(target);
}

From source file:net.sf.joost.trax.TransformerImpl.java

/**
 * Setter for {@link Processor#outputProperties}
 *
 * @param oformat A <code>Properties</code> object, that replaces the
 *        current set of output properties.
 * @throws IllegalArgumentException/* w ww  .  ja  v  a2  s.c o  m*/
 */
public void setOutputProperties(Properties oformat) throws IllegalArgumentException {
    if (oformat == null) {
        processor.initOutputProperties(); // re-initialize
    } else {
        IllegalArgumentException iE;
        // check properties in oformat
        for (Enumeration e = oformat.keys(); e.hasMoreElements();) {
            Object propKey = e.nextElement();
            if (ignoredProperties.contains(propKey)) {
                if (log != null)
                    log.warn("Output property '" + propKey + "' is not supported and will be ignored");
                continue;
            }
            if (!supportedProperties.contains(propKey)) {
                iE = new IllegalArgumentException("Invalid output property '" + propKey + "'");
                if (log != null)
                    log.error(iE);
                throw iE;
            }
            String propVal = oformat.getProperty((String) propKey);
            if (OutputKeys.METHOD.equals(propKey) && !isValidOutputMethod(propVal)) {
                iE = new IllegalArgumentException(
                        "Unsupported output method " + oformat.getProperty((String) propKey));
                if (log != null)
                    log.error(iE);
                throw iE;
            }
        }
        processor.outputProperties = (Properties) oformat.clone();
    }
}