Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

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

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, 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.redhat.red.build.koji.it.AbstractWithSetupIT.java

protected void stageImport(String importsDirPath, CloseableHttpClient client) throws Exception {
    InputStream is = getResourceStream(importsDirPath, "staging.properties");

    Properties p = new Properties();
    try {// w ww  .  jav  a  2  s .c o  m
        p.load(is);
    } finally {
        closeQuietly(is);
    }

    p.stringPropertyNames().forEach((fname) -> {
        String targetPath = p.getProperty(fname);
        if (isEmpty(targetPath)) {
            fail("No target path for staging file: " + fname + "!");
        }

        uploadFile(getResourceStream(importsDirPath, fname), targetPath, client);
    });
}

From source file:org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor.java

private void addWithPrefix(Properties properties, Properties other, String prefix) {
    for (String key : other.stringPropertyNames()) {
        String prefixed = prefix + key;
        properties.setProperty(prefixed, other.getProperty(key));
    }//  w  w w . jav a  2 s  .c o  m
}

From source file:org.okj.commons.config.SystemPropertiesLoader.java

/** 
 * @see org.storevm.eosgi.properties.loader.PropertiesLoader#load()
 *//*ww w.  j a  v  a2s  . c  om*/
@Override
public void load() {
    //1. ?
    if (StringUtils.isNotBlank(System.getProperty(WORK_HOME_NAME))) {
        this.location = System.getProperty(WORK_HOME_NAME);
    }

    //2. ?
    if (StringUtils.isBlank(location)) {
        this.location = System.getProperty("user.dir");
    }

    //3. ?
    File config = new File(this.location);

    //?
    if (!config.isFile()) {
        config = new File(config, SYSTEM_PROPS_FILE);
        LogUtils.info(LOGGER, "??, location={0}", config.getAbsolutePath());
    }

    try {
        if (!config.exists()) {
            config.createNewFile(); //?
        }

        //?
        Properties props = new Properties();
        props.load(new FileInputStream(config));
        Set<String> names = props.stringPropertyNames();
        for (String name : names) {
            System.setProperty(name, props.getProperty(name));
        }
    } catch (IOException ex) {
        LogUtils.error(LOGGER, "???", ex);
    }
}

From source file:com.heliosapm.streams.collector.ds.pool.PoolConfig.java

