Example usage for org.apache.commons.configuration Configuration getProperty

List of usage examples for org.apache.commons.configuration Configuration getProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getProperty.

Prototype

Object getProperty(String key);

Source Link

Document

Gets a property from the configuration.

Usage

From source file:org.ambraproject.service.user.UserServiceImpl.java

@Required
public void setConfiguration(Configuration configuration) {
    this.configuration = configuration;

    Object val = configuration.getProperty(ConfigurationStore.ADVANCED_USAGE_LOGGING);
    if (val != null && val.equals("true")) {
        advancedLogging = true;//  w w  w .j  ava2s  .  com
    }
}

From source file:org.ambraproject.struts2.AmbraFreemarkerConfig.java

private void loadConfig2(Configuration configuration) {
    int numJournals = configuration.getList("ambra.freemarker.journal.name").size();
    for (int k = 0; k < numJournals; k++) {
        final String journal = "ambra.freemarker.journal(" + k + ")";
        final String journalName = configuration.getString(journal + ".name");
        if (log.isDebugEnabled()) {
            log.debug("reading journal name: " + journalName);
        }//from  ww  w . j a  va2  s.co  m
        JournalConfig jc = journals.get(journalName);
        if (jc == null) {
            if (log.isDebugEnabled()) {
                log.debug("journal Not found, creating: " + journalName);
            }
            jc = new JournalConfig();
            journals.put(journalName, jc);
        }

        if (jc.getDefaultTitle() == null) {
            final String title = configuration.getString(journal + ".default.title");
            if (title != null) {
                jc.setDefaultTitle(title);
            }
        }

        if (jc.getMetaDescription() == null) {
            final String metaDescription = configuration.getString(journal + ".metaDescription");
            if (metaDescription != null) {
                jc.setMetaDescription(metaDescription);
            }
        }

        if (jc.getMetaKeywords() == null) {
            final String metaKeywords = configuration.getString(journal + ".metaKeywords");
            if (metaKeywords != null) {
                jc.setMetaKeywords(metaKeywords);
            }
        }

        if (jc.getDisplayName() == null) {
            final String displayName = configuration.getString(journal + ".displayName");
            if (displayName != null) {
                jc.setDisplayName(displayName);
            }
        }

        if (jc.getArticleTitlePrefix() == null) {
            final String articleTitlePrefix = configuration.getString(journal + ".articleTitlePrefix");
            if (articleTitlePrefix != null) {
                jc.setArticleTitlePrefix(articleTitlePrefix);
            }
        }

        if (jc.getDefaultCss() == null) {
            final List fileList = configuration.getList(journal + ".default.css.file");
            String[] defaultCss;
            if (fileList.size() > 0) {
                defaultCss = new String[fileList.size()];
                Iterator iter = fileList.iterator();
                for (int i = 0; i < fileList.size(); i++) {
                    defaultCss[i] = dirPrefix + subdirPrefix + iter.next();
                }
                jc.setDefaultCss(defaultCss);
            }
        }

        if (jc.getDefaultJavaScript() == null) {
            final List fileList = configuration.getList(journal + ".default.javascript.file");
            String javascriptFile;
            String[] defaultJavaScript;
            if (fileList.size() > 0) {
                defaultJavaScript = new String[fileList.size()];
                Iterator iter = fileList.iterator();
                for (int i = 0; i < fileList.size(); i++) {
                    javascriptFile = (String) iter.next();
                    if (javascriptFile.endsWith(".ftl")) {
                        defaultJavaScript[i] = subdirPrefix + javascriptFile;
                    } else {
                        defaultJavaScript[i] = dirPrefix + subdirPrefix + javascriptFile;
                    }
                }
                jc.setDefaultJavaScript(defaultJavaScript);
            }
        }

        final int numPages = configuration.getList(journal + ".page.name").size();

        for (int i = 0; i < numPages; i++) {
            String page = journal + ".page(" + i + ")";
            String pageName = configuration.getString(page + ".name");
            if (log.isDebugEnabled())
                log.debug("Reading config for page name: " + pageName);

            if (!jc.getTitles().containsKey(pageName)) {
                final String title = configuration.getString(page + ".title");
                if (title != null) {
                    jc.getTitles().put(pageName, title);
                }
            }

            if (!jc.getCssFiles().containsKey(pageName)) {
                List<String> list = configuration.getList(page + ".css.file");
                String[] cssArray = new String[list.size()];
                int j = 0;
                for (String fileName : list) {
                    cssArray[j++] = dirPrefix + subdirPrefix + fileName;
                }
                if (cssArray.length > 0
                        || cssArray.length == 0 && configuration.getProperty(page + ".css") != null) {
                    jc.getCssFiles().put(pageName, cssArray);
                }
            }

            if (!jc.getJavaScriptFiles().containsKey(pageName)) {
                List<String> list = configuration.getList(page + ".javascript.file");
                String[] javaScriptArray = new String[list.size()];
                int j = 0;
                for (String fileName : list) {
                    if (fileName.endsWith(".ftl")) {
                        javaScriptArray[j++] = subdirPrefix + fileName;
                    } else {
                        javaScriptArray[j++] = dirPrefix + subdirPrefix + fileName;
                    }
                }

                if (javaScriptArray.length > 0 || javaScriptArray.length == 0
                        && configuration.getProperty(page + ".javascript") != null) {
                    jc.getJavaScriptFiles().put(pageName, javaScriptArray);
                }
            }
        }
    }

}

