Example usage for java.util Properties propertyNames

List of usage examples for java.util Properties propertyNames

Introduction

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

Prototype

public Enumeration<?> propertyNames() 

Source Link

Document

Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:com.wallabystreet.kinjo.common.transport.ws.ServiceDescriptor.java

/**
 * Creates a new instance of this type, using the given parameters.
 * /*  w  ww .  j a va 2  s. co  m*/
 * @param pkg
 *            The name of the package this service resides at.
 * @param props
 *            A list of additional properties this service should store.
 * @throws MalformedServiceException,
 *             IIF an error occures during service creation.
 */
ServiceDescriptor(String pkg, Properties props) throws MalformedServiceException {
    /* create standard service descriptor */
    this(pkg);

    /* load additional properties */
    Enumeration e = props.propertyNames();
    while (e.hasMoreElements()) {
        String property = (String) e.nextElement();
        this.properties.setProperty(property, props.getProperty(property));
    }
}

From source file:com.pearson.dashboard.util.Util.java

public static RegressionData getRegressionSetDetails(String tabUniqueId) throws IOException {
    File file = new File(System.getProperty("user.home"), "config/regression.properties");
    InputStream streamProject = new FileInputStream(file);
    Properties regressionProperties = new Properties();
    regressionProperties.load(streamProject);
    for (Enumeration<String> en = (Enumeration<String>) regressionProperties.propertyNames(); en
            .hasMoreElements();) {//from   ww  w.  j  a  v  a 2s .  com
        String key = (String) en.nextElement();
        String params = regressionProperties.getProperty(key);
        if (null != params) {
            String param[] = params.split(":");
            if (param[0].equalsIgnoreCase(tabUniqueId)) {
                RegressionData regressionData = new RegressionData();

                regressionData.setCutoffDate(param[1]);

                String iossets[] = param[2].split("~");
                String sets[] = iossets[1].split(",");
                List<String> iostestSets = new ArrayList<String>();
                for (String set : sets) {
                    iostestSets.add(set);
                }
                regressionData.setIosTestSetsIds(iostestSets);

                String winsets[] = param[3].split("~");
                List<String> wintestSets = new ArrayList<String>();
                if (winsets.length > 1) {
                    sets = winsets[1].split(",");
                    for (String set : sets) {
                        wintestSets.add(set);
                    }
                }
                regressionData.setWinTestSetsIds(wintestSets);

                return regressionData;
            }
        }
    }
    return null;
}

From source file:net.sf.joost.stx.Processor.java

/**
 * Create an <code>XMLReader</code> object (a SAX Parser)
 * @throws SAXException if a SAX Parser couldn't be created
 *///  ww  w .  j  a  v  a 2  s.c om
public static XMLReader createXMLReader() throws SAXException {
    // Using pure SAX2, not JAXP
    XMLReader reader = null;
    try {
        // try default parser implementation
        reader = XMLReaderFactory.createXMLReader();
    } catch (SAXException e) {
        String prop = System.getProperty("org.xml.sax.driver");
        if (prop != null) {
            // property set, but still failed
            throw new SAXException("Can't create XMLReader for class " + prop);
            // leave the method here
        }
        // try another SAX implementation
        String PARSER_IMPLS[] = { "org.apache.xerces.parsers.SAXParser", // Xerces
                "org.apache.crimson.parser.XMLReaderImpl", // Crimson
                "gnu.xml.aelfred2.SAXDriver" // Aelfred nonvalidating
        };
        for (int i = 0; i < PARSER_IMPLS.length; i++) {
            try {
                reader = XMLReaderFactory.createXMLReader(PARSER_IMPLS[i]);
                break; // for (...)
            } catch (SAXException e1) {
            } // continuing
        }
        if (reader == null) {
            throw new SAXException("Can't find SAX parser implementation.\n"
                    + "Please specify a parser class via the system property " + "'org.xml.sax.driver'");
        }
    }

    // set features and properties that have been put
    // into the system properties (e.g. via command line)
    Properties sysProps = System.getProperties();
    for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements();) {
        String propKey = (String) e.nextElement();
        if (propKey.startsWith(EXTERN_SAX_FEATURE_PREFIX)) {
            reader.setFeature(propKey.substring(EXTERN_SAX_FEATURE_PREFIX.length()),
                    Boolean.parseBoolean(sysProps.getProperty(propKey)));
            continue;
        }
        if (propKey.startsWith(EXTERN_SAX_PROPERTY_PREFIX)) {
            reader.setProperty(propKey.substring(EXTERN_SAX_PROPERTY_PREFIX.length()),
                    sysProps.getProperty(propKey));
            continue;
        }
    }

    if (DEBUG)
        log.debug("Using " + reader.getClass().getName());
    return reader;
}