/**
 * Creates and deploys an ObjectPool based on the passed config props
 * @param p The configuration properties
 * @return the created GenericObjectPool
 *//* w  ww  .  j a va  2 s  . c o m*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private static GenericObjectPool<?> deployPool(final Properties p) {
    final String factoryName = (String) p.remove(POOLED_OBJECT_FACTORY_KEY);
    final String poolName = p.getProperty(NAME.name().toLowerCase());
    if (poolName == null || poolName.trim().isEmpty())
        throw new RuntimeException("Pool was not assigned a name");
    if (factoryName == null || factoryName.trim().isEmpty())
        throw new RuntimeException("No pooled object factory defined");
    final GenericObjectPoolConfig cfg = DEFAULT_CONFIG.clone();
    try {
        final Class<PooledObjectFactoryBuilder<?>> clazz = loadFactoryClass(factoryName);
        final Constructor<PooledObjectFactoryBuilder<?>> ctor = clazz.getDeclaredConstructor(Properties.class);
        final PooledObjectFactoryBuilder<?> factory = ctor.newInstance(p);
        for (final String key : p.stringPropertyNames()) {
            if (isPoolConfig(key)) {
                final PoolConfig pc = decode(key);
                pc.apply(cfg, p.get(key));
            }
        }
        final PooledObjectFactory<?> pooledObjectFactory = factory.factory();
        GenericObjectPool<?> pool = new GenericObjectPool(pooledObjectFactory, cfg);
        pool.setSwallowedExceptionListener(EX_LISTENER);
        if (factory instanceof PoolAwareFactory) {
            ((PoolAwareFactory) factory).setPool(pool);
        }
        GlobalCacheService.getInstance().put("pool/" + poolName, pool);
        pool.setAbandonedConfig(Abandoned.create(p));
        pool.preparePool();
        return pool;
    } catch (Exception ex) {
        throw new RuntimeException("Failed to create GenericObjectPool from properties [" + p + "]", ex);
    }
}

From source file:org.jboss.dashboard.i18n.XmlToBundleConverter.java

public void inject(Map<Locale, Properties> bundles) throws Exception {
    if (xmlFile != null && xmlFile.exists()) {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(xmlFile);

        // Inject the i18n properties.
        for (Locale locale : bundles.keySet()) {
            Properties bundle = bundles.get(locale);
            for (String key : bundle.stringPropertyNames()) {
                Element node = lookupNode(doc, locale, key);
                if (node != null) {
                    String value = bundle.getProperty(key);
                    injectNode(node, locale, value);
                }//from  w  w  w .  j ava 2  s.  co m
            }
        }

        // Serialize the updated XML doc to file.
        Format format = Format.getPrettyFormat();
        format.setIndent("  ");
        format.setEncoding("UTF-8");
        FileOutputStream fos = new FileOutputStream(xmlFile);
        OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");

        // Escape all the strings to an ASCII neutral encoding.
        XMLOutputter outp = new XMLOutputter(format) {
            public String escapeAttributeEntities(String str) {
                return StringEscapeUtils.escapeXml(str);
            }

            public String escapeElementEntities(String str) {
                return StringEscapeUtils.escapeXml(str);
            }
        };
        outp.output(doc, osw);
        fos.close();
    }
}

From source file:org.niord.web.conf.SiteTextsServletFilter.java

/**
 * Returns the web translations as a javascript snippet that sets the $translateProvider translations.
 *//*from  w  w  w .  ja v  a  2  s .  co  m*/
private String getWebTranslations() {

    StringBuilder str = new StringBuilder("\n");
    for (String lang : app.getLanguages()) {

        str.append("$translateProvider.translations('").append(lang).append("', {\n");

        // Construct a properties object with all language-specific values from all included dictionaries
        Properties langDict = dictionaryService.getDictionariesAsProperties(WEB_DICTIONARIES, lang);

        // Generate the javascript key-values
        langDict.stringPropertyNames().stream().sorted().forEach(key -> {
            String value = langDict.getProperty(key);
            str.append(String.format("'%s'", key)).append(" : ").append(encodeValue(value)).append(",\n");
        });

        str.append("});\n");
    }

    str.append("$translateProvider.preferredLanguage('").append(app.getDefaultLanguage()).append("');\n");

    return str.toString();
}

From source file:org.apache.syncope.core.init.ContentLoader.java

@Transactional
public void load() {
    // 1. Check wether we are allowed to load default content into the DB
    final List<SyncopeConf> res = confDAO.findAll();

    if (res == null || res.size() > 0) {
        LOG.info("Data found in the database, leaving untouched");
        return;//from www.j  av  a 2 s  .  co  m
    }

    LOG.info("Empty database found, loading default content");

    // 2. Create views
    LOG.debug("Creating views");
    try {
        InputStream viewsStream = getClass().getResourceAsStream("/views.xml");
        Properties views = new Properties();
        views.loadFromXML(viewsStream);

        for (String idx : views.stringPropertyNames()) {
            LOG.debug("Creating view {}", views.get(idx).toString());

            final String updateViews = views.get(idx).toString().replaceAll("\\n", " ");
            entityManager.createNativeQuery(updateViews).executeUpdate();
        }

        LOG.debug("Views created, go for indexes");
    } catch (Exception e) {
        LOG.error("While creating views", e);
    }

    // 3. Create indexes
    LOG.debug("Creating indexes");
    try {
        InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml");
        Properties indexes = new Properties();
        indexes.loadFromXML(indexesStream);

        for (String idx : indexes.stringPropertyNames()) {
            LOG.debug("Creating index {}", indexes.get(idx).toString());

            final String updateIndexed = indexes.get(idx).toString();
            entityManager.createNativeQuery(updateIndexed).executeUpdate();
        }

        LOG.debug("Indexes created, go for default content");
    } catch (Exception e) {
        LOG.error("While creating indexes", e);
    }

    // noop workflow
    //        entityManager.createNativeQuery("DELETE FROM ACT_GE_PROPERTY").executeUpdate();

    // 4. Load default content
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        parser.parse(getClass().getResourceAsStream("/content.xml"), importExport);
        LOG.debug("Default content successfully loaded");
    } catch (Exception e) {
        LOG.error("While loading default content", e);
    }
}

