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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Usage

From source file:com.moviejukebox.reader.MovieJukeboxLibraryReader.java

public static Collection<MediaLibraryPath> parse(File libraryFile) {
    Collection<MediaLibraryPath> mlp = new ArrayList<>();

    if (!libraryFile.exists() || libraryFile.isDirectory()) {
        LOG.error("The moviejukebox library input file you specified is invalid: {}", libraryFile.getName());
        return mlp;
    }//w  w  w .  j av  a2s  .  c  om

    try {
        XMLConfiguration c = new XMLConfiguration(libraryFile);

        List<HierarchicalConfiguration> fields = c.configurationsAt("library");
        for (HierarchicalConfiguration sub : fields) {
            // sub contains now all data about a single medialibrary node
            String path = sub.getString("path");
            String nmtpath = sub.getString("nmtpath"); // This should be depreciated
            String playerpath = sub.getString("playerpath");
            String description = sub.getString("description");
            boolean scrapeLibrary = true;

            String scrapeLibraryString = sub.getString("scrapeLibrary");
            if (StringTools.isValidString(scrapeLibraryString)) {
                try {
                    scrapeLibrary = sub.getBoolean("scrapeLibrary");
                } catch (Exception ignore) {
                    /* ignore */ }
            }

            long prebuf = -1;
            String prebufString = sub.getString("prebuf");
            if (prebufString != null && !prebufString.isEmpty()) {
                try {
                    prebuf = Long.parseLong(prebufString);
                } catch (NumberFormatException ignore) {
                    /* ignore */ }
            }

            // Note that the nmtpath should no longer be used in the library file and instead "playerpath" should be used.
            // Check that the nmtpath terminates with a "/" or "\"
            if (nmtpath != null) {
                if (!(nmtpath.endsWith("/") || nmtpath.endsWith("\\"))) {
                    // This is the NMTPATH so add the unix path separator rather than File.separator
                    nmtpath = nmtpath + "/";
                }
            }

            // Check that the playerpath terminates with a "/" or "\"
            if (playerpath != null) {
                if (!(playerpath.endsWith("/") || playerpath.endsWith("\\"))) {
                    // This is the PlayerPath so add the Unix path separator rather than File.separator
                    playerpath = playerpath + "/";
                }
            }

            List<Object> excludes = sub.getList("exclude[@name]");
            File medialibfile = new File(path);
            if (medialibfile.exists()) {
                MediaLibraryPath medlib = new MediaLibraryPath();
                medlib.setPath(medialibfile.getCanonicalPath());
                if (playerpath == null || StringUtils.isBlank(playerpath)) {
                    medlib.setPlayerRootPath(nmtpath);
                } else {
                    medlib.setPlayerRootPath(playerpath);
                }
                medlib.setExcludes(excludes);
                medlib.setDescription(description);
                medlib.setScrapeLibrary(scrapeLibrary);
                medlib.setPrebuf(prebuf);
                mlp.add(medlib);

                if (description != null && !description.isEmpty()) {
                    LOG.info("Found media library: {}", description);
                } else {
                    LOG.info("Found media library: {}", path);
                }
                // Save the media library to the log file for reference.
                LOG.debug("Media library: {}", medlib);

            } else {
                LOG.info("Skipped invalid media library: {}", path);
            }
        }
    } catch (ConfigurationException | IOException ex) {
        LOG.error("Failed parsing moviejukebox library input file: {}", libraryFile.getName());
        LOG.error(SystemTools.getStackTrace(ex));
    }
    return mlp;
}

From source file:elaborate.editor.config.Configuration.java

private static void extractRenditions(HierarchicalConfiguration config) {
    int n = config.getMaxIndex("rendition");
    for (int i = 0; i <= n; i++) {
        String messageId = config.getString("rendition(" + i + ")[@id]");
        if (messageId != null) {
            String message = config.getString("rendition(" + i + ")");
            renditions.put(messageId, message);
        }/*ww w.  ja  v  a  2 s .co m*/
    }
}

From source file:elaborate.editor.config.Configuration.java

private static void extractMessages(String parentId, HierarchicalConfiguration config) {
    int n = config.getMaxIndex("message");
    for (int i = 0; i <= n; i++) {
        String messageId = config.getString("message(" + i + ")[@id]");
        if (messageId != null) {
            String message = config.getString("message(" + i + ")");
            if (message != null) {
                message = message.replaceAll("\\{", "<").replaceAll("\\}", ">");
            }//from  www  .  j  ava 2s  .c o m
            messages.put(parentId + "." + messageId, message);
        }
    }
}

From source file:com.sinfonier.util.XMLProperties.java

/**
 * Get Integer from xml configuration file.
 * //  www  . jav  a 2  s  . c  o  m
 * @param xml
 * @param property
 */
public static Integer getInt(HierarchicalConfiguration xml, String property) {
    if (xml.getString(property) == null || xml.getString(property).equals(""))
        throw new XMLConfigException("Error in XML Configuration. Property " + property + " null or empty");
    return xml.getInt(property);
}

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java

