Example usage for org.apache.commons.configuration XMLConfiguration XMLConfiguration

List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration

Introduction

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

Prototype

public XMLConfiguration() 

Source Link

Document

Creates a new instance of XMLConfiguration.

Usage

From source file:org.accada.hal.ControllerProperties.java

/**
 * Loads the configuration file/* ww  w.  j  a  va  2s  . co m*/
 * 
 * @param propFile The name of the configuration file
 * @throws IOException
 */
private void loadConfig() throws IOException {
    conf = new XMLConfiguration();
    URL url = ResourceLocator.getURL(configFile, defaultConfigFile, this.getClass());
    try {
        conf.load(url);
    } catch (ConfigurationException e) {
        log.error("Could not find properties file: " + configFile);
        throw new IOException("Properties file not found.");
    }
}

From source file:org.accada.hal.impl.sim.BatchSimulator.java

/**
 * initializes the fields and starts the simulator.
 *
 * @throws SimulatorException if the event input file could not be opened.
 *//*from  ww w . j a va  2 s . c  o m*/
private void initSimulator() throws SimulatorException {
    // load properties from config file
    XMLConfiguration config = new XMLConfiguration();
    URL fileurl = ResourceLocator.getURL(configFile, defaultConfigFile, this.getClass());
    try {
        config.load(fileurl);
    } catch (ConfigurationException ce) {
        throw new SimulatorException("Can not load config file '" + configFile + "'.");
    }

    // get properties
    String file = config.getString("batchfile");
    cycles = config.getLong("iterations");

    // find batchfile
    URL batchfileurl = ResourceLocator.getURL(file, file, this.getClass());

    try {
        eventFile = new File(batchfileurl.toURI());
    } catch (URISyntaxException e1) {
        throw new SimulatorException("Can not creat URI of batchfile '" + file + "'.");
    }
    rfidThread = null;
    threadRunning = false;
    stopRequested = false;

    try {
        // tries to open file
        FileReader in = new FileReader(eventFile);
        in.close();

        // start simulator thread
        start();
    } catch (IOException e) {
        throw new SimulatorException("Cannot open event file '" + file + "': " + e);
    }
}

From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java

/**
 * implements the initialize method of the SimulatorServerEngine
  * /*w  ww.j  a v a 2  s.  c o  m*/
  * @param controller 
 * @throws SimulatorServerException 
 */
public void initialize(SimulatorServerController controller, String propFile, String defaultPropFile)
        throws SimulatorServerException {
    this.controller = controller;

    // load language
    String prefix = propFile.substring(0, propFile.lastIndexOf("/")) + "/GUIText_";
    String postfix = ".xml";
    String language = null;
    guiTextConfig = new XMLConfiguration();
    boolean loaded = false;

    // try default language
    if (!loaded) {
        language = LOCALE.getLanguage();
        String langFile = prefix + language + postfix;
        URL fileurl = ResourceLocator.getURL(langFile, langFile, this.getClass());
        try {
            guiTextConfig.load(fileurl);
            loaded = true;
        } catch (ConfigurationException ce) {
            throw new SimulatorServerException("Graphic simulator server language file not found.");
        }
    }

    // load properties
    try {
        propsConfig = new XMLConfiguration();
        URL fileurl = ResourceLocator.getURL(propFile, defaultPropFile, this.getClass());
        propsConfig.load(fileurl);
    } catch (ConfigurationException ce) {
        throw new SimulatorServerException("Could not load properties file.");
    }

    // initialize GUI
    initializeGUI();
    LOG.info("GraphicSimulatorServer started");
}

From source file:org.accada.reader.rprm.core.msg.MessageLayerConfiguration.java

/**
 * Singleton implementation of properties file accessor.
 * /* w ww.  j a  v a  2 s  .co  m*/
 * @return properties instance
 */
private static XMLConfiguration getProperties(final String propFile, final String defaultPropFile) {
    if (configuration == null) {
        // properties
        configuration = new XMLConfiguration();
        try {
            // load resource from where this class is located
            Exception ex = new Exception();
            StackTraceElement[] sTrace = ex.getStackTrace();
            String className = sTrace[0].getClassName();
            Class c = Class.forName(className);
            URL fileurl = ResourceLocator.getURL(propFile, defaultPropFile, c);
            configuration.load(fileurl);
        } catch (ConfigurationException e) {
            log.error("Could not find properties file: " + propFile);
        } catch (ClassNotFoundException cnfe) {
            log.error("Could not find properties file: " + propFile);
        }
    }
    return configuration;
}

From source file:org.apache.giraph.rexster.io.formats.TestAbstractRexsterInputFormat.java

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    final XMLConfiguration properties = new XMLConfiguration();
    final RexsterApplication application;
    final List<HierarchicalConfiguration> graphConfigs;
    final InputStream rexsterConf;
    final int scriptEngineThreshold;
    final String scriptEngineInitFile;
    final List<String> scriptEngineNames;

    /* prepare all databases */
    for (int i = 0; i < DATABASES.length; ++i) {
        prepareDb(DATABASES[i]);//from w w w  .ja  v  a 2s.c  o  m
    }

    /* start the Rexster HTTP server using the prepared rexster configuration */
    rexsterConf = this.getClass().getResourceAsStream(REXSTER_CONF);
    properties.load(rexsterConf);
    rexsterConf.close();

    graphConfigs = properties.configurationsAt(Tokens.REXSTER_GRAPH_PATH);
    application = new XmlRexsterApplication(graphConfigs);
    this.server = new HttpRexsterServer(properties);

    scriptEngineThreshold = properties.getInt("script-engine-reset-threshold", EngineController.RESET_NEVER);
    scriptEngineInitFile = properties.getString("script-engine-init", "");

    /* allow scriptengines to be configured so that folks can drop in
       different gremlin flavors. */
    scriptEngineNames = properties.getList("script-engines");

    if (scriptEngineNames == null) {
        // configure to default with gremlin-groovy
        EngineController.configure(scriptEngineThreshold, scriptEngineInitFile);
    } else {
        EngineController.configure(scriptEngineThreshold, scriptEngineInitFile,
                new HashSet<String>(scriptEngineNames));
    }

    this.server.start(application);
}