From source file:gaffer.graph.hook.OperationAuthoriser.java

private void loadOpAuthMap(final Properties props) {
    for (final String opClassName : props.stringPropertyNames()) {
        final Class<? extends Operation> opClass;
        try {/* w  ww.  j a va2 s  .  c  o m*/
            opClass = Class.forName(opClassName).asSubclass(Operation.class);
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(e);
        }
        final Set<String> auths = new HashSet<>();
        for (final String auth : props.getProperty(opClassName).split(AUTH_SEPARATOR)) {
            if (!StringUtils.isEmpty(auth)) {
                auths.add(auth);
            }
        }
        setOpAuths(opClass, auths);
    }
}

From source file:org.apache.hive.hplsql.Arguments.java

/**
 * Parse the command line arguments/*www  .j a  v a2  s.com*/
 */
public boolean parse(String[] args) {
    try {
        commandLine = new GnuParser().parse(options, args);
        execString = commandLine.getOptionValue('e');
        fileName = commandLine.getOptionValue('f');
        main = commandLine.getOptionValue("main");
        Properties p = commandLine.getOptionProperties("hiveconf");
        for (String key : p.stringPropertyNames()) {
            vars.put(key, p.getProperty(key));
        }
        p = commandLine.getOptionProperties("hivevar");
        for (String key : p.stringPropertyNames()) {
            vars.put(key, p.getProperty(key));
        }
        p = commandLine.getOptionProperties("define");
        for (String key : p.stringPropertyNames()) {
            vars.put(key, p.getProperty(key));
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        return false;
    }
    return true;
}

From source file:org.opencastproject.serviceregistry.impl.OsgiIncidentService.java

private void storeIncidentTexts(Bundle bundle) {
    logger.info(format("Scanning bundle %s, (ID %d) for incident localizations", bundle.getSymbolicName(),
            bundle.getBundleId()));//from  www .j a v  a2  s  .c  o  m
    final Enumeration l10n = bundle.findEntries(INCIDENT_L10N_DIR, PROPERTIES_GLOB, false);
    while (l10n != null && l10n.hasMoreElements()) {
        final URL resourceUrl = (URL) l10n.nextElement();
        final String resourceFileName = resourceUrl.getFile();
        // e.g. org.opencastproject.composer.properties or org.opencastproject.composer_de.properties
        final String fullResourceName = FilenameUtils.getBaseName(resourceFileName);
        final String[] fullResourceNameParts = fullResourceName.split("_");
        // part 0 contains the key base, e.g. org.opencastproject.composer
        final String keyBase = fullResourceNameParts[0];
        final List<String> locale = mlist(fullResourceNameParts).drop(1).value();
        final Properties texts = loadPropertiesFromUrl(resourceUrl);
        for (String key : texts.stringPropertyNames()) {
            final String text = texts.getProperty(key);
            final String dbKey = mlist(keyBase, key).concat(locale).mkString(".");
            logger.debug(format("Storing text %s=%s", dbKey, text));
            penv.tx(Queries.persistOrUpdate(IncidentTextDto.mk(dbKey, text)));
        }
    }
}