From source file:org.apache.atlas.ApplicationProperties.java

private static void logConfiguration(Configuration configuration) {
    if (LOG.isDebugEnabled()) {
        Iterator<String> keys = configuration.getKeys();
        LOG.debug("Configuration loaded:");
        while (keys.hasNext()) {
            String key = keys.next();
            LOG.debug("{} = {}", key, configuration.getProperty(key));
        }//  w  ww .j  a  v  a2s.co  m
    }
}

From source file:org.apache.atlas.web.resources.AdminResource.java

private String getEditableEntityTypes(Configuration config) {
    String ret = DEFAULT_EDITABLE_ENTITY_TYPES;

    if (config != null && config.containsKey(editableEntityTypes)) {
        Object value = config.getProperty(editableEntityTypes);

        if (value instanceof String) {
            ret = (String) value;
        } else if (value instanceof Collection) {
            StringBuilder sb = new StringBuilder();

            for (Object elem : ((Collection) value)) {
                if (sb.length() > 0) {
                    sb.append(",");
                }/*from   w  ww .j a v  a  2  s  .  com*/

                sb.append(elem.toString());
            }

            ret = sb.toString();
        }
    }

    return ret;
}

From source file:org.apache.bookkeeper.common.conf.ComponentConfiguration.java

protected void loadConf(Configuration loadedConf) {
    loadedConf.getKeys().forEachRemaining(fullKey -> {
        if (fullKey.startsWith(componentPrefix)) {
            String componentKey = fullKey.substring(componentPrefix.length());
            setProperty(componentKey, loadedConf.getProperty(fullKey));
        }/* ww w  .j  av a  2s.c om*/
    });
}

From source file:org.apache.distributedlog.DistributedLogConfiguration.java

/**
 * Load configuration from other configuration object.
 *
 * @param baseConf Other configuration object
 *///w  ww .  j a v a2 s .  c  o  m
public void loadConf(Configuration baseConf) {
    for (Iterator<String> iter = baseConf.getKeys(); iter.hasNext();) {
        String key = iter.next();
        setProperty(key, baseConf.getProperty(key));
    }
}

From source file:org.apache.falcon.metadata.GraphUpdateUtils.java

