List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getString
public String getString(String key, String defaultValue)
From source file:com.webcohesion.enunciate.modules.jaxb.JaxbModule.java
public Map<String, String> getExternalExamples() { HashMap<String, String> examples = new HashMap<String, String>(); List<HierarchicalConfiguration> exampleElements = this.config.configurationsAt("examples.example"); for (HierarchicalConfiguration exampleElement : exampleElements) { examples.put(exampleElement.getString("[@type]", ""), exampleElement.getString("[@example]", "...")); }/* w w w.j a v a 2 s . c o m*/ return examples; }
From source file:com.norconex.collector.http.delay.impl.ReferenceDelayResolver.java
@Override protected void loadDelaysFromXML(XMLConfiguration xml) throws IOException { List<HierarchicalConfiguration> nodes = xml.configurationsAt("pattern"); for (HierarchicalConfiguration node : nodes) { delayPatterns.add(/*from w w w .java2 s .c o m*/ new DelayReferencePattern(node.getString("", ""), node.getLong("[@delay]", DEFAULT_DELAY))); } }
From source file:com.norconex.importer.handler.tagger.impl.HierarchyTagger.java
@Override protected void loadHandlerFromXML(XMLConfiguration xml) throws IOException { List<HierarchicalConfiguration> nodes = xml.configurationsAt("hierarchy"); for (HierarchicalConfiguration node : nodes) { addHierarcyDetails(node.getString("[@fromField]", null), node.getString("[@toField]", null), node.getString("[@fromSeparator]", null), node.getString("[@toSeparator]", null), node.getBoolean("[@overwrite]", false)); }/* w ww. j a v a 2s . c o m*/ }
From source file:com.github.steveash.typedconfig.resolver.type.simple.StringValueResolverFactory.java
@Override public ValueResolver makeForThis(final ConfigBinding binding, final HierarchicalConfiguration config, ConfigFactoryContext context) {//from www . j av a 2 s.c o m final String key = binding.getConfigKeyToLookup(); return new ConvertableValueResolver(String.class, key) { @Override public String resolve() { return config.getString(binding.getConfigKeyToLookup(), null); } }; }
From source file:com.webcohesion.enunciate.modules.jackson.JacksonModule.java
public Map<String, String> getMixins() { HashMap<String, String> mixins = new HashMap<String, String>(); List<HierarchicalConfiguration> mixinElements = this.config.configurationsAt("mixin"); for (HierarchicalConfiguration mixinElement : mixinElements) { mixins.put(mixinElement.getString("[@target]", ""), mixinElement.getString("[@source]", "")); }/*from w w w. j a v a2 s . c om*/ return mixins; }
From source file:com.webcohesion.enunciate.modules.idl.IDLModule.java
public Map<String, WsdlConfig> getWsdlConfigs() { HashMap<String, WsdlConfig> configs = new HashMap<String, WsdlConfig>(); List<HierarchicalConfiguration> wsdls = this.config.configurationsAt("wsdl"); for (HierarchicalConfiguration wsdl : wsdls) { WsdlConfig wsdlConfig = new WsdlConfig(); wsdlConfig.setFilename(wsdl.getString("[@filename]", null)); wsdlConfig.setNamespace(wsdl.getString("[@namespace]", null)); wsdlConfig.setInlineSchema(wsdl.getBoolean("[@inlineSchema]", true)); String useFile = wsdl.getString("[@useFile]", null); if (useFile != null) { File file = resolveFile(useFile); if (!file.exists()) { throw new EnunciateException( String.format("Invalid wsdl config: file %s does not exist.", useFile)); }// www. j a va2 s . c o m wsdlConfig.setUseFile(file); } configs.put(wsdlConfig.getNamespace(), wsdlConfig); } return configs; }
From source file:com.vmware.qe.framework.datadriven.impl.supplier.CSVDataSupplier.java
public HierarchicalConfiguration getData(final String className, HierarchicalConfiguration context) { HierarchicalConfiguration testData = null; try {// w ww. ja v a2 s . c om Class<?> clazz = Class.forName(className); String dataFilePath = null; URL dataFileURL = null; String dataFileName = context.getString("supplier.dataFile", null); log.debug("Checking the data file in argument..."); if (dataFileName == null || dataFileName.equals("")) { log.debug("Data file not given in argument..Using DataFileFinder.."); dataFilePath = DDUtils.findDataFile(className, ".csv", context); } else { log.debug("Got data file in argument"); dataFilePath = dataFileName; } log.debug("Data file path: " + dataFilePath); if (dataFilePath == null) { return null;// No data found, hence it's a normal test case. } dataFileURL = clazz.getResource(dataFilePath); CsvMapReader reader = new CsvMapReader(new InputStreamReader(dataFileURL.openStream()), CsvPreference.STANDARD_PREFERENCE); String list[] = reader.getHeader(true); Map<String, String> map = null; testData = new HierarchicalConfiguration(); int i = 0; while ((map = reader.read(list)) != null) { String testId = null; HierarchicalConfiguration newData = new HierarchicalConfiguration(); Set<Map.Entry<String, String>> entrySet = map.entrySet(); for (Map.Entry<String, String> entry : entrySet) { if (entry.getKey().equals("test-id")) { newData.addProperty("[@test-id]", entry.getValue()); testId = entry.getValue(); continue; } newData.addProperty(entry.getKey(), entry.getValue()); } testData.addNodes("data(" + i + ")", newData.getRootNode().getChildren()); if (testId != null) { testData.addProperty("data(" + i + ")[@test-id]", testId); } i++; } reader.close(); } catch (Exception ex) { throw new DDException("Error in loading data file", ex); } return testData; }
From source file:com.webcohesion.enunciate.modules.idl.IDLModule.java
public Map<String, SchemaConfig> getSchemaConfigs() { HashMap<String, SchemaConfig> configs = new HashMap<String, SchemaConfig>(); List<HierarchicalConfiguration> schemas = this.config.configurationsAt("schema"); for (HierarchicalConfiguration schema : schemas) { SchemaConfig schemaConfig = new SchemaConfig(); schemaConfig.setAppinfo(schema.getString("[@appinfo]", null)); schemaConfig.setFilename(schema.getString("[@filename]", null)); schemaConfig.setJaxbBindingVersion(schema.getString("[@jaxbBindingVersion]", null)); schemaConfig.setLocation(schema.getString("[@location]", null)); String ns = schema.getString("[@namespace]", null); if ("".equals(ns)) { //default namspace to be represented as null. ns = null;/*from w w w.j a v a2 s .c o m*/ } schemaConfig.setNamespace(ns); String useFile = schema.getString("[@useFile]", null); if (useFile != null) { File file = resolveFile(useFile); if (!file.exists()) { throw new EnunciateException( String.format("Invalid schema config: file %s does not exist.", useFile)); } schemaConfig.setUseFile(file); } configs.put(schemaConfig.getNamespace(), schemaConfig); } return configs; }
From source file:com.norconex.collector.http.url.impl.GenericURLNormalizer.java
@Override public void loadFromXML(Reader in) { XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in); String xmlNorms = xml.getString("normalizations"); if (StringUtils.isNotBlank(xmlNorms)) { normalizations.clear();/*from w w w . j a va 2 s . c om*/ for (String norm : StringUtils.split(xmlNorms, ',')) { try { normalizations.add(Normalization.valueOf(norm.trim())); } catch (Exception e) { LOG.error("Invalid normalization: \"" + norm + "\".", e); } } } List<HierarchicalConfiguration> xmlReplaces = xml.configurationsAt("replacements.replace"); if (!replaces.isEmpty()) { replaces.clear(); } for (HierarchicalConfiguration node : xmlReplaces) { String match = node.getString("match", ""); String replacement = node.getString("replacement", ""); replaces.add(new Replace(match, replacement)); } }
From source file:com.github.steveash.typedconfig.resolver.type.simple.EnumValueResolverFactory.java
@Override public ValueResolver makeForThis(final ConfigBinding binding, final HierarchicalConfiguration config, ConfigFactoryContext context) {//from w w w . j av a 2 s . co m final Class enumType = binding.getDataType().getRawType(); final String key = binding.getConfigKeyToLookup(); return new ValueResolver() { @Override public Object resolve() { String enumLabel = config.getString(binding.getConfigKeyToLookup(), null); if (StringUtils.isBlank(enumLabel)) return null; return resolveEnumInstance(enumLabel); } private Object resolveEnumInstance(String enumLabel) { try { return Enum.valueOf(enumType, enumLabel); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("The value of the configuration key " + key + " is " + enumLabel + " which is not a member of the enum " + enumType.getName(), e); } } @Override public Object convertDefaultValue(String defaultValue) { return resolveEnumInstance(defaultValue); } @Override public String configurationKeyToLookup() { return key; } }; }