List of usage examples for org.apache.commons.configuration XMLConfiguration load
private void load(InputSource source) throws ConfigurationException
From source file:org.onosproject.driver.XmlConfigParser.java
public static HierarchicalConfiguration loadXml(InputStream xmlStream) { XMLConfiguration cfg = new XMLConfiguration(); try {/* w w w . j a v a 2s .c o m*/ cfg.load(xmlStream); return cfg; } catch (ConfigurationException e) { throw new IllegalArgumentException("Cannot load xml from Stream", e); } }
From source file:org.onosproject.drivers.odtn.InfineraOpenConfigDeviceDiscovery.java
private List<PortDescription> discoverPorts() throws ConfigurationException, IOException { DeviceId did = data().deviceId();/* ww w . ja v a2s .co m*/ NetconfSession ns = Optional.ofNullable(handler().get(NetconfController.class)) .map(c -> c.getNetconfDevice(did)).map(NetconfDevice::getSession) .orElseThrow(() -> new IllegalStateException("No NetconfSession found for " + did)); // TODO convert this method into non-blocking form? String reply = ns.asyncGet().join().toString(); // workaround until asyncGet().join() start failing exceptionally String data = null; if (reply.startsWith("<data")) { data = reply; } if (data == null) { log.error("No valid response found from {}:\n{}", did, reply); return ImmutableList.of(); } XMLConfiguration cfg = new XMLConfiguration(); cfg.load(CharSource.wrap(data).openStream()); return discoverPorts(cfg); }
From source file:org.onosproject.drivers.odtn.InfineraOpenConfigDeviceDiscoveryTest.java
@Test public void testToPortDescription() throws ConfigurationException, IOException { // CHECKSTYLE:OFF String input = "<data>\n" + " <interfaces xmlns=\"http://openconfig.net/yang/interfaces\">\n" + " <interface>\n" + " <name>CARRIERCTP.1-L1-1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>CARRIERCTP.1-L1-1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>CARRIERCTP.1-L1-2</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>CARRIERCTP.1-L1-2</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>CARRIERCTP.1-L1-3</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>CARRIERCTP.1-L1-3</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>CARRIERCTP.1-L1-4</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>CARRIERCTP.1-L1-4</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>CARRIERCTP.1-L1-5</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>CARRIERCTP.1-L1-5</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>CARRIERCTP.1-L1-6</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>CARRIERCTP.1-L1-6</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>GIGECLIENTCTP.1-A-2-T1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>GIGECLIENTCTP.1-A-2-T1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>GIGECLIENTCTP.1-A-2-T2</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>GIGECLIENTCTP.1-A-2-T2</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>GIGECLIENTCTP.1-L1-1-1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>GIGECLIENTCTP.1-L1-1-1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>GIGECLIENTCTP.1-L2-1-1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>GIGECLIENTCTP.1-L2-1-1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>NCTGIGE.1-NCT-1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" + " <name>NCTGIGE.1-NCT-1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>NCTGIGE.1-NCT-2</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" + " <name>NCTGIGE.1-NCT-2</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>OCHCTP.1-L1-1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>OCHCTP.1-L1-1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>SCHCTP.1-L1-1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>SCHCTP.1-L1-1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>TRIBPTP.1-A-2-T1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>TRIBPTP.1-A-2-T1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>TRIBPTP.1-A-2-T2</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>TRIBPTP.1-A-2-T2</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " <interface>\n" + " <name>XTSCGPTP.1-L1</name>\n" + " <config>\n" + " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + " <name>XTSCGPTP.1-L1</name>\n" + " <description/>\n" + " <enabled>true</enabled>\n" + " </config>\n" + " </interface>\n" + " </interfaces>\n" + "</data>\n"; // CHECKSTYLE:ON InfineraOpenConfigDeviceDiscovery sut = new InfineraOpenConfigDeviceDiscovery(); XMLConfiguration cfg = new XMLConfiguration(); cfg.load(CharSource.wrap(input).openStream()); List<PortDescription> ports = sut.discoverPorts(cfg); assertThat(ports, hasSize(4));/*from www. j a v a 2 s . c o m*/ PortDescription portDescription; portDescription = ports.get(0); assertThat(portDescription.portNumber().toLong(), is(1L)); assertThat(portDescription.portNumber().name(), is("GIGECLIENTCTP.1-A-2-T1")); assertThat(portDescription.annotations().value(OC_NAME), is("GIGECLIENTCTP.1-A-2-T1")); assertThat(portDescription.annotations().value(OC_TYPE), is("GIGECLIENTCTP.1-A-2-T1")); assertThat(portDescription.annotations().value(ODTN_PORT_TYPE), is(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value())); portDescription = ports.get(3); assertThat(portDescription.portNumber().toLong(), is(102L)); assertThat(portDescription.portNumber().name(), is("GIGECLIENTCTP.1-L2-1-1")); assertThat(portDescription.annotations().value(OC_NAME), is("GIGECLIENTCTP.1-L2-1-1")); assertThat(portDescription.annotations().value(OC_TYPE), is("GIGECLIENTCTP.1-L2-1-1")); assertThat(portDescription.annotations().value(ODTN_PORT_TYPE), is(OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value())); }
From source file:org.onosproject.drivers.odtn.OpenConfigDeviceDiscoveryTest.java
@Test public void testToPortDescription() throws ConfigurationException, IOException { // CHECKSTYLE:OFF String input = "<data>\n" + "<components xmlns=\"http://openconfig.net/yang/platform\">\n" + "\n" + " <component>\n" + " <name>TPC_1_1_4_N2_200G</name>\n" + " <config>\n" + " <name>TPC_1_1_4_N2_200G</name>\n" + " </config>\n" + " <state>\n" + " <name>TPC_1_1_4_N2_200G</name>\n" + " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:LINECARD</type>\n" + " </state>\n" + " </component>\n" + "\n" + " <component>\n" + " <name>CLIPORT_1_1_4_1</name>\n" + " <config>\n" + " <name>CLIPORT_1_1_4_1</name>\n" + " </config>\n" + " <state>\n" + " <name>CLIPORT_1_1_4_1</name>\n" + " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" + " </state>\n" + " </component>\n" + "\n" + " <component>\n" + " <name>LINEPORT_1_1_4</name>\n" + " <config>\n" + " <name>LINEPORT_1_1_4</name>\n" + " </config>\n" + " <state>\n" + " <name>LINEPORT_1_1_4</name>\n" + " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" + " </state>\n" + " </component>\n" + "\n" + " <component>\n" + " <name>TRANSCEIVER_1_1_4_1</name>\n" + " <config>\n" + " <name>TRANSCEIVER_1_1_4_1</name> \n" + " </config>\n" + " <state>\n" + " <name>TRANSCEIVER_1_1_4_1</name>\n" + " <type xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:TRANSCEIVER</type>\n" + " </state>\n" + " <properties>\n" + " <property>\n" + " <name>onos-index</name>\n" + " <config>\n" + " <name>onos-index</name>\n" + " <value>42</value>\n" + " </config>\n" + " </property>\n" + " </properties>\n" + " <transceiver xmlns=\"http://openconfig.net/yang/platform/transceiver\">\n" + " <config>\n" + " <enabled>true</enabled>\n" + " <form-factor-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" + " <ethernet-pmd-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" + " </config>\n" + " <state>\n" + " <enabled>true</enabled>\n" + " <form-factor-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" + " <ethernet-pmd-preconf xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" + " </state>\n" + " </transceiver>\n" + " </component>\n" + "\n" + " <component>\n" + " <name>OPTCHANNEL_1_1_4</name>\n" + " <config>\n" + " <name>OPTCHANNEL_1_1_4</name>\n" + " </config>\n" + " <state>\n" + " <name>OPTCHANNEL_1_1_4</name>\n" + " <type xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:OPTICAL_CHANNEL</type>\n" + " </state>\n" + " <optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">\n" + " <config>\n" + " <frequency>191500000</frequency>\n" + " <target-output-power>0.0</target-output-power>\n" + " </config>\n" + " <state>\n" + " <frequency>191500000</frequency>\n" + " <target-output-power>0.0</target-output-power>\n" + " </state>\n" + " </optical-channel>\n" + " </component>\n" + "\n" + "</components>\n" + "</data>"; // CHECKSTYLE:ON OpenConfigDeviceDiscovery sut = new OpenConfigDeviceDiscovery(); XMLConfiguration cfg = new XMLConfiguration(); cfg.load(CharSource.wrap(input).openStream()); List<PortDescription> ports = sut.discoverPorts(cfg); assertThat(ports, hasSize(1));/*from www. j a v a2s . c o m*/ PortDescription portDescription = ports.get(0); assertThat(portDescription.portNumber().toLong(), is(42L)); assertThat(portDescription.portNumber().name(), is("TRANSCEIVER_1_1_4_1")); assertThat(portDescription.annotations().value(OC_NAME), is("TRANSCEIVER_1_1_4_1")); assertThat(portDescription.annotations().value(OC_TYPE), is("oc-platform-types:TRANSCEIVER")); }
From source file:org.onosproject.drivers.utilities.YangXmlUtils.java
/** * Method to read an input stream into a XMLConfiguration. * @param xmlStream inputstream containing XML description * @return the XMLConfiguration object/*from w w w . java2s . c o m*/ */ public XMLConfiguration loadXml(InputStream xmlStream) { XMLConfiguration cfg = new XMLConfiguration(); try { cfg.load(xmlStream); return cfg; } catch (ConfigurationException e) { throw new IllegalArgumentException("Cannot load xml from Stream", e); } }
From source file:org.onosproject.maven.OnosAppMojo.java
private void loadAppFile(File appFile) throws MojoExecutionException { XMLConfiguration xml = new XMLConfiguration(); xml.setRootElementName(APP);/* w w w .j a v a 2s. c o m*/ try (FileInputStream stream = new FileInputStream(appFile)) { xml.load(stream); xml.setAttributeSplittingDisabled(true); xml.setDelimiterParsingDisabled(true); name = xml.getString(NAME); version = eval(xml.getString(VERSION)); featuresRepo = eval(xml.getString(FEATURES_REPO)); artifacts = xml.configurationsAt(ARTIFACT).stream() .map(cfg -> eval(cfg.getRootNode().getValue().toString())).collect(Collectors.toList()); } catch (ConfigurationException e) { throw new MojoExecutionException("Unable to parse app.xml file", e); } catch (FileNotFoundException e) { throw new MojoExecutionException("Unable to find app.xml file", e); } catch (IOException e) { throw new MojoExecutionException("Unable to read app.xml file", e); } }
From source file:org.onosproject.net.driver.XmlDriverLoader.java
/** * Loads the specified drivers resource as an XML stream and parses it to * produce a ready-to-register driver provider. * * @param driversStream stream containing the drivers definitions * @param resolver driver resolver//from w w w . j av a 2 s . com * @return driver provider * @throws java.io.IOException if issues are encountered reading the stream * or parsing the driver definitions within */ public DefaultDriverProvider loadDrivers(InputStream driversStream, DriverResolver resolver) throws IOException { try { XMLConfiguration cfg = new XMLConfiguration(); cfg.setRootElementName(DRIVERS); cfg.setAttributeSplittingDisabled(true); cfg.load(driversStream); return loadDrivers(cfg, resolver); } catch (ConfigurationException e) { throw new IOException("Unable to load drivers", e); } }
From source file:org.ow2.aspirerfid.demos.warehouse.management.UI.WMS.java
private void loadShipmentInfo() { XMLConfiguration config = new XMLConfiguration(); config.setListDelimiter(','); URL fileurl2 = this.getClass().getClassLoader().getResource("/WarehouseParameters.xml"); URL fileurl = this.getClass().getResource("/WarehouseParameters.xml"); DeliveryItem item;/*from w ww . jav a 2s .c o m*/ Shipment shipment; String invoiceId; int items; try { config.load(fileurl); } catch (Exception e) { e.printStackTrace(); } int invoicesNumber = config.getMaxIndex("invoices.invoice") + 1; shipments = new HashMap<String, Shipment>(); for (int i = 0; i < invoicesNumber; i++) { invoiceId = config.getString("invoices.invoice(" + i + ").invoiceGroupName"); shipment = new Shipment(invoiceId); items = config.getMaxIndex("invoices.invoice(" + i + ").merchandise.packetsContent") + 1; for (int j = 0; j < items; j++) { item = new DeliveryItem(); item.setCompany(config .getString("invoices.invoice(" + i + ").merchandise.packetsContent(" + j + ").company")); item.setItemCode(config.getString( "invoices.invoice(" + i + ").merchandise.packetsContent(" + j + ").packetsGroupName")); item.setDescription(config.getString( "invoices.invoice(" + i + ").merchandise.packetsContent(" + j + ").description")); item.setMeasurementID(config.getString( "invoices.invoice(" + i + ").merchandise.packetsContent(" + j + ").measurementID")); item.setExpectedQuantity(new BigInteger(config.getString( "invoices.invoice(" + i + ").merchandise.packetsContent(" + j + ").expectedQuantity"))); shipment.addItem(item); } shipments.put(invoiceId, shipment); } }
From source file:org.powertac.server.ServerPropertiesService.java
/** * Loads the properties from classpath, default config file, * and user-specified config file, just in case it's not already been * loaded. This is done when properties are first requested, to ensure * that the logger has been initialized. Because the CompositeConfiguration * treats its config sources in FIFO order, this should be called <i>after</i> * any user-specified config is loaded.//from www . j av a2 s . com */ void lazyInit() { // only do this once if (initialized) return; initialized = true; // find and load the default properties file log.info("lazyInit"); try { File defaultProps = new File("config/server.properties"); if (defaultProps.canRead()) { log.debug("adding " + defaultProps.getName()); config.addConfiguration(new PropertiesConfiguration(defaultProps)); } } catch (Exception e1) { log.warn("config/server.properties not found: " + e1.toString()); } // set up the classpath props try { Resource[] xmlResources = context.getResources("classpath*:config/properties.xml"); for (Resource xml : xmlResources) { if (validXmlResource(xml)) { log.info("loading config from " + xml.getURI()); XMLConfiguration xconfig = new XMLConfiguration(); xconfig.load(xml.getInputStream()); config.addConfiguration(xconfig); } } Resource[] propResources = context.getResources("classpath*:config/*.properties"); for (Resource prop : propResources) { if (validPropResource(prop)) { log.info("loading config from " + prop.getURI()); PropertiesConfiguration pconfig = new PropertiesConfiguration(); pconfig.load(prop.getInputStream()); config.addConfiguration(pconfig); } } } catch (ConfigurationException e) { log.error("Error loading configuration: " + e.toString()); } catch (Exception e) { log.error("Error loading configuration: " + e.toString()); } // set up the configurator configurator.setConfiguration(config); }
From source file:org.restcomm.connect.core.service.util.UriUtilsTest.java
@Test public void testResolveRelativeUrl() throws Exception { URL url = this.getClass().getResource("/restcomm.xml"); XMLConfiguration xml = new XMLConfiguration(); xml.setDelimiterParsingDisabled(true); xml.setAttributeSplittingDisabled(true); xml.load(url); RestcommConfiguration conf = new RestcommConfiguration(xml); String domainName = "amazing.restcomm.com"; HttpConnector httpConnector = new HttpConnector("http", "127.0.0.1", 8080, false); HttpConnectorList httpConnectorList = new HttpConnectorList( Arrays.asList(new HttpConnector[] { httpConnector })); when(jBossConnectorDiscover.findConnectors()).thenReturn(httpConnectorList); URI relativeUri = URI.create("/restcomm/recording.wav"); Assert.assertEquals("http://127.0.0.1:8080/restcomm/recording.wav", uriUtils.resolve(relativeUri).toString()); }