List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration()
XMLConfiguration
. From source file:ch.admin.suis.msghandler.config.SedexCertConfigFactory.java
/** * Factory constructor./*from w w w .j av a2 s. c o m*/ * * @param configFile File object referencing the file certificateConfiguration.xml rom the sedex configuratioon. * @throws ConfigurationException if the file doen't exist or if doesn't conform to the required XML Schema. */ public SedexCertConfigFactory(File configFile) throws ConfigurationException { FileUtils.isFile(configFile, ".certificateConfigFile[@filePath]"); XMLConfiguration xmlConfig = new XMLConfiguration(); // disable the schema validation by XMLConfiguration, since the config file does not contain a schema location xmlConfig.setSchemaValidation(false); xmlConfig.setFile(configFile); try { XMLValidator.validateSedexCertificateConfig(configFile); xmlConfig.load(); } catch (ConfigurationException ex) { LOG.error("XML File: " + configFile.getAbsolutePath() + " could not be loaded. It seems the XML file is not valid"); throw ex; } parseFile(xmlConfig, configFile.getAbsolutePath()); }
From source file:com.cedarsoft.configuration.xml.XmlConfigurationManagerTest.java
@Before public void setUp() throws Exception { configuration = new XMLConfiguration(); manager = new XmlConfigurationManager(configuration); file = tmp.newFile("config.xml"); configuration.setFile(file);// w ww .j ava 2 s . c om }
From source file:net.lmxm.ute.beans.configuration.ApplicationPreferences.java
/** * Instantiates a new application preferences. * * @param configurationFile the configuration file *//*from w w w . java2s . c om*/ public ApplicationPreferences(final File configurationFile) { final String prefix = "ApplicationPreferences() :"; LOGGER.debug("{} entered. configurationFile={}", prefix, configurationFile); XMLConfiguration xmlConfiguration = null; try { xmlConfiguration = new XMLConfiguration(); final File preferencesFile = new File(configurationFile.getParent(), PREFERENCES_FILE_NAME); if (!preferencesFile.exists()) { LOGGER.debug("{} preferences file does not exist, creating a new file", prefix); createEmptyPreferencesFile(preferencesFile); } LOGGER.debug("{} loading preferences", prefix); xmlConfiguration.load(preferencesFile); } catch (final org.apache.commons.configuration.ConfigurationException e) { LOGGER.debug(prefix + " ConfigurationException caught trying to load configuration", e); throw new ConfigurationException(ExceptionResourceType.ERROR_LOADING_PREFERENCES_FILE, e); } configuration = xmlConfiguration; LOGGER.debug("{} leaving", prefix); }
From source file:com.epam.cme.mdp3.core.cfg.Configuration.java
/** * Loads and parse CME MDP Configuration. * * @param uri URI to CME MDP Configuration (config.xml, usually available on CME FTP) * @throws ConfigurationException if failed to parse configuration file * @throws MalformedURLException if URI to Configuration is malformed *//*from w w w . j av a 2 s . c o m*/ private void load(final URI uri) throws ConfigurationException, MalformedURLException { // todo: if to implement the same via standard JAXB then dep to apache commons configuration will be not required final XMLConfiguration configuration = new XMLConfiguration(); configuration.setDelimiterParsingDisabled(true); configuration.load(uri.toURL()); for (final HierarchicalConfiguration channelCfg : configuration.configurationsAt("channel")) { final ChannelCfg channel = new ChannelCfg(channelCfg.getString("[@id]"), channelCfg.getString("[@label]")); for (final HierarchicalConfiguration connCfg : channelCfg.configurationsAt("connections.connection")) { final String id = connCfg.getString("[@id]"); final FeedType type = FeedType.valueOf(connCfg.getString("type[@feed-type]")); final TransportProtocol protocol = TransportProtocol .valueOf(connCfg.getString("protocol").substring(0, 3)); final Feed feed = Feed.valueOf(connCfg.getString("feed")); final String ip = connCfg.getString("ip"); final int port = connCfg.getInt("port"); final List<String> hostIPs = Arrays.asList(connCfg.getStringArray("host-ip")); final ConnectionCfg connection = new ConnectionCfg(feed, id, type, protocol, ip, hostIPs, port); channel.addConnection(connection); connCfgs.put(connection.getId(), connection); } channelCfgs.put(channel.getId(), channel); } }
From source file:com.eyeq.pivot4j.ui.condition.NotConditionTest.java
@Test public void testSettingsManagement() throws ConfigurationException { RenderContext context = createDummyRenderContext(); NotCondition not = new NotCondition(conditionFactory); not.setSubCondition(TestCondition.FALSE); XMLConfiguration configuration = new XMLConfiguration(); configuration.setRootElementName("condition"); not.saveSettings(configuration);//from ww w .j a va2s.c o m not = new NotCondition(conditionFactory); not.restoreSettings(configuration); assertThat("Sub condition should not be null.", not.getSubCondition(), is(notNullValue())); assertThat("'!false' should be true.", not.matches(context), is(true)); System.out.println("Saved configuration : "); configuration.save(System.out); }
From source file:m.c.m.proxyma.ProxymaServlet.java
/** * Initialize the servlet and the proxyma environment. *///from w w w. j a v a2 s . co m @Override public void init() { try { //Obtain configuration parameters.. ServletConfig config = this.getServletConfig(); String proxymaConfigFile = this.getInitParameter("ProxymaConfigurationFile"); String proxymaContextName = this.getInitParameter("ProxymaContextName"); String proxymaLogsDirectory = this.getInitParameter("ProxymaLogsDir"); //if the config file init-parameter is notspecified use the default configuration if (proxymaConfigFile == null) proxymaConfigFile = config.getServletContext().getRealPath("/WEB-INF/proxyma-config.xml"); //Hack to get the servlet path reading it directly from the deployment descriptor. //Valid until apache will put a getServletMappings() method into the ServletConfig class. XMLConfiguration deploymentDescriptor = null; try { deploymentDescriptor = new XMLConfiguration(); deploymentDescriptor.setFile(new File(config.getServletContext().getRealPath("/WEB-INF/web.xml"))); deploymentDescriptor.setValidating(false); deploymentDescriptor.load(); } catch (ConfigurationException ex) { Logger.getLogger("").log(Level.SEVERE, "Unable to load web.xml", ex); } deploymentDescriptor.setExpressionEngine(new XPathExpressionEngine()); String servletPath = deploymentDescriptor .getString("servlet-mapping[servlet-name='" + config.getServletName() + "']/url-pattern"); String proxymaServletContext = config.getServletContext().getContextPath() + servletPath.replaceFirst("/\\*$", GlobalConstants.EMPTY_STRING); //Check if the logs directory init-parameter ends with "/" if (!proxymaLogsDirectory.endsWith("/")) { proxymaLogsDirectory = proxymaLogsDirectory + "/"; } //Create a new proxyma facade this.proxyma = new ProxymaFacade(); //Create a new proxyma context this.proxymaContext = proxyma.createNewContext(proxymaContextName, proxymaServletContext, proxymaConfigFile, proxymaLogsDirectory); //Create a reverse proxy engine for this servlet thread this.proxymaEngine = proxyma.createNewProxyEngine(proxymaContext); } catch (IllegalAccessException ex) { ex.printStackTrace(); } }
From source file:com.bibisco.manager.ConfigManager.java
private ConfigManager(String pStrConfigurationFilePath) { mXMLConfiguration = new XMLConfiguration(); mXMLConfiguration.setFileName(pStrConfigurationFilePath); mXMLConfiguration.setExpressionEngine(new XPathExpressionEngine()); try {/*from ww w. j a va 2 s.c om*/ mXMLConfiguration.load(); } catch (ConfigurationException e) { mLog.error(e, "Error while reading configuration from file ", CONFIG_FILENAME); throw new BibiscoException(e, "bibiscoException.configManager.errorWhileReadingConfiguration", e.getMessage()); } mBlnCache = true; mLog.debug("ConfigManager initialized using file ", pStrConfigurationFilePath); }
From source file:com.example.TestClass.java
@Test public void testWithSeparatingWhitespace() throws Exception { String source = "<configuration><key0></key0><key1>,</key1> <key2></key2><key3></key3></configuration>"; XMLConfiguration config = new XMLConfiguration(); config.load(new StringReader(source)); checkConfiguration(config);/*from ww w. ja v a 2 s . co m*/ }
From source file:elaborate.editor.config.Configuration.java
public XMLConfiguration load(Reader reader) { try {/*from w ww . j a v a 2 s. co m*/ messages = Maps.newTreeMap(); AbstractConfiguration.setDefaultListDelimiter(','); XMLConfiguration config = new XMLConfiguration(); config.clear(); config.load(reader); processConfiguration(config); xmlConfig = config; return config; } catch (ConfigurationException e) { throw new RuntimeException("Failed to load configuration", e); } }
From source file:cn.quickj.Setting.java
/** * setting.xml???/*from w w w. j a va 2 s . c o m*/ * * @param rootPath * @throws Exception * */ public static void load(String rootPath) throws Exception { if (initFinished == true) return; XMLConfiguration config; String settingPath = ""; if (rootPath == null) { // WebApplication Setting.xml String classPath = Thread.currentThread().getContextClassLoader().getResource("").getPath(); Pattern p = Pattern.compile("([\\S]+/)WEB-INF[\\S]+"); Matcher m = p.matcher(classPath); if (m.find()) webRoot = m.group(1); } else webRoot = rootPath; try { webRoot = URLDecoder.decode(webRoot, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (webRoot.endsWith(".xml")) { settingPath = webRoot; int lastPos = webRoot.lastIndexOf('\\'); if (lastPos == -1) lastPos = webRoot.lastIndexOf('/'); webRoot = webRoot.substring(0, lastPos); } else { if (!webRoot.endsWith("/") && !webRoot.endsWith("\\")) webRoot = webRoot + "/"; settingPath = webRoot + "WEB-INF/setting.xml"; } log.info("Loading setting file:" + settingPath); config = new XMLConfiguration(); // ?????? config.setDelimiterParsingDisabled(true); config.load(settingPath); /* * @Deprecated * ????unittest?runserver? * war?XML? String strRunMode = * config.getString("runmode", "development"); if * (strRunMode.equals("production")) runMode = PROD_MODE; else if * (strRunMode.equals("test")) runMode = TEST_MODE; else runMode = * DEV_MODE; */ String strRunMode = getRunMode(); packageRoot = config.getString("package", packageRoot); fieldBySetter = config.getBoolean("web.fieldBySetter", false); DEFAULT_CHARSET = config.getString("web.charset", "utf-8"); longDateFormat = config.getString("web.long-dateformat", "yyyy-MM-dd HH:mm:ss"); license = config.getString("license"); shortDateFormat = config.getString("web.short-dateformat", "yyyy-MM-dd"); String strLocale = config.getString("web.locale", Locale.getDefault().getDisplayName()); theme = config.getString("web.theme"); locale = new Locale(strLocale); sessionClass = config.getString("web.session.class", "cn.quickj.session.MemHttpSession"); sessionDomain = config.getString("web.session.domain", null); sessionTimeOut = config.getInt("web.session.timeout", 30 * 60); defaultUri = config.getString("web.defaultUri"); uploadDir = config.getString("web.upload.directory", System.getProperty("java.io.tmpdir")); uploadMaxSize = config.getInt("web.upload.max-size", 4096); jdbcDriver = config.getString("database." + strRunMode + ".driver", ""); usedb = (jdbcDriver.length() != 0); jdbcUser = config.getString("database." + strRunMode + ".user", "root"); jdbcUrl = config.getString("database." + strRunMode + ".url", ""); jdbcPassword = config.getString("database." + strRunMode + ".password", ""); maxActive = config.getInt("database." + strRunMode + ".pool.maxActive", 10); initActive = config.getInt("database." + strRunMode + ".pool.initActive", 2); maxIdle = config.getInt("database." + strRunMode + ".pool.maxIdle", 1800); dialect = config.getString("database." + strRunMode + ".dialect", null); tablePrefix = config.getString("database.prefix", ""); cacheClass = config.getString("cache.class", "cn.quickj.cache.SimpleCache"); cacheParam = config.getString("cache.param", "capacity=50000"); // ?? queueEnabled = "true".equalsIgnoreCase(config.getString("queue.enable", "false")); queueParam = config.getString("queue.param", "capacity=50000"); loadPlugin(config); loadApplicationConfig(); initFinished = true; }