From source file:org.sonatype.nexus.rt.prefs.FilePreferences.java

@Override
protected void flushSpi() throws BackingStoreException {
    final File file = FilePreferencesFactory.getPreferencesFile();

    synchronized (file) {
        Properties p = new Properties();
        try {/*from  w w  w .j a v a  2  s . c  o  m*/

            StringBuilder sb = new StringBuilder();
            getPath(sb);
            String path = sb.toString();

            if (file.exists()) {
                final FileInputStream in = new FileInputStream(file);
                try {
                    p.load(in);
                } finally {
                    IOUtils.closeQuietly(in);
                }

                List<String> toRemove = new ArrayList<String>();

                // Make a list of all direct children of this node to be removed
                final Enumeration<?> pnen = p.propertyNames();
                while (pnen.hasMoreElements()) {
                    String propKey = (String) pnen.nextElement();
                    if (propKey.startsWith(path)) {
                        String subKey = propKey.substring(path.length());
                        // Only do immediate descendants
                        if (subKey.indexOf('.') == -1) {
                            toRemove.add(propKey);
                        }
                    }
                }

                // Remove them now that the enumeration is done with
                for (String propKey : toRemove) {
                    p.remove(propKey);
                }
            }

            // If this node hasn't been removed, add back in any values
            if (!isRemoved) {
                for (String s : root.keySet()) {
                    p.setProperty(path + s, root.get(s));
                }
            }

            final FileOutputStream out = new FileOutputStream(file);
            try {
                p.store(out, "FilePreferences");
            } finally {
                IOUtils.closeQuietly(out);
            }
        } catch (IOException e) {
            throw new BackingStoreException(e);
        }
    }
}

From source file:com.granule.json.utils.internal.JSONObject.java

/**
 * Internal method to write out a proper JSON attribute string.
 * @param writer The writer to use while serializing
 * @param attrs The attributes in a properties object to write out
 * @param depth How far to indent the JSON text.
 * @param compact Whether or not to use pretty indention output, or compact output, format
 * @throws IOException Trhown if an error occurs on write.
 *//*www  .  j  a  va2s. c o m*/
private void writeAttributes(Writer writer, Properties attrs, int depth, boolean compact) throws IOException {
    if (logger.isLoggable(Level.FINER))
        logger.entering(className, "writeAttributes(Writer, Properties, int, boolean)");

    if (attrs != null) {
        Enumeration props = attrs.propertyNames();

        if (props != null && props.hasMoreElements()) {
            while (props.hasMoreElements()) {
                String prop = (String) props.nextElement();
                writeAttribute(writer, escapeAttributeNameSpecialCharacters(prop), (String) attrs.get(prop),
                        depth + 1, compact);
                if (props.hasMoreElements()) {
                    try {
                        if (!compact) {
                            writer.write(",\n");
                        } else {
                            writer.write(",");
                        }
                    } catch (Exception ex) {
                        IOException iox = new IOException("Error occurred on serialization of JSON text.");
                        iox.initCause(ex);
                        throw iox;
                    }
                }
            }
        }
    }

    if (logger.isLoggable(Level.FINER))
        logger.exiting(className, "writeAttributes(Writer, Properties, int, boolean)");
}

From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java

@Override
public boolean sendMessage(Run<?, ?> build, TaskListener listener, MessageUtils.MESSAGE_TYPE type, String props,
        String content) {/*  w  ww  .j a va  2 s  .  co  m*/
    Connection connection = null;
    Session session = null;
    MessageProducer publisher = null;

    try {
        String ltopic = getTopic();
        if (provider.getAuthenticationMethod() != null && ltopic != null && provider.getBroker() != null) {
            ActiveMQConnectionFactory connectionFactory = provider.getConnectionFactory();
            connection = connectionFactory.createConnection();
            connection.start();

            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = session.createTopic(ltopic);
            publisher = session.createProducer(destination);

            TextMessage message;
            message = session.createTextMessage("");
            message.setJMSType(JSON_TYPE);

            message.setStringProperty("CI_NAME", build.getParent().getName());
            message.setStringProperty("CI_TYPE", type.getMessage());
            if (!build.isBuilding()) {
                message.setStringProperty("CI_STATUS",
                        (build.getResult() == Result.SUCCESS ? "passed" : "failed"));
            }

            StrSubstitutor sub = new StrSubstitutor(build.getEnvironment(listener));

            if (props != null && !props.trim().equals("")) {
                Properties p = new Properties();
                p.load(new StringReader(props));
                @SuppressWarnings("unchecked")
                Enumeration<String> e = (Enumeration<String>) p.propertyNames();
                while (e.hasMoreElements()) {
                    String key = e.nextElement();
                    message.setStringProperty(key, sub.replace(p.getProperty(key)));
                }
            }

            message.setText(sub.replace(content));

            publisher.send(message);
            log.info("Sent " + type.toString() + " message for job '" + build.getParent().getName()
                    + "' to topic '" + ltopic + "':\n" + formatMessage(message));
        } else {
            log.severe("One or more of the following is invalid (null): user, password, topic, broker.");
            return false;
        }

    } catch (Exception e) {
        log.log(Level.SEVERE, "Unhandled exception in perform.", e);
    } finally {
        if (publisher != null) {
            try {
                publisher.close();
            } catch (JMSException e) {
            }
        }
        if (session != null) {
            try {
                session.close();
            } catch (JMSException e) {
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
            }
        }
    }
    return true;
}

From source file:be.ugent.intec.halvade.HalvadeOptions.java

