List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:com.sinfonier.util.XMLProperties.java
/** * Constructor/*from w w w . jav a2s .c o m*/ * * @param componentName Name of the component * @param type ComponentType * @param xmlPath Path to XML file */ public XMLProperties(String componentName, ComponentType type, String xmlPath) { this.componentName = componentName; this.componentType = type; try { xml = new XMLConfiguration(xmlPath); xml.setDefaultListDelimiter((char) 0); xml.setExpressionEngine(new XPathExpressionEngine()); } catch (ConfigurationException e) { e.printStackTrace(); } }
From source file:com.versatus.jwebshield.securitylock.SecurityCheckListener.java
/** * @see ServletContextListener#contextInitialized(ServletContextEvent) *///from w ww. j a v a 2s . c o m @Override public void contextInitialized(ServletContextEvent sce) { String file = sce.getServletContext().getInitParameter("configFile"); if (file != null) { try { XMLConfiguration config = new XMLConfiguration(file); SubnodeConfiguration fields = config.configurationAt("securityLock"); int triesToLock = fields.getInt("triesToLock"); // lockSql = fields.getString("lockSql"); // dbJndiName = fields.getString("dbJndiName"); timeToLock = fields.getInt("timeToLockMin"); // lockCheckSql = fields.getString("lockCheckSql"); DBHelper dbh = new DBHelper(config); securityLockService = new SecurityLockService(dbh, config); securityLockService.setTriesToLock(triesToLock); // logger.info("contextInitialized: lockCheckInterval=" // + lockCheckInterval); logger.info("contextInitialized: timeToLock=" + timeToLock); // logger.info("contextInitialized: lockSql=" + lockSql); // logger.info("contextInitialized: lockCheckSql=" + // lockCheckSql); // logger.info("contextInitialized: dbJndiName=" + dbJndiName); } catch (Exception cex) { logger.error("init: unable to load configFile " + file, cex); } } else { logger.error("init: No configFile specified"); } // TimerTask lockCheckTimer = new LockCheckTimerTask(); // timer.schedule(lockCheckTimer, 10000, (lockCheckInterval * 60 * // 1000)); }
From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactory.java
public Config create(File file) throws InvalidConfigException { try {/* w ww . j a va2s .c om*/ StopWatch stopWatch = new StopWatch(); stopWatch.start(); LOGGER.debug("Validating config file {}", file); schema.newValidator().validate(new StreamSource(file)); LOGGER.debug("Loading config file {}", file); HierarchicalConfiguration configuration = new XMLConfiguration(file); int offset = configuration.getInt("listing.offset"); int days = configuration.getInt("listing.days"); int synopsis = configuration.getInt("listing.synopsis"); String regionId = configuration.getString("listing.regionId"); Map<Integer, ChannelConfig> channelConfigById = loadChannelConfigs(configuration); Config config = new Config(offset, days, synopsis, regionId, new ArrayList<>(channelConfigById.values())); LOGGER.debug("Loaded {} from {} in {}", config, file, formatDurationWords(stopWatch.getTime())); return config; } catch (Throwable e) { throw new InvalidConfigException(e.getMessage(), e); } }
From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfig.java
/** * Constructor pulls file out of the jar or reads from disk and sets up refresh policy. * /* w w w. j a v a 2 s.c o m*/ * @param expressionEngine * the expression engine to use. Null results in default expression engine */ protected void readConfig() { try { ExpressionEngine expressionEngine = new XPathExpressionEngine(); String configPath = getConfigName(); FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); File dataDirConfigFile = new File(configPath); // LOG.info("Reading settings from " + dataDirConfigFile.getAbsolutePath()); if (!dataDirConfigFile.exists()) { // Load a default from the classpath: // Note: we don't let new XMLConfiguration() lookup the resource // url directly because it may not be able to find the desired // classloader to load the URL from. URL configResourceUrl = this.getClass().getClassLoader().getResource(configPath); if (configResourceUrl == null) { throw new RuntimeException("unable to load resource: " + configPath); } XMLConfiguration tmpConfig = new XMLConfiguration(configResourceUrl); // Copy over a default configuration since none exists: // Ensure data dir location exists: if (dataDirConfigFile.getParentFile() != null && !dataDirConfigFile.getParentFile().exists() && !dataDirConfigFile.getParentFile().mkdirs()) { throw new RuntimeException("could not create directories."); } tmpConfig.save(dataDirConfigFile); LOG.info("Saving settings file to " + dataDirConfigFile.getAbsolutePath()); } if (dataDirConfigFile.exists()) { config = new XMLConfiguration(dataDirConfigFile); } else { // extract from jar and write to throw new IllegalStateException("Config file does not exist or cannot be created"); } if (expressionEngine != null) { config.setExpressionEngine(expressionEngine); } configFile = dataDirConfigFile; // reload at most once per thirty seconds on configuration queries. config.setReloadingStrategy(reloadingStrategy); initConfig(config); } catch (ConfigurationException e) { LOG.error("Error reading settings file: " + e, e); throw new RuntimeException(e); } }
From source file:com.egreen.tesla.server.api.ComponentContextLoader.java
private void create() throws ConfigurationException, IOException, FileNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, MalformedURLException, InstantiationException, NotFoundException, CannotCompileException, SQLException { String path = (String) context.getInitParameter(CONTEXT_CONFIG_LOCATION); xmlAppConfiguration = new XMLConfiguration(realPath + path); configuration = new Configurations(xmlAppConfiguration); context.setAttribute("configuration", configuration); String appName = xmlAppConfiguration.getString("server.name"); LOGGER.info(appName);// w w w.ja v a2s.c o m context.setAttribute("name", appName); String componentPath = realPath + xmlAppConfiguration.getString("server.component.base-path", "/component"); LOGGER.info(componentPath); ComponentManager instance = ComponentManager.getInstance(); instance.loadComponents(componentPath, context); DataBaseRepositaryManager dataBaseRepositaryManager = DataBaseRepositaryManager.getINSTANCE(); dataBaseRepositaryManager.init(configuration.getDBSettings()); dataBaseRepositaryManager.addEntities(instance.getEntities()); SessionFactory sessionFactory = dataBaseRepositaryManager.buildRepo(); context.setAttribute(ServicePool.class.getName(), new ServicePool(instance)); context.setAttribute(SessionFactory.class.getName(), sessionFactory); context.setAttribute("component_manager", instance); }
From source file:com.abiquo.abicloud.model.config.ConfigurationManager.java
/** * Loads the XML/*from w ww. jav a 2s . c o m*/ * * @throws ConfigurationException */ private void loadXML() throws ConfigurationException { URL configUrl = this.getClass().getClassLoader().getResource(DEFAULT_CONFIG_FILE); XMLConfiguration xmlConfig = new XMLConfiguration(configUrl); /** * Hypervisors */ // Vmware hpervisor VmwareHypervisorConfiguration vmwareHyperConfig = new VmwareHypervisorConfiguration(); vmwareHyperConfig.setDatastoreSanName( xmlConfig.getString("hypervisors.vmware.SanDatastore[@name]", "nfsrepository")); vmwareHyperConfig .setDatastoreVmfsName(xmlConfig.getString("hypervisors.vmware.VmfsDatastore[@name]", "datastore1")); vmwareHyperConfig.setDatacenterName(xmlConfig.getString("hypervisors.vmware.datacenter", "ha-datacenter")); vmwareHyperConfig.setUser(xmlConfig.getString("hypervisors.vmware.user", "root")); vmwareHyperConfig.setPassword(xmlConfig.getString("hypervisors.vmware.password", null)); vmwareHyperConfig.setIgnorecert(xmlConfig.getBoolean("hypervisors.vmware.ignorecert", true)); configuration.setVmwareHyperConfig(vmwareHyperConfig); /** * Repository */ configuration.setRemoteHost(xmlConfig.getString("repository.remoteHost", null)); configuration.setRemotePath(xmlConfig.getString("repository.remotePath", "/opt/vm_repository")); }
From source file:com.termmed.control.executor.PatternExecutor.java
/** * Execute./*from w w w. j a v a2s . co m*/ * * @throws IOException Signals that an I/O exception has occurred. * @throws Exception the exception */ public void execute() throws IOException, Exception { logger.logInfo("Starting patterns execution"); XMLConfiguration xmlConfig; try { xmlConfig = new XMLConfiguration(configFile); } catch (ConfigurationException e) { logger.logInfo("ClassificationRunner - Error happened getting params configFile." + e.getMessage()); throw e; } String runControls = xmlConfig.getString("patternExecutions.runControlPatterns"); if (runControls == null || !runControls.toLowerCase().equals("true")) { return; } resultOutputFolder = I_Constants.PATTERN_OUTPUT_FOLDER; File resultTmpFolder = new File(resultOutputFolder); if (!resultTmpFolder.exists()) { resultTmpFolder.mkdirs(); } else { FileHelper.emptyFolder(resultTmpFolder); } this.releaseDate = xmlConfig.getString("releaseDate"); this.previousReleaseDate = xmlConfig.getString("previousReleaseDate"); getNewConcepts(); getChangedConcepts(); excludes = new HashSet<String>(); Object prop = xmlConfig.getProperty("patternExecutions.exclusions.patternId"); if (prop != null) { if (prop instanceof Collection) { for (String loopProp : (Collection<String>) prop) { excludes.add(loopProp); } } else if (prop instanceof String) { excludes.add((String) prop); } } String relativePath = "src/main/resources/"; String path = "org/ihtsdo/control/patterns"; if (new File(relativePath).isDirectory()) { path = relativePath + path; logger.logInfo("Getting patterns from file system: " + path); executeFromFileSystem(path); } else { logger.logInfo("Getting patterns from resources: " + path); executeFromResources(path); } }
From source file:edu.usc.goffish.gopher.impl.client.GopherClient.java
/** * Initialize the system to run a new application. * @param gopherConfig Gopher Configuration file Path * @param gofsConfig Gofs Configuration File Path * @param graphId Id of the graph// w ww. jav a 2s . co m * @param jarFile application jar file name * @param clzz application class name */ public void initialize(String gopherConfig, String gofsConfig, String graphId, String jarFile, String clzz) { /** * Assume application jar is copied already * Send the init command with data // application_jar:app_class:number_of_processors:graphId,uri */ try { gofs = new PropertiesConfiguration(gofsConfig); gopher = new XMLConfiguration(gopherConfig); gofs.load(); gopher.load(); String nameNodeUri = gofs.getString(GoFSFormat.GOFS_NAMENODE_LOCATION_KEY); nameNode = new RemoteNameNode(URI.create(nameNodeUri)); int numberOfProcessors = nameNode.getDataNodes().size(); String data = jarFile + seperator + clzz + seperator + numberOfProcessors + seperator + graphId + seperator + nameNodeUri; System.out.println("Sending Init message : " + data); BSPMessage message = new BSPMessage(); message.setData(data.getBytes()); message.setType(BSPMessage.INIT); String location = gopher.getString(DeploymentTool.DATA_FLOW_HOST); int port = gopher.getInt(DeploymentTool.DATA_FLOW_DATA_PORT); int controlPort = gopher.getInt(DeploymentTool.DATA_FLOW_CONTROL_PORT); TransportInfoBase otherEndTransportInfo = new TransportInfoBase(); otherEndTransportInfo.getParams().put(TransportConstants.HOST_ADDR, location); otherEndTransportInfo.getParams().put(TransportConstants.TCP_LISTEN_PORT, String.valueOf(port)); TransportInfoBase otherEndControlInfo = new TransportInfoBase(); otherEndControlInfo.getParams().put(TransportConstants.HOST_ADDR, location); otherEndControlInfo.getParams().put(TransportConstants.TCP_LISTEN_PORT, String.valueOf(controlPort)); otherEndTransportInfo.setControlChannelInfo(otherEndControlInfo); Node.Port otherEndport = new Node.Port(); otherEndport.setPortName("in"); otherEndport.setTransportType("TCP"); otherEndport.setDataTransferMode("Push"); otherEndport.setTransportInfo(otherEndTransportInfo); Map<String, Object> params = new HashMap<String, Object>(); params.put("KEY", null); params.put("QUEUE", null); params.put("SERVER_SIDE", "false"); sender = SenderFactory.createDefaultSender(); sender.init(params); sender.connect(otherEndport, null); Message tempMessage = new MessageImpl(); tempMessage.putPayload(BitConverter.getBytes(message)); sender.send(tempMessage); } catch (ConfigurationException e) { String message = "Error Processing configuration"; handleException(message, e); } catch (IOException e) { String message = "I/O Error while initializing Gopher client"; handleException(message, e); } catch (ClassNotFoundException e) { String message = "Unexpected error while Creating Sender "; handleException(message, e); } catch (InstantiationException e) { String message = "Unexpected error while Creating Sender "; handleException(message, e); } catch (IllegalAccessException e) { String message = "Unexpected error while Creating Sender "; handleException(message, e); } }
From source file:com.servioticy.dispatcher.DispatcherContext.java
public void loadConf(String path) { HierarchicalConfiguration config;/*from w w w .j av a 2 s . c om*/ try { if (path == null) { config = new XMLConfiguration(DispatcherContext.DEFAULT_CONFIG_PATH); } else { config = new XMLConfiguration(path); } config.setExpressionEngine(new XPathExpressionEngine()); this.restBaseURL = config.getString("servioticyAPI", this.restBaseURL); ArrayList<String> updates = new ArrayList<String>(); if (config.containsKey("spouts/updates/addresses/address[1]")) { for (int i = 1; config.containsKey("spouts/updates/addresses/address[" + i + "]"); i++) { updates.add(config.getString("spouts/updates/addresses/address[" + i + "]")); } } else { for (String address : this.updatesAddresses) { updates.add(address); } } this.updatesAddresses = (String[]) updates.toArray(new String[] {}); this.updatesPort = config.getInt("spouts/updates/port", this.updatesPort); this.updatesQueue = config.getString("spouts/updates/name", this.updatesQueue); ArrayList<String> actions = new ArrayList<String>(); if (config.containsKey("spouts/actions/addresses/address[1]")) { for (int i = 1; config.containsKey("spouts/actions/addresses/address[" + i + "]"); i++) { actions.add(config.getString("spouts/actions/addresses/address[" + i + "]")); } } else { for (String address : this.actionsAddresses) { actions.add(address); } } this.actionsAddresses = (String[]) actions.toArray(new String[] {}); this.actionsPort = config.getInt("spouts/actions/port", this.actionsPort); this.actionsQueue = config.getString("spouts/actions/name", this.actionsQueue); this.benchmark = config.getBoolean("benchmark", this.benchmark); this.externalPubAddress = config.getString("publishers/external/address", this.externalPubAddress); this.externalPubPort = config.getInt("publishers/external/port", this.externalPubPort); this.externalPubUser = config.getString("publishers/external/username", this.externalPubUser); this.externalPubPassword = config.getString("publishers/external/password", this.externalPubPassword); this.externalPubClassName = config.getString("publishers/external/class", this.externalPubClassName); this.internalPubAddress = config.getString("publishers/internal/address", this.internalPubAddress); this.internalPubPort = config.getInt("publishers/internal/port", this.internalPubPort); this.internalPubUser = config.getString("publishers/internal/username", this.internalPubUser); this.internalPubPassword = config.getString("publishers/internal/password", this.internalPubPassword); this.internalPubClassName = config.getString("publishers/internal/class", this.internalPubClassName); this.actionsPubAddress = config.getString("publishers/actions/address", this.actionsPubAddress); this.actionsPubPort = config.getInt("publishers/actions/port", this.actionsPubPort); this.actionsPubUser = config.getString("publishers/actions/username", this.actionsPubUser); this.actionsPubPassword = config.getString("publishers/actions/password", this.actionsPubPassword); this.actionsPubClassName = config.getString("publishers/actions/class", this.actionsPubClassName); this.benchResultsDir = config.getString("benchResultsDir", this.benchResultsDir); } catch (Exception e) { e.printStackTrace(); return; } }
From source file:com.vangent.hieos.empi.codes.CodesConfig.java
/** * * @param codesConfigLocation//from ww w. ja v a 2 s . co m * @throws EMPIException */ public void loadConfiguration(String codesConfigLocation) throws EMPIException { try { XMLConfiguration xmlConfig = new XMLConfiguration(codesConfigLocation); // First load code sets (and index by code system name). List hcCodeSets = xmlConfig.configurationsAt(CODE_SETS); for (Iterator it = hcCodeSets.iterator(); it.hasNext();) { HierarchicalConfiguration hcCodeSet = (HierarchicalConfiguration) it.next(); this.loadCodeSet(hcCodeSet); } // Now load mappings (and index by code system type). List hcCodeSetMappings = xmlConfig.configurationsAt(CODE_SET_MAPPINGS); for (Iterator it = hcCodeSetMappings.iterator(); it.hasNext();) { HierarchicalConfiguration hcCodeSetMapping = (HierarchicalConfiguration) it.next(); this.loadCodeSetMapping(hcCodeSetMapping); } } catch (ConfigurationException ex) { throw new EMPIException("EMPIConfig: Could not load codes configuration from " + codesConfigLocation + " " + ex.getMessage()); } }