List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:org.jhub1.agent.configuration.PropertiesImpl.java
public PropertiesImpl() throws ConfigurationException { reloadingStrategy = new ManagedReloadingStrategy(); config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new PropertiesConfiguration("agent.properties")); config.addConfiguration(new PropertiesConfiguration("agent.internal.properties")); try {/*from ww w .j a v a2s .c o m*/ XMLConfiguration fromFile = new XMLConfiguration("settings.xml"); fromFile.setReloadingStrategy(reloadingStrategy); reloadFlag = true; config.addConfiguration(fromFile); } catch (ConfigurationException ce) { log.error("Problem with loading custom configuration: " + ce.getMessage()); } config.addConfiguration(new XMLConfiguration("settings.default.xml")); }
From source file:org.jvoicexml.systemtest.mobicents.BroadcastServletDemo.java
public void init(ServletConfig servletConfig) throws ServletException { System.out.println("init servletConfig:" + servletConfig); VNXLog.info("init servletConfig:" + servletConfig); super.init(servletConfig); sipFactory = (SipFactory) getServletContext().getAttribute(SIP_FACTORY); clock = (TimerService) getServletContext().getAttribute(TIMER_SERVICE); VNXLog.info("init sipFactory:" + sipFactory + " clock:" + clock); try {//www . ja va 2 s . c o m VNXLog.info("****** the BroadcastServletDemo servlet ********* "); properties = new Properties(); // VNXLog.info("set servlet context :BroadcastServletDemo:" + this); //loading media configuration String path = VAppCfg.CATALINA_HOME + "conf/MediaServer.xml"; VNXLog.info("loading configuration file located at " + path); // Load the vnxivr configuration. XMLConfiguration configuration = null; configuration = new XMLConfiguration(path); VNXLog.info("load media server configurations"); servers = new MgcpServerManager(); servers.configure(configuration.subset("media-server-manager")); servers.start(); } catch (ConfigurationException e) { VNXLog.error(e); } catch (Exception e) { VNXLog.error("couldn't start the underlying MGCP Stack"); VNXLog.error(e); } }
From source file:org.kepler.configuration.SerializationComparisonTest.java
/** * test the commons interface for reading properties *///w ww . j a v a2 s .com public void testCommonsRead() { try { File f = new File("configuration-manager/resources/configurations/configuration.xml"); assertTrue(f.exists()); XMLConfiguration config = new XMLConfiguration(f); //get the conditionals of query and read some properties ArrayList al = (ArrayList) config .getProperty("ecogridService.queryList.query.AND.OR.condition.concept"); assertTrue(config.getString("ecogridService.queryList.query.AND.OR.condition(1).concept") .equals("keyword")); assertTrue( config.getString("ecogridService.queryList.query.AND.OR.condition(3).operator").equals("LIKE")); //break the config down into a smaller subset of just the queryList HierarchicalConfiguration sub = config.configurationAt("ecogridService.queryList"); al = (ArrayList) sub.getProperty("query.returnField"); al = (ArrayList) sub.getProperty("query(0).returnField"); //get the 2nd returnfield of the first query assertTrue(((String) al.get(1)).equals("entityName")); } catch (Exception e) { e.printStackTrace(); fail("Commons error: " + e.getMessage()); } System.out.println(); System.out.println(); }
From source file:org.kitodo.config.ConfigProject.java
/** * Constructor for ConfigProject.//w w w . j a va 2 s . c o m * * @param projectTitle * for which configuration is going to be read * @throws IOException * if config file not found */ public ConfigProject(String projectTitle) throws IOException { KitodoConfigFile configFile = KitodoConfigFile.PROJECT_CONFIGURATION; if (!configFile.exists()) { throw new IOException("File not found: " + configFile.getAbsolutePath()); } try { this.config = new XMLConfiguration(configFile.getAbsolutePath()); } catch (ConfigurationException e) { logger.error(e.getMessage(), e); this.config = new XMLConfiguration(); } this.config.setListDelimiter('&'); this.config.setReloadingStrategy(new FileChangedReloadingStrategy()); int countProjects = this.config.getMaxIndex("project"); for (int i = 0; i <= countProjects; i++) { String title = this.config.getString("project(" + i + ")[@name]"); if (title.equals(projectTitle)) { this.projectTitle = "project(" + i + ")."; break; } } try { this.config.getBoolean(this.projectTitle + "createNewProcess.opac[@use]"); } catch (NoSuchElementException e) { this.projectTitle = "project(0)."; } }
From source file:org.kitodo.config.OPACConfig.java
private static XMLConfiguration getConfig() { if (config != null) { return config; }//from w w w . j a v a 2 s . c o m KitodoConfigFile kitodoConfigOpacFile = KitodoConfigFile.OPAC_CONFIGURATION; if (!kitodoConfigOpacFile.exists()) { String message = "File not found: " + kitodoConfigOpacFile.getAbsolutePath(); throw new ConfigException(message, new FileNotFoundException(message)); } try { config = new XMLConfiguration(kitodoConfigOpacFile.getFile()); } catch (ConfigurationException e) { logger.error(e); config = new XMLConfiguration(); } config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); return config; }
From source file:org.kitodo.editor.XMLEditor.java
/** * Load the content of the XML configuration file with the given name * 'configurationFile'./*from w w w.java 2 s. co m*/ * * @param configurationFile * name of the configuration to be loaded */ public void loadXMLConfiguration(String configurationFile) { try (StringWriter stringWriter = new StringWriter()) { currentConfigurationFile = configurationFile; XMLConfiguration currentConfiguration = new XMLConfiguration( ConfigCore.getKitodoConfigDirectory() + currentConfigurationFile); currentConfiguration.save(stringWriter); this.xmlConfigurationString = stringWriter.toString(); } catch (ConfigurationException e) { String errorMessage = "ERROR: Unable to load configuration file '" + configurationFile + "'."; logger.error(errorMessage + " " + e.getMessage()); this.xmlConfigurationString = errorMessage; } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:org.kitodo.production.editor.XMLEditor.java
/** * Load the content of the XML configuration file with the given name * 'configurationFile'.//w ww . j ava 2 s . c om * * @param configurationFile * name of the configuration to be loaded */ public void loadXMLConfiguration(String configurationFile) { try (StringWriter stringWriter = new StringWriter()) { currentConfigurationFile = configurationFile; this.configurationFile = KitodoConfigFile.getByName(configurationFile); XMLConfiguration currentConfiguration = new XMLConfiguration(this.configurationFile.getAbsolutePath()); currentConfiguration.save(stringWriter); this.xmlConfigurationString = stringWriter.toString(); } catch (ConfigurationException e) { String errorMessage = "ERROR: Unable to load configuration file '" + configurationFile + "'."; logger.error(errorMessage + " " + e.getMessage()); this.xmlConfigurationString = errorMessage; } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:org.kitodo.production.exporter.ExportXmlLog.java
private HashMap<String, String> getMetsFieldsFromConfig(boolean useAnchor) { String xmlpath = "mets." + PROPERTY; if (useAnchor) { xmlpath = "anchor." + PROPERTY; }/*w w w . j a va 2 s . c o m*/ HashMap<String, String> fields = new HashMap<>(); try { File file = new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_exportXml.xml"); if (file.exists() && file.canRead()) { XMLConfiguration config = new XMLConfiguration(file); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex(xmlpath); for (int i = 0; i <= count; i++) { String name = config.getString(xmlpath + "(" + i + ")[@name]"); String value = config.getString(xmlpath + "(" + i + ")[@value]"); fields.put(name, value); } } } catch (ConfigurationException | RuntimeException e) { logger.debug(e.getMessage(), e); fields = new HashMap<>(); } return fields; }
From source file:org.kitodo.production.exporter.ExportXmlLog.java
private HashMap<String, String> getNamespacesFromConfig() { HashMap<String, String> nss = new HashMap<>(); try {//from ww w.ja v a 2s .c o m File file = new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_exportXml.xml"); if (file.exists() && file.canRead()) { XMLConfiguration config = new XMLConfiguration(file); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex("namespace"); for (int i = 0; i <= count; i++) { String name = config.getString("namespace(" + i + ")[@name]"); String value = config.getString("namespace(" + i + ")[@value]"); nss.put(name, value); } } } catch (ConfigurationException | RuntimeException e) { logger.debug(e.getMessage(), e); nss = new HashMap<>(); } return nss; }
From source file:org.kitodo.production.metadata.display.helper.ConfigDisplayRules.java
/** * Reads given xml file into XMLConfiguration. *//*from ww w .ja va2 s . c o m*/ private ConfigDisplayRules() { String configPath = KitodoConfigFile.METADATA_DISPLAY_RULES.getAbsolutePath(); try { config = new XMLConfiguration(configPath); config.setReloadingStrategy(new FileChangedReloadingStrategy()); getDisplayItems(); } catch (ConfigurationException e) { /* * no configuration file found, default configuration (textarea) will be used, * nothing to do here */ } }