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

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

Introduction

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

Prototype

public List configurationsAt(String key) 

Source Link

Document

Returns a list of sub configurations for all configuration nodes selected by the given key.

Usage

From source file:org.apache.james.http.jetty.JettyHttpServerFactory.java

private Configuration buildConfiguration(HierarchicalConfiguration serverConfig) {
    Builder builder = Configuration.builder();

    boolean randomPort = serverConfig.getBoolean("port[@random]", false);
    Integer port = serverConfig.getInteger("port[@fixed]", null);
    if (randomPort && port != null) {
        throw new ConfigurationException("Random port is not compatible with fixed port");
    }/*from   w w w.  j  ava2s  . c  o m*/
    if (randomPort) {
        builder.randomPort();
    }
    if (port != null) {
        builder.port(port);
    }
    for (HierarchicalConfiguration mapping : serverConfig.configurationsAt("mappings.mapping")) {
        String classname = mapping.getString("servlet");
        Class<? extends Servlet> servletClass = findServlet(classname);
        builder.serve(mapping.getString("path")).with(servletClass);
    }
    for (HierarchicalConfiguration mapping : serverConfig.configurationsAt("filters.mapping")) {
        String classname = mapping.getString("filter");
        Class<? extends Filter> filterClass = findFilter(classname);
        builder.filter(mapping.getString("path")).with(filterClass);
    }
    return builder.build();
}

From source file:org.apache.james.imapserver.netty.IMAPServerFactory.java

@Override
protected List<AbstractConfigurableAsyncServer> createServers(Logger log, HierarchicalConfiguration config)
        throws Exception {

    List<AbstractConfigurableAsyncServer> servers = new ArrayList<AbstractConfigurableAsyncServer>();
    List<HierarchicalConfiguration> configs = config.configurationsAt("imapserver");

    for (HierarchicalConfiguration serverConfig : configs) {
        IMAPServer server = createServer();
        server.setLog(log);//from  ww w.  j  a v  a2s . c  o  m
        server.setFileSystem(fileSystem);
        server.setImapDecoder(decoder);
        server.setImapEncoder(encoder);
        server.setImapProcessor(processor);
        server.configure(serverConfig);
        servers.add(server);
    }

    return servers;

}

From source file:org.apache.james.lmtpserver.netty.LMTPServerFactory.java

@Override
protected List<AbstractConfigurableAsyncServer> createServers(Logger log, HierarchicalConfiguration config)
        throws Exception {
    List<AbstractConfigurableAsyncServer> servers = new ArrayList<AbstractConfigurableAsyncServer>();
    List<HierarchicalConfiguration> configs = config.configurationsAt("lmtpserver");

    for (HierarchicalConfiguration serverConfig : configs) {
        LMTPServer server = createServer();
        server.setFileSystem(fileSystem);
        server.setProtocolHandlerLoader(loader);
        server.setLog(log);//  www .java 2 s .c  o m
        server.configure(serverConfig);
        servers.add(server);
    }

    return servers;
}

From source file:org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration.java

private static ImmutableMap<QuotaThreshold, RenderingInformation> readThresholds(
        HierarchicalConfiguration config) {
    return config.configurationsAt(XmlKeys.THRESHOLDS).stream()
            .map(node -> Pair.of(node.getDouble(XmlKeys.THRESHOLD_VALUE),
                    RenderingInformation.from(Optional.ofNullable(node.getString(XmlKeys.BODY_TEMPLATE)),
                            Optional.ofNullable(node.getString(XmlKeys.SUBJECT_TEMPLATE)))))
            .collect(Guavate.toImmutableMap(pair -> new QuotaThreshold(pair.getLeft()), Pair::getRight));
}

From source file:org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.java

/**
 * Load {@link CompositeMatcher} implementations and their child
 * {@link Matcher}'s//w  w  w.j a  v  a  2 s  .  c o  m
 * 
 * CompositeMatcher were added by JAMES-948
 * 
 * @param compMap
 * @param compMatcherConfs
 * @return compositeMatchers
 * @throws ConfigurationException
 * @throws MessagingException
 * @throws NotCompliantMBeanException
 */
