tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@hyperreal.org
Subject cvs commit: jakarta-tomcat/src/examples/jsp/simpletag foo.jsp
Date Wed, 20 Oct 1999 11:13:42 GMT
akv         99/10/20 04:13:42

  Modified:    src/examples/WEB-INF/classes/jsp/tags/META-INF taglib.tld
               src/examples/WEB-INF/classes/jsp/tags/examples FooTag.java
                        LogTag.java
               src/examples/jsp/simpletag foo.jsp
  Added:       src/examples/WEB-INF/classes/jsp/tags/examples
                        ExampleTagBase.java
  Log:
  Updated this example to be compliant with the JSP 1.1 PR2 spec. This example
  is a bit old; before the TagSupport and BodyTagSupport classes were introduced.
  
  I'm going to clean this up later to use those classes.
  
  Revision  Changes    Path
  1.2       +1 -1      jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/META-INF/taglib.tld
  
  Index: taglib.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/META-INF/taglib.tld,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- taglib.tld	1999/10/09 00:34:17	1.1
  +++ taglib.tld	1999/10/20 11:13:40	1.2
  @@ -53,7 +53,7 @@
   	Perform a server side action; Log the message.
       </info>
       <attribute>
  -	<name>tobrowser</name>
  +	<name>toBrowser</name>
   	<required>false</required>
       </attribute>
     </tag>
  
  
  
  1.2       +36 -31    jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/examples/FooTag.java
  
  Index: FooTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/examples/FooTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FooTag.java	1999/10/09 00:34:18	1.1
  +++ FooTag.java	1999/10/20 11:13:41	1.2
  @@ -13,50 +13,55 @@
    * <foo att1="..." att2="...." att3="...." />
    */
   
  -public class FooTag extends Tag {
  -
  -    private String atts[];
  +public class FooTag 
  +    extends ExampleTagBase 
  +    implements BodyTag 
  +{
  +    private String atts[] = new String[3];
       int i = 0;
       
  -    /**
  -     * Create a new Foo tag handler
  -     *
  -     * @param prefix the tag library prefix used in the directive
  -     * @param tagname the tag name described in the TLD
  -     */
  -    public FooTag(String prefix, String tagname) {
  -	super(prefix, tagname);
  +    private final void setAtt(int index, String value) {
  +        atts[index] = value;
  +    }
  +    
  +    public void setAtt1(String value) {
  +        setAtt(0, value);
  +    }
  +    
  +    public void setAtt2(String value) {
  +        setAtt(1, value);
       }
   
  +    public void setAtt3(String value) {
  +        setAtt(2, value);
  +    }
  +    
       /**
        * Process start tag
        *
  -     * @return EVAL_BODY
  +     * @return EVAL_BODY_INCLUDE
        */
       public int doStartTag() {
  -        atts = new String[3];
  -        i = 0;
  -	atts[0] = tagData.getAttributeString("att1");
  -	atts[1] = tagData.getAttributeString("att2");
  -	atts[2] = tagData.getAttributeString("att3");
  -        
  -        pageContext.setAttribute("member", atts[i]);
  -        
  -	return EVAL_BODY;
  +	return EVAL_BODY_TAG;
       }
   
  -    public void doBeforeBody() throws JspError {
  +    public void doInitBody() throws JspError {
  +        pageContext.setAttribute("member", atts[i]);
  +        i++;
       }
  -
  +    
       public int doAfterBody() throws JspError {
  -        i++;
  -        if (i == 3) {
  -            bodyOut.writeOut(getPreviousOut());
  -            return SKIP_BODY;
  -        } else
  -            pageContext.setAttribute("member", atts[i]);
  -        
  -        return EVAL_BODY;
  +        try {
  +            if (i == 3) {
  +                bodyOut.writeOut(bodyOut.getEnclosingWriter());
  +                return SKIP_BODY;
  +            } else
  +                pageContext.setAttribute("member", atts[i]);
  +            i++;
  +            return EVAL_BODY_TAG;
  +        } catch (IOException ex) {
  +            throw new JspError(ex.toString());
  +        }
       }
   }
   
  
  
  
  1.2       +23 -12    jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/examples/LogTag.java
  
  Index: LogTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/examples/LogTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogTag.java	1999/10/09 00:34:18	1.1
  +++ LogTag.java	1999/10/20 11:13:41	1.2
  @@ -4,29 +4,40 @@
   import javax.servlet.jsp.*;
   import javax.servlet.jsp.tagext.*;
   
  +import java.io.IOException;
  +
   /**
    * Log the contents of the body. Could be used to handle errors etc. 
    */
  -public class LogTag extends Tag {
  +public class LogTag 
  +    extends ExampleTagBase
  +    implements BodyTag 
  +{
       boolean toBrowser = false;
       
  -    public LogTag(String prefix, String tagname) {
  -        super(prefix, tagname);
  +    public void setToBrowser(String value) {
  +        if (value == null)
  +            toBrowser = false;
  +        else if (value.equalsIgnoreCase("true"))
  +            toBrowser = true;
  +        else
  +            toBrowser = false;
       }
  -    
   
       public int doStartTag() {
  -        String value = tagData.getAttributeString("tobrowser");
  -        toBrowser = value.equalsIgnoreCase("true") ? true : false;
  -        return EVAL_BODY;
  +        return EVAL_BODY_TAG;
       }
       
       public int doAfterBody() throws JspError {
  -        String s = bodyOut.getString();
  -        System.err.println(s);
  -        if (toBrowser)
  -            bodyOut.writeOut(getPreviousOut());
  -        return SKIP_BODY;
  +        try {
  +            String s = bodyOut.getString();
  +            System.err.println(s);
  +            if (toBrowser)
  +                bodyOut.writeOut(bodyOut.getEnclosingWriter());
  +            return SKIP_BODY;
  +        } catch (IOException ex) {
  +            throw new JspError(ex.toString());
  +        }
       }
   }
   
  
  
  
  1.1                  jakarta-tomcat/src/examples/WEB-INF/classes/jsp/tags/examples/ExampleTagBase.java
  
  Index: ExampleTagBase.java
  ===================================================================
  package examples;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  public abstract class ExampleTagBase implements Tag {
  
      public void setParent(Tag parent) {
          this.parent = parent;
      }
  
      public void setBodyContent(BodyContent bodyOut) {
          this.bodyOut = bodyOut;
      }
  
      public void setPageContext(PageContext pageContext) {
          this.pageContext = pageContext;
      }
  
      public Tag getParent() {
          return this.parent;
      }
      
      public int doStartTag() throws JspException {
          return SKIP_BODY;
      }
  
      public int doEndTag() throws JspException {
          return EVAL_PAGE;
      }
      
  
      // Default implementations for BodyTag methods as well
      // just in case a tag decides to implement BodyTag.
      public void doInitBody() throws JspError {
      }
  
      public int doAfterBody() throws JspError {
          return SKIP_BODY;
      }
  
      public void release() {
          bodyOut = null;
          pageContext = null;
          parent = null;
      }
      
      protected BodyContent bodyOut;
      protected PageContext pageContext;
      protected Tag parent;
  }
  
  
  
  1.3       +1 -1      jakarta-tomcat/src/examples/jsp/simpletag/foo.jsp
  
  Index: foo.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/examples/jsp/simpletag/foo.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- foo.jsp	1999/10/14 04:01:39	1.2
  +++ foo.jsp	1999/10/20 11:13:42	1.3
  @@ -12,6 +12,6 @@
   Did you see me on the stderr window?
   </akv:log>
   
  -<akv:log tobrowser="true">
  +<akv:log toBrowser="true">
   Did you see me on the browser window as well?
   </akv:log>
  
  
  

Mime
View raw message