protected boolean parseArguments(String[] args, Configuration halvadeConf) throws ParseException {
    createOptions();//from   ww  w  .j a  v a  2  s .  co  m
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(options, args);

    in = line.getOptionValue("I");
    out = line.getOptionValue("O");
    if (!out.endsWith("/"))
        out += "/";
    ref = line.getOptionValue("R");
    sites = line.getOptionValue("D");
    halvadeBinaries = line.getOptionValue("B");
    hdfsSites = sites.split(",");
    if (line.hasOption("bam")) {
        useBamInput = true;
    }
    if (line.hasOption("rna")) {
        rnaPipeline = true;
        if (line.hasOption("star"))
            STARGenome = line.getOptionValue("star");
        if (!useBamInput && STARGenome == null) {
            throw new ParseException(
                    "the '-rna' option requires --star pointing to the location of the STAR reference directory if alignment with STAR aligner is required (fastq).");
        }
    }

    if (line.hasOption("tmp")) {
        tmpDir = line.getOptionValue("tmp");
    }
    if (line.hasOption("stargtf")) {
        stargtf = line.getOptionValue("stargtf");
    }
    if (line.hasOption("refdir")) {
        localRefDir = line.getOptionValue("refdir");
        if (!localRefDir.endsWith("/"))
            localRefDir += "/";
    }
    if (line.hasOption("nodes")) {
        nodes = Integer.parseInt(line.getOptionValue("nodes"));
    }
    if (line.hasOption("vcores")) {
        vcores = Integer.parseInt(line.getOptionValue("vcores"));
    }
    if (line.hasOption("smt")) {
        smtEnabled = true;
    }
    if (line.hasOption("remove_dups")) {
        keepDups = false;
    }
    if (line.hasOption("mem")) {
        mem = Double.parseDouble(line.getOptionValue("mem"));
    }
    if (line.hasOption("rpr")) {
        readCountsPerRegionFile = line.getOptionValue("rpr");
    }
    if (line.hasOption("mpn")) {
        setMapContainers = false;
        mapContainersPerNode = Integer.parseInt(line.getOptionValue("mpn"));
    }
    if (line.hasOption("rpn")) {
        setReduceContainers = false;
        reducerContainersPerNode = Integer.parseInt(line.getOptionValue("rpn"));
    }
    if (line.hasOption("mapmem")) {
        overrideMapMem = (int) (Double.parseDouble(line.getOptionValue("mapmem")) * 1024);
    }
    if (line.hasOption("redmem")) {
        overrideRedMem = (int) (Double.parseDouble(line.getOptionValue("redmem")) * 1024);
    }
    if (line.hasOption("scc")) {
        stand_call_conf = Integer.parseInt(line.getOptionValue("scc"));
    }
    if (line.hasOption("sec")) {
        stand_emit_conf = Integer.parseInt(line.getOptionValue("sec"));
    }
    if (line.hasOption("count")) {
        countOnly = true;
    }
    if (line.hasOption("report_all")) {
        reportAll = true;
    }
    if (line.hasOption("illumina")) {
        fixQualEnc = true;
    }
    if (line.hasOption("keep")) {
        keepFiles = true;
    }
    if (line.hasOption("update_rg")) {
        updateRG = true;
    }
    if (line.hasOption("redistribute")) {
        redistribute = true;
    }
    if (line.hasOption("single")) {
        paired = false;
    }
    if (line.hasOption("justalign")) {
        justAlign = true;
        combineVcf = false;
    }
    if (line.hasOption("aln")) {
        aln = Integer.parseInt(line.getOptionValue("aln"));
        if (aln < 0 || aln > 3)
            aln = 0; // default value
    }
    if (line.hasOption("J")) {
        java = line.getOptionValue("J");
    }
    if (line.hasOption("gff")) {
        gff = line.getOptionValue("gff");
    }
    if (line.hasOption("dryrun")) {
        dryRun = true;
        combineVcf = false;
    }
    if (line.hasOption("drop")) {
        keepChrSplitPairs = false;
    }
    //        if (line.hasOption("cov")) {
    //            coverage = Double.parseDouble(line.getOptionValue("cov"));
    //        }
    if (line.hasOption("merge_bam")) {
        mergeBam = true;
    }
    if (line.hasOption("c")) {
        justCombine = true;
        combineVcf = true;
    }
    if (line.hasOption("filter_dbsnp")) {
        filterDBSnp = true;
    }
    if (line.hasOption("reorder_regions")) {
        reorderRegions = true;
    }
    if (line.hasOption("haplotypecaller")) {
        useGenotyper = false;
    }
    if (line.hasOption("elprep")) {
        useElPrep = true;
    }
    if (line.hasOption("id")) {
        RGID = line.getOptionValue("id");
    }
    if (line.hasOption("lb")) {
        RGLB = line.getOptionValue("lb");
    }
    if (line.hasOption("pl")) {
        RGPL = line.getOptionValue("pl");
    }
    if (line.hasOption("pu")) {
        RGPU = line.getOptionValue("pu");
    }
    if (line.hasOption("sm")) {
        RGSM = line.getOptionValue("sm");
    }
    if (line.hasOption("bed")) {
        bedFile = line.getOptionValue("bed");
    }
    if (line.hasOption("fbed")) {
        filterBed = line.getOptionValue("fbed");
    }
    if (line.hasOption("v")) {
        Logger.SETLEVEL(Integer.parseInt(line.getOptionValue("v")));
    }

    if (line.hasOption("CA")) {
        Properties props = line.getOptionProperties("CA");
        Enumeration names = props.propertyNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            addCustomArguments(halvadeConf, name, props.getProperty(name));
        }
    }
    return true;
}

From source file:org.wso2.carbon.identity.oauth2.util.OAuth2Util.java

