I have a CompositeConfiguration object which has some property configurations and some XMLConfigurations.For the XMLConfiguration, the DefaultExpressionEngine is set as XPathExpressionEngine
One of the .properties file has properties starting with "." eg : .propertyName="name"
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
XMLConfiguration xmlConfig = new XMLConfiguration("xmlFile.xml");
xmlConfig.setDefaultExpressionEngine(new XPathExpressionEngine());
compositeConfiguration.addConfiguration(xmlConfig);
compositeConfiguration.addConfiguration(new PropertiesConfiguration(new File("file1.properties")));
compositeConfiguration.addConfiguration(new PropertiesConfiguration(new File("file2.properties")));
compositeConfiguration.addConfiguration(new PropertiesConfiguration(new File("file3.properties")));
compositeConfiguration.getProperty(".propertyName");
I get the following exception:
org.apache.commons.jxpath.JXPathInvalidSyntaxException: Invalid XPath: '.propertyName'. Syntax error after "."
at org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:63)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpression(JXPathContextReferenceImpl.java:249)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.iteratePointers(JXPathContextReferenceImpl.java:616)
at org.apache.commons.jxpath.JXPathContext.selectNodes(JXPathContext.java:686)
at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.query(XPathExpressionEngine.java:183)
at org.apache.commons.configuration.HierarchicalConfiguration.fetchNodeList(HierarchicalConfiguration.java:958)
at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.fetchNodeList(AbstractHierarchicalFileConfiguration.java:439)
at org.apache.commons.configuration.HierarchicalConfiguration.getProperty(HierarchicalConfiguration.java:344)
at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.getProperty(AbstractHierarchicalFileConfiguration.java:392)
at org.apache.commons.configuration.HierarchicalConfiguration.containsKey(HierarchicalConfiguration.java:725)
at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.containsKey(AbstractHierarchicalFileConfiguration.java:360)
at org.apache.commons.configuration.CompositeConfiguration.getProperty(CompositeConfiguration.java:261)
This exception is because CompositeConfiguration goes through each configuration and call getProperty on that configuration with the key which is ".propertyName" in this case. When the XPathExpression Engine is used to get the value from the XMLConfiguration, it breaks saying invalid xpath.
This seems like an easily possible/common scenario. Has anyone else faced similar issue ? Is there any way to get around this problem ?
Any other configuration types I could use ? I am using CompositeConfiguration because I want to use give priority to properties loaded first.
Any hints will be of great help to me please.
Thanks, Tejas