From source file:org.apache.giraph.rexster.io.formats.TestRexsterLongDoubleFloatIOFormat.java

/**
 * Start the Rexster server by preparing the configuration file loaded via
 * the resources and setting other important parameters.
 *//*from ww  w .  j a va 2s.  c  om*/
@SuppressWarnings("unchecked")
private static void startRexsterServer() throws Exception {
    InputStream rexsterConf = TestRexsterLongDoubleFloatIOFormat.class.getResourceAsStream(REXSTER_CONF);
    XMLConfiguration properties = new XMLConfiguration();
    properties.load(rexsterConf);
    rexsterConf.close();

    List<HierarchicalConfiguration> graphConfigs = properties.configurationsAt(Tokens.REXSTER_GRAPH_PATH);
    RexsterApplication application = new XmlRexsterApplication(graphConfigs);
    server = new HttpRexsterServer(properties);

    int scriptEngineThreshold = properties.getInt("script-engine-reset-threshold",
            EngineController.RESET_NEVER);
    String scriptEngineInitFile = properties.getString("script-engine-init", "");

    /* allow scriptengines to be configured so that folks can drop in
       different gremlin flavors. */
    List<String> scriptEngineNames = properties.getList("script-engines");

    if (scriptEngineNames == null) {
        /* configure to default with gremlin-groovy */
        EngineController.configure(scriptEngineThreshold, scriptEngineInitFile);
    } else {
        EngineController.configure(scriptEngineThreshold, scriptEngineInitFile,
                new HashSet<String>(scriptEngineNames));
    }
    server.start(application);
}

From source file:org.apache.james.container.spring.lifecycle.ConfigurationProviderImpl.java

/**
 * Load the xmlConfiguration from the given resource.
 * //  ww  w.  jav  a  2s.co  m
 * @param r
 * @return
 * @throws ConfigurationException
 * @throws IOException
 */
private XMLConfiguration getConfig(Resource r) throws ConfigurationException, IOException {
    XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);

    // Don't split attributes which can have bad side-effects with matcher-conditions.
    // See JAMES-1233
    config.setAttributeSplittingDisabled(true);

    // Use InputStream so we are not bound to File implementations of the
    // config
    config.load(r.getInputStream());
    return config;
}

From source file:org.apache.james.container.spring.lifecycle.osgi.OSGIConfigurationProvider.java

@Override
public HierarchicalConfiguration getConfiguration(String beanName) throws ConfigurationException {
    XMLConfiguration config = new XMLConfiguration();
    FileInputStream fis = null;/* w  w w .j  a v a  2  s.c  om*/
    config.setDelimiterParsingDisabled(true);

    // Don't split attributes which can have bad side-effects with matcher-conditions.
    // See JAMES-1233
    config.setAttributeSplittingDisabled(true);

    // Use InputStream so we are not bound to File implementations of the
    // config
    try {
        fis = new FileInputStream("/tmp/" + beanName + ".xml");
        config.load(fis);
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Bean " + beanName);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
                // Left empty on purpose
            }
        }
    }

    return config;
}

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

private HierarchicalConfiguration loadConfiguration(InputStream configuration)
        throws org.apache.commons.configuration.ConfigurationException {
    XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);
    config.setAttributeSplittingDisabled(true);
    config.load(configuration);//from  w ww. j a  va2s .c  o m
    return config;
}

From source file:org.apache.james.mock.server.imap4.configuration.Imap4ServerXMLConfigurationBuilder.java

public static XMLConfiguration createConfigurationWithPort(int port) throws ConfigurationException {
    Document document = DocumentHelper.createDocument();
    Element imapserversRootElt = document.addElement("imapservers");
    Element imapServerElt = imapserversRootElt.addElement("imapserver");
    imapServerElt.addAttribute("enabled", "true");
    imapServerElt.addElement("jmxName").setText("imapserver");
    imapServerElt.addElement("bind").setText(String.format("0.0.0.0:%1$s", port));
    imapServerElt.addElement("connectionBacklog").setText("200");
    Element tlsElt = imapServerElt.addElement("tls");
    tlsElt.addAttribute("socketTLS", "false").addAttribute("startTLS", "false");
    tlsElt.addElement("keystore").setText("file://conf/keystore");
    tlsElt.addElement("secret").setText("yoursecret");
    tlsElt.addElement("provider").setText("org.bouncycastle.jce.provider.BouncyCastleProvider");
    imapServerElt.addElement("plainAuthDisallowed").setText("false");
    imapServerElt.addElement("compress").setText("false");
    imapServerElt.addElement("maxLineLength").setText("65536");
    imapServerElt.addElement("inMemorySizeLimit").setText("65536");
    Element handlerElt = imapServerElt.addElement("handler");
    handlerElt.addElement("connectionLimit").setText("0");
    handlerElt.addElement("connectionLimitPerIP").setText("0");

    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    StringReader in = new StringReader(document.asXML());
    try {/*from  w  w w.ja  va2  s  .  c  o m*/
        xmlConfiguration.load(in);
    } finally {
        closeQuietly(in);
    }

    return xmlConfiguration;
}