public static List<String> getOIDCScopes(String tenantDomain) {
    try {// w w  w  .  j a  v a2 s  . c  om
        int tenantId = OAuthComponentServiceHolder.getInstance().getRealmService().getTenantManager()
                .getTenantId(tenantDomain);
        Registry registry = OAuth2ServiceComponentHolder.getRegistryService().getConfigSystemRegistry(tenantId);

        if (registry.resourceExists(OAuthConstants.SCOPE_RESOURCE_PATH)) {
            Resource resource = registry.get(OAuthConstants.SCOPE_RESOURCE_PATH);
            Properties properties = resource.getProperties();
            Enumeration e = properties.propertyNames();
            List<String> scopes = new ArrayList();
            while (e.hasMoreElements()) {
                scopes.add((String) e.nextElement());
            }
            return scopes;
        }
    } catch (RegistryException | UserStoreException e) {
        log.error("Error while retrieving registry collection for :" + OAuthConstants.SCOPE_RESOURCE_PATH, e);
    }
    return new ArrayList<>();
}

From source file:com.pearson.dashboard.util.Util.java

private static List<Tab> getSubTabs(String tabUniqueId) throws IOException {
    File file = new File(System.getProperty("user.home"), "config/subtab.properties");
    InputStream streamSubTab = new FileInputStream(file);

    Properties subTabProperties = new Properties();
    subTabProperties.load(streamSubTab);

    List<Tab> subTabs = new ArrayList<Tab>();
    for (Enumeration<String> enSub = (Enumeration<String>) subTabProperties.propertyNames(); enSub
            .hasMoreElements();) {//from w w  w. j  ava  2 s.  co  m
        String keySub = (String) enSub.nextElement();
        String paramsSub = subTabProperties.getProperty(keySub);
        if (null != paramsSub) {
            String paramSub[] = paramsSub.split(":");
            if (null != paramSub[6] && paramSub[6].equalsIgnoreCase(tabUniqueId)) {
                Tab subTtab = new Tab();
                subTtab.setTabIndex(Integer.parseInt(paramSub[0]));
                subTtab.setTabDisplayName(paramSub[1]);
                subTtab.setTabUniqueId(paramSub[2]);
                if (paramSub[3].equals("null")) {
                    subTtab.setRelease(null);
                } else {
                    subTtab.setRelease(paramSub[3]);
                }
                if (null != paramSub[4] && !"null".equals(paramSub[4])) {
                    subTtab.setCutoffDate(paramSub[4]);
                }
                if (null != paramSub[5] && "true".equals(paramSub[5])) {
                    subTtab.setRegressionData(true);
                } else {
                    subTtab.setRegressionData(false);
                }
                subTtab.setTabType("Child");
                subTtab.setInformation(paramSub[7]);
                if (paramSub[8].equals("null")) {
                    subTtab.setTag(null);
                } else {
                    subTtab.setTag(paramSub[8]);
                }
                subTabs.add(subTtab);
            }
        }
    }
    Collections.sort(subTabs);
    return subTabs;
}

From source file:org.smartfrog.avalanche.util.BuildUtils.java

public boolean configure(Properties confOptions, String envp[]) {
    if (!instDir.exists()) {
        log.error("The directory " + installDir + " does not exist");
        return false;
    }//  w  ww  . java2s. c  o  m
    if (!instDir.isDirectory()) {
        log.error(installDir + " is not a directory");
        return false;
    }
    if (!instDir.canRead()) {
        log.error("The directory " + installDir + " does not have read permissions");
        return false;
    }
    if (!instDir.canWrite()) {
        log.error("The directory " + installDir + " does not have write permissions");
        return false;
    }

    String cmd = new String("/home/sandya/gt4.0.1-all-source-installer/configure");
    Enumeration e = confOptions.propertyNames();
    String options = null;
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = confOptions.getProperty(key);
        options = " " + key + "=" + value + " ";
        cmd = cmd + options;
    }

    //log.info("Command : " + cmd);

    boolean success = true;
    BufferedReader cmdError = null;
    BufferedReader cmdOutput = null;
    try {
        Process p = rt.exec(cmd, envp, instDir);
        cmdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        cmdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = null;
        while ((line = cmdError.readLine()) != null) {
            log.info("CmdError : " + line);
        }
        while ((line = cmdOutput.readLine()) != null) {
            log.info("CmdOutput : " + line);
        }
    } catch (IOException ioe) {
        success = false;
        log.error(ioe);
    } finally {
        try {
            cmdError.close();
            cmdOutput.close();
        } catch (IOException ioe) {
            success = false;
            log.error(ioe);
        }

    }
    return success;
}