commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wer...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core IncludeTag.java
Date Wed, 05 Jun 2002 07:00:58 GMT
werken      2002/06/05 00:00:58

  Modified:    jelly/src/java/org/apache/commons/jelly JellyContext.java
               jelly/src/java/org/apache/commons/jelly/expression/jexl
                        JexlExpression.java
               jelly/src/java/org/apache/commons/jelly/tags/core
                        IncludeTag.java
  Log:
  The <core:include> tag now can tag 2 additional attributes:
  
  	inhert="(true|false)" which describes that the included
  	jellyscript inherits all variables from the one that
  	actually uses the <include>.
  
  	export="(true|false)" which describes that the included
  	jellyscript exports all of its locally-set variables
  	to the one that actually uses the <include>.
  
  Things seem to still work.
  
  Revision  Changes    Path
  1.9       +60 -0     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JellyContext.java	30 May 2002 16:47:17 -0000	1.8
  +++ JellyContext.java	5 Jun 2002 07:00:58 -0000	1.9
  @@ -97,6 +97,12 @@
   
       /** The parent context */
       private JellyContext parent;
  +
  +    /** Do we inherit variables from parent context? */
  +    private boolean shouldInherit = false;
  +
  +    /** Do we export our variables to parent context? */
  +    private boolean shouldExport  = false;
       
       /**
        * The class loader to use for instantiating application objects.
  @@ -148,6 +154,36 @@
           return parent;
       }
   
  +    public void setExport(boolean shouldExport) {
  +        this.shouldExport = shouldExport;
  +    }
  +
  +    public boolean getExport() {
  +        return this.shouldExport;
  +    }
  +
  +    public void setInherit(boolean shouldInherit) {
  +        this.shouldInherit = shouldInherit;
  +    }
  +
  +    public boolean getInherit() {
  +        return this.shouldInherit;
  +    }
  +
  +    public Object getScopedVariable(String name) {
  +        if ( getInherit() ) {
  +            return findVariable( name );
  +        }
  +
  +        return getVariable( name );
  +    }
  +
  +    public void setScopedVariable(String name, Object value) {
  +        if ( getExport() ) {
  +            getParent().setScopedVariable( name, value );
  +        }
  +    }
  +
       /** 
        * Finds the variable value of the given name in this context or in any other parent
context.
        * If this context does not contain the variable, then its parent is used and then
its parent 
  @@ -167,11 +203,18 @@
           
       /** @return the value of the given variable name */
       public Object getVariable(String name) {
  +        if ( getInherit() ) {
  +            return getParent().findVariable( name );
  +        }
           return variables.get(name);
       }
   
       /** Sets the value of the given variable name */
       public void setVariable(String name, Object value) {
  +        if ( getExport() ) {
  +            getParent().setVariable( name, value );
  +            return;
  +        }
           if (value == null) {
               variables.remove(name);
           }
  @@ -328,6 +371,23 @@
           
           URL newJellyContextURL = getJellyContextURL(url);
           JellyContext newJellyContext = new JellyContext(this, newJellyContextURL);
  +        script.run(newJellyContext, output);
  +    }
  +
  +    public void runScript(String uri, XMLOutput output,
  +                          boolean export, boolean inherit) throws Exception {
  +        URL url = getResource(uri);
  +        if (url == null) {
  +            throw new JellyException("Could not find Jelly script: " + url);
  +        }
  +        Script script = compileScript(url);
  +        
  +        URL newJellyContextURL = getJellyContextURL(url);
  +        JellyContext newJellyContext = new JellyContext(this, newJellyContextURL);
  +
  +        newJellyContext.setExport( export );
  +        newJellyContext.setInherit( inherit );
  +
           script.run(newJellyContext, output);
       }
   
  
  
  
  1.5       +84 -24    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java
  
  Index: JexlExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JexlExpression.java	17 May 2002 15:18:14 -0000	1.4
  +++ JexlExpression.java	5 Jun 2002 07:00:58 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java,v
