Java Code Examples for org.apache.commons.configuration.XMLConfiguration#configurationsAt()

The following examples show how to use org.apache.commons.configuration.XMLConfiguration#configurationsAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Configuration.java    From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Loads and parse CME MDP Configuration.
 *
 * @param uri URI to CME MDP Configuration (config.xml, usually available on CME FTP)
 * @throws ConfigurationException if failed to parse configuration file
 * @throws MalformedURLException  if URI to Configuration is malformed
 */
private void load(final URI uri) throws ConfigurationException, MalformedURLException {
    // todo: if to implement the same via standard JAXB then dep to apache commons configuration will be not required
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.setDelimiterParsingDisabled(true);
    configuration.load(uri.toURL());
    for (final HierarchicalConfiguration channelCfg : configuration.configurationsAt("channel")) {
        final ChannelCfg channel = new ChannelCfg(channelCfg.getString("[@id]"), channelCfg.getString("[@label]"));

        for (final HierarchicalConfiguration connCfg : channelCfg.configurationsAt("connections.connection")) {
            final String id = connCfg.getString("[@id]");
            final FeedType type = FeedType.valueOf(connCfg.getString("type[@feed-type]"));
            final TransportProtocol protocol = TransportProtocol.valueOf(connCfg.getString("protocol").substring(0, 3));
            final Feed feed = Feed.valueOf(connCfg.getString("feed"));
            final String ip = connCfg.getString("ip");
            final int port = connCfg.getInt("port");
            final List<String> hostIPs = Arrays.asList(connCfg.getStringArray("host-ip"));

            final ConnectionCfg connection = new ConnectionCfg(feed, id, type, protocol, ip, hostIPs, port);
            channel.addConnection(connection);
            connCfgs.put(connection.getId(), connection);
        }
        channelCfgs.put(channel.getId(), channel);
    }
}
 
Example 2
Source File: RORClient.java    From development with Apache License 2.0 6 votes vote down vote up
public List<String> listServerTypes() throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_SERVER_TYPE);
	XMLConfiguration response = execute(request);
	List<String> result = new LinkedList<String>();
	if (response != null) {
		List<HierarchicalConfiguration> types = response
				.configurationsAt("servertypes.servertype");
		for (HierarchicalConfiguration type : types) {
			String name = type.getString("name");
			if (name != null && name.trim().length() > 0) {
				result.add(name);
			}
		}
	}
	return result;
}
 
Example 3
Source File: RORClient.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of all available LPlatform configurations.
 * 
 * @param verbose
 *            set to <code>true</code> to retrieve extended information
 * @return the list of configurations (may be empty but not
 *         <code>null</code>)
 * @throws RORException
 */
public List<LPlatformConfiguration> listLPlatforms(boolean verbose)
		throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_LPLATFORM);
	request.put(LParameter.VERBOSE, (verbose ? "true" : "false"));
	XMLConfiguration result = execute(request);

	List<LPlatformConfiguration> resultList = new LinkedList<LPlatformConfiguration>();
	if (result != null) {
		List<HierarchicalConfiguration> platforms = result
				.configurationsAt("lplatforms.lplatform");
		for (HierarchicalConfiguration platform : platforms) {
			resultList.add(new LPlatformConfiguration(platform));
		}
	}
	return resultList;
}
 
Example 4
Source File: RORClient.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves a list of templates available for the tenant.
 * 
 * @return the list
 * @throws RORException
 */
public List<LPlatformDescriptor> listLPlatformDescriptors()
		throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_LPLATFORM_DESCR);
	XMLConfiguration result = execute(request);

	List<LPlatformDescriptor> resultList = new LinkedList<LPlatformDescriptor>();
	if (result != null) {
		List<HierarchicalConfiguration> descriptors = result
				.configurationsAt("lplatformdescriptors.lplatformdescriptor");
		for (HierarchicalConfiguration descriptor : descriptors) {
			resultList.add(new LPlatformDescriptor(descriptor));
		}
	}
	return resultList;
}
 
Example 5
Source File: RORClient.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves a list of disk images available for the tenant.
 * 
 * @return the list
 * @throws RORException
 */