public static void main(String[] args) {
    if (args.length != 2) {
        usage();//w w w.ja  va2 s  . co m
        System.exit(1);
    }
    System.out.println(BANNER_MSG);
    String operation = args[0].toLowerCase();
    if (!(operation.equals(EXPORT) || operation.equals(IMPORT))) {
        usage();
        System.exit(1);
    }
    String utilsDir = args[1];
    File utilsDirFile = new File(utilsDir);
    if (!utilsDirFile.isDirectory()) {
        System.err.println(utilsDir + " is not a valid directory");
        System.exit(1);
    }
    String jsonFile = new File(utilsDirFile, INSTANCE_JSON_FILE).getAbsolutePath();
    try {
        Graph graph;
        if (operation.equals(EXPORT)) {
            graph = MetadataMappingService.initializeGraphDB();
            GraphSONWriter.outputGraph(graph, jsonFile);
            System.out.println("Exported instance metadata to " + jsonFile);
        } else {
            // Backup existing graphDB dir
            Configuration graphConfig = MetadataMappingService.getConfiguration();
            String graphStore = (String) graphConfig.getProperty("storage.directory");
            File graphStoreFile = new File(graphStore);
            File graphDirBackup = new File(graphStore + "_backup");
            if (graphDirBackup.exists()) {
                FileUtils.deleteDirectory(graphDirBackup);
            }
            FileUtils.copyDirectory(graphStoreFile, graphDirBackup);

            // delete graph dir first and then init graphDB to ensure IMPORT happens into empty DB.
            FileUtils.deleteDirectory(graphStoreFile);
            graph = MetadataMappingService.initializeGraphDB();

            // Import, if there is an exception restore backup.
            try {
                GraphSONReader.inputGraph(graph, jsonFile);
                System.out.println("Imported instance metadata to " + jsonFile);
            } catch (Exception ex) {
                String errorMsg = ex.getMessage();
                if (graphStoreFile.exists()) {
                    FileUtils.deleteDirectory(graphStoreFile);
                }
                FileUtils.copyDirectory(graphDirBackup, graphStoreFile);
                throw new FalconException(errorMsg);
            }
        }
    } catch (Exception e) {
        System.err.println("Error " + operation + "ing JSON data to " + jsonFile + ", " + e.getMessage());
        e.printStackTrace(System.out);
        System.exit(1);
    }
    System.exit(0);
}

From source file:org.apache.marmotta.loader.core.test.CLITest.java

@Test
public void testStatisticsWithout() throws ParseException {
    Configuration cfg = MarmottaLoader.parseOptions(new String[] { "-s", "-f", "file1.ttl" });

    Assert.assertNotNull(cfg.getProperty(LoaderOptions.STATISTICS_ENABLED));
    Assert.assertNull(cfg.getProperty(LoaderOptions.STATISTICS_GRAPH));

    Assert.assertTrue(cfg.getBoolean(LoaderOptions.STATISTICS_ENABLED));
}

From source file:org.apache.marmotta.loader.core.test.CLITest.java

@Test
public void testStatisticsWith() throws ParseException {
    Configuration cfg = MarmottaLoader.parseOptions(new String[] { "-s", "file.png", "-f", "file1.ttl" });

    Assert.assertNotNull(cfg.getProperty(LoaderOptions.STATISTICS_ENABLED));
    Assert.assertNotNull(cfg.getProperty(LoaderOptions.STATISTICS_GRAPH));

    Assert.assertTrue(cfg.getBoolean(LoaderOptions.STATISTICS_ENABLED));
    Assert.assertEquals("file.png", cfg.getString(LoaderOptions.STATISTICS_GRAPH));
}

From source file:org.apache.marmotta.loader.core.test.CLITest.java

@Test
public void testProperties() throws ParseException {
    Configuration cfg = MarmottaLoader
            .parseOptions(new String[] { "-D", "prop1=value1", "-D", "prop2=value2", "-f", "file1.ttl" });

    Assert.assertNotNull(cfg.getProperty("prop1"));
    Assert.assertNotNull(cfg.getProperty("prop2"));

    Assert.assertEquals("value1", cfg.getString("prop1"));
    Assert.assertEquals("value2", cfg.getString("prop2"));

}