private List<Matcher> loadCompositeMatchers(String state, Map<String, Matcher> compMap,
        List<HierarchicalConfiguration> compMatcherConfs) throws ConfigurationException, MessagingException {
    List<Matcher> matchers = new ArrayList<Matcher>();

    for (HierarchicalConfiguration c : compMatcherConfs) {
        String compName = c.getString("[@name]", null);
        String matcherName = c.getString("[@match]", null);
        String invertedMatcherName = c.getString("[@notmatch]", null);

        Matcher matcher = null;
        if (matcherName != null && invertedMatcherName != null) {
            // if no matcher is configured throw an Exception
            throw new ConfigurationException("Please configure only match or nomatch per mailet");
        } else if (matcherName != null) {
            matcher = matcherLoader.getMatcher(createMatcherConfig(matcherName));
            if (matcher instanceof CompositeMatcher) {
                CompositeMatcher compMatcher = (CompositeMatcher) matcher;

                List<Matcher> childMatcher = loadCompositeMatchers(state, compMap,
                        c.configurationsAt("matcher"));
                for (Matcher aChildMatcher : childMatcher) {
                    compMatcher.add(aChildMatcher);
                }
            }
        } else if (invertedMatcherName != null) {
            Matcher m = matcherLoader.getMatcher(createMatcherConfig(invertedMatcherName));
            if (m instanceof CompositeMatcher) {
                CompositeMatcher compMatcher = (CompositeMatcher) m;

                List<Matcher> childMatcher = loadCompositeMatchers(state, compMap,
                        c.configurationsAt("matcher"));
                for (Matcher aChildMatcher : childMatcher) {
                    compMatcher.add(aChildMatcher);
                }
            }
            matcher = new MatcherInverter(m);
        }
        if (matcher == null)
            throw new ConfigurationException("Unable to load matcher instance");
        matchers.add(matcher);
        if (compName != null) {
            // check if there is already a composite Matcher with the name
            // registered in the processor
            if (compMap.containsKey(compName))
                throw new ConfigurationException(
                        "CompositeMatcher with name " + compName + " is already defined in processor " + state);
            compMap.put(compName, matcher);
        }
    }
    return matchers;
}

From source file:org.apache.james.managesieveserver.netty.ManageSieveServerFactory.java

@Override
protected List<AbstractConfigurableAsyncServer> createServers(Logger log, HierarchicalConfiguration config)
        throws Exception {
    List<AbstractConfigurableAsyncServer> servers = new ArrayList<AbstractConfigurableAsyncServer>();
    List<HierarchicalConfiguration> configs = config.configurationsAt("managesieveserver");

    for (HierarchicalConfiguration serverConfig : configs) {
        ManageSieveServer server = new ManageSieveServer(8000, manageSieveProcessor);
        server.setLog(log);/*from  w w w .  j  a v  a2 s .  c  o  m*/
        server.setFileSystem(fileSystem);
        server.configure(serverConfig);
        servers.add(server);
    }

    return servers;
}

From source file:org.apache.james.modules.mailbox.ListenerConfiguration.java

private static Optional<HierarchicalConfiguration> extractSubconfiguration(
        HierarchicalConfiguration configuration) {
    return configuration.configurationsAt("configuration").stream().findFirst();
}

From source file:org.apache.james.modules.mailbox.ListenersConfiguration.java

public static ListenersConfiguration from(HierarchicalConfiguration configuration) {
    return new ListenersConfiguration(configuration.configurationsAt("listener").stream()
            .map(ListenerConfiguration::from).collect(Guavate.toImmutableList()));
}

From source file:org.apache.james.smtpserver.netty.SMTPServerFactory.java

@Override
protected List<AbstractConfigurableAsyncServer> createServers(Logger log, HierarchicalConfiguration config)
        throws Exception {

    List<AbstractConfigurableAsyncServer> servers = new ArrayList<AbstractConfigurableAsyncServer>();
    List<HierarchicalConfiguration> configs = config.configurationsAt("smtpserver");

    for (HierarchicalConfiguration serverConfig : configs) {
        SMTPServer server = createServer();
        server.setDnsService(dns);/*from   w ww .j  a v  a 2 s .co m*/
        server.setProtocolHandlerLoader(loader);
        server.setLog(log);
        server.setFileSystem(fileSystem);
        server.configure(serverConfig);
        servers.add(server);
    }

    return servers;
}

From source file:org.apereo.lap.model.PipelineConfig.java

