tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler UninterpretedTagBeginGenerator.java UninterpretedTagEndGenerator.java BaseJspListener.java DelegatingListener.java JspParseEventListener.java ParseEventListener.java ParserXJspSaxHandler.java
Date Wed, 04 Oct 2000 20:01:07 GMT
pierred     00/10/04 13:01:07

  Modified:    jasper/src/share/org/apache/jasper/compiler
                        BaseJspListener.java DelegatingListener.java
                        JspParseEventListener.java ParseEventListener.java
                        ParserXJspSaxHandler.java
  Added:       jasper/src/share/org/apache/jasper/compiler
                        UninterpretedTagBeginGenerator.java
                        UninterpretedTagEndGenerator.java
  Log:
  Well formed XML fragments can appear where #PCDATA can appear
  in an XJSP (JSP page as an XML document) page.
  No need to wrap these XML fragments inside CDATA sections
  anymore in the XJSP page.
  
  ParseXJspSaxHandler
    - startElement now makes the distiction between a custom tag
      and an 'uninterpreted' tag
    - processCustomTagBegin() adjusted given that some code has
      been moved in startElement() so we know immediately if we
      deal with a custom tag or not.
    - Node class now has internal state telling whether a node
      is an 'uninterpreted' tag or not.
    - characters encountered while in an 'uninterpreted tag'
      are simply passed through as char data.
      (just like for body content of jsp:root)
  
  JspParseEventListener
    - Two new methods to handle the 'uninterpreted' tags:
      handleUninterpretedTagBegin() and handleUninterpretedTagEnd()
  
  ParseEventListener
  BaseJspListener
  DelegatingListener
    - Added the two new methods required in JspParseEventListener
      (these classes are pretty much no-ops... should do some
       cleanup and get rid of them eventually)
  
  UninterpretedTagBeginGenerator
  UninterpretedTagEndGenerator
     - New Generators to handle uninterpreted tags
  
  Revision  Changes    Path
  1.3       +11 -3     jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/BaseJspListener.java
  
  Index: BaseJspListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/BaseJspListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseJspListener.java	2000/09/19 19:23:31	1.2
  +++ BaseJspListener.java	2000/10/04 20:01:05	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/BaseJspListener.java,v
1.2 2000/09/19 19:23:31 pierred Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/09/19 19:23:31 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/BaseJspListener.java,v
1.3 2000/10/04 20:01:05 pierred Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/04 20:01:05 $
    *
    * ====================================================================
    * 
  @@ -187,4 +187,12 @@
   
       public void handleRootBegin(Hashtable attrs) {};
       public void handleRootEnd() {};
  +
  +    public void handleUninterpretedTagBegin(Mark start, Mark stop,
  +					    String rawName, Hashtable attrs)
  +	throws JasperException {}
  +
  +    public void handleUninterpretedTagEnd(Mark start, Mark stop,
  +					  String rawName)
  +	throws JasperException {}
   }
  
  
  
  1.3       +11 -3     jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/DelegatingListener.java
  
  Index: DelegatingListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/DelegatingListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DelegatingListener.java	2000/09/19 19:23:32	1.2
  +++ DelegatingListener.java	2000/10/04 20:01:05	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/DelegatingListener.java,v
1.2 2000/09/19 19:23:32 pierred Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/09/19 19:23:32 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/DelegatingListener.java,v
1.3 2000/10/04 20:01:05 pierred Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/04 20:01:05 $
    *
    * ====================================================================
    * 
  @@ -213,5 +213,13 @@
   
       public void handleRootBegin(Hashtable attrs) {};
       public void handleRootEnd() {};
  +
  +    public void handleUninterpretedTagBegin(Mark start, Mark stop,
  +					    String rawName, Hashtable attrs)
  +	throws JasperException {}
  +
  +    public void handleUninterpretedTagEnd(Mark start, Mark stop,
  +					  String rawName)
  +	throws JasperException {}
   }
   
  
  
  
  1.4       +25 -3     jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java
  
  Index: JspParseEventListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JspParseEventListener.java	2000/10/04 05:10:50	1.3
  +++ JspParseEventListener.java	2000/10/04 20:01:05	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