1.4 2002/05/17 15:18:14 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/17 15:18:14 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java,v
1.5 2002/06/05 07:00:58 werken Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/06/05 07:00:58 $
    *
    * ====================================================================
    *
  @@ -57,12 +57,14 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: JexlExpression.java,v 1.4 2002/05/17 15:18:14 jstrachan Exp $
  + * $Id: JexlExpression.java,v 1.5 2002/06/05 07:00:58 werken Exp $
    */
   
   package org.apache.commons.jelly.expression.jexl;
   
   import java.util.Map;
  +import java.util.Set;
  +import java.util.Collection;
   
   import org.apache.commons.jelly.JellyContext;
   
  @@ -84,7 +86,7 @@
    * along with some extra features like object method invocation.
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   
   public class JexlExpression extends ExpressionSupport {
  @@ -111,25 +113,7 @@
   
           try {
   
  -            JexlContext jexlContext = new JexlContext() {
  -
  -                Map ctx;
  -
  -                public void setVars(Map vars) {
  -
  -                    ctx = vars;
  -
  -                }
  -
  -                public Map getVars() {
  -
  -                    return ctx;
  -
  -                }
  -
  -            };
  -
  -            jexlContext.setVars(context.getVariables());
  +            JexlContext jexlContext = new JellyJexlContext( context );
   
               if (log.isDebugEnabled()) {
   
  @@ -151,4 +135,80 @@
   
       }
   
  +}
  +
  +class JellyJexlContext implements JexlContext {
  +
  +    private Map vars;
  +
  +    JellyJexlContext(JellyContext context) {
  +        this.vars = new JellyMap( context );
  +    }
  +
  +    public void setVars(Map vars) {
  +        this.vars.clear();
  +        this.vars.putAll( vars );
  +    }
  +
  +    public Map getVars() {
  +        return this.vars;
  +    }
  +}
  +
  +
  +class JellyMap implements Map {
  +
  +    private JellyContext context;
  +
  +    JellyMap(JellyContext context) {
  +        this.context = context;
  +    }
  +
  +    public Object get(Object key) {
  +        return context.getScopedVariable( (String) key );
  +    }
  +
  +    public void clear() {
  +        // not implemented
  +    }
  +
  +    public boolean containsKey(Object key) {
  +        return ( get( key ) != null );
  +    }
  +
  +    public boolean containsValue(Object value) {
  +        return false;
  +    }
  +
  +    public Set entrySet() {
  +        return null;
  +    }
  +
  +    public boolean isEmpty() {
  +        return false;
  +    }
  +
  +    public Set keySet() {
  +        return null;
  +    }
  +        
  +    public Object put(Object key, Object value) {
  +        return null;
  +    }
  +
  +    public void putAll(Map t) {
  +        // not implemented
  +    }
  +
  +    public Object remove(Object key) {
  +        return null;
  +    }
  +
  +    public int size() {
  +        return -1;
  +    }
  +
  +    public Collection values() {
  +        return null;
  +    }
   }
  
  
  
  1.5       +30 -7     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java
  
  Index: IncludeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IncludeTag.java	17 May 2002 15:18:08 -0000	1.4
  +++ IncludeTag.java	5 Jun 2002 07:00:58 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java,v
1.4 2002/05/17 15:18:08 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/17 15:18:08 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IncludeTag.java,v
1.5 2002/06/05 07:00:58 werken Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/06/05 07:00:58 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: IncludeTag.java,v 1.4 2002/05/17 15:18:08 jstrachan Exp $
  + * $Id: IncludeTag.java,v 1.5 2002/06/05 07:00:58 werken Exp $
    */
   
   package org.apache.commons.jelly.tags.core;
  @@ -77,15 +77,39 @@
   /** A tag which conditionally evaluates its body based on some condition
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.4 $
  +  * @version $Revision: 1.5 $
     */
   
   public class IncludeTag extends TagSupport {
   
       private String uri;
   
  +    private boolean shouldExport;
  +    private boolean shouldInherit;
  +
       public IncludeTag() {
  +        this.shouldExport = false;
  +        this.shouldInherit = false;
  +    }
  +
  +    public void setInherit(String inherit) {
  +        if ( "true".equals( inherit ) ) {
  +            this.shouldInherit = true;
  +        }
  +    }
   
  +    public void setExport(String export) {
  +        if ( "true".equals( export ) ) {
  +            this.shouldExport = true;
  +        }
  +    }
  +
  +    public boolean getInherit() {
  +        return this.shouldInherit;
  +    }
  +
  +    public boolean getExport() {
  +        return this.shouldExport;
       }
   
       // Tag interface
  @@ -104,8 +128,7 @@
   
           // take off the script name from the URL
   
  -        context.runScript(uri, output);
  -
  +        context.runScript(uri, output, getExport(), getInherit() );
       }
   
       // Properties
  
  
  

--
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