public List<DiskImage> listDiskImages() throws IaasException {
	HashMap<String, String> request = getBasicParameters();
	request.put(LParameter.ACTION, LOperation.LIST_DISKIMAGE);
	XMLConfiguration result = execute(request);

	List<DiskImage> resultList = new LinkedList<DiskImage>();
	if (result != null) {
		List<HierarchicalConfiguration> images = result
				.configurationsAt("diskimages.diskimage");
		for (HierarchicalConfiguration image : images) {
			resultList.add(new RORDiskImage(image));
		}
	}
	return resultList;
}
 
Example 6
Source File: MyConfigurationXMLUtils.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取树状结构数据
 */
public void getHierarchicalExample() {

    try {
        XMLConfiguration config = new XMLConfiguration("properties-website-job.xml");
        log.info(config.getFileName());
        //   log.info(config.getStringByEncoding("jdbc.oracle.work.235.url", "GBK"));

        //包含 websites.site.name 的集合
        Object prop = config.getProperty("websites.site.name");

        if (prop instanceof Collection) {
            //  System.out.println("Number of tables: " + ((Collection<?>) prop).size());
            Collection<String> c = (Collection<String>) prop;
            int i = 0;

            for (String s : c) {

                System.out.println("sitename :" + s);

                List<HierarchicalConfiguration> fields = config.configurationsAt("websites.site(" + String.valueOf(i) + ").fields.field");
                for (HierarchicalConfiguration sub : fields) {
                    // sub contains all data about a single field
                    //此处可以包装成 bean
                    String name = sub.getString("name");
                    String type = sub.getString("type");
                    System.out.println("name :" + name + " , type :" + type);
                }

                i++;
                System.out.println(" === ");
            }
        }
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }


}
 
Example 7
Source File: OpenRoadmDeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the external links as a list of XML hieriarchical configs.
 *  @param session the NETConf session to the OpenROADM device.
 *  @return a list of hierarchical conf. each one external link.
 */
List<HierarchicalConfiguration> getExternalLinks(NetconfSession session) {
    try {
        String reply = session.rpc(getDeviceExternalLinksBuilder()).get();
        XMLConfiguration extLinksConf = //
            (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        extLinksConf.setExpressionEngine(new XPathExpressionEngine());
        return extLinksConf.configurationsAt(
                "/data/org-openroadm-device/external-link");
    } catch (NetconfException | InterruptedException | ExecutionException e) {
        log.error("[OPENROADM] {} exception getting external links", did());
        return ImmutableList.of();
    }
}
 
Example 8
Source File: OpenRoadmDeviceDescription.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the circuit packs from the device as a list of XML hierarchical configs.
 *  @param session the NETConf session to the OpenROADM device.
 *  @return a list of hierarchical conf. each one circuit pack.
 */
List<HierarchicalConfiguration> getCircuitPacks(NetconfSession session) {
    try {
        String reply = session.rpc(getDeviceCircuitPacksBuilder()).get();
        XMLConfiguration cpConf = //
            (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        cpConf.setExpressionEngine(new XPathExpressionEngine());
        return cpConf.configurationsAt(
                "/data/org-openroadm-device/circuit-packs");
    } catch (NetconfException | InterruptedException | ExecutionException e) {
        log.error("[OPENROADM] {} exception getting circuit packs", did());
        return ImmutableList.of();
    }
}
 
Example 9
Source File: NokiaOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
private List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());
    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
            .map(this::toPortDescriptionInternal)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example 10
Source File: OpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
protected List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());

    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
        .map(this::toPortDescription)
        .filter(Objects::nonNull)
        .collect(Collectors.toList());
}
 
Example 11
Source File: InfineraOpenConfigDeviceDiscovery.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Parses port information from OpenConfig XML configuration.
 *
 * @param cfg tree where the root node is {@literal <data>}
 * @return List of ports
 */
@VisibleForTesting
protected List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    // If we want to use XPath
    cfg.setExpressionEngine(new XPathExpressionEngine());

    // converting components into PortDescription.
    List<HierarchicalConfiguration> components = cfg.configurationsAt("interfaces/interface");
    return components.stream()
            .map(this::toPortDescription)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example 12
Source File: ZteDeviceDiscoveryImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
private List<PortDescription> discoverPorts(XMLConfiguration cfg) {
    cfg.setExpressionEngine(new XPathExpressionEngine());
    List<HierarchicalConfiguration> components = cfg.configurationsAt("components/component");
    return components.stream()
            .filter(this::isPortComponent)
            .map(this::toPortDescriptionInternal)
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}