List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:ch.kostceco.tools.kostsimy.service.impl.ConfigurationServiceImpl.java
private XMLConfiguration getConfig() { if (this.config == null) { try {/*from w ww . j av a 2 s . c o m*/ String path = "configuration/kostsimy.conf.xml"; URL locationOfJar = KOSTSimy.class.getProtectionDomain().getCodeSource().getLocation(); String locationOfJarPath = locationOfJar.getPath(); if (locationOfJarPath.endsWith(".jar")) { File file = new File(locationOfJarPath); String fileParent = file.getParent(); path = fileParent + "/" + path; } config = new XMLConfiguration(path); } catch (ConfigurationException e) { LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI) + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_1)); LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI) + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_2)); LOGGER.logError(getTextResourceService().getText(MESSAGE_XML_MODUL_CI) + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_3)); System.exit(1); } } return config; }
From source file:de.teamgrit.grit.util.config.Configuration.java
/** * Loads the configuration from the specified File. * /*from w w w. j a v a2 s .c o m*/ * @param file * the file the config is stored in * @throws ConfigurationException * if the configuration file can't be read. * @throws FileNotFoundException * if the file can't be found */ public Configuration(File file) throws ConfigurationException, FileNotFoundException { LOGGER.info("Loading configuration from file: " + file.getAbsolutePath()); if (!file.exists()) { LOGGER.warning("Could not find configuration file: " + file.getAbsolutePath()); throw new FileNotFoundException(file.getAbsolutePath()); } m_configXML = file; m_config = new XMLConfiguration(file); // set xpath engine for more powerful queries m_config.setExpressionEngine(new XPathExpressionEngine()); loadToMember(); // save(); }
From source file:edu.cornell.med.icb.R.RUtils.java
public static void main(final String[] args) throws ParseException, ConfigurationException { final Options options = new Options(); final Option helpOption = new Option("h", "help", false, "Print this message"); options.addOption(helpOption);/*from w w w . j a v a2 s . c o m*/ final Option startupOption = new Option(Mode.startup.name(), Mode.startup.name(), false, "Start Rserve process"); final Option shutdownOption = new Option(Mode.shutdown.name(), Mode.shutdown.name(), false, "Shutdown Rserve process"); final Option validateOption = new Option(Mode.validate.name(), Mode.validate.name(), false, "Validate that Rserve processes are running"); final OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(startupOption); optionGroup.addOption(shutdownOption); optionGroup.addOption(validateOption); optionGroup.setRequired(true); options.addOptionGroup(optionGroup); final Option portOption = new Option("port", "port", true, "Use specified port to communicate with the Rserve process"); portOption.setArgName("port"); portOption.setType(int.class); options.addOption(portOption); final Option hostOption = new Option("host", "host", true, "Communicate with the Rserve process on the given host"); hostOption.setArgName("hostname"); hostOption.setType(String.class); options.addOption(hostOption); final Option userOption = new Option("u", "username", true, "Username to send to the Rserve process"); userOption.setArgName("username"); userOption.setType(String.class); options.addOption(userOption); final Option passwordOption = new Option("p", "password", true, "Password to send to the Rserve process"); passwordOption.setArgName("password"); passwordOption.setType(String.class); options.addOption(passwordOption); final Option configurationOption = new Option("c", "configuration", true, "Configuration file or url to read from"); configurationOption.setArgName("configuration"); configurationOption.setType(String.class); options.addOption(configurationOption); final Parser parser = new BasicParser(); final CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException e) { usage(options); throw e; } int exitStatus = 0; if (commandLine.hasOption("h")) { usage(options); } else { Mode mode = null; for (final Mode potentialMode : Mode.values()) { if (commandLine.hasOption(potentialMode.name())) { mode = potentialMode; break; } } final ExecutorService threadPool = Executors.newCachedThreadPool(); if (commandLine.hasOption("configuration")) { final String configurationFile = commandLine.getOptionValue("configuration"); LOG.info("Reading configuration from " + configurationFile); XMLConfiguration configuration; try { final URL configurationURL = new URL(configurationFile); configuration = new XMLConfiguration(configurationURL); } catch (MalformedURLException e) { // resource is not a URL: attempt to get the resource from a file LOG.debug("Configuration is not a valid url"); configuration = new XMLConfiguration(configurationFile); } configuration.setValidating(true); final int numberOfRServers = configuration.getMaxIndex("RConfiguration.RServer") + 1; boolean failed = false; for (int i = 0; i < numberOfRServers; i++) { final String server = "RConfiguration.RServer(" + i + ")"; final String host = configuration.getString(server + "[@host]"); final int port = configuration.getInt(server + "[@port]", RConfigurationUtils.DEFAULT_RSERVE_PORT); final String username = configuration.getString(server + "[@username]"); final String password = configuration.getString(server + "[@password]"); final String command = configuration.getString(server + "[@command]", DEFAULT_RSERVE_COMMAND); if (executeMode(mode, threadPool, host, port, username, password, command) != 0) { failed = true; // we have other hosts to check so keep a failed state } } if (failed) { exitStatus = 3; } } else { final String host = commandLine.getOptionValue("host", "localhost"); final int port = Integer.valueOf(commandLine.getOptionValue("port", "6311")); final String username = commandLine.getOptionValue("username"); final String password = commandLine.getOptionValue("password"); exitStatus = executeMode(mode, threadPool, host, port, username, password, null); } threadPool.shutdown(); } System.exit(exitStatus); }
From source file:com.sonicle.webtop.core.app.DataSourcesConfig.java
public void parseConfiguration(File file) throws ConfigurationException { HikariConfigMap sources = null;//from ww w. j a va 2 s . c om String serviceId = null, sourceName = null; XMLConfiguration config = new XMLConfiguration(file); List<HierarchicalConfiguration> elServices = config.configurationsAt("service"); for (HierarchicalConfiguration elService : elServices) { serviceId = elService.getString("[@id]", null); if (serviceId == null) { logger.warn("Missing attribute [id] in [{}]", elService.toString()); continue; } // Iterates over service' sources sources = new HikariConfigMap(); List<HierarchicalConfiguration> elSources = elService.configurationsAt("dataSource"); for (HierarchicalConfiguration elSource : elSources) { sourceName = elSource.getString("[@name]", ConnectionManager.DEFAULT_DATASOURCE); logger.trace("name: {}", sourceName); try { sources.put(sourceName, parseDataSource(elSource)); } catch (ParseException ex) { logger.warn("Error parsing dataSource definition [{}]", ex, elSource.toString()); } } hm.put(serviceId, sources); } }
From source file:net.handle.servlet.SettingsTest.java
@Test public void testValidConfiguration() throws Exception { // control variables String datatypesRequestParameterName = "include"; Template defaultErrorResponseTemplate = new Template(Mimetype.APPLICATION_RDF_XML, "error", Template.Type.ERROR_RESPONSE); Template defaultHandleResponseTemplate = new Template(Mimetype.APPLICATION_RDF_XML, "handle", Template.Type.HANDLE_RESPONSE); Map<Mimetype, Template> errorResponseTemplates = new HashMap<Mimetype, Template>(); errorResponseTemplates.put(Mimetype.APPLICATION_RDF_XML, new Template(Mimetype.APPLICATION_RDF_XML, "error", Template.Type.ERROR_RESPONSE)); errorResponseTemplates.put(Mimetype.TEXT_PLAIN, new Template(Mimetype.TEXT_PLAIN, "error", Template.Type.ERROR_RESPONSE)); errorResponseTemplates.put(Mimetype.APPLICATION_XHTML_XML, new Template(Mimetype.APPLICATION_XHTML_XML, "error", Template.Type.ERROR_RESPONSE)); String formatRequestParameterName = "format"; String handleIdRequestParameterName = "id"; Map<Mimetype, Template> handleResponseTemplates = new HashMap<Mimetype, Template>(); handleResponseTemplates.put(Mimetype.APPLICATION_RDF_XML, new Template(Mimetype.APPLICATION_RDF_XML, "handle", Template.Type.HANDLE_RESPONSE)); handleResponseTemplates.put(Mimetype.APPLICATION_JSON, new Template(Mimetype.APPLICATION_JSON, "handle", Template.Type.HANDLE_RESPONSE)); handleResponseTemplates.put(Mimetype.TEXT_RDF_N3, new Template(Mimetype.TEXT_RDF_N3, "handle", Template.Type.HANDLE_RESPONSE)); String indexRequestParameterName = "index"; int[] preferredProtocols = Protocol.toIntArray("http, tcp"); String typeRequestParameterName = "type"; boolean traceMessages = true; // instantiate configuration Configuration configuration = new XMLConfiguration(SettingsTest.class.getResource("/OpenHandleTest.xml")); Settings settings = new Settings(configuration); // settings should match control assertEquals(datatypesRequestParameterName, settings.getDatatypesRequestParameterName()); assertEquals(defaultErrorResponseTemplate, settings.getDefaultErrorResponseTemplate()); assertEquals(defaultHandleResponseTemplate, settings.getDefaultHandleResponseTemplate()); assertEquals(errorResponseTemplates, settings.getErrorResponseTemplates()); assertEquals(formatRequestParameterName, settings.getFormatRequestParameterName()); assertEquals(handleIdRequestParameterName, settings.getHandleIdRequestParameterName()); assertEquals(handleResponseTemplates, settings.getHandleResponseTemplates()); assertEquals(indexRequestParameterName, settings.getIndexRequestParameterName()); assertEquals(Protocol.toString(preferredProtocols), Protocol.toString(settings.getPreferredProtocols())); assertEquals(typeRequestParameterName, settings.getTypeRequestParameterName()); assertEquals(traceMessages, settings.isTraceMessages()); }
From source file:com.nokia.ant.taskdefs.AntConfigurationTask.java
private void importFile(final File file) { try {/*from w w w . j av a2s. c om*/ String filename = file.getName(); Configuration config = null; if (filename.endsWith(".txt")) { config = new PropertiesConfiguration(file); } else if (filename.endsWith(".xml")) { config = new XMLConfiguration(file); } Iterator keysIter = config.getKeys(); while (keysIter.hasNext()) { String key = (String) keysIter.next(); getProject().setProperty(key, config.getString(key)); } } catch (ConfigurationException e) { throw new BuildException("Not able to import the ANT file " + e.getMessage()); } }
From source file:com.boozallen.cognition.ingest.storm.bolt.starter.LineRegexReplaceInRegionBoltTest.java
@Test public void testConfigureFields() throws Exception { XMLConfiguration conf = new XMLConfiguration(getResource(this.getClass(), "fields.xml")); bolt.configureFields(conf);//from ww w. j a va 2 s.c o m assertThat(bolt.fieldList.size(), is(3)); }
From source file:ch.kostceco.tools.siardval.service.impl.ConfigurationServiceImpl.java
private XMLConfiguration getConfig() { if (this.config == null) { try {/*from ww w . j av a2 s .c om*/ String path = "configuration/SIARDVal.conf.xml"; URL locationOfJar = SIARDVal.class.getProtectionDomain().getCodeSource().getLocation(); String locationOfJarPath = locationOfJar.getPath(); if (locationOfJarPath.endsWith(".jar")) { File file = new File(locationOfJarPath); String fileParent = file.getParent(); path = fileParent + "/" + path; } config = new XMLConfiguration(path); } catch (ConfigurationException e) { LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_1)); // Das Konfigurations-File konnte nicht gelesen werden. LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_2)); // Im gleichen Verzeichnis wie das ".jar"-File muss sich ein // Ordner namens "configuration" befinden. LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_3)); // Im configuration-Ordner wiederum muss die Konfigurationsdatei // "SIARDVal.conf.xml" liegen. System.exit(1); } } return config; }
From source file:com.xemantic.tadedon.configuration.ConfigurationsTest.java
/** * copying of XML properties does not work at the moment * @throws IOException/*from w w w.j a v a 2 s .com*/ * @throws ConfigurationException */ @Test @Ignore public void shouldCopyXmlPropertyWithoutComments() throws IOException, ConfigurationException { // given File confFile1 = new File("src/test/data/conf1.xml"); File confFile2 = new File("src/test/data/conf2.xml"); File confFile3 = new File("src/test/data/conf3.xml"); File outConfFile = new File(testConfDir, "outConf.xml"); Files.copy(confFile1, outConfFile); XMLConfiguration conf2 = new XMLConfiguration(confFile2); XMLConfiguration outConf = new XMLConfiguration(outConfFile); // when //Configurations.copyProperty("bar", conf2, outConf); outConf.save(); // then assertThat(Files.equal(outConfFile, confFile3), is(true)); }
From source file:ch.kostceco.tools.tiffval.service.impl.ConfigurationServiceImpl.java
private XMLConfiguration getConfig() { if (this.config == null) { try {/* w ww . j a v a 2 s.c om*/ String path = "configuration/TIFFVal.conf.xml"; URL locationOfJar = TIFFVal.class.getProtectionDomain().getCodeSource().getLocation(); String locationOfJarPath = locationOfJar.getPath(); if (locationOfJarPath.endsWith(".jar")) { File file = new File(locationOfJarPath); String fileParent = file.getParent(); path = fileParent + "/" + path; } config = new XMLConfiguration(path); } catch (ConfigurationException e) { System.out.print( "\r "); System.out.flush(); System.out.print("\r"); System.out.flush(); LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_1)); LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_2)); LOGGER.logInfo(getTextResourceService().getText(MESSAGE_CONFIGURATION_ERROR_3)); System.exit(1); } } return config; }