Unfortunately the library is in pretty sad shape becuase of over-reliance on  a 
SAX Parser which has hardcoded values
and in your case the XML you provided was incorrect for at least 3 of those 
parameters

In the meanwhile feel free to use supplied 
org.apache.commons.configuration.CommonsConfigurationTest.java  instead

I will be filing a detailed JIRA as soon as I finish sending this email (and 
will copy you0

Many thanks for pointing out this show-stopping bug Ron!
Martin Gainty 
_____________________________________
place inlined CommonsConfigurationTest.java in 
/src/test/java/org/apache/commons/configuration/CommonsConfigurationTest.java
mvn package will build and execute this test file
_____________________________________

package org.apache.commons.configuration;

import org.w3c.dom.NodeList;

public class CommonsConfigurationTest extends junit.framework.TestCase
{
    public CommonsConfigurationTest() { ; }
    public CommonsConfigurationTest(String name)
    {
        super(name);
        
System.out.println("CommonsConfigurationTest::CommonsConfigurationTest(name) 
name="+name);
    }
    protected void setUp() throws Exception
    {
        System.out.println("CommonsConfigurationTest::setUp");
    }
    protected void tearDown() throws Exception
    {
        System.out.println("CommonsConfigurationTest::tearDown");
    }
    public org.apache.commons.configuration.XMLConfiguration config=null;
    public java.io.File file  = null;
    public org.w3c.dom.Document document = null;
    public org.w3c.dom.NodeList rootNodeList = null;

    public org.w3c.dom.NodeList configurationList = null;
    public org.w3c.dom.NodeList headerList = null;
    public org.w3c.dom.NodeList lookupsList = null;
    public org.w3c.dom.NodeList lookupList = null;
    public org.w3c.dom.NodeList variablesList = null;
    public org.w3c.dom.NodeList variableList = null;
    public java.util.Properties props = new java.util.Properties();
    public org.w3c.dom.Node rootNode = null;
    public void test()
    {
        //try
        //{
           System.out.println("CommonsConfigurationTest::test before file = new 
java.io.File('configuration.xml') ");
           file= new java.io.File("C:/TEMP/configuration.xml");
           System.out.println("CommonsConfigurationTest::test file = "+file);
        //}
        //catch(java.io.IOException ex)
        //{
        //    System.err.println("CommonsConfigurationTest::test has thrown 
IOException  message="+ex.getMessage());
        //    return;
        //}
        try
        {

            org.apache.commons.configuration.tree.DefaultExpressionEngine 
engine = new org.apache.commons.configuration.tree.DefaultExpressionEngine();
            System.out.println("CommonsConfigurationTest::test LINE 51 engine = 
"+engine);
// Use a slash as property delimiter
            engine.setPropertyDelimiter("/");
// Indices should be provided in curly brackets
            engine.setIndexStart("{");
            engine.setIndexEnd("}");
// For attributes use simply a @
            engine.setAttributeStart("@");
            engine.setAttributeEnd(null);
// A Backslash is used for escaping property delimiters
            engine.setEscapedDelimiter("\\/");

// Now install this engine as the global engine
            HierarchicalConfiguration.setDefaultExpressionEngine(engine);

// Access properties using the new syntax
            //System.out.println("CommonsConfigurationTest::test() before 
config = new XMLConfiguration()");
            //XMLConfiguration config = new XMLConfiguration();
            //System.out.println("CommonsConfigurationTest::test() before 
config.load() LNE 35 config="+config);
            //try
            //{
            //    config.load("C:/TEMP/configuration.xml");
            //}
            //catch(Exception excp)
            //{
            //}

            //try
           // {
                    //System.out.println("CommonsConfiguration::test() before 
document = config.getDocument()");
                    //document = config.getDocument();
            //}
            //catch(Exception excp)
            //{
           // }
           if(document == null)
           {
                System.out.println("CommonsConfigurationTest::test() LINE 88 
before fXmlFile = new java.io.File('C:/temp/configuration.xml'); ");
                java.io.File fXmlFile = new 
java.io.File("C:/temp/configuration.xml");
                System.out.println("CommonsConfigurationTest::test LINE 90 
fXmlFile = "+fXmlFile);
                   javax.xml.parsers.DocumentBuilderFactory dbFactory = 
javax.xml.parsers.DocumentBuilderFactory.newInstance();
                   System.out.println("CommonsConfigurationTest::test LINE 92 
dbFactory = "+dbFactory);
                   javax.xml.parsers.DocumentBuilder dBuilder = 
dbFactory.newDocumentBuilder();
                   System.out.println("CommonsConfigurationTest::test LINE 94 
dBuilder="+dBuilder);
                   System.out.println("CommonsConfigurationTest::test LINE 95 
before document = dBuilder.parse(fXmlFile)");
                this.document = dBuilder.parse(fXmlFile);
                this.document.getDocumentElement().normalize();
           }
           System.out.println("CommonsConfigurationTest::test() LINE 98 
document=" + this.document );
           //rootNode = config.getRoot();
           //System.out.println("CommonsConfigurationTest::getRootNode() LINE 
37 rootNode = " + rootNode);
           //System.out.println("CommonsConfigurationTest::getRootElementNode() 
LINE 101 getRootElementName()="+config.getRootElementName());

            //rootNodeList = rootNode.getChildNodes();
            
//System.out.println("CommonsConfigurationTest::getRootElementNode() 
rootNodeList = "+rootNodeList);
            
//System.out.println("CommonsConfigurationTest::getRootElementNode() 
rootNodeList length = "+rootNodeList.getLength());

            System.out.println("CommonsConfigurationTest::getRootElementNode() 
LINE 108 Root element :" + this.document.getDocumentElement().getNodeName());
       //test for ron
            System.out.println("CommonsConfigurationTest:test LINE 108 document 
= "+this.document);
            configurationList = 
this.document.getElementsByTagName("configuration");
               System.out.println("CommonsConfigurationTest::test Object 
config.getProperty(configuration) =" +configurationList.item(0) );

           headerList = this.document.getElementsByTagName("header");
            System.out.println("CommonsConfigurationTest::test LINE 36 
header.length="+headerList.getLength());
           System.out.println("CommonsConfigurationTest::test LINE 36 
header="+headerList.item(0));

           lookupsList = this.document.getElementsByTagName("lookups");
           System.out.println("CommonsConfigurationTest::test LINE 36 
header.lookups="+lookupsList.item(0) );

           lookupList = this.document.getElementsByTagName("lookup");
           System.out.println("CommonsConfigurationTest::test LINE 36 
header.lookups.lookup with / "+lookupList.item(0) );

           variablesList = this.document.getElementsByTagName("variables");
           System.out.println("CommonsConfigurationTest::test LINE 89 variables 
lookup = "+variablesList.item(0) );

           variableList = this.document.getElementsByTagName("variable");
           System.out.println("CommonsConfigurationTest::test LINE 38 variable 
length"+variableList.getLength() );
           org.w3c.dom.Node valueNode = variableList.item(0);
           if (valueNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
           {
                       org.w3c.dom.Element eElement = (org.w3c.dom.Element) 
valueNode;
                       System.out.println("id : " + 
eElement.getAttribute("id"));
                       //org.w3c.dom.NodeList nodeList = 
eElement.getElementsByTagName("value");
                       //System.out.println("CommonsConfigurationTest::test 
LINE 135 nodeList="+nodeList);
                       System.out.println("value : " + 
eElement.getAttribute("value") );
                       //org.w3c.dom.Node node = nodeList.item(0);
                       //System.out.println("CommonsConfigurationTest::test 
LINE 135 node="+node);
                       //org.w3c.dom.NamedNodeMap map = node.getAttributes();
                       //System.out.println("value : " + 
map.getNamedItem("value") );  //node.getTextContent());
           }

           props.load( new 
java.io.FileInputStream("C:/temp/example.properties")   );
           System.out.println("CommonsConfigurationTest::test LINE 39 
(config.getProperty) properties.reloadingStrategy ="+ 
props.getProperty("mobile.rest.host")   );

        }
        catch (Exception e) {
            System.out.println("CommonsConfigurationTest::test LINE 55 has 
thrown Exception message="+e.getMessage());
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
}



> From: ronald.difra...@capitalone.com
> To: user@commons.apache.org
> Date: Fri, 11 Jul 2014 11:27:14 -0400
> Subject: RE: Commons Config: Variable Interpolation
> 
> Here's the full XML file:
> 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> 
> <configuration>
>       <header>
>               <result />
>               <lookups>
>                       <lookup config-prefix="expr"
>                               
> config-class="org.apache.commons.configuration.interpol.ExprLookup">
>                               <variables>
>                                       <variable name="net" 
> value="Class:java.net.InetAddress" />
>                               </variables>
>                       </lookup>
>               </lookups>
>       </header>
> 
>       <system />
> 
>       <properties fileName=" example.properties" listDelimiter="|">
>               <reloadingStrategy refreshDelay="10000"
>                       
> config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"
>  />
>       </properties>
> 
> </configuration>
> 
> And the referenced properties file:
> 
>       mobile.rest.host=${expr:$[net.localHost.hostName]}
> 
> 
> Ron DiFrango
> 
> 
> 
> -----Original Message-----
> From: Martin Gainty [mailto:mgai...@hotmail.com] 
> Sent: Friday, July 11, 2014 11:25 AM
> To: Commons Users List
> Subject: RE: Commons Config: Variable Interpolation
> 
> 
> 
> > From: ronald.difra...@capitalone.com
> > To: user@commons.apache.org
> > Date: Fri, 11 Jul 2014 11:02:45 -0400
> > Subject: RE: Commons Config: Variable Interpolation
> > 
> > Just to complete it, the code looks like:
> > 
> > DefaultConfigurationBuilder factory = new 
> > DefaultConfigurationBuilder("example.xml");
> > Configuration config = factory.getConfiguration();
> 
> MG>no clue which properties are defined in example.xml so lets add a new 
> MG>property called mobile.rest.host here 
> MG>config.addProperty("mobile.rest.host", "maps.google.com");
> 
> > System.out.println("Host Name = " + 
> > config.getString("mobile.rest.host"));
> MG>?
> > 
> > Ron DiFrango
> > 
> > 
> > -----Original Message-----
> > From: DiFrango, Ronald (CONT) [mailto:ronald.difra...@capitalone.com]
> > Sent: Friday, July 11, 2014 10:49 AM
> > To: user@commons.apache.org
> > Subject: Commons Config: Variable Interpolation
> > 
> > I'm attempting to perform Variable Interpolation as outlined here:
> > 
> > http://commons.apache.org/proper/commons-configuration/userguide/howto
> > _basicfeatures.html#Variable_Interpolation
> > 
> > I'm using an XML file as the starter so I added the following blurb to the 
> > beginning of the file:
> > 
> > <header>
> >               <result />
> >               <lookups>
> >                      <lookup config-prefix="expr"
> >                            
> > config-class="org.apache.commons.configuration.interpol.ExprLookup">
> >                            <variables>
> >                                   <variable name="net" 
> > value="Class:java.net.InetAddress" />
> >                            </variables>
> >                      </lookup>
> >               </lookups>
> >        </header>
> MG>
> <override>
>       <xml mobileRestHost="String.lowercase(net.localHost.hostName)"></xml>
> </override>
> MG>?
> 
> > 
> > And then in my properties file that is loaded I did:
> > 
> > mobile.rest.host=${expr:$[net.localHost.hostName]}
> > 
> > But it did not work any thoughts on what I'm doing wrong?
> > 
> > Thanks,
> > 
> > Ron
> > 
> > 
> > ________________________________________________________
> > 
> > The information contained in this e-mail is confidential and/or proprietary 
> > to Capital One and/or its affiliates. The information transmitted herewith 
> > is intended only for use by the individual or entity to which it is 
> > addressed.  If the reader of this message is not the intended recipient, 
> > you are hereby notified that any review, retransmission, dissemination, 
> > distribution, copying or other use of, or taking of any action in reliance 
> > upon this information is strictly prohibited. If you have received this 
> > communication in error, please contact the sender and delete the material 
> > from your computer.
> > ________________________________________________________
> > 
> > The information contained in this e-mail is confidential and/or proprietary 
> > to Capital One and/or its affiliates. The information transmitted herewith 
> > is intended only for use by the individual or entity to which it is 
> > addressed.  If the reader of this message is not the intended recipient, 
> > you are hereby notified that any review, retransmission, dissemination, 
> > distribution, copying or other use of, or taking of any action in reliance 
> > upon this information is strictly prohibited. If you have received this 
> > communication in error, please contact the sender and delete the material 
> > from your computer.
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> > 
>                                         
> ________________________________________________________
> 
> The information contained in this e-mail is confidential and/or proprietary 
> to Capital One and/or its affiliates. The information transmitted herewith is 
> intended only for use by the individual or entity to which it is addressed.  
> If the reader of this message is not the intended recipient, you are hereby 
> notified that any review, retransmission, dissemination, distribution, 
> copying or other use of, or taking of any action in reliance upon this 
> information is strictly prohibited. If you have received this communication 
> in error, please contact the sender and delete the material from your 
> computer.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 
                                          

Reply via email to