Example usage for org.apache.commons.configuration2.builder.fluent Configurations Configurations

List of usage examples for org.apache.commons.configuration2.builder.fluent Configurations Configurations

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.builder.fluent Configurations Configurations.

Prototype

public Configurations() 

Source Link

Document

Creates a new Configurations instance with default settings.

Usage

From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java

public static IPDescriptiveMetadata createBagitMetadata(Map<String, String> metadata, List<String> ancestors,
        Path metadataPath) {//from   w w w.  j  a  v a2s . c om
    try {
        FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new Configurations()
                .propertiesBuilder(metadataPath.toFile());
        Files.createFile(metadataPath);
        PropertiesConfiguration config = builder.getConfiguration();

        for (Entry<String, String> entry : metadata.entrySet()) {
            config.setProperty(entry.getKey(), entry.getValue());
        }

        for (String ancestor : ancestors) {
            config.addProperty(IPConstants.BAGIT_PARENT, ancestor);
        }

        builder.save();
    } catch (IOException | ConfigurationException e) {
        LOGGER.error("Could not save bagit metadata content on file", e);
    }

    return new IPDescriptiveMetadata(metadataPath.getFileName().toString(), new IPFile(metadataPath),
            new MetadataType(BAGIT), "");
}

From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java

public static Map<String, String> getBagitInfo(Path metadataPath) {
    Map<String, String> metadataList = new HashMap<>();
    try {/*from w w  w  .  j  a  v a2 s.  co m*/
        PropertiesConfiguration config = new Configurations().properties(metadataPath.toFile());
        Iterator<String> keys = config.getKeys();

        while (keys.hasNext()) {
            String key = keys.next();
            metadataList.put(key, config.getString(key));
        }
    } catch (ConfigurationException e) {
        LOGGER.error("Could not load properties with bagit metadata", e);
    }

    return metadataList;
}

From source file:resources.PreferenceSettings.java

public PreferenceSettings(String filePath) {//Open PreferenceSettings File
    preferenceSettingList = new ArrayList();
    this.filePath = filePath;

    Configurations configs = new Configurations();
    File file = new File(filePath);
    try {//from  ww  w.j ava2s  .c o m
        XMLConfiguration config = configs.xml(file);
        //Common Settings
        forecastDBBasedDir = config.getString("ForecastDB.baseDir");
        List<String> optionParamNameList = config.getList(String.class,
                "optionParameters.optionParameter[@typeName]");
        List<String> optionParamContentList = config.getList(String.class, "optionParameters.optionParameter");
        optionParamMap = new HashMap();

        for (int i = 0; i < optionParamNameList.size(); i++) {
            optionParamMap.put(optionParamNameList.get(i), optionParamContentList.get(i));
        }

        List<String> languageNameList = config.getList(String.class, "Language[@name]");
        List<String> languageDateFormatList = config.getList(String.class, "Language.dateFormat");
        List<String> languageLocaleFormatList = config.getList(String.class, "Language.locale");
        for (int i = 0; i < languageNameList.size(); i++) {
            String langName = languageNameList.get(i);
            String dateFormat = languageDateFormatList.get(i);
            String localeCode = languageLocaleFormatList.get(i);
            System.out.println("Language : " + langName + " " + dateFormat + " " + localeCode);

            PreferenceSetting ps = new PreferenceSetting(langName);
            ps.setForecastDBDir(forecastDBBasedDir + langName + "/LinkForecastData/");
            ps.setDateFormat(dateFormat, localeCode);
            preferenceSettingList.add(ps);
        }
    } catch (ConfigurationException cex) {
        System.out.println(cex.toString());
    }
}

From source file:resources.ResourceManager.java

public List<LinkMapImport> readWpExport(String fileName, List<String> catListToExclude) {// writeWPExportToResource for import
    List<LinkMapImport> linkMapList = new ArrayList();
    String thisFilePath = wpPath + fileName;

    Configurations configs = new Configurations();
    File file = new File(thisFilePath);

    try {/*from w w w.  j av a2s  .  co m*/
        //XMLConfiguration config = configs.xml(file);
        HierarchicalConfiguration configH = configs.xml(file);

        List<HierarchicalConfiguration> itemList = configH.configurationsAt("channel.item");

        //For Each Post Item
        for (HierarchicalConfiguration item : itemList) {
            boolean pass = false;
            List<HierarchicalConfiguration> catList = item.configurationsAt("category");

            //Check Category List
            for (HierarchicalConfiguration cat : catList) {
                //Filter category domain 
                if (cat.getString("[@domain]").equals("category") == false) {
                    continue;
                }

                //System.out.println(cat.getString(""));
                //if cagetory doamin check if is category to exclude
                //catListToExclude.stream().anyMatch(s -> s.equalsIgnoreCase(cat.getString("")));
                if (catListToExclude.contains(cat.getString(""))) {
                    pass = true;
                    break;
                }

            }

            //if pass var is true just continue
            if (pass) {
                continue;
            }

            //If everything is good Add to Link Map List
            String title = item.getString("title");
            String link = item.getString("link");

            String contentEncoded = item.getString("content:encoded");
            String avg = parseAvgOrHitRatio(contentEncoded);
            linkMapList.add(new LinkMapImport(LinkMap.forecastDataToLinkMap(title, link, ":"), avg));
        }

    } catch (ConfigurationException cex) {
        System.out.println(cex.toString());
    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        return linkMapList;
    }

}

From source file:resources.ResourceManager.java

public List<String> getCategoryExcludeList(String fileName) {
    List<String> returnList = new ArrayList();
    String thisFilePath = catExcludePath + fileName.trim();

    Configurations configs = new Configurations();
    File file = new File(thisFilePath);

    try {// w  ww  .ja v  a  2s  . c o m
        XMLConfiguration config = configs.xml(file);

        returnList = config.getList(String.class, "category");
        System.out.println("Category Exception List read : ");
        returnList.forEach(System.out::println);
    } catch (ConfigurationException cex) {
        System.out.println(cex.toString());
    } finally {
        return returnList;
    }

}

From source file:test.CommonConfig.java

public static void main1(String args[]) {
    Configurations configs = new Configurations();
    File file = new File("test/paths.xml");
    System.out.println(file.getName());
    try {//  w  w  w  . j av  a2 s  .co m
        XMLConfiguration config = configs.xml("test/paths.xml");
        String stage = config.getString("processing[@stage]");
        List<String> paths = config.getList(String.class, "processing.paths.path");
        System.out.println("Processing stage: " + stage);
        for (String p : paths)
            System.out.println("processing.paths: " + p);
        String lang = config.getString("language[@lang]");
        String item = config.getString("language.item");
        System.out.println("Lnag : " + lang);
        System.out.println("item : " + item);
    } catch (ConfigurationException cex) {
        //System.out.println(cex.toString());
    }

}