List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getList
public List getList(String key)
From source file:au.com.dw.testdatacapturej.config.Configuration.java
/** * Load the constructor configurations from file. * //from w w w . j a v a2 s . c om * 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:au.com.dw.testdatacapturej.config.Configuration.java
/** * Load the setter configurations from file. * /*from w w w . j a va2s .co m*/ * An example of the XML structure: * * <setter class="dummy.Classname"> * <argument> * <field-name>paramFieldName</field-name> * <alternative>ignore</alternative> * </argument> * <argument> * <field-name>param2FieldName</field-name> * <alternative>ignore</alternative> * </argument> * * . * . * . * * Note that the <alternative> tag is currently unused, it is a placeholder for future dev is we * want to substitute a setter method name. * */ private void readSetterConfigFile(String[] configFileNames) { XMLConfiguration xmlConfig = null; try { for (String fileName : configFileNames) { xmlConfig = new XMLConfiguration(fileName); if (xmlConfig != null) { // get all the setter nodes and iterate through them List<?> constructorNodes = xmlConfig.configurationsAt("setter"); 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("field.field-name")); if (paramFieldNames != null && !paramFieldNames.isEmpty()) { setters.put(className, paramFieldNames); } } } } } catch (ConfigurationException cex) { cex.printStackTrace(); } }
From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java
@Override public DeploySystem<DbEnvironment> readSystem(FileObject sourcePath) { HierarchicalConfiguration sysCfg = getConfig(sourcePath); DbPlatform systemDbPlatform = dbPlatformConfiguration.valueOf(sysCfg.getString("[@type]")); MutableList<String> sourceDirs = ListAdapter.adapt(sysCfg.getList("[@sourceDirs]")); ImmutableSet<String> acceptedExtensions = ListAdapter.adapt(sysCfg.getList("[@acceptedExtensions]")).toSet() .toImmutable();/*from ww w .j a v a 2s . c om*/ MutableList<DbEnvironment> envList = Lists.mutable.empty(); for (HierarchicalConfiguration envCfg : iterConfig(sysCfg, "environments.dbEnvironment")) { DbEnvironment dbEnv = new DbEnvironment(); FileObject rootDir = sourcePath.getType() == FileType.FILE ? sourcePath.getParent() : sourcePath; // Use coreSourcePath and additionalSourceDirs here (instead of setSourceDirs) to facilitate any external integrations dbEnv.setCoreSourcePath(rootDir); dbEnv.setAdditionalSourceDirs(sourceDirs); dbEnv.setAcceptedExtensions(acceptedExtensions); dbEnv.setCleanBuildAllowed(envCfg.getBoolean("[@cleanBuildAllowed]", false)); dbEnv.setDbHost(envCfg.getString("[@dbHost]")); dbEnv.setDbPort(envCfg.getInt("[@dbPort]", 0)); dbEnv.setDbServer(envCfg.getString("[@dbServer]")); dbEnv.setDbSchemaPrefix(envCfg.getString("[@dbSchemaPrefix]")); dbEnv.setDbSchemaSuffix(envCfg.getString("[@dbSchemaSuffix]")); dbEnv.setDbDataSourceName(envCfg.getString("[@dbDataSourceName]")); dbEnv.setJdbcUrl(envCfg.getString("[@jdbcUrl]")); MutableMap<String, String> tokens = Maps.mutable.empty(); for (HierarchicalConfiguration tok : iterConfig(envCfg, "tokens.token")) { tokens.put(tok.getString("[@key]"), tok.getString("[@value]")); } dbEnv.setTokens(tokens.toImmutable()); // Allow the groups + users to be tokenized upfront for compatibility w/ the EnvironmentInfraSetup classes Tokenizer tokenizer = new Tokenizer(dbEnv.getTokens(), dbEnv.getTokenPrefix(), dbEnv.getTokenSuffix()); dbEnv.setGroups(iterConfig(sysCfg, "groups.group").collect(convertCfgToGroup(tokenizer))); dbEnv.setUsers(iterConfig(sysCfg, "users.user").collect(convertCfgToUser(tokenizer))); if (envCfg.getString("[@driverClass]") != null) { dbEnv.setDriverClassName(envCfg.getString("[@driverClass]")); } dbEnv.setName(envCfg.getString("[@name]")); dbEnv.setDefaultUserId(envCfg.getString("[@defaultUserId]")); dbEnv.setDefaultPassword(envCfg.getString("[@defaultPassword]")); dbEnv.setDefaultTablespace(envCfg.getString("[@defaultTablespace]")); // TODO add include/exclude schemas functionality MutableList<Schema> schemaObjs = Lists.mutable.withAll(iterConfig(sysCfg, "schemas.schema")) .collect(convertCfgToSchema(systemDbPlatform)); MutableSet<String> schemasToInclude = iterString(envCfg, "includeSchemas").toSet(); MutableSet<String> schemasToExclude = iterString(envCfg, "excludeSchemas").toSet(); if (!schemasToInclude.isEmpty() && !schemasToExclude.isEmpty()) { throw new IllegalArgumentException("Environment " + dbEnv.getName() + " has includeSchemas [" + schemasToInclude + "] and excludeSchemas [" + schemasToExclude + "] defined; please only specify one of them"); } else if (!schemasToInclude.isEmpty()) { schemaObjs = schemaObjs.select(Predicates.attributeIn(Schema.TO_NAME, schemasToInclude)); } else if (!schemasToExclude.isEmpty()) { schemaObjs = schemaObjs.reject(Predicates.attributeIn(Schema.TO_NAME, schemasToExclude)); } MutableMap<String, String> schemaNameOverrides = Maps.mutable.empty(); MutableSet<String> schemaNames = schemaObjs.collect(Schema.TO_NAME).toSet(); for (HierarchicalConfiguration schemaOverride : iterConfig(envCfg, "schemaOverrides.schemaOverride")) { String schema = schemaOverride.getString("[@schema]"); if (schemaObjs.collect(Schema.TO_NAME).contains(schema)) { schemaNameOverrides.put(schema, schemaOverride.getString("[@overrideValue]")); } else { throw new IllegalArgumentException( "Schema override definition value " + schema + " is not defined in the schema list " + schemaNames + " for environment " + dbEnv.getName()); } } dbEnv.setSchemaNameOverrides(schemaNameOverrides.toImmutable()); // ensure that we only store the unique schema names here dbEnv.setSchemas(UnifiedSetWithHashingStrategy .newSet(HashingStrategies.fromFunction(Schema.TO_NAME), schemaObjs).toImmutable()); dbEnv.setPersistToFile(envCfg.getBoolean("[@persistToFile]", false)); dbEnv.setDisableAuditTracking(envCfg.getBoolean("[@disableAuditTracking]", false)); dbEnv.setRollbackDetectionEnabled(envCfg.getBoolean("[@rollbackDetectionEnabled]", sysCfg.getBoolean("[@rollbackDetectionEnabled]", true))); dbEnv.setAutoReorgEnabled( envCfg.getBoolean("[@autoReorgEnabled]", sysCfg.getBoolean("[@autoReorgEnabled]", true))); dbEnv.setInvalidObjectCheckEnabled(envCfg.getBoolean("[@invalidObjectCheckEnabled]", sysCfg.getBoolean("[@invalidObjectCheckEnabled]", true))); dbEnv.setReorgCheckEnabled( envCfg.getBoolean("[@reorgCheckEnabled]", sysCfg.getBoolean("[@reorgCheckEnabled]", true))); dbEnv.setChecksumDetectionEnabled(envCfg.getBoolean("[@checksumDetectionEnabled]", sysCfg.getBoolean("[@checksumDetectionEnabled]", false))); dbEnv.setMetadataLineReaderVersion( envCfg.getInt("[@metadataLineReaderVersion]", sysCfg.getInt("[@metadataLineReaderVersion]", dbPlatformConfiguration.getFeatureToggleVersion("metadataLineReaderVersion")))); dbEnv.setCsvVersion(envCfg.getInt("[@csvVersion]", sysCfg.getInt("[@csvVersion]", dbPlatformConfiguration.getFeatureToggleVersion("csvVersion")))); int legacyDirectoryStructureEnabledValue = envCfg.getInt("[@legacyDirectoryStructureEnabled]", sysCfg.getInt("[@legacyDirectoryStructureEnabled]", dbPlatformConfiguration.getFeatureToggleVersion("legacyDirectoryStructureEnabled"))); dbEnv.setLegacyDirectoryStructureEnabled(legacyDirectoryStructureEnabledValue == 1); // 1 == legacy, 2 == new MutableMap<String, String> extraEnvAttrs = Maps.mutable.empty(); for (String extraEnvAttr : dbPlatformConfiguration.getExtraEnvAttrs()) { String attrStr = "[@" + extraEnvAttr + "]"; extraEnvAttrs.put(extraEnvAttr, envCfg.getString(attrStr, sysCfg.getString(attrStr))); } dbEnv.setExtraEnvAttrs(extraEnvAttrs.toImmutable()); ImmutableList<HierarchicalConfiguration> envPermissions = iterConfig(envCfg, "permissions.permission"); ImmutableList<HierarchicalConfiguration> sysPermissions = iterConfig(sysCfg, "permissions.permission"); if (!envPermissions.isEmpty()) { dbEnv.setPermissions(envPermissions.collect(convertCfgToPermission(tokenizer))); } else if (!sysPermissions.isEmpty()) { dbEnv.setPermissions(sysPermissions.collect(convertCfgToPermission(tokenizer))); } DbPlatform platform; if (envCfg.getString("[@inMemoryDbType]") != null) { platform = dbPlatformConfiguration.valueOf(envCfg.getString("[@inMemoryDbType]")); } else { platform = systemDbPlatform; } dbEnv.setSystemDbPlatform(systemDbPlatform); dbEnv.setPlatform(platform); String delim = sysCfg.getString("[@dataDelimiter]"); if (delim != null) { if (delim.length() == 1) { dbEnv.setDataDelimiter(delim.charAt(0)); } else { throw new IllegalArgumentException( "dataDelimiter must be 1 character long. instead, got [" + delim + "]"); } } String nullToken = sysCfg.getString("[@nullToken]"); if (nullToken != null) { dbEnv.setNullToken(nullToken); } dbEnv.setAuditTableSql(getProperty(sysCfg, envCfg, "auditTableSql")); envList.add(dbEnv); } CollectionUtil.verifyNoDuplicates(envList, DbEnvironment.TO_NAME, "Invalid configuration from " + sourcePath + "; not expecting duplicate env names"); return new DeploySystem<DbEnvironment>(envList); }
From source file:au.com.dw.testdatacapturej.config.Configuration.java
/** * Load the collection configurations from file. * /*from w ww . j a v a 2 s . com*/ * An example of the XML structure: * * <collection-config> * * <container class="dummy.ClassName"> * <argument> * <field-name>collectionFieldName</field-name> * <adder-method>adderMethodName</adder-method> * </argument> * </container> * . * . * . * */ private void readCollectionConfigFile(String[] configFileNames) { XMLConfiguration xmlConfig = null; try { for (String fileName : configFileNames) { xmlConfig = new XMLConfiguration(fileName); if (xmlConfig != null) { // get all the collection nodes and iterate through them List<?> collectionNodes = xmlConfig.configurationsAt("container"); for (Iterator<?> it = collectionNodes.iterator(); it.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); // sub contains now all data about a single field String className = sub.getString("[@class]"); List<String> collectionFieldNames = configUtil .toStringList(sub.getList("argument.field-name")); // not sure if this is the best way to handle multiple sub elements List<String> adderMethodNames = configUtil .toStringList(sub.getList("argument.adder-method")); // TODO need more error checking here in case of incorrect configuration if (collectionFieldNames != null && !collectionFieldNames.isEmpty() && adderMethodNames != null && !adderMethodNames.isEmpty()) { List<CollectionAdderConfig> collectionConfigs = new ArrayList<CollectionAdderConfig>(); for (int i = 0; i < collectionFieldNames.size(); i++) { CollectionAdderConfig collectionConfig = new CollectionAdderConfig(); collectionConfig.setFieldName(collectionFieldNames.get(i)); collectionConfig.setAdderMethodName(adderMethodNames.get(i)); collectionConfigs.add(collectionConfig); } adderCollections.put(className, collectionConfigs); } } } } } catch (ConfigurationException cex) { cex.printStackTrace(); } }
From source file:edu.psu.citeseerx.messaging.MsgService.java
/** * Configures a JMS provider based on configuration, passing execution * to other handlers for specific channel descriptors. * @param config/*from w w w. ja v a 2s .c om*/ * @throws Exception */ private void processProvider(HierarchicalConfiguration config) throws Exception { String url = config.getString("url"); String clientID = config.getString("clientID"); JMSProvider provider = new JMSProvider(url); provider.setClientID(clientID); jmsProviders.put(url, provider); System.out.println("processing provider: " + url); List queues = config.getList("queue.name"); for (int i = 0; i < queues.size(); i++) { processChannel(provider, config.configurationAt("queue(" + i + ")"), QUEUE); } List topics = config.getList("topic.name"); for (int i = 0; i < topics.size(); i++) { processChannel(provider, config.configurationAt("topic(" + i + ")"), TOPIC); } }
From source file:com.sm.store.BuildRemoteConfig.java
private StoreConfig buildStoreConfig(HierarchicalConfiguration configuration) { StringBuilder sb = new StringBuilder(); String name = configuration.getString("name"); if (name == null) sb.append("store name is not defined "); String path = configuration.getString("path", "data"); String filename = configuration.getString("filename", name); boolean delay = configuration.getBoolean("delay", true); int mode = configuration.getInt("mode", 0); int freq = configuration.getInt("freq", this.freq == 0 ? 1 : this.freq); int batchSize = configuration.getInt("batchSize", 10); String logPath = configuration.getString("logPath", "log"); List<String> replicaUrl = configuration.getList("replicaUrl"); long replciaTimeout = configuration.getLong("replicaTimeout", 60000); if (replicaUrl == null) sb.append("no replicaUrl is defined"); boolean sorted = configuration.getBoolean("sorted", false); if (sb.length() > 0) { throw new RuntimeException("error on buildStoreConfig " + sb.toString()); } else {/* w w w. j a va2 s . c om*/ StoreConfig storeConfig = new StoreConfig(name, path, freq, replicaUrl, batchSize, delay, mode, sorted); storeConfig.setGetTriggerName(configuration.getString("getTrigger")); storeConfig.setPutTriggerName(configuration.getString("putTrigger")); storeConfig.setDeleteTriggerName(configuration.getString("deleteTrigger")); storeConfig.setUseMaxCache(configuration.getBoolean("useMaxCache", false)); storeConfig.setMaxCacheMemory(configuration.getInt("maxCacheMemory", 20000)); storeConfig.setUseLRU(configuration.getBoolean("useLRU", false)); storeConfig.setLogPath(logPath); storeConfig.setReplicaTimeout(replciaTimeout); //add pstReplicaURl storeConfig.setPstReplicaUrl(configuration.getList("pstReplicaUrl")); storeConfig.setSerializeClass(configuration.getString("serializeClass")); return storeConfig; } }
From source file:com.moviejukebox.model.Library.java
private static void fillCertificationMap(String xmlCertificationFilename) { File xmlCertificationFile = new File(xmlCertificationFilename); if (xmlCertificationFile.exists() && xmlCertificationFile.isFile() && xmlCertificationFilename.toUpperCase().endsWith("XML")) { try {//from w w w . j a v a2s . c om XMLConfiguration conf = new XMLConfiguration(xmlCertificationFile); List<HierarchicalConfiguration> certifications = conf.configurationsAt("certification"); for (HierarchicalConfiguration certification : certifications) { String masterCertification = certification.getString(LIT_NAME); List<Object> subcertifications = certification.getList("subcertification"); for (Object subcertification : subcertifications) { CERTIFICATIONS_MAP.put((String) subcertification, masterCertification); } } if (conf.containsKey("default")) { defaultCertification = conf.getString("default"); LOG.info("Found default certification: {}", defaultCertification); } } catch (ConfigurationException error) { LOG.error("Failed parsing moviejukebox certification input file: {}", xmlCertificationFile.getName()); LOG.error(SystemTools.getStackTrace(error)); } } else { LOG.error("The moviejukebox certification input file you specified is invalid: {}", xmlCertificationFile.getName()); } }
From source file:com.moviejukebox.model.Library.java
private static void fillGenreMap(String xmlGenreFilename) { File xmlGenreFile = new File(xmlGenreFilename); if (xmlGenreFile.exists() && xmlGenreFile.isFile() && xmlGenreFilename.toUpperCase().endsWith("XML")) { try {/*from ww w . j a va2 s . c o m*/ XMLConfiguration c = new XMLConfiguration(xmlGenreFile); List<HierarchicalConfiguration> genres = c.configurationsAt("genre"); for (HierarchicalConfiguration genre : genres) { String masterGenre = genre.getString(LIT_NAME); LOG.trace("New masterGenre parsed : (" + masterGenre + ")"); List<Object> subgenres = genre.getList("subgenre"); for (Object subgenre : subgenres) { LOG.trace("New genre added to map : (" + subgenre + "," + masterGenre + ")"); GENRES_MAP.put((String) subgenre, masterGenre); } } } catch (ConfigurationException error) { LOG.error("Failed parsing moviejukebox genre input file: {}", xmlGenreFile.getName()); LOG.error(SystemTools.getStackTrace(error)); } } else { LOG.error("The moviejukebox genre input file you specified is invalid: {}", xmlGenreFile.getName()); } }
From source file:com.moviejukebox.reader.MovieJukeboxLibraryReader.java
public static Collection<MediaLibraryPath> parse(File libraryFile) { Collection<MediaLibraryPath> mlp = new ArrayList<>(); if (!libraryFile.exists() || libraryFile.isDirectory()) { LOG.error("The moviejukebox library input file you specified is invalid: {}", libraryFile.getName()); return mlp; }/*from w ww . j a va 2s .c om*/ try { XMLConfiguration c = new XMLConfiguration(libraryFile); List<HierarchicalConfiguration> fields = c.configurationsAt("library"); for (HierarchicalConfiguration sub : fields) { // sub contains now all data about a single medialibrary node String path = sub.getString("path"); String nmtpath = sub.getString("nmtpath"); // This should be depreciated String playerpath = sub.getString("playerpath"); String description = sub.getString("description"); boolean scrapeLibrary = true; String scrapeLibraryString = sub.getString("scrapeLibrary"); if (StringTools.isValidString(scrapeLibraryString)) { try { scrapeLibrary = sub.getBoolean("scrapeLibrary"); } catch (Exception ignore) { /* ignore */ } } long prebuf = -1; String prebufString = sub.getString("prebuf"); if (prebufString != null && !prebufString.isEmpty()) { try { prebuf = Long.parseLong(prebufString); } catch (NumberFormatException ignore) { /* ignore */ } } // Note that the nmtpath should no longer be used in the library file and instead "playerpath" should be used. // Check that the nmtpath terminates with a "/" or "\" if (nmtpath != null) { if (!(nmtpath.endsWith("/") || nmtpath.endsWith("\\"))) { // This is the NMTPATH so add the unix path separator rather than File.separator nmtpath = nmtpath + "/"; } } // Check that the playerpath terminates with a "/" or "\" if (playerpath != null) { if (!(playerpath.endsWith("/") || playerpath.endsWith("\\"))) { // This is the PlayerPath so add the Unix path separator rather than File.separator playerpath = playerpath + "/"; } } List<Object> excludes = sub.getList("exclude[@name]"); File medialibfile = new File(path); if (medialibfile.exists()) { MediaLibraryPath medlib = new MediaLibraryPath(); medlib.setPath(medialibfile.getCanonicalPath()); if (playerpath == null || StringUtils.isBlank(playerpath)) { medlib.setPlayerRootPath(nmtpath); } else { medlib.setPlayerRootPath(playerpath); } medlib.setExcludes(excludes); medlib.setDescription(description); medlib.setScrapeLibrary(scrapeLibrary); medlib.setPrebuf(prebuf); mlp.add(medlib); if (description != null && !description.isEmpty()) { LOG.info("Found media library: {}", description); } else { LOG.info("Found media library: {}", path); } // Save the media library to the log file for reference. LOG.debug("Media library: {}", medlib); } else { LOG.info("Skipped invalid media library: {}", path); } } } catch (ConfigurationException | IOException ex) { LOG.error("Failed parsing moviejukebox library input file: {}", libraryFile.getName()); LOG.error(SystemTools.getStackTrace(ex)); } return mlp; }
From source file:com.eyeq.pivot4j.impl.PivotModelImpl.java
/** * @see com.eyeq.pivot4j.state.Configurable#restoreSettings(org.apache.commons.configuration.HierarchicalConfiguration) *///from ww w . jav a2 s . c o m @Override public synchronized void restoreSettings(HierarchicalConfiguration configuration) { if (configuration == null) { throw new NullArgumentException("configuration"); } String mdx = configuration.getString("mdx"); setMdx(mdx); if (mdx == null) { if (logger.isWarnEnabled()) { logger.warn("The configuration does not contain valid MDX query."); } return; } if (!isInitialized()) { initialize(); } this.sorting = configuration.getBoolean("sort[@enabled]", false); this.sortPosMembers = null; this.sortCriteria = SortCriteria.ASC; this.topBottomCount = 10; Quax quaxToSort = null; if (sorting) { List<Object> sortPosUniqueNames = configuration.getList("sort.member"); if (sortPosUniqueNames != null && !sortPosUniqueNames.isEmpty()) { try { Cube cube = getCube(); this.sortPosMembers = new ArrayList<Member>(sortPosUniqueNames.size()); for (Object uniqueName : sortPosUniqueNames) { Member member = cube.lookupMember( IdentifierNode.parseIdentifier(uniqueName.toString()).getSegmentList()); if (member == null) { if (logger.isWarnEnabled()) { logger.warn("Sort position member not found " + uniqueName); } break; } sortPosMembers.add(member); } } catch (OlapException e) { throw new PivotException(e); } } this.topBottomCount = configuration.getInt("sort[@topBottomCount]", 10); String sortName = configuration.getString("sort[@criteria]"); if (sortName != null) { this.sortCriteria = SortCriteria.valueOf(sortName); } int ordinal = configuration.getInt("sort[@ordinal]", -1); if (ordinal > 0) { for (Axis axis : queryAdapter.getAxes()) { Quax quax = queryAdapter.getQuax(axis); if (quax.getOrdinal() == ordinal) { quaxToSort = quax; break; } } } } queryAdapter.setQuaxToSort(quaxToSort); this.cellSet = null; }