1.3 2000/10/04 05:10:50 pierred Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/10/04 05:10:50 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
1.4 2000/10/04 20:01:05 pierred Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/10/04 20:01:05 $
    *
    * ====================================================================
    *
  @@ -961,6 +961,28 @@
           xo.addRootAttrs(attrs);
       }
       
  +    public void handleUninterpretedTagBegin(Mark start, Mark stop,
  +					    String rawName, Hashtable attrs) 
  +	throws JasperException
  +    {
  +        UninterpretedTagBeginGenerator gen = 
  +	    new UninterpretedTagBeginGenerator(rawName, attrs);
  +        Generator genWrapper = new GeneratorWrapper(gen, start, stop);
  +	addGenerator(genWrapper);
  +        xo.append(rawName, attrs);
  +    }
  +
  +    public void handleUninterpretedTagEnd(Mark start, Mark stop,
  +					  String rawName)
  +	throws JasperException
  +    {
  +        UninterpretedTagEndGenerator gen = 
  +	    new UninterpretedTagEndGenerator(rawName);
  +        Generator genWrapper = new GeneratorWrapper(gen, start, stop);
  +	addGenerator(genWrapper);
  +        xo.append(rawName);
  +    }
  +
       /**
        * validate the XML stream of the JSP document against the
        * libraries used by the document.
  
  
  
  1.3       +9 -3      jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParseEventListener.java
  
  Index: ParseEventListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParseEventListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ParseEventListener.java	2000/09/19 19:23:31	1.2
  +++ ParseEventListener.java	2000/10/04 20:01:05	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParseEventListener.java,v
1.2 2000/09/19 19:23:31 pierred Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/09/19 19:23:31 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParseEventListener.java,v
1.3 2000/10/04 20:01:05 pierred Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/04 20:01:05 $
    *
    * ====================================================================
    * 
  @@ -133,5 +133,11 @@
       public void handleRootBegin(Hashtable attrs);
       public void handleRootEnd();
   
  +    public void handleUninterpretedTagBegin(Mark start, Mark stop,
  +					    String rawName, Hashtable attrs)
  +	throws JasperException;
  +    public void handleUninterpretedTagEnd(Mark start, Mark stop,
  +					  String rawName)
  +	throws JasperException;
   }
   
  
  
  
  1.2       +42 -22    jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserXJspSaxHandler.java
  
  Index: ParserXJspSaxHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ParserXJspSaxHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParserXJspSaxHandler.java	2000/09/19 19:19:21	1.1
  +++ ParserXJspSaxHandler.java	2000/10/04 20:01:06	1.2
  @@ -177,7 +177,7 @@
   	//p("|" + String.valueOf(ch, start, length) + "|");
   
   	Node node = (Node)stack.peek();
  -	if (node.isRoot()) {
  +	if (node.isRoot() || node.isUninterpretedTag()) {
   	    // template data in <jsp:root>.
   	    //p("these chars are added directly in jsp:root");
   	    try {
  @@ -258,9 +258,28 @@
   	    } else if (name.equals("jsp:useBean")) {
   		jspHandler.handleBean(
   				      node.start, node.start, attrsToHashtable(node.attrs));
  -	    } else if (name.length()<4 || !name.substring(0,4).equals("jsp:")) {
  -		// custom tag
  -		processCustomTagBegin();
  +	    } else if (name.length()<4 || 
  +		       !name.substring(0,4).equals("jsp:")) {
  +		// custom tag or 'uninterpreted' tag
  +		int i = name.indexOf(':');
  +		boolean isCustomTag = false;
  +		if (i != -1) {
  +		    String prefix = name.substring(0, i);
  +		    String shortTagName = name.substring(i+1);
  +		    TagLibraries libraries = jspHandler.getTagLibraries();
  +		    if (libraries.isUserDefinedTag(prefix, shortTagName)) {
  +			// custom tag
  +			isCustomTag = true;
  +			processCustomTagBegin(prefix, shortTagName);
  +		    }
  +		}
  +		if (!isCustomTag) {
  +		    // uninterpreted tag
  +		    node.setUninterpreted(true);
  +		    jspHandler.handleUninterpretedTagBegin(
  +				node.start, node.start, 
  +				node.rawName, attrsToHashtable(node.attrs));
  +		}
   	    }
   	} catch (Exception ex) {
   	    throw new SAXException(ex);
  @@ -377,11 +396,13 @@
   		jspHandler.handlePlugin(
   		    node.start, stop, attrsToHashtable(node.attrs), params, fallback);
   	    } else {
  -		// Ought to be a custom tag
  -		//p("should be nodetag");
  -		//p(node);
  -		//p("class is: " + node.getClass().getName());
  -		processCustomTagEnd((NodeTag)node, stop);
  +		if (node.isUninterpretedTag()) {
  +		    // this is an 'uninterpreted' tag
  +		    jspHandler.handleUninterpretedTagEnd(stop, stop, rawName);
  +		} else {
  +		    // this is a custom tag
  +		    processCustomTagEnd((NodeTag)node, stop);
  +		}
   	    }
   	} catch (Exception ex) {
   	    ex.printStackTrace();
  @@ -389,23 +410,12 @@
   	}
       }
   
  -    private void processCustomTagBegin() 
  +    private void processCustomTagBegin(String prefix, String shortTagName) 
   	throws ParseException, JasperException 
       {
   	Node node = (Node)stack.pop();
  -	String tag = node.rawName;
  -	int i = tag.indexOf(':');
  -	if (i == -1) throw new ParseException("unknown tag: " + tag);
  -	
  -	String prefix = tag.substring(0, i);
  -	String shortTagName = tag.substring(i+1);
  -	
   	TagLibraries libraries = jspHandler.getTagLibraries();
   	
  -	if (!libraries.isUserDefinedTag(prefix, shortTagName)) {
  -	    throw new ParseException(node.start, "invalid tag: " + node.rawName);
  -	}
  -
   	if (shortTagName == null) {
   	    throw new ParseException(node.start, "Nothing after the :");
   	}
  @@ -414,7 +424,8 @@
   	TagInfo ti = tli.getTag(shortTagName);
               
   	if (ti == null) {
  -	    throw new ParseException(node.start, "Unable to locate TagInfo for "+tag);
  +	    throw new ParseException(node.start, 
  +	       "Unable to locate TagInfo for " + prefix + ":" + shortTagName);
   	}
   	node = new NodeTag(node, prefix, shortTagName, tli, ti);
   	stack.push(node);
  @@ -593,6 +604,7 @@
   	Mark start;
   
   	boolean isRoot;
  +	boolean isUninterpretedTag = false;
   	StringBuffer text = null;
   
   	Node(Node node) {
  @@ -619,6 +631,14 @@
   
   	boolean isRoot() {
   	    return isRoot;
  +	}
  +
  +	void setUninterpreted(boolean isUninterpretedTag) {
  +	    this.isUninterpretedTag = isUninterpretedTag;
  +	}
  +
  +	boolean isUninterpretedTag() {
  +	    return isUninterpretedTag;
   	}
   
   	void validate(boolean canHaveAttributes,
  
  
  
  1.1                  jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/UninterpretedTagBeginGenerator.java
  
  Index: UninterpretedTagBeginGenerator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/UninterpretedTagBeginGenerator.java,v
1.1 2000/10/04 20:01:06 pierred Exp $
   * $Revision: 1.1 $
   * $Date: 2000/10/04 20:01:06 $
   *
   * ====================================================================
   * 
   * 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 apache@apache.org.
   *
   * 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.compiler;
  
  import java.util.Hashtable;
  import java.util.Enumeration;
  
  /**
   * Generates the start element of an uninterpreted tag.
   *
   * @author Pierre Delisle
   */
  public class UninterpretedTagBeginGenerator
      extends GeneratorBase
      implements ServiceMethodPhase
  {
      private static final String singleQuote = "'";
      private static final String doubleQuote = "\\\"";
  
      private String tag;
      private Hashtable attrs;
  
      public UninterpretedTagBeginGenerator(String tag, Hashtable attrs) {
  	this.tag = tag;
  	this.attrs = attrs;
      }
  
      public void generate(ServletWriter writer, Class phase) {
  	writer.indent();
      	writer.print("out.write(\"");
  
  	StringBuffer sb = new StringBuffer();
          sb.append("<").append(tag);
          if (attrs == null) {
              sb.append(">");
          } else {
              sb.append(" ");
              Enumeration enum = attrs.keys();
              while (enum.hasMoreElements()) {
  		String quote = doubleQuote;
                  String name = (String)enum.nextElement();
                  String value = (String)attrs.get(name);
  		if (value.indexOf('"') != -1) quote = singleQuote;
                  sb.append("  ").append(name).append("=").append(quote);
  		sb.append(value).append(quote);
              }
              sb.append(">");
          }
  	writer.print(sb.toString());
  	writer.print("\");\n");
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/UninterpretedTagEndGenerator.java
  
  Index: UninterpretedTagEndGenerator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/UninterpretedTagEndGenerator.java,v
1.1 2000/10/04 20:01:06 pierred Exp $
   * $Revision: 1.1 $
   * $Date: 2000/10/04 20:01:06 $
   *
   * ====================================================================
   * 
   * 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 apache@apache.org.
   *
   * 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.compiler;
  
  /**
   * Generates the start element of an uninterpreted tag.
   *
   * @author Pierre Delisle
   */
  public class UninterpretedTagEndGenerator
      extends GeneratorBase
      implements ServiceMethodPhase
  {
      private String tag;
  
      public UninterpretedTagEndGenerator(String tag) {
  	this.tag = tag;
      }
  
      public void generate(ServletWriter writer, Class phase) {
  	StringBuffer sb = new StringBuffer();
  	writer.indent();
      	writer.print("out.write(\"");
          sb.append("</").append(tag).append(">");
  	writer.print(sb.toString());
  	writer.print("\");\n");
      }
  }
  
  
  

Mime
View raw message