private static Function<HierarchicalConfiguration, Permission> convertCfgToPermission(
        final Tokenizer tokenizer) {
    return new Function<HierarchicalConfiguration, Permission>() {
        @Override/*  w w w  .j av  a2s  .  c o m*/
        public Permission valueOf(HierarchicalConfiguration cfg) {
            return new Permission(cfg.getString("[@scheme]"),
                    iterConfig(cfg, "grant").collect(convertCfgToGrant(tokenizer)));
        }
    };
}

From source file:edu.cwru.sepia.Main.java

private static Runner getRunner(HierarchicalConfiguration globalConfig, StateCreator stateCreator,
        Agent[] agents) throws ClassNotFoundException, IllegalArgumentException, SecurityException,
        InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Class<?> runnerClass = Class.forName(globalConfig.getString("runner.ClassName"));
    CombinedConfiguration config = new CombinedConfiguration();
    config.addConfiguration(globalConfig.configurationAt("model"), "model", "model");
    config.addConfiguration(globalConfig.configurationAt("runner.properties"), "runner.properties",
            "runner.properties");
    return (edu.cwru.sepia.runner.Runner) runnerClass
            .getConstructor(Configuration.class, StateCreator.class, Agent[].class)
            .newInstance(config, stateCreator, agents);
}

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java

private static Function<HierarchicalConfiguration, Group> convertCfgToGroup(final Tokenizer tokenizer) {
    return new Function<HierarchicalConfiguration, Group>() {
        @Override// w  w  w.  j a v  a  2s  .  c om
        public Group valueOf(HierarchicalConfiguration cfg) {
            return new Group(tokenizer.tokenizeString(cfg.getString("[@name]")));
        }
    };
}

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java

private static Function<HierarchicalConfiguration, User> convertCfgToUser(final Tokenizer tokenizer) {
    return new Function<HierarchicalConfiguration, User>() {
        @Override/*from www  . ja  va2  s.  co  m*/
        public User valueOf(HierarchicalConfiguration cfg) {
            return new User(tokenizer.tokenizeString(cfg.getString("[@name]")), cfg.getString("[@password]"),
                    cfg.getBoolean("[@admin]", false));
        }
    };
}

From source file:com.norconex.jef4.status.JobSuiteStatusSnapshot.java

private static JobStatusTreeNode loadTreeNode(IJobStatus parentStatus, HierarchicalConfiguration jobXML,
        String suiteName, IJobStatusStore store) throws IOException {
    if (jobXML == null) {
        return null;
    }//from  w w  w.  ja  v  a 2s  . c om
    String jobId = jobXML.getString("[@name]");
    IJobStatus jobStatus = store.read(suiteName, jobId);
    List<HierarchicalConfiguration> xmls = jobXML.configurationsAt("job");
    List<JobStatusTreeNode> childNodes = new ArrayList<JobStatusTreeNode>();
    if (xmls != null) {
        for (HierarchicalConfiguration xml : xmls) {
            JobStatusTreeNode child = loadTreeNode(jobStatus, xml, suiteName, store);
            if (child != null) {
                childNodes.add(child);
            }
        }
    }
    return new JobStatusTreeNode(parentStatus, jobStatus, childNodes);
}

From source file:com.servioticy.queueclient.QueueClient.java

private static QueueClient createInstance(String configPath, String type, String baseAddress,
        String relativeAddress) throws QueueClientException {

    QueueClient instance;//from   ww  w  .j av  a  2 s.c o  m

    try {
        File f = new File(configPath);
        if (!f.exists()) {
            if (Thread.currentThread().getContextClassLoader().getResource(configPath) == null) {
                KestrelMemcachedClient kInstance = new KestrelMemcachedClient();
                kInstance.setBaseAddress(baseAddress);
                kInstance.setRelativeAddress(relativeAddress);
                kInstance.setExpire(0);
                return kInstance;
            }
        }
        String className;
        HierarchicalConfiguration config, queueConfig;

        config = new XMLConfiguration(configPath);
        config.setExpressionEngine(new XPathExpressionEngine());

        className = config.getString("queue[type='" + type + "']/className");
        instance = (QueueClient) Class.forName(className).newInstance();
        instance.setBaseAddress(baseAddress);
        instance.setRelativeAddress(relativeAddress);
        queueConfig = (HierarchicalConfiguration) config
                .configurationAt("queue[type='" + type + "']/concreteConf");
        instance.init(queueConfig);

    } catch (InstantiationException e) {
        String errMsg = "Unable to instantiate the queue class (" + e.getMessage() + ").";
        logger.error(errMsg);
        throw new QueueClientException(errMsg);
    } catch (IllegalAccessException e) {
        String errMsg = "Unable to load the queue class (" + e.getMessage() + ").";
        logger.error(errMsg);
        throw new QueueClientException(errMsg);
    } catch (ClassNotFoundException e) {
        String errMsg = "The queue class does not exist (" + e.getMessage() + ").";
        logger.error(errMsg);
        throw new QueueClientException(errMsg);
    } catch (ConfigurationException e) {
        String errMsg = "'" + configPath + "' configuration file is malformed (" + e.getMessage() + ").";
        logger.error(errMsg);
        throw new QueueClientException(errMsg);
    }

    return instance;
}