List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:org.encuestame.core.test.config.XmlConfigurationText.java
/** * @throws ConfigurationException// w w w . jav a 2s . c o m * */ @Test public void testXmlFile() { // final ConfigurationManager configurationManager = new // ConfigurationManager("encuestame-config.xml"); // System.out.println(configurationManager.getIntProperty("encuestame.database.version")); XMLConfiguration xmlConfiguration = null; try { Resource res = new ClassPathResource("properties-test/encuestame-test-config.xml"); // System.out.println(res.getFilename()); // System.out.println(res.getFile().getAbsolutePath()); xmlConfiguration = new XMLConfiguration(res.getFile()); // System.out.println(xmlConfiguration.getString("encuestame.database.version")); // System.out.println(xmlConfiguration.getString("database.version")); xmlConfiguration.setAutoSave(true); xmlConfiguration.addProperty("juan", "juan"); // System.out.println(xmlConfiguration.getString("administration")); // System.out.println(xmlConfiguration.getString("version")); // System.out.println(xmlConfiguration.getRootElementName()); // System.out.println(xmlConfiguration.getKeys()); final Iterator i = xmlConfiguration.getKeys(); while (i.hasNext()) { Object object = (Object) i.next(); //System.out.println(object); } // System.out.println(xmlConfiguration.getList("social-networks.social-network.social-network-name")); // System.out.println(xmlConfiguration.getList("social-networks.social-network.social-network-name").size()); // System.out.println(xmlConfiguration.getList("social-networks")); // System.out.println(xmlConfiguration.getList("social-networks").size()); List fields = xmlConfiguration.configurationsAt("tables.table(0).fields.field"); for (Iterator it = fields.iterator(); it.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); // sub contains all data about a single field String fieldName = sub.getString("name"); String fieldType = sub.getString("type"); } } catch (ConfigurationException e) { e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.firstopen.singularity.devicemgr.emulators.EmulatorManager.java
/** * @param args/*from w ww . java 2s .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.glite.slcs.acl.impl.XMLFileAccessControlList.java
/** * Loads the ACL XML FileConfiguration.//from www . ja v a 2 s. co m * * @param filename * The ACL XML filename to load. * @return The FileConfiguration object. * @throws SLCSConfigurationException * If an configration error occurs while loading the file. */ static private XMLConfiguration createACLXMLConfiguration(String filename) throws SLCSConfigurationException { XMLConfiguration config = null; try { LOG.info("XMLConfiguration file=" + filename); config = new XMLConfiguration(filename); if (LOG.isDebugEnabled()) { File configFile = config.getFile(); LOG.debug("XMLConfiguration file=" + configFile.getAbsolutePath()); } } catch (ConfigurationException e) { LOG.error("Failed to create XMLConfiguration: " + filename, e); throw new SLCSConfigurationException("Failed to create XMLConfiguration: " + filename, e); } return config; }
From source file:org.glite.slcs.acl.impl.XMLFileProcessor.java
/** * Constructor.//ww w . ja v a 2 s . c om * * @param filename * The XML file * @throws SLCSException * If an error occurs. */ public XMLFileProcessor(String filename) throws SLCSException { // create the xml file try { config_ = new XMLConfiguration(filename); File configFile = config_.getFile(); filename_ = configFile.getAbsolutePath(); if (LOG.isDebugEnabled()) { LOG.debug("XMLConfiguration file=" + filename_); } } catch (ConfigurationException e) { LOG.error("Failed to create XMLConfiguration: " + filename, e); throw new SLCSConfigurationException("Failed to create XMLConfiguration: " + filename, e); } // create the operation queue operationsQueue_ = new LinkedList(); // create the process thread and start it processingThread_ = new ProcessingThread(); processingThread_.start(); }
From source file:org.glite.slcs.config.SLCSConfiguration.java
/** * Creates a XMLConfiguration loaded with the given file. * /* w ww . j a v a 2 s .co m*/ * @param filename * The file name to load the XML configuration from. * @return The new FileConfiguration object * @throws SLCSConfigurationException * If a configuration error occurs while loading the XML file. */ static protected FileConfiguration loadConfiguration(String filename) throws SLCSConfigurationException { XMLConfiguration config = null; try { LOG.info("XMLConfiguration file=" + filename); config = new XMLConfiguration(filename); LOG.debug("XMLConfiguration resolved file=" + config.getFile().getAbsolutePath()); } catch (ConfigurationException e) { LOG.error("Failed to create XMLConfiguration: " + filename, e); throw new SLCSConfigurationException("Failed to create XMLConfiguration: " + filename, e); } return config; }
From source file:org.glite.slcs.config.SLCSConfiguration.java
/** * Creates a XMLConfiguration loaded from the given url. * //from w ww . j a v a2s . c o m * @param url * The URL of the file to load the XML configuration from. * @return The new FileConfiguration object * @throws SLCSConfigurationException * If a configuration error occurs while downloading and loading the XML file. */ static protected FileConfiguration downloadConfiguration(URL url) throws SLCSConfigurationException { XMLConfiguration config = null; try { LOG.info("XMLConfiguration url=" + url); config = new XMLConfiguration(url); } catch (ConfigurationException e) { LOG.error("Failed to download XMLConfiguration from: " + url, e); throw new SLCSConfigurationException("Failed to download XMLConfiguration from: " + url, e); } return config; }
From source file:org.glite.slcs.group.impl.XMLFileGroupManager.java
/** * Loads the groups XMLConfiguration file. * //w w w. j av a 2 s .c o m * @param filename * The groups XML filename to load. * @return The loaded {@link XMLConfiguration} object. * @throws SLCSConfigurationException * If an configration error occurs while loading the file. */ static private XMLConfiguration createGroupsConfiguration(String filename) throws SLCSConfigurationException { XMLConfiguration config = null; try { config = new XMLConfiguration(filename); if (LOG.isDebugEnabled()) { File configFile = config.getFile(); LOG.debug("XMLConfiguration file=" + configFile.getAbsolutePath()); } } catch (ConfigurationException e) { LOG.error("Failed to create XMLConfiguration: " + filename, e); throw new SLCSConfigurationException("Failed to create XMLConfiguration: " + filename, e); } return config; }
From source file:org.goobi.api.display.helper.ConfigDispayRules.java
/** * reads given xml file into XMLConfiguration. */// w w w.j ava 2 s .c o m private ConfigDispayRules() { configPfad = ConfigCore.getKitodoConfigDirectory() + "kitodo_metadataDisplayRules.xml"; try { config = new XMLConfiguration(configPfad); config.setReloadingStrategy(new FileChangedReloadingStrategy()); getDisplayItems(); } catch (ConfigurationException e) { /* * no configuration file found, default configuration (textarea) * will be used, nothing to do here */ } }
From source file:org.goobi.api.display.helper.ConfigDisplayRules.java
/** * Reads given xml file into XMLConfiguration. */// w w w. j a v a 2s .c om private ConfigDisplayRules() { String configPath = ConfigCore.getKitodoConfigDirectory() + FileNames.METADATA_DISPLAY_RULES_FILE; try { config = new XMLConfiguration(configPath); config.setReloadingStrategy(new FileChangedReloadingStrategy()); getDisplayItems(); } catch (ConfigurationException e) { /* * no configuration file found, default configuration (textarea) will be used, * nothing to do here */ } }
From source file:org.goobi.production.cli.WebInterfaceConfig.java
/** * Get credentials.//from w ww .j a v a 2s. c om * * @param requestIp * String * @param requestPassword * String * @return list of Strings */ public static List<String> getCredentials(String requestIp, String requestPassword) { ArrayList<String> allowed = new ArrayList<>(); try { XMLConfiguration config = new XMLConfiguration( ConfigCore.getKitodoConfigDirectory() + "kitodo_webapi.xml"); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex("credentials"); for (int i = 0; i <= count; i++) { String ip = config.getString("credentials(" + i + ")[@ip]"); String password = config.getString("credentials(" + i + ")[@password]"); if (requestIp.startsWith(ip) && requestPassword.equals(password)) { int countCommands = config.getMaxIndex("credentials(" + i + ").command"); for (int j = 0; j <= countCommands; j++) { allowed.add(config.getString("credentials(" + i + ").command(" + j + ")[@name]")); } } } } catch (Exception e) { allowed = new ArrayList<>(); } return allowed; }