public static PipelineConfig makeConfigFromXML(ConfigurationService configurationService,
        StorageService storage, XMLConfiguration xmlConfig) {
    PipelineConfig pc = new PipelineConfig();
    pc.filename = xmlConfig.getFileName();
    pc.name = xmlConfig.getString("name");
    pc.type = xmlConfig.getString("type");
    pc.description = xmlConfig.getString("description");
    // special handling for stats metadata
    HierarchicalConfiguration stats = xmlConfig.configurationAt("stats");
    Iterator<String> statsKeys = stats.getKeys();
    while (statsKeys.hasNext()) {
        String next = statsKeys.next();
        try {/*from w ww  . ja  v  a  2 s  .c o m*/
            Float f = stats.getFloat(next);
            pc.stats.put(next, f);
        } catch (Exception e) {
            // skip this float and warn
            logger.warn("Unable to get float from " + next + " <stats> field (skipping it): " + e);
        }
    }

    // load the lists
    // sources
    List<HierarchicalConfiguration> sourceFields = xmlConfig.configurationsAt("sources.source");
    for (HierarchicalConfiguration field : sourceFields) {
        try {
            pc.addInputHandlerField(field.getString("type"), field, configurationService, storage);
        } catch (Exception e) {
            // skip this input and warn
            logger.warn("Unable to load input field (" + field.toString() + ") (skipping it): " + e);
        }
    }

    // load the lists
    // inputs
    List<HierarchicalConfiguration> inputFields = xmlConfig.configurationsAt("inputs.fields.field");
    for (HierarchicalConfiguration field : inputFields) {
        try {
            pc.addInputField(InputField.make(field.getString("name"), field.getBoolean("required", false)));
        } catch (Exception e) {
            // skip this input and warn
            logger.warn("Unable to load input field (" + field.toString() + ") (skipping it): " + e);
        }
    }
    // processors
    List<HierarchicalConfiguration> processors = xmlConfig.configurationsAt("processors.processor");
    for (HierarchicalConfiguration processor : processors) {
        try {
            String pType = processor.getString("type");
            Processor.ProcessorType pt = Processor.ProcessorType.fromString(pType); // IllegalArgumentException if invalid
            if (pt == Processor.ProcessorType.KETTLE_JOB) {
                pc.addProcessor(
                        Processor.makeKettleJob(processor.getString("name"), processor.getString("file")));
            } else if (pt == Processor.ProcessorType.KETTLE_TRANSFORM) {
                pc.addProcessor(Processor.makeKettleTransform(processor.getString("name"),
                        processor.getString("file")));
            } else if (pt == Processor.ProcessorType.KETTLE_DATA) {
                Processor p = new Processor();
                p.type = Processor.ProcessorType.KETTLE_DATA;
                p.name = processor.getString("name");
                p.count = processor.getInt("count");
                pc.addProcessor(p);
                logger.warn("KETTLE DATA processor loaded (" + p.toString() + ")");
            } // Add other types here as needed
        } catch (Exception e) {
            // skip this processor and warn
            logger.warn("Unable to load processor (" + processor.toString() + ") (skipping it): " + e);
        }
    }
    // outputs
    List<HierarchicalConfiguration> outputs = xmlConfig.configurationsAt("outputs.output");
    for (HierarchicalConfiguration output : outputs) {

        // TODO - we need to rethink output handling
        // don't want to add code every time we need to support a new output type
        try {
            String oType = output.getString("type");
            Output.OutputType ot = Output.OutputType.fromString(oType); // IllegalArgumentException if invalid
            if (ot == Output.OutputType.CSV) {
                Output o = Output.makeCSV(output.getString("from"), output.getString("filename"));
                // load the output fields
                List<HierarchicalConfiguration> outputFields = output.configurationsAt("fields.field");
                for (HierarchicalConfiguration outputField : outputFields) {
                    o.addFieldCSV(outputField.getString("source"), outputField.getString("header"));
                }
                pc.addOutput(o);
            } else if (ot == Output.OutputType.STORAGE) {
                Output o = Output.makeStorage(output.getString("from"), output.getString("to"));
                // load the output fields
                List<HierarchicalConfiguration> outputFields = output.configurationsAt("fields.field");
                for (HierarchicalConfiguration outputField : outputFields) {
                    o.addFieldStorage(outputField.getString("source"), outputField.getString("target"));
                }
                pc.addOutput(o);
            } else if (ot == Output.OutputType.SSPEARLYALERT) {
                Output o = new Output();
                o.type = Output.OutputType.SSPEARLYALERT;
                o.from = output.getString("from");
                o.to = output.getString("to");

                List<HierarchicalConfiguration> outputFields = output.configurationsAt("fields.field");
                for (HierarchicalConfiguration outputField : outputFields) {
                    OutputField field = new OutputField(o.type, outputField.getString("source"),
                            outputField.getString("target"), null);
                    o.fields.add(field);
                }
                pc.addOutput(o);
            }
            // Add other types here as needed
        } catch (Exception e) {
            // skip this processor and warn
            logger.warn("Unable to load output (" + output.toString() + ") (skipping it): " + e);
        }
    }
    return pc;
}