kinman      2003/02/14 17:41:46

  Modified:    jasper2/src/share/org/apache/jasper/compiler Node.java
                        TagPluginManager.java
               jasper2/src/share/org/apache/jasper/compiler/tagplugin
                        TagPluginContext.java
               jasper2/src/share/org/apache/jasper/tagplugins/jstl
                        tagPlugins.xml
  Added:       jasper2/src/share/org/apache/jasper/tagplugins/jstl
                        Choose.java Otherwise.java When.java
  Log:
  - Add a facility to communicate with parent nodes in plugin interface.
  - Implement plugins for <c:choose>, <c:when>, and <c:otherwise>
  
  Revision  Changes    Path
  1.56      +17 -3     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Node.java 13 Feb 2003 23:25:05 -0000      1.55
  +++ Node.java 15 Feb 2003 01:41:42 -0000      1.56
  @@ -65,6 +65,8 @@
   import javax.servlet.jsp.tagext.*;
   import org.xml.sax.Attributes;
   import org.apache.jasper.JasperException;
  +import org.apache.jasper.compiler.tagplugin.TagPluginContext;
  +
   
   /**
    * An internal data representation of a JSP page or a JSP docuement (XML).
  @@ -985,10 +987,14 @@
        private Node.CustomTag customTagParent;
        private Integer numCount;
        private boolean useTagPlugin;
  +     private TagPluginContext tagPluginContext;
  +
        /**
         * The following two fields are used for holding the Java
         * scriptlets that the tag plugins may generate.  Meaningful
         * only if useTagPlugin is true;
  +      * Could move them into TagPluginContextImpl, but we'll need
  +      * to cast tagPluginContext to TagPluginContextImpl all the time...
         */
        private Nodes atSTag;
        private Nodes atETag;
  @@ -1215,6 +1221,14 @@
   
        public boolean useTagPlugin() {
            return useTagPlugin;
  +     }
  +
  +     public void setTagPluginContext(TagPluginContext tagPluginContext) {
  +         this.tagPluginContext = tagPluginContext;
  +     }
  +
  +     public TagPluginContext getTagPluginContext() {
  +         return tagPluginContext;
        }
   
        public void setAtSTag(Nodes sTag) {
  
  
  
  1.15      +29 -10    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagPluginManager.java
  
  Index: TagPluginManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagPluginManager.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TagPluginManager.java     14 Feb 2003 01:33:03 -0000      1.14
  +++ TagPluginManager.java     15 Feb 2003 01:41:43 -0000      1.15
  @@ -175,13 +175,15 @@
        }
   
        TagPluginContext tagPluginContext = new TagPluginContextImpl(n, pageInfo);
  +     n.setTagPluginContext(tagPluginContext);
        tagPlugin.doTag(tagPluginContext);
       }
   
       static class TagPluginContextImpl implements TagPluginContext {
  -     Node.CustomTag node;
  -     Node.Nodes curNodes;
  -     PageInfo pageInfo;
  +     private Node.CustomTag node;
  +     private Node.Nodes curNodes;
  +     private PageInfo pageInfo;
  +     private HashMap pluginAttributes;
   
        TagPluginContextImpl(Node.CustomTag n, PageInfo pageInfo) {
            this.node = n;
  @@ -191,6 +193,23 @@
            curNodes = new Node.Nodes();
            n.setAtSTag(curNodes);
            n.setUseTagPlugin(true);
  +         pluginAttributes = new HashMap();
  +     }
  +
  +     public TagPluginContext getParentContext() {
  +         Node parent = node.getParent();
  +         if (! (parent instanceof Node.CustomTag)) {
  +             return null;
  +         }
  +         return ((Node.CustomTag) parent).getTagPluginContext();
  +     }
  +
  +     public void setAttribute(String key, Object value) {
  +         pluginAttributes.put(key, value);
  +     }
  +
  +     public Object getAttribute(String key) {
  +         return pluginAttributes.get(key);
        }
   
        public boolean isScriptless() {
  @@ -198,21 +217,21 @@
        }
   
        public boolean isConstantAttribute(String attribute) {
  -         Node.JspAttribute attr = getAttribute(attribute);
  +         Node.JspAttribute attr = getNodeAttribute(attribute);
            if (attr == null)
                return false;
            return attr.isLiteral();
        }
   
        public String getConstantAttribute(String attribute) {
  -         Node.JspAttribute attr = getAttribute(attribute);
  +         Node.JspAttribute attr = getNodeAttribute(attribute);
               if (attr == null)
                return null;
            return attr.getValue();
        }
   
        public boolean isAttributeSpecified(String attribute) {
  -         return getAttribute(attribute) != null;
  +         return getNodeAttribute(attribute) != null;
        }
   
        public String getTemporaryVariableName() {
  @@ -252,7 +271,7 @@
            curNodes = node.getAtETag();
        }
   
  -     private Node.JspAttribute getAttribute(String attribute) {
  +     private Node.JspAttribute getNodeAttribute(String attribute) {
            Node.JspAttribute[] attrs = node.getJspAttributes();
            for (int i=0; i < attrs.length; i++) {
                if (attrs[i].getName().equals(attribute)) {
  
  
  
  1.10      +24 -3     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPluginContext.java
  
  Index: TagPluginContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPluginContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TagPluginContext.java     14 Feb 2003 01:33:03 -0000      1.9
  +++ TagPluginContext.java     15 Feb 2003 01:41:45 -0000      1.10
  @@ -142,5 +142,26 @@
        * is deemed too compilicated for optimization.
        */
       void dontUseTagPlugin();
  +
  +    /**
  +     * Get the PluginContext for the parent of this custom tag.  NOTE:
  +     * The operations available for PluginContext so obtained is limited
  +     * to getAttribute and setAttribute, and queries (e.g. isScriptless(),
  +     * There should be no generate*().
  +     * @return The pluginContext for the parent node.
  +     *         null if the parent is not a custom tag, or if the pluginConxt
  +     *         if not available (because useTagPlugin is false, e.g).
  +     */
  +    TagPluginContext getParentContext();
  +
  +    /**
  +     * Associate the attribute with a value in the current tagplugin context.
  +     */
  +    void setAttribute(String attr, Object value);
  +
  +    /**
  +     * Get the value of an attribute in the current tagplugin context.
  +     */
  +    Object getAttribute(String attr);
   }
   
  
  
  
  1.3       +12 -0     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/tagPlugins.xml
  
  Index: tagPlugins.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/tagPlugins.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- tagPlugins.xml    14 Feb 2003 01:33:03 -0000      1.2
  +++ tagPlugins.xml    15 Feb 2003 01:41:46 -0000      1.3
  @@ -4,6 +4,18 @@
       <plugin-class>org.apache.jasper.tagplugins.jstl.If</plugin-class>
     </tag-plugin>
     <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.common.core.ChooseTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.Choose</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.rt.core.WhenTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.When</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
  +    <tag-class>org.apache.taglibs.standard.tag.common.core.OtherwiseTag</tag-class>
  +    <plugin-class>org.apache.jasper.tagplugins.jstl.Otherwise</plugin-class>
  +  </tag-plugin>
  +  <tag-plugin>
       <tag-class>org.apache.taglibs.standard.tag.rt.core.ForEachTag</tag-class>
       <plugin-class>org.apache.jasper.tagplugins.jstl.ForEach</plugin-class>
     </tag-plugin>
  
  
  
  1.1                  
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/Choose.java
  
  Index: Choose.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/Choose.java,v
 1.1 2003/02/15 01:41:46 kinman Exp $
   * $Revision: 1.1 $
   * $Date: 2003/02/15 01:41:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.jasper.tagplugins.jstl;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class Choose implements TagPlugin {
  
      public void doTag(TagPluginContext ctxt) {
  
        // Not much to do here, much of the work will be done in the
        // containing tags, <c:when> and <c:otherwise>.
  
        ctxt.generateBody();
        // See comments in When.java for the reason "}" is generated here.
        ctxt.generateJavaSource("}");
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/Otherwise.java
  
  Index: Otherwise.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/Otherwise.java,v
 1.1 2003/02/15 01:41:46 kinman Exp $
   * $Revision: 1.1 $
   * $Date: 2003/02/15 01:41:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.jasper.tagplugins.jstl;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class Otherwise implements TagPlugin {
  
      public void doTag(TagPluginContext ctxt) {
  
        // See When.java for the reason whey "}" is need at the beginng and
        // not at the end.
        ctxt.generateJavaSource("} else {");
        ctxt.generateBody();
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/When.java
  
  Index: When.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/tagplugins/jstl/When.java,v
 1.1 2003/02/15 01:41:46 kinman Exp $
   * $Revision: 1.1 $
   * $Date: 2003/02/15 01:41:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.jasper.tagplugins.jstl;
  
  import org.apache.jasper.compiler.tagplugin.*;
  
  public final class When implements TagPlugin {
  
      public void doTag(TagPluginContext ctxt) {
        // Get the parent context to determine if this is the first <c:when>
        TagPluginContext parentContext = ctxt.getParentContext();
        if (parentContext == null) {
            ctxt.dontUseTagPlugin();
            return;
        }
  
        if ("true".equals(parentContext.getAttribute("hasBeenHere"))) {
            ctxt.generateJavaSource("} else if(");
            // See comment below for the reason we generate the extra "}" here.
        }
        else {
            ctxt.generateJavaSource("if(");
            parentContext.setAttribute("hasBeenHere", "true");
        }
        ctxt.generateAttribute("test");
        ctxt.generateJavaSource("){");
        ctxt.generateBody();
  
        // We don't generate the closing "}" for the "if" here because there
        // may be whitespaces in between <c:when>'s.  Instead we delay
        // generating it until the next <c:when> or <c:otherwise> or
        // <c:choose>
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to