Example usage for org.apache.commons.configuration HierarchicalConfiguration getList

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getList

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration getList.

Prototype

public List getList(String key) 

Source Link

Usage

From source file:org.yamj.core.tools.GenreXmlTools.java

@PostConstruct
public void init() {
    String genreFileName = PropertyTools.getProperty("yamj3.genre.fileName");
    if (StringUtils.isBlank(genreFileName)) {
        LOG.trace("No valid genre file name configured");
        return;//from w w w.  j av a  2 s  .com
    }
    if (!StringUtils.endsWithIgnoreCase(genreFileName, "xml")) {
        LOG.warn("Invalid genre file name specified: {}", genreFileName);
        return;
    }

    File xmlFile;
    if (StringUtils.isBlank(FilenameUtils.getPrefix(genreFileName))) {
        // relative path given
        String path = System.getProperty("yamj3.home");
        if (StringUtils.isEmpty(path)) {
            path = ".";
        }
        xmlFile = new File(FilenameUtils.concat(path, genreFileName));
    } else {
        // absolute path given
        xmlFile = new File(genreFileName);
    }

    if (!xmlFile.exists() || !xmlFile.isFile()) {
        LOG.warn("Genres file does not exist: {}", xmlFile.getPath());
        return;
    }
    if (!xmlFile.canRead()) {
        LOG.warn("Genres file not readble: {}", xmlFile.getPath());
        return;
    }

    LOG.debug("Initialize genres from file: {}", xmlFile.getPath());

    try {
        XMLConfiguration c = new XMLConfiguration(xmlFile);

        List<HierarchicalConfiguration> genres = c.configurationsAt("genre");
        for (HierarchicalConfiguration genre : genres) {
            String masterGenre = genre.getString("[@name]");
            List<Object> subGenres = genre.getList("subgenre");
            for (Object subGenre : subGenres) {
                LOG.debug("New genre added to map: {} -> {}", subGenre, masterGenre);
                GENRES_MAP.put(((String) subGenre).toLowerCase(), masterGenre);
            }
        }

        try {
            this.commonStorageService.updateGenresXml(GENRES_MAP);
        } catch (Exception ex) {
            LOG.warn("Failed update genres xml in database", ex);
        }
    } catch (Exception ex) {
        LOG.error("Failed parsing genre input file: " + xmlFile.getPath(), ex);
    }
}

From source file:pl.psnc.synat.wrdz.zmkd.config.ZdtConfiguration.java

/**
 * Creates the configuration object form the {@value #CONFIG_FILE} file.
 *//*from w  w w. j  a  v a  2  s .  c o m*/
@PostConstruct
@SuppressWarnings("unchecked")
protected void init() {
    try {
        config = new XMLConfiguration(CONFIG_FILE);

        formatsByName = new HashMap<String, Format>();
        formatsByPlugin = new HashMap<Plugin, Set<Format>>();

        List<HierarchicalConfiguration> formats = config.configurationsAt("formats.format");
        for (HierarchicalConfiguration format : formats) {
            String name = format.getString("name");
            FormatType type = FormatType.valueOf(format.getString("type").toUpperCase());
            List<String> iris = format.getList("iri");

            List<String> plugins = format.getList("supported-by.plugin");
            EnumSet<Plugin> supportedBy = EnumSet.noneOf(Plugin.class);
            for (String plugin : plugins) {
                supportedBy.add(Plugin.valueOf(plugin));
            }

            formatsByName.put(name, new Format(name, type, iris, supportedBy));
        }

        for (Format format : formatsByName.values()) {
            for (Plugin plugin : format.getSupportedBy()) {
                if (!formatsByPlugin.containsKey(plugin)) {
                    formatsByPlugin.put(plugin, new HashSet<Format>());
                }
                formatsByPlugin.get(plugin).add(format);
            }
        }

        for (Entry<Plugin, Set<Format>> entry : formatsByPlugin.entrySet()) {
            entry.setValue(Collections.unmodifiableSet(entry.getValue()));
        }

    } catch (IllegalArgumentException e) {
        logger.error("Loading the configuration failed.", e);
        throw new WrdzConfigurationError(e);
    } catch (ConfigurationException e) {
        logger.error("Loading the configuration failed.", e);
        throw new WrdzConfigurationError(e);
    }
}