List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:au.com.dw.testdatacapturej.config.Configuration.java
/** * Load the constructor configurations from file. * //w ww. j av a 2 s . co m * An example of the XML structure: * * <constructor-config> * * <constructor class="dummy.ClassName"> * <argument> * <field-name>paramFieldName</field-name> * </argument> * <argument> * <field-name>param2FieldName</field-name> * </argument> * </constructor> * . * . * . * */ private void readConstructorConfigFile(String[] configFileNames) { XMLConfiguration xmlConfig = null; try { for (String fileName : configFileNames) { xmlConfig = new XMLConfiguration(fileName); if (xmlConfig != null) { // get all the constructor nodes and iterate through them List<?> constructorNodes = xmlConfig.configurationsAt("constructor"); for (Iterator<?> it = constructorNodes.iterator(); it.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); // sub contains now all data about a single field String className = sub.getString("[@class]"); List<String> paramFieldNames = configUtil.toStringList(sub.getList("argument.field-name")); if (paramFieldNames != null && !paramFieldNames.isEmpty()) { constructors.put(className, paramFieldNames); } } } } } catch (ConfigurationException cex) { cex.printStackTrace(); } }
From source file:com.sinfonier.util.XMLProperties.java
/** * Get property from component./* ww w . jav a2 s. com*/ * * @param property Property to get * @param componentName Name of the component * @param componentType Type of the component * @param xmlPath Path to xml file configuration * @return Property value or null if doesn't exists */ public static String getPropertyFromComponent(String property, String componentName, ComponentType componentType, String xmlPath) { String result = null; XMLConfiguration xml; try { xml = new XMLConfiguration(xmlPath); xml.setExpressionEngine(new XPathExpressionEngine()); switch (componentType) { case BOLT: result = xml.getString("bolts/bolt[@abstractionId='" + componentName + "']/" + property); break; case SPOUT: result = xml.getString("spouts/spout[@abstractionId='" + componentName + "']/" + property); break; case DRAIN: result = xml.getString("drains/drain[@abstractionId='" + componentName + "']/" + property); break; case OPTIONS: break; } } catch (ConfigurationException e) { e.printStackTrace(); } return result; }
From source file:com.knowbout.nlp.keywords.KeywordFinderTest.java
public void setUp() throws Exception { Configuration config = new XMLConfiguration("src/main/webapp/WEB-INF/config/base/system.xml"); Config.setConfiguration(config);/* ww w . j ava 2 s. c o m*/ }
From source file:com.evolveum.midpoint.pwdfilter.opendj.PasswordPusher.java
private void readConfig() throws InitializationException { String configFile = "/opt/midpoint/opendj-pwdpusher.xml"; if (System.getProperty("config") != null) { configFile = System.getProperty("config"); }/*from w ww .j ava 2 s.c o m*/ File f = new File(configFile); if (!f.exists() || !f.canRead()) { throw new IllegalArgumentException("Config file " + configFile + " does not exist or is not readable"); } try { XMLConfiguration config = new XMLConfiguration(f); String notifierDN = "cn=" + config.getString("passwordpusher.statusNotifierName") + ",cn=Account Status Notification Handlers"; String ldapURL = config.getString("passwordpusher.ldapServerURL"); boolean ldapSSL = config.getBoolean("passwordpusher.ldapServerSSL"); String ldapUsername = config.getString("passwordpusher.ldapServerUsername"); String ldapPassword = config.getString("passwordpusher.ldapServerPassword"); Hashtable<Object, Object> env = new Hashtable<Object, Object>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL + "/cn=config"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, ldapUsername); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); if (ldapSSL) { env.put(Context.SECURITY_PROTOCOL, "ssl"); } try { DirContext context = new InitialDirContext(env); Attributes attr = context.getAttributes(notifierDN); this.endPoint = attr.get("ds-cfg-referrals-url").get(0).toString(); this.username = attr.get("ds-cfg-midpoint-username").get(0).toString(); this.password = attr.get("ds-cfg-midpoint-password").get(0).toString(); this.pwdChangeDirectory = attr.get("ds-cfg-midpoint-passwordcachedir").get(0).toString(); } catch (NamingException ne) { throw new InitializationException( ERR_MIDPOINT_PWDSYNC_READING_CONFIG_FROM_LDAP.get(ne.getMessage()), ne); } } catch (ConfigurationException ce) { throw new InitializationException(ERR_MIDPOINT_PWDSYNC_PARSING_XML_CONFIG.get(ce.getMessage()), ce); } }
From source file:com.termmed.idcreation.IdCreation.java
/** * Gets the params.//from w w w . j a va2s.c om * * @return the params * @throws ConfigurationException the configuration exception */ private void getParams() throws ConfigurationException { try { xmlConfig = new XMLConfiguration(config); } catch (ConfigurationException e) { log.info("IdCreation - Error happened getting params file." + e.getMessage()); throw e; } componentFile = xmlConfig.getString(I_Constants.RELATIONSHIP_FILE); String nSpace = xmlConfig.getString(I_Constants.NAMESPACE); if (nSpace != null) { namespaceId = Integer.parseInt(nSpace); } String partId = xmlConfig.getString(I_Constants.PARTITION); if (partId != null) { partitionId = Long.parseLong(partId); } endPointURL = xmlConfig.getString(I_Constants.ENDPOINTURL); username = xmlConfig.getString(I_Constants.USERNAME); pass = xmlConfig.getString(I_Constants.PASSWORD); releaseDate = xmlConfig.getString(I_Constants.RELEASEDATE); log.info("Id Creation - Parameters:"); log.info("Input file : " + componentFile); log.info("NamespaceId : " + namespaceId); log.info("PartitionId : " + partitionId); log.info("End point url : " + endPointURL); log.info("Username : " + username); log.info("Release date : " + releaseDate); }
From source file:com.iontorrent.utils.settings.Config.java
protected void setXMLConfig(String configFile) { try {//from ww w . j a v a2s .c o m fConfig = new XMLConfiguration(configFile); } catch (Exception cex) { err("Failed to retriev service configuration file. " + configFile); } }
From source file:com.iontorrent.utils.settings.Config.java
protected void setXMLConfig(URL configFile) { try {//from www . j av a 2 s. c o m fConfig = new XMLConfiguration(configFile); } catch (Exception cex) { err("Couldn't get config xml file from url " + configFile + ": " + cex.getMessage()); } }
From source file:com.versatus.jwebshield.filter.SecurityTokenFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { String file = filterConfig.getInitParameter("configFile"); if (file != null) { UrlExclusionList urlExList = new UrlExclusionList(); filterConfig.getServletContext().setAttribute(SecurityConstant.CSRF_CHECK_URL_EXCL_LIST_ATTR_NAME, urlExList);//from w w w . ja va 2 s.c om try { XMLConfiguration config = new XMLConfiguration(file); List<Object> exclusionList = config.getList("urlExclusions"); tokenTimeout = config.getInteger("tokenTimeout", 1800); checkReferer = config.getBoolean("checkReferer", true); csrfCookieName = config.getString(SecurityConstant.CSRFCOOKIENAME_PARAM); if (exclusionList != null) { for (Object obj : exclusionList) { urlExList.addUrl((String) obj); } } logger.info("init: exclusionList=" + exclusionList); logger.info("init: urlExList=" + urlExList); logger.info("init: csrfCookieName=" + csrfCookieName); } catch (Exception cex) { logger.error("init: unable to load configFile " + file, cex); } } else { logger.error("init: No configFile specified"); } }
From source file:gda.configuration.properties.JakartaPropertiesConfig.java
/** * Load in a single property data source, or a "config.xml" descriptor file (specifying multiple data sources). * Properties are added to the global composite property data set. * <p>// w ww . j a v a 2 s .c o m * <p> * N.B. Due to underlying Jakarta (commons configuration) implementation, any previously loaded properties (with * duplicate keys) will override subsequently loaded properties. ie clients should load in override (eg user) data * before loading default (eg core) data. * <p> * <p> * N.B. Also system properties are currently loaded before any calls to loadPropertyData, so they take precedence * over everything. * * @param listName * the path name of the property data source. If the name ends in "config.xml" then the file is treated * as a Jakarta commons configuration descriptor file. If the file ends in ".xml" it is loaded as a * Jakarta XML property configuration file. Otherwise it is loaded as a legacy flat-file key-value pair * plain text property file. N.B. Although Jakarta supports other data sources, eg JDBC, these are not * yet supported via this method. * @throws ConfigurationException * @see gda.configuration.properties.PropertiesConfig#loadPropertyData(java.lang.String) */ @Override public void loadPropertyData(String listName) throws ConfigurationException { Configuration userConfig = null; if (listName.contains(".xml")) { if (listName.endsWith("config.xml")) { // create a JCC configuration factory from a JCC config // descriptor // file and make a JCC configuration interface/object from it ConfigurationFactory factory = new ConfigurationFactory(); // README - fix to get relative paths in config.xml working. // See comment for this method for explanation. configFactoryBasePathBugWorkaround(factory, listName); // now try to load in config.xml - relative paths should now // work factory.setConfigurationFileName(listName); userConfig = factory.getConfiguration(); } else { // load a JCC XML-format property file userConfig = new XMLConfiguration(listName); } } else { if (listName.contains(".properties")) { // load a classic java properties flat-textfile, // containing just name-value pairs - with extended JCC syntax userConfig = new PropertiesConfiguration(listName); } } if (userConfig != null) { config.addConfiguration(userConfig); configMap.put(listName, userConfig); } }
From source file:edu.psu.citeseerx.utility.ConfigurationManager.java
private void readConfiguration() throws ConfigurationException { config = new XMLConfiguration(configurationLocation); }