List of usage examples for org.apache.commons.configuration XMLConfiguration getProperty
public Object getProperty(String key)
From source file:org.apache.rya.indexing.smarturi.duplication.conf.DuplicateDataConfig.java
private static Map<String, List<String>> parseEquivalentTermsMap(final XMLConfiguration xmlConfig) { final Map<String, List<String>> equivalentTermsMap = new LinkedHashMap<>(); final Object prop = xmlConfig.getProperty("termMappings.termMapping.term"); if (prop != null) { if (prop instanceof Collection) { final int size = ((Collection<?>) prop).size(); for (int i = 0; i < size; i++) { final String termElement = "termMappings.termMapping(" + i + ")"; parseTermMapping(termElement, xmlConfig, equivalentTermsMap); }/*from w ww . ja va2 s . c o m*/ } else { final String termElement = "termMappings.termMapping"; parseTermMapping(termElement, xmlConfig, equivalentTermsMap); } } return equivalentTermsMap; }
From source file:org.efaps.earchive.Shell.java
public static void main(final String[] _args) { final XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); for (final String arg : _args) { if (arg.startsWith("-")) { final int index = arg.indexOf('='); config.addProperty((index > 0) ? arg.substring(1, index) : arg.substring(1), (index > 0) ? arg.substring(index + 1) : null); }//from w w w . ja v a2 s.co m } final String configUrl = (String) config.getProperty("Dshell.parameter.configFile"); final File file = new File(configUrl); if (configUrl != null) { final XMLConfiguration config2 = new XMLConfiguration(); config2.setDelimiterParsingDisabled(true); try { config2.load(file); } catch (final ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(config2.getString("type")); final String type = config2.getString("type"); final String factory = config2.getString("factory"); final String connection = config2.getString("connection"); try { StartupDatabaseConnection.startup(type, factory, convertToMap(connection), "org.objectweb.jotm.Current"); reloadCache(); } catch (final StartupException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final EFapsException e) { // TODO Auto-generated catch block e.printStackTrace(); } final SVNProxyServer server = SVNProxyServer.get(); server.start(); } else { //TODO fehler } }
From source file:org.firstopen.singularity.devicemgr.emulators.EmulatorManager.java
/** * @param args/*from w ww . j a v a 2 s . c o m*/ * @throws Exception */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { XMLConfiguration config; try { URL url = ClassLoader.getSystemResource("emulation.xml"); config = new XMLConfiguration(url); Object obj = config.getProperty("emulatons.emulator.class"); Collection<String> classes = null; if (obj instanceof Collection) { classes = (Collection<String>) obj; } else throw new ClassNotFoundException("property is not of type Collection"); Thread[] threads = new Thread[50]; int i = 0; for (String className : classes) { List<String> portList = (List<String>) config.getList("emulations.emulator(" + i + ").ports"); Class c = Class.forName(className); log.info("Shutdown manager registered..."); ShutdownManager sdm = new ShutdownManager(); Runtime.getRuntime().addShutdownHook(sdm); Class partypes[] = new Class[1]; partypes[0] = String.class; Constructor ct = c.getConstructor(partypes); for (String port : portList) { Object arglist[] = new Object[1]; arglist[0] = new Integer(37); arglist[1] = new Integer(47); Object emulator = ct.newInstance(arglist); ShutdownManager.addManagedObject((Shutdown) emulator); threads[i] = new Thread((Runnable) emulator); threads[i].start(); } // end for all ports i++; } // end for all emulators for (Thread thread : threads) { thread.join(); } } catch (Exception e) { throw e; } }
From source file:org.ihtsdo.statistics.runner.Runner.java
/** * Inits the file providers./* w w w . j av a2 s . c o m*/ * * @param file the file * @throws Exception the exception */ private static void initFileProviders(File file) throws Exception { logger.logInfo("Initializing file providers"); XMLConfiguration xmlConfig; try { xmlConfig = new XMLConfiguration(file); } catch (ConfigurationException e) { logger.logInfo("ClassificationRunner - Error happened getting params configFile." + e.getMessage()); throw e; } String releaseFolder = xmlConfig.getString("releaseFullFolder"); if (releaseFolder == null || releaseFolder.trim().equals("") || !new File(releaseFolder).exists()) { throw new Exception("Release folder doesn't exist."); } File sourceFolder = new File(releaseFolder); Object prop = xmlConfig.getProperty("releaseDependencies.releaseFullFolder"); HashSet<String> releaseDependencies = null; if (prop != null) { if (prop instanceof Collection) { releaseDependencies = new HashSet<String>(); for (String loopProp : (Collection<String>) prop) { releaseDependencies.add(loopProp); } } else if (prop instanceof String) { releaseDependencies = new HashSet<String>(); releaseDependencies.add((String) prop); System.out.println(prop); } } String releaseDate = xmlConfig.getString("releaseDate"); String previousReleaseDate = xmlConfig.getString("previousReleaseDate"); CurrentFile.init(sourceFolder, new File("release" + releaseDate), releaseDependencies, releaseDate); PreviousFile.init(sourceFolder, new File("release" + previousReleaseDate), releaseDependencies, previousReleaseDate); }
From source file:org.kepler.configuration.CommonsConfigurationReader.java
public static boolean addMatch(List<String> addKeys, List<String> addedKeys, XMLConfiguration addXmlConfig, XMLConfiguration addedXmlConfig) { if (addKeys.size() != addedKeys.size()) return false; HashMap<String, String> matchedKeys = new HashMap<String, String>(); for (String addKey : addKeys) { boolean keyMatchFound = false; for (String addedKey : addedKeys) { if (trimmedKey(addKey).equals(trimmedKey(addedKey))) { keyMatchFound = true;/*from w ww .j a v a 2 s . c o m*/ matchedKeys.put(addKey, addedKey); } } if (!keyMatchFound) return false; } for (Map.Entry<String, String> entry : matchedKeys.entrySet()) { Object addProperty = addXmlConfig.getProperty(entry.getKey()); Object addedProperty = addedXmlConfig.getProperty(entry.getValue()); if (!addProperty.equals(addedProperty)) return false; } return true; }
From source file:org.kepler.configuration.CommonsConfigurationReader.java
/** * Author: David Welker// w w w .j a va2 s . co m * * This method applies unrun add directives to the configuration. * @param addXml * @param xmlconfig */ private boolean applyAddDirectives(Module module, File addXml, XMLConfiguration xmlconfig) throws ConfigurationException { String addXmlFilename = addXml.getName(); String addedXmlFilename = addXmlFilename.substring(0, addXmlFilename.length() - 4) + "ed.xml"; File addedXml = new File(DotKeplerManager.getInstance().getModuleConfigurationDirectory(module.getName()), addedXmlFilename); Iterator i; XMLConfiguration addXmlConfig = new XMLConfiguration(); addXmlConfig.setDelimiterParsingDisabled(true); addXmlConfig.load(addXml); XMLConfiguration addedXmlConfig = new XMLConfiguration(); addedXmlConfig.setDelimiterParsingDisabled(true); if (addedXml.exists()) addedXmlConfig.load(addedXml); i = addXmlConfig.getKeys(); if (!i.hasNext()) return false; List<String> firstParts = new ArrayList<String>(); while (i.hasNext()) { String key = (String) i.next(); if (key.contains(".")) { String candidate = key.substring(0, key.indexOf('.')); if (!firstParts.contains(candidate)) firstParts.add(candidate); } } for (String firstPart : firstParts) { int maxAddIndex = addXmlConfig.getMaxIndex(firstPart); int maxAddedIndex = addedXmlConfig.getMaxIndex(firstPart); int addIndex = xmlconfig.getMaxIndex(firstPart) + 1; List<String> removeKeys = new ArrayList<String>(); for (int j = 0; j <= maxAddIndex; j++) { List<String> addKeys = new ArrayList<String>(); Iterator x1 = addXmlConfig.getKeys(firstPart + "(" + j + ")"); while (x1.hasNext()) { String key = (String) x1.next(); addKeys.add(key); } for (int k = 0; k <= maxAddedIndex; k++) { List<String> addedKeys = new ArrayList<String>(); Iterator x2 = addedXmlConfig.getKeys(firstPart + "(" + k + ")"); while (x2.hasNext()) { String key = (String) x2.next(); addedKeys.add(key); } if (addMatch(addKeys, addedKeys, addXmlConfig, addedXmlConfig)) { for (String addKey : addKeys) removeKeys.add(addKey); } } } for (int j = removeKeys.size() - 1; j >= 0; j--) { String removeKey = removeKeys.get(j); addXmlConfig.clearProperty(removeKey); } for (int j = 0; j <= maxAddIndex; j++) { String addXMLKey = firstPart + "(" + j + ")"; i = addXmlConfig.getKeys(addXMLKey); while (i.hasNext()) { String addXmlConfigKey = (String) i.next(); String lastPart = addXmlConfigKey.substring(addXmlConfigKey.indexOf('.') + 1, addXmlConfigKey.length()); String originalXmlConfigKey = firstPart + "(" + (addIndex + j) + ")." + lastPart; String addedXmlConfigKey = firstPart + "(" + (maxAddedIndex + 1 + j) + ")." + lastPart; xmlconfig.addProperty(originalXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey)); addedXmlConfig.addProperty(addedXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey)); } } } List<String> addedKeys = new ArrayList<String>(); i = addedXmlConfig.getKeys(); while (i.hasNext()) addedKeys.add((String) i.next()); i = addXmlConfig.getKeys(); while (i.hasNext()) { String addKey = (String) i.next(); if (addKey.contains(".")) continue; Object value = addXmlConfig.getProperty(addKey); if (addedKeys.contains(addKey)) { if (addedXmlConfig.getProperty(addKey).equals(value)) continue; } xmlconfig.addProperty(addKey, value); addedXmlConfig.addProperty(addKey, value); } addedXmlConfig.save(addedXml); return true; }
From source file:org.kepler.configuration.ConfigurationTest.java
public static void addTest() throws Exception { System.out.println("AddTest"); File configDir = Module.make("configuration-manager").getConfigurationsDir(); File configDirectivesDir = new File(configDir.getParentFile(), "config-directives"); System.out.println(configDir); System.out.println(configDirectivesDir); System.out.println();/* w w w .ja v a 2s. c om*/ File originalXml = new File(configDir, "original.xml"); File addXml = new File(configDirectivesDir, "add.xml"); File addedXml = new File(configDirectivesDir, "added.xml"); File newXml = new File(configDirectivesDir, "new.xml"); XMLConfiguration xmlconfig = new XMLConfiguration(); xmlconfig.setDelimiterParsingDisabled(true); xmlconfig.load(originalXml); Iterator i; XMLConfiguration addXmlConfig = new XMLConfiguration(); addXmlConfig.setDelimiterParsingDisabled(true); addXmlConfig.load(addXml); XMLConfiguration addedXmlConfig = new XMLConfiguration(); addedXmlConfig.setDelimiterParsingDisabled(true); if (addedXml.exists()) addedXmlConfig.load(addedXml); i = addXmlConfig.getKeys(); if (!i.hasNext()) return; List<String> firstParts = new ArrayList<String>(); while (i.hasNext()) { String key = (String) i.next(); if (key.contains(".")) { String candidate = key.substring(0, key.indexOf('.')); if (!firstParts.contains(candidate)) firstParts.add(candidate); } } for (String firstPart : firstParts) { System.out.println("firstPart = " + firstPart); int maxAddIndex = addXmlConfig.getMaxIndex(firstPart); int maxAddedIndex = addedXmlConfig.getMaxIndex(firstPart); int addIndex = xmlconfig.getMaxIndex(firstPart) + 1; List<String> removeKeys = new ArrayList<String>(); for (int j = 0; j <= maxAddIndex; j++) { List<String> addKeys = new ArrayList<String>(); Iterator x1 = addXmlConfig.getKeys(firstPart + "(" + j + ")"); while (x1.hasNext()) { String key = (String) x1.next(); addKeys.add(key); } for (int k = 0; k <= maxAddedIndex; k++) { List<String> addedKeys = new ArrayList<String>(); Iterator x2 = addedXmlConfig.getKeys(firstPart + "(" + k + ")"); while (x2.hasNext()) { String key = (String) x2.next(); addedKeys.add(key); } if (addMatch(addKeys, addedKeys, addXmlConfig, addedXmlConfig)) { for (String addKey : addKeys) removeKeys.add(addKey); } } } for (int j = removeKeys.size() - 1; j >= 0; j--) { String removeKey = removeKeys.get(j); addXmlConfig.clearProperty(removeKey); } System.out.println("Adding config..."); for (int j = 0; j <= maxAddIndex; j++) { String addXMLKey = firstPart + "(" + j + ")"; i = addXmlConfig.getKeys(addXMLKey); while (i.hasNext()) { String addXmlConfigKey = (String) i.next(); String lastPart = addXmlConfigKey.substring(addXmlConfigKey.indexOf('.') + 1, addXmlConfigKey.length()); String originalXmlConfigKey = firstPart + "(" + (addIndex + j) + ")." + lastPart; String addedXmlConfigKey = firstPart + "(" + (maxAddedIndex + 1 + j) + ")." + lastPart; xmlconfig.addProperty(originalXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey)); addedXmlConfig.addProperty(addedXmlConfigKey, addXmlConfig.getProperty(addXmlConfigKey)); } } } System.out.println("Simple adds..."); List<String> addedKeys = new ArrayList<String>(); i = addedXmlConfig.getKeys(); while (i.hasNext()) addedKeys.add((String) i.next()); i = addXmlConfig.getKeys(); while (i.hasNext()) { String addKey = (String) i.next(); if (addKey.contains(".")) continue; Object value = addXmlConfig.getProperty(addKey); if (addedKeys.contains(addKey)) { if (addedXmlConfig.getProperty(addKey).equals(value)) continue; } xmlconfig.addProperty(addKey, value); addedXmlConfig.addProperty(addKey, value); } addedXmlConfig.save(addedXml); xmlconfig.save(newXml); }
From source file:org.kepler.configuration.ConfigurationTest.java
public static void changeTest() throws Exception { System.out.println("ChangeTest"); File configDir = Module.make("configuration-manager").getConfigurationsDir(); File configDirectivesDir = new File(configDir.getParentFile(), "config-directives"); System.out.println(configDir); System.out.println(configDirectivesDir); System.out.println();/*w w w. ja va2 s . co m*/ File originalXml = new File(configDir, "original.xml"); File changeXml = new File(configDirectivesDir, "change.xml"); File changedXml = new File(configDirectivesDir, "changed.xml"); XMLConfiguration originalXmlConfig = new XMLConfiguration(); originalXmlConfig.setDelimiterParsingDisabled(true); originalXmlConfig.load(originalXml); Iterator i; i = originalXmlConfig.getKeys(); System.out.println("Original.xml:"); while (i.hasNext()) { String key = (String) i.next(); System.out.println(key + " = " + originalXmlConfig.getProperty(key)); } System.out.println(); XMLConfiguration changeXmlConfig = new XMLConfiguration(); changeXmlConfig.setDelimiterParsingDisabled(true); changeXmlConfig.load(changeXml); XMLConfiguration changedXmlConfig = new XMLConfiguration(); changedXmlConfig.setDelimiterParsingDisabled(true); if (changedXml.exists()) changedXmlConfig.load(changedXml); i = changeXmlConfig.getKeys(); System.out.println("Change.xml:"); while (i.hasNext()) { String key = (String) i.next(); System.out.println(key + " = " + changeXmlConfig.getProperty(key)); } System.out.println(); i = changeXmlConfig.getKeys(); while (i.hasNext()) { String key = (String) i.next(); Object value = changeXmlConfig.getProperty(key); Object changed = changedXmlConfig.getProperty(key); if (changed == null || !value.equals(changed)) { originalXmlConfig.setProperty(key, value); changedXmlConfig.setProperty(key, value); } } i = originalXmlConfig.getKeys(); System.out.println("New Config:"); while (i.hasNext()) { String key = (String) i.next(); System.out.println(key + " = " + originalXmlConfig.getProperty(key)); } System.out.println(); i = changedXmlConfig.getKeys(); System.out.println("Changed.xml"); while (i.hasNext()) { String key = (String) i.next(); System.out.println(key + " = " + changedXmlConfig.getProperty(key)); } System.out.println(); changedXmlConfig.save(changedXml); }
From source file:org.kepler.configuration.ConfigurationTest.java
public static void removeTest() throws Exception { System.out.println("RemoveTest"); File configDir = Module.make("configuration-manager").getConfigurationsDir(); File configDirectivesDir = new File(configDir.getParentFile(), "config-directives"); System.out.println(configDir); System.out.println(configDirectivesDir); System.out.println();//from w w w . jav a2 s . com File originalXml = new File(configDir, "original.xml"); File removeXml = new File(configDirectivesDir, "remove.xml"); File removedXml = new File(configDirectivesDir, "removed.xml"); File newXml = new File(configDirectivesDir, "new.xml"); XMLConfiguration originalXmlConfig = new XMLConfiguration(); originalXmlConfig.setDelimiterParsingDisabled(true); originalXmlConfig.load(originalXml); Iterator i; XMLConfiguration removeXmlConfig = new XMLConfiguration(); removeXmlConfig.setDelimiterParsingDisabled(true); removeXmlConfig.load(removeXml); XMLConfiguration removedXmlConfig = new XMLConfiguration(); removedXmlConfig.setDelimiterParsingDisabled(true); if (removedXml.exists()) removedXmlConfig.load(removedXml); i = removeXmlConfig.getKeys(); while (i.hasNext()) { String key = (String) i.next(); Object value = removeXmlConfig.getProperty(key); Object removed = removedXmlConfig.getProperty(key); if (removed == null || !value.equals(removed)) { originalXmlConfig.clearProperty(key); removedXmlConfig.setProperty(key, value); } } removedXmlConfig.save(removedXml); originalXmlConfig.save(newXml); }
From source file:org.kepler.configuration.SerializationComparisonTest.java
/** * test the commons interface for reading properties *///from w w w .ja v a 2 s .c o m public void testCommonsRead() { try { File f = new File("configuration-manager/resources/configurations/configuration.xml"); assertTrue(f.exists()); XMLConfiguration config = new XMLConfiguration(f); //get the conditionals of query and read some properties ArrayList al = (ArrayList) config .getProperty("ecogridService.queryList.query.AND.OR.condition.concept"); assertTrue(config.getString("ecogridService.queryList.query.AND.OR.condition(1).concept") .equals("keyword")); assertTrue( config.getString("ecogridService.queryList.query.AND.OR.condition(3).operator").equals("LIKE")); //break the config down into a smaller subset of just the queryList HierarchicalConfiguration sub = config.configurationAt("ecogridService.queryList"); al = (ArrayList) sub.getProperty("query.returnField"); al = (ArrayList) sub.getProperty("query(0).returnField"); //get the 2nd returnfield of the first query assertTrue(((String) al.get(1)).equals("entityName")); } catch (Exception e) { e.printStackTrace(); fail("Commons error: " + e.getMessage()); } System.out.println(); System.out.println(); }