List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:org.ihtsdo.statistics.runner.Runner.java
/** * Inits the file providers./* w w w.j a va 2s . com*/ * * @param file the file * @throws Exception the exception */ private static void initFileProviders(File file) throws Exception { logger.logInfo("Initializing file providers"); XMLConfiguration xmlConfig; try { xmlConfig = new XMLConfiguration(file); } catch (ConfigurationException e) { logger.logInfo("ClassificationRunner - Error happened getting params configFile." + e.getMessage()); throw e; } String releaseFolder = xmlConfig.getString("releaseFullFolder"); if (releaseFolder == null || releaseFolder.trim().equals("") || !new File(releaseFolder).exists()) { throw new Exception("Release folder doesn't exist."); } File sourceFolder = new File(releaseFolder); Object prop = xmlConfig.getProperty("releaseDependencies.releaseFullFolder"); HashSet<String> releaseDependencies = null; if (prop != null) { if (prop instanceof Collection) { releaseDependencies = new HashSet<String>(); for (String loopProp : (Collection<String>) prop) { releaseDependencies.add(loopProp); } } else if (prop instanceof String) { releaseDependencies = new HashSet<String>(); releaseDependencies.add((String) prop); System.out.println(prop); } } String releaseDate = xmlConfig.getString("releaseDate"); String previousReleaseDate = xmlConfig.getString("previousReleaseDate"); CurrentFile.init(sourceFolder, new File("release" + releaseDate), releaseDependencies, releaseDate); PreviousFile.init(sourceFolder, new File("release" + previousReleaseDate), releaseDependencies, previousReleaseDate); }
From source file:org.jahia.loganalyzer.configuration.LogParserConfiguration.java
public LogParserConfiguration() { try {// w ww .j a va 2 s. c o m File overrideFile = new File("parser-config.xml"); XMLConfiguration config; if (overrideFile.exists()) { logger.info("Using overriden local parser-config.xml file for configuration..."); config = new XMLConfiguration(overrideFile); } else { logger.info("Using default parser-config.xml file for configuration..."); ClassLoader threadContextClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); config = new XMLConfiguration("parser-config.xml"); Thread.currentThread().setContextClassLoader(threadContextClassLoader); } contextMapping = config.getString("context-mapping"); servletMapping = config.getString("servlet-mapping"); dateFormatString = config.getString("date-format"); perfMatchingPattern = config.getString("analyzers.perf-analyzer.matching-pattern"); exceptionFirstLinePattern = config.getString("analyzers.exception-analyzer.firstline-pattern"); exceptionSecondLinePattern = config.getString("analyzers.exception-analyzer.secondline-pattern"); exceptionCausedByPattern = config.getString("analyzers.exception-analyzer.causedby-pattern"); standardLogAnalyzerPattern = config.getString("analyzers.standardlog-analyzer.matching-pattern"); } catch (ConfigurationException ce) { logger.error("Configuration could not be loaded, ignoring and using defaults", ce); } }
From source file:org.jboss.forge.shell.env.ConfigurationImpl.java
@Unwraps public Configuration getConfiguration() throws ConfigurationException { Project project = shell.getCurrentProject(); if ((project != null) && !project.equals(this.currentProject)) { currentProject = project;/*from w ww. j a v a 2s .c o m*/ ScopedConfigurationAdapter projectConfig = new ScopedConfigurationAdapter(); XMLConfiguration projectLocalConfig; try { projectLocalConfig = new XMLConfiguration( getProjectSettings(project).getUnderlyingResourceObject()); projectLocalConfig.setEncoding("UTF-8"); } catch (org.apache.commons.configuration.ConfigurationException e) { throw new ConfigurationException(e); } projectLocalConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); projectLocalConfig.setAutoSave(true); ConfigurationAdapter adapter = BeanManagerUtils.getContextualInstance(bm, ConfigurationAdapter.class, new ConfigAdapterQualifierLiteral()); adapter.setParent(projectConfig); adapter.setDelegate(projectLocalConfig); adapter.setBeanManager(bm); projectConfig.setScopedConfiguration(ConfigurationScope.PROJECT, adapter); projectConfig.setScopedConfiguration(ConfigurationScope.USER, getUserConfig()); this.projectConfig = projectConfig; return projectConfig; } else if ((project != null) && project.equals(this.currentProject)) { return projectConfig; } return getUserConfig(); }
From source file:org.jboss.forge.shell.env.ConfigurationImpl.java
public Configuration getUserConfig() throws ConfigurationException { // FIXME NPE caused when no project exists because config param is null if (userConfig == null) { XMLConfiguration globalXml;/*from www. j a v a2s. c om*/ try { globalXml = new XMLConfiguration(environment.getUserConfiguration().getUnderlyingResourceObject()); globalXml.setEncoding("UTF-8"); } catch (org.apache.commons.configuration.ConfigurationException e) { throw new ConfigurationException(e); } globalXml.setReloadingStrategy(new FileChangedReloadingStrategy()); globalXml.setAutoSave(true); ConfigurationAdapter adapter = BeanManagerUtils.getContextualInstance(bm, ConfigurationAdapter.class, new ConfigAdapterQualifierLiteral()); adapter.setDelegate(globalXml); adapter.setBeanManager(bm); userConfig = new ScopedConfigurationAdapter(ConfigurationScope.USER, adapter); } return userConfig; }
From source file:org.jdag.launcher.JDAGLauncher.java
/** * CTOR// w w w . jav a2 s . c om */ @SuppressWarnings("static-access") public JDAGLauncher(String[] args) { try { Option classPathFileOption = OptionBuilder.withDescription("<the file containing class path>").hasArg() .create(OPTION_JDAG_HOME); Options options = new Options(); options.addOption(classPathFileOption); CommandLineParser commandLineParser = new GnuParser(); CommandLine commandLine = commandLineParser.parse(options, args); if (!commandLine.hasOption(OPTION_JDAG_HOME)) { LOG.severe("The file containing class path is not specified" + " Hence aborting"); } File libDir = new File(commandLine.getOptionValue(OPTION_JDAG_HOME) + File.separator + LIB_DIR); if (!libDir.exists()) { throw new RuntimeException("Not able to resolve the library directory" + " Please check " + libDir.getAbsolutePath() + " exists"); } File[] dependentLibraries = libDir.listFiles(); if (dependentLibraries.length == 0) { throw new RuntimeException("Not able to locate dependent jars " + " in " + libDir); } StringBuilder builder = new StringBuilder(); File confDir = new File(commandLine.getOptionValue(OPTION_JDAG_HOME) + File.separator + CONF_DIR); if (!confDir.exists()) { throw new RuntimeException( "Unable to locate the conf directory" + " " + confDir.getAbsolutePath()); } builder.append(confDir.getAbsolutePath()); for (File f : dependentLibraries) { builder.append(File.pathSeparator); builder.append(f.getAbsolutePath()); } myClassPath = builder.toString(); File f = new File(ClassLoader.getSystemClassLoader().getResource(TOPOLOGY_FILE).getFile()); myTopologyConfiguration = new XMLConfiguration(f); } catch (ConfigurationException e) { LOG.log(Level.SEVERE, "Exception when loading the topology file", e); throw new RuntimeException(e); } catch (ParseException e) { LOG.log(Level.SEVERE, "Exception while parsing command line arguments", e); throw new RuntimeException(e); } }
From source file:org.jevis.commons.cli.ConfigurationHelper.java
/** * Create an new configuration skeleton/*from w ww. ja v a 2s .com*/ * * @param file * @throws ConfigurationException */ public void createConfigFile(File file) throws ConfigurationException { //TODO: XPath expressions for a better implementation see http://www.code-thrill.com/2012/05/configuration-that-rocks-with-apache.html XMLConfiguration config = new XMLConfiguration(file); config.setProperty("jevis.datasource.class", "org.jevis.api.sql.JEVisDataSourceSQL"); config.setProperty("jevis.datasource.host", "openjevis.org"); config.setProperty("jevis.datasource.schema", "jevis"); config.setProperty("jevis.datasource.port", "13306"); config.setProperty("jevis.datasource.username", "jevis"); config.setProperty("jevis.datasource.password", "jevistest"); config.save(); }
From source file:org.jevis.commons.config.XMLConfigFileReader.java
/** * Create an new XMLConfigFileReader with the given XML-file. * * @param file/*from w w w .jav a 2s. co m*/ * @throws ConfigurationException */ public XMLConfigFileReader(File file) throws ConfigurationException { xmlConfig = new XMLConfiguration(file); }
From source file:org.jevis.jealarm.Config.java
/** * Create an new Configuration out of an xml file * * @param file/*from w w w . j av a 2 s. c o m*/ * @throws ConfigurationException */ public Config(String file) throws ConfigurationException { File cFile = new File(file); if (cFile.exists()) { XMLConfiguration configFile = new XMLConfiguration(cFile); jevisUser = configFile.getString("jevis.user"); jevisPW = configFile.getString("jevis.password"); jevisURL = configFile.getString("jevis.server"); jevisPort = configFile.getInt("jevis.port"); jevisSchema = configFile.getString("jevis.schema"); jevisDBUser = configFile.getString("jevis.dbuser"); jevisDBPassword = configFile.getString("jevis.dbpassword"); smtpUser = configFile.getString("sender.user"); smtpPW = configFile.getString("sender.password"); smtpServer = configFile.getString("sender.smtp"); smtpSSL = configFile.getBoolean("sender.ssl"); smtpPort = configFile.getInt("sender.port"); smtpFrom = configFile.getString("sender.from"); smtpSignatur = configFile.getString("sender.signatur"); // System.out.println("jevisUser: " + jevisUser); // System.out.println("jevisPW: " + jevisPW); // System.out.println("jevisURL: " + jevisURL); // System.out.println("jevisPort: " + jevisPort); // System.out.println("smtpUser: " + smtpUser); // System.out.println("smtpPW: " + smtpPW); // System.out.println("smtpServer: " + smtpServer); int i = 0; while (configFile.getString("alarm(" + i + ").subject") != null) { // System.out.println("--------------"); // System.out.println("Alarm[" + i + "]" + configFile.getString("alarm(" + i + ").subject")); try { Alarm alarm = new Alarm(configFile.getString("alarm(" + i + ").subject"), configFile.getStringArray("alarm(" + i + ").datapoint"), configFile.getStringArray("alarm(" + i + ").recipient"), configFile.getStringArray("alarm(" + i + ").bcc"), configFile.getInt("alarm(" + i + ").timelimit"), configFile.getInt("alarm(" + i + ").ignoreold"), configFile.getString("alarm(" + i + ").greeting"), configFile.getString("alarm(" + i + ").message"), configFile.getBoolean("alarm(" + i + ").ignorefalse", true)); // System.out.println("recipient: " + configFile.getStringArray("alarm(" + i + ").recipient").length); alarms.add(alarm); } catch (Exception ex) { System.out.println("Configiration error: " + ex); } i++; } System.out.println("--------------"); } else { System.out.println("Abbort, configfile dows not exists"); } }
From source file:org.jevis.jeconfig.JEConfig.java
private void loadConfiguration(String url) { try {/*from ww w . j a v a2 s . co m*/ XMLConfiguration config = new XMLConfiguration(url); config.getString("webservice.port"); } catch (ConfigurationException ex) { Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.jevis.rest.Config.java
private static void readConfigurationFile() { try {/*from w w w . j a v a 2 s .co m*/ if (!_fileIsLoaded) { File cfile = new File("config.xml"); if (cfile.exists()) { // Logger.getLogger(Config.class.getName()).log(Level.INFO, "using Configfile: " + cfile.getAbsolutePath()); logger.info("using Configfile: {}", cfile.getAbsolutePath()); XMLConfiguration config = new XMLConfiguration(cfile); _port = config.getString("webservice.port"); _dbport = config.getString("datasource.port"); _dbip = config.getString("datasource.url"); _dbuser = config.getString("datasource.login"); _dbpw = config.getString("datasource.password"); _schema = config.getString("datasource.schema"); //Woraround solution for the registration service _rootUser = config.getString("sysadmin.username"); _rootPW = config.getString("sysadmin.password"); _demoRoot = config.getLong("registration.root"); _demoGroup = config.getLong("registration.demogroup"); _registratioKey = config.getString("registration.apikey"); _fileIsLoaded = true; } else { logger.fatal("Warning configfile does not exist: {}", cfile.getAbsolutePath()); // Logger.getLogger(Config.class.getName()).log(Level.SEVERE, "Warning configfile does not exist: " + cfile.getAbsolutePath()); } } } catch (ConfigurationException ex) { logger.fatal("Unable to read config", ex); // Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } }