commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/util foo.properties suite.jelly
Date Thu, 19 Dec 2002 10:52:33 GMT
jstrachan    2002/12/19 02:52:33

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/util
                        PropertiesTag.java
               jelly/src/test/org/apache/commons/jelly/util suite.jelly
  Added:       jelly/src/test/org/apache/commons/jelly/util foo.properties
  Log:
  Added the ability of the <util:properties> tag to create a new Properties variable
if required. This can be handy for loading properties from a file and then passing them as
a variable to some Maven task for example
  
  Revision  Changes    Path
  1.4       +24 -7     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/util/PropertiesTag.java
  
  Index: PropertiesTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/util/PropertiesTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertiesTag.java	11 Dec 2002 12:41:00 -0000	1.3
  +++ PropertiesTag.java	19 Dec 2002 10:52:33 -0000	1.4
  @@ -78,6 +78,7 @@
   public class PropertiesTag extends TagSupport {
       private String file;
       private String uri;
  +    private String var;
   
       public PropertiesTag() {
       }
  @@ -104,13 +105,18 @@
           }
           Properties props = new Properties();
           props.load(is);
  -        Enumeration enum = props.propertyNames();
  -        while (enum.hasMoreElements()) {
  -            String key = (String) enum.nextElement();
  -            String value = props.getProperty(key);
  -            
  -            // @todo we should parse the value in case its an Expression
  -            context.setVariable(key, value);
  +        if (var != null) {
  +            context.setVariable(var, props);
  +        }
  +        else {
  +            Enumeration enum = props.propertyNames();
  +            while (enum.hasMoreElements()) {
  +                String key = (String) enum.nextElement();
  +                String value = props.getProperty(key);
  +                
  +                // @todo we should parse the value in case its an Expression
  +                context.setVariable(key, value);
  +            }
           }
   
       }
  @@ -131,6 +137,17 @@
        */
       public void setUri(String uri) {
           this.uri = uri;
  +    }
  +
  +    /**
  +     * If this is defined then a Properties object containing all the
  +     * properties will be created and exported, otherwise the current variable
  +     * scope will be set to the value of the properties.
  +     * 
  +     * @param var The var to set
  +     */
  +    public void setVar(String var) {
  +        this.var = var;
       }
   
   }
  
  
  
  1.5       +18 -0     jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/util/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/util/suite.jelly,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- suite.jelly	16 Nov 2002 10:15:45 -0000	1.4
  +++ suite.jelly	19 Dec 2002 10:52:33 -0000	1.5
  @@ -100,5 +100,23 @@
         and placed the result into a variable
       </test:assertEquals>
     </test:case>
  +
  +  <test:case name="testProperties">
  +  	
  +  	<util:properties uri="foo.properties"/>
  +  	
  +    <test:assertEquals expected="ABC" actual="${foo}"/>
  +    
  +  </test:case>
  +	
  +  <test:case name="testPropertiesVar">
  +  	
  +  	<util:properties uri="foo.properties" var="props"/>
  +  	
  +    <test:assertEquals expected="ABC" actual="${props.foo}"/>
  +    
  +    <log:info>Loaded properties value ${props}</log:info>
  +    
  +  </test:case>
   	
   </test:suite>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/util/foo.properties
  
  Index: foo.properties
  ===================================================================
  foo=ABC
  bar=XYZ
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message