[
https://issues.apache.org/jira/browse/CONFIGURATION-664?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15982050#comment-15982050
]
Gary Gregory commented on CONFIGURATION-664:
--------------------------------------------
I have some XML that looks like this:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<Proxy uuid="b19a44a6-fddd-4683-b97d-f92871a0ad1e" printEnvironment="true"
printMinEnvironment="true" logEnvironment="true"
logMinEnvironment="true" port="9090">
<OriginServer uri="http://localhost:54321">
<UriSimplePattern matches="/abc*" />
<UriSimplePattern matches="/xyz*" />
</OriginServer>
<OriginServer uri="http://localhost:54322">
<UriSimplePattern matches="/data*" />
</OriginServer>
</Proxy>
{code}
I build my config like this:
{code:java}
public XMLConfiguration parseXmlFile(final FileObject fileObject) throws
ConfigurationException, FileSystemException {
if (fileObject != null && !fileObject.exists()) {
LOGGER.debug("No configuration file {}", fileObject);
return defaultXMLConfiguration();
}
LOGGER.debug("Parsing configuration {}", fileObject);
final Parameters params = new Parameters();
// @formatter:off
final FileBasedConfigurationBuilder<XMLConfiguration> builder = new
FileBasedConfigurationBuilder<>(XMLConfiguration.class)
.configure(params.xml()
.setFileSystem(new VFSFileSystem())
.setFileName(fileObject.getURL().toString()));
// @formatter:on
return builder.getConfiguration();
}
{code}
But no matter which get API I get, I cannot get a list or array of
"OriginServer" nodes. So I am left to get the in-memory node model and traverse
that to cherry pick what I need from the XML.
All of these return false:
coreConfig.containsKey("OriginServer")
coreConfig.containsKey("Proxy")
coreConfig.containsKey("Proxy.OriginServer")
The method {{getKeys()}} lists the right stuff:
{code:java}
com.google.common.collect.Lists.newArrayList(coreConfig.getKeys())
{code}
{noformat}
(java.util.ArrayList<E>) [[@printEnvironment], [@printMinEnvironment],
[@port], [@logMinEnvironment], [@logEnvironment], [@uuid], OriginServer[@uri],
OriginServer.UriSimplePattern[@matches]]
{noformat}
These return nulls or empty lists:
coreConfig.getList("OriginServer")
coreConfig.getList("Proxy.OriginServer")
coreConfig.getProperty("OriginServer")
coreConfig.getProperties("OriginServer")
Thoughts?
> Add API
> org.apache.commons.configuration2.tree.ImmutableNode.getChildren(String)
> --------------------------------------------------------------------------------
>
> Key: CONFIGURATION-664
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-664
> Project: Commons Configuration
> Issue Type: New Feature
> Reporter: Gary Gregory
> Assignee: Gary Gregory
> Fix For: 2.2
>
>
> Add API
> org.apache.commons.configuration2.tree.ImmutableNode.getChildren(String):
> {code:java}
> /**
> * Returns a list with the children of this node. This list cannot be
> * modified.
> * @param name the node name to find
> *
> * @return a list with the child nodes
> */
> public List<ImmutableNode> getChildren(final String name)
> {
> final List<ImmutableNode> list = new ArrayList<>();
> if (name == null) {
> return list;
> }
> for (final ImmutableNode node : children)
> {
> if (name.equals(node.getNodeName()))
> {
> list.add(node);
> }
> }
> return list;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)