jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From felip...@apache.org
Subject cvs commit: jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib CustomerFmtTag.java EscapeHtmlTag.java EvenTag.java FileTag.java Functions.java LocalesTag.java NullAttributeException.java OddTag.java ResourceTag.java UsCustomerTag.java
Date Fri, 27 Feb 2004 05:02:03 GMT
felipeal    2004/02/26 21:02:03

  Added:       standard/examples/src/org/apache/taglibs/standard/examples/taglib
                        CustomerFmtTag.java EscapeHtmlTag.java EvenTag.java
                        FileTag.java Functions.java LocalesTag.java
                        NullAttributeException.java OddTag.java
                        ResourceTag.java UsCustomerTag.java
  Log:
  fixing jsptl/standard issue
  
  Revision  Changes    Path
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/CustomerFmtTag.java
  
  Index: CustomerFmtTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import java.io.IOException;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import javax.servlet.jsp.jstl.core.*;
  
  import org.apache.taglibs.standard.examples.beans.Customer;
  
  /**
   * <p>Tag handler for &lt;customerFmt&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class CustomerFmtTag extends TagSupport {
      
      //*********************************************************************
      // Instance variables
      
      /** Holds value of property customer. */
      private Customer customer;
      
      /** Holds value of property fmt. */
      private String fmt;
      
      //*********************************************************************
      // Constructors
      
      public CustomerFmtTag() {
          super();
          init();
      }
      
      private void init() {
          customer = null;
          fmt = null;
      }    
      
      //*********************************************************************
      // TagSupport methods
      
      public int doStartTag() throws JspException {
          JspWriter out = pageContext.getOut();
          try {
              if (fmt.equalsIgnoreCase("short")) {
                  out.println(customer.getFirstName() + " " +
                  customer.getLastName());
              } else if (fmt.equalsIgnoreCase("long")) {
                  out.println(customer.getFirstName() + " " +
                  customer.getLastName() + " " + customer.getAddress());
              } else {
                  out.println("invalid format");
              }
          } catch (IOException ex) {}
          
          return SKIP_BODY;
      }
      
      // Releases any resources we may have (or inherit)
      public void release() {
          super.release();
          init();
      }
      
      //*********************************************************************
      // Accessors
      
      /**
       * Getter for property customer.
       * @return Value of property customer.
       */
      public Customer getCustomer() {
          return customer;
      }
      
      /**
       * Setter for property customer.
       * @param customer New value of property customer.
       */
      public void setCustomer(Customer customer) {
          this.customer = customer;
      }
      
      /**
       * Getter for property fmt.
       * @return Value of property fmt.
       */
      public String getFmt() {
          return fmt;
      }
      
      /**
       * Setter for property fmt.
       * @param fmt New value of property fmt.
       */
      public void setFmt(String fmt) {
          this.fmt = fmt;
      }    
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/EscapeHtmlTag.java
  
  Index: EscapeHtmlTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import java.io.*;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  import org.apache.taglibs.standard.examples.util.*;
  
  /**
   * <p>Tag handler for &lt;escapeHtml&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class EscapeHtmlTag extends BodyTagSupport {
      
      //*********************************************************************
      // Instance variables
      
      private Object reader;
      private Object writer;
      
      //*********************************************************************
      // Constructors
      
      public EscapeHtmlTag() {
          super();
          init();
      }
      
      private void init() {
          reader = null;
          writer = null;
      }
      
      
      //*********************************************************************
      // Tag's properties
      
      /**
       * Tag's 'reader' attribute
       */
      public void setReader(Object reader) {
          this.reader = reader;
      }
      
      /**
       * Tag's 'writer' attribute
       */
      public void setWriter(Object writer) {
          this.writer = writer;
      }
      
      //*********************************************************************
      // TagSupport methods
      
      public int doEndTag() throws JspException {
          Reader in;
          Writer out;
          
          if (reader == null) {
              String bcs = getBodyContent().getString().trim();
              if (bcs == null || bcs.equals("")) {
                  throw new JspTagException("In &lt;escapeHtml&gt;, 'reader' " +
                  "not specified and no non-whitespace content inside the tag.");
              }
              in = Util.castToReader(bcs);
          } else {
              in = Util.castToReader(reader);
          }
          
          if (writer == null) {
              out = pageContext.getOut();
          } else {
              out = Util.castToWriter(writer);
          }
          
          transform(in, out);
          return EVAL_PAGE;
      }
      
      /**
       * Releases any resources we may have (or inherit)
       */
      public void release() {
          super.release();
          init();
      }
      
      //*********************************************************************
      // Tag's scific behavior methods
      
      /**
       * Transform
       */
      public void transform(Reader reader, Writer writer)
      throws JspException {
          int c;
          try {
              writer.write("<pre>");
              while ((c = reader.read()) != -1) {
                  if (c == '<') {
                      writer.write("&lt;");
                  } else if (c == '>') {
                      writer.write("&gt;");
                  } else {
                      writer.write(c);
                  }
              }
              writer.write("</pre>");
          } catch (IOException ex) {
              throw new JspException("EscapeHtml: " +
              "error copying chars", ex);
          }
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/EvenTag.java
  
  Index: EvenTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import javax.servlet.jsp.jstl.core.*;
  
  /**
   * <p>Tag handler for &lt;odd&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class EvenTag extends TagSupport {
      
      //*********************************************************************
      // TagSupport methods
      
      public int doStartTag() throws JspException {
          LoopTag iteratorTag = (LoopTag)findAncestorWithClass(
          this, LoopTag.class);
          if (iteratorTag == null) {
              throw new JspTagException("<even> must be nested within a LoopTag");
          }
          
          int count = iteratorTag.getLoopStatus().getCount();
          return (count % 2 == 0) ? EVAL_BODY_INCLUDE : SKIP_BODY;
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/FileTag.java
  
  Index: FileTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import java.io.*;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  import org.apache.taglibs.standard.examples.util.*;
  
  /**
   * <p>Tag handler for &lt;file&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class FileTag extends TagSupport {
      
      //*********************************************************************
      // Instance variables
      
      private String id;
      private String file;
      
      private Reader reader;
      
      //*********************************************************************
      // Constructors
      
      public FileTag() {
          super();
          init();
      }
      
      private void init() {
          id = null;
          file = null;
      }
      
      //*********************************************************************
      // Tag's properties
      
      /**
       * Tag's 'id' attribute
       */
      public void setId(String id) {
          this.id = id;
      }
      
      /**
       * Tag's 'file' attribute
       */
      public void setfile(String file) {
          this.file = file;
      }
      
      //*********************************************************************
      // TagSupport methods
      
      public int doStartTag() throws JspException {
          reader = getReaderFromFile(file);
          exposeVariable(reader);
          return EVAL_BODY_INCLUDE;
      }
      
      public int doEndTag() throws JspException {
          try {
              reader.close();
          } catch (IOException ex) {}
          reader = null;
          return EVAL_PAGE;
      }
      
      /**
       * Releases any files we may have (or inherit)
       */
      public void release() {
          super.release();
          init();
      }
      
      //*********************************************************************
      // Tag's specific behavior methods
      
      public Reader getReaderFromFile(String name) throws JspException {
          InputStream in = pageContext.getServletContext().
              getResourceAsStream(name);
          if (in == null) {
              throw new JspException("Could not access " + name);
          }
  
          return new InputStreamReader(in);
      }
  
      
      //*********************************************************************
      // Utility methods
          
      private void exposeVariable(Reader reader) {
          if (id != null) {
              pageContext.setAttribute(id, reader);
          }
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/Functions.java
  
  Index: Functions.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import java.lang.reflect.Array;
  import java.util.*;
  import javax.servlet.jsp.*;
  
  /**
   * <p>Exmaples taglib Functions</p>
   * 
   * @author Pierre Delisle
   */
  
  public class Functions {
  
      /**
       * Display the collection types supported by c:forEach.
       */
      public static String display(Object obj) throws JspTagException {
          if (obj == null) return "";         
          if (obj instanceof String) return obj.toString();
          /*
          if (obj instanceof Collection) {
              return "FIXME";
          }
          if (obj instanceof Map) {
              return "FIXME";
          }        
          if (obj instanceof Iterator) {
              Iterator iter = (Iterator)obj;
              while (iter.hasNext()) {
                  iter.next();
              }
              return "FIXME";
          }            
          if (obj instanceof Enumeration) {
              Enumeration enum = (Enumeration)obj;
              while (enum.hasMoreElements()) {
                  enum.nextElement();
              }
              return "FIXME";
          }
          */
          try {
              StringBuffer buf = new StringBuffer();
              int count = Array.getLength(obj);
              for (int i=0; i<count; i++) {
                  buf.append(Array.get(obj, i).toString());
                  if (i<count-1) buf.append("<font color='red'> &#149; </font>");
              }
              return buf.toString();
          } catch (IllegalArgumentException ex) {}
          throw new JspTagException("Bad Item");        
      }      
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/LocalesTag.java
  
  Index: LocalesTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import java.util.Locale;
  import javax.servlet.jsp.JspException;
  import javax.servlet.jsp.jstl.core.LoopTagSupport;
  
  /**
   * <p>Tag handler for &lt;locales&gt;
   *
   * @author Felipe Leme <jstl@felipeal.net>
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class LocalesTag extends LoopTagSupport {
  
      private static final Locale[] locales = Locale.getAvailableLocales();
      private int pointer; 
      private String varTotal;
  
      public void setVarTotal( String value ) {
  	varTotal = value;
      }
  
      public void prepare() {
  	pointer = 0;
  	if ( varTotal!=null && varTotal.length()>0 ) {
  	    pageContext.setAttribute( varTotal, new Integer(locales.length) );
  	}
      
      } 
  
      public boolean hasNext() {
  	return pointer < locales.length;
      }  
  
      public Object next() {
  	return locales[ pointer++ ];
      }
    
      public void setBegin( int value ) {
    	super.begin = value;
      }
    
      public void setEnd( int value ) {
    	super.end = value;
      }                     
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/NullAttributeException.java
  
  Index: NullAttributeException.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import javax.servlet.jsp.JspTagException;
  
  /**
   * <p>NullAttributeException is a JspTagException that will be thrown
   * by the JSTL RI handlers when a tag attribute illegally evaluates
   * to 'null'.</p>
   *
   * @author Shawn Bayern
   */
  
  public class NullAttributeException extends JspTagException {
  
      /**
       * Constructs a ExpressionException with appropriate information.
       *
       * @param tag The name of the tag in which the error occurred.
       * @param att The attribute value for which the error occurred.
       */
      public NullAttributeException(String tag, String att) {
  	super("The '" + att + "' attribute illegally evaluated to 'null' "
  	    + "in &lt;" + tag + "&gt;.");
      }
  }
  
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/OddTag.java
  
  Index: OddTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import javax.servlet.jsp.jstl.core.*;
  
  /**
   * <p>Tag handler for &lt;odd&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class OddTag extends TagSupport {
      
      //*********************************************************************
      // TagSupport methods
      
      public int doStartTag() throws JspException {
          LoopTag iteratorTag = (LoopTag)findAncestorWithClass(
                  this, LoopTag.class);
          if (iteratorTag == null) {
              throw new JspTagException("<odd> must be nested within a LoopTag");
          }
          
          int count = iteratorTag.getLoopStatus().getCount();
          System.out.println("count: " + count);
                  System.out.println("count odd/even: " + (count % 2));
          return (count % 2 == 1) ? EVAL_BODY_INCLUDE : SKIP_BODY;
      }
  }
  
  
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/ResourceTag.java
  
  Index: ResourceTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import java.io.*;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  import org.apache.taglibs.standard.examples.util.*;
  
  /**
   * <p>Tag handler for &lt;resource&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class ResourceTag extends TagSupport {
      
      //*********************************************************************
      // Instance variables
      
      private String id;
      private String resource;
      
      private Reader reader;
      
      //*********************************************************************
      // Constructors
      
      public ResourceTag() {
          super();
          init();
      }
      
      private void init() {
          id = null;
          resource = null;
      }
      
      //*********************************************************************
      // Tag's properties
      
      /**
       * Tag's 'id' attribute
       */
      public void setId(String id) {
          this.id = id;
      }
      
      /**
       * Tag's 'resource' attribute
       */
      public void setResource(String resource) {
          this.resource = resource;
      }
      
      //*********************************************************************
      // TagSupport methods
      
      public int doStartTag() throws JspException {
          reader = getReaderFromResource(resource);
          exposeVariable(reader);
          return EVAL_BODY_INCLUDE;
      }
      
      public int doEndTag() throws JspException {
          try {
              reader.close();
          } catch (IOException ex) {}
          reader = null;
          return EVAL_PAGE;
      }
      
      /**
       * Releases any resources we may have (or inherit)
       */
      public void release() {
          super.release();
          init();
      }
      
      //*********************************************************************
      // Tag's scific behavior methods
      
      private Reader getReaderFromResource(String name) throws JspException {
          HttpServletRequest request =
          (HttpServletRequest)pageContext.getRequest();
          HttpServletResponse response =
          (HttpServletResponse)pageContext.getResponse();
          RequestDispatcher rd = null;
          
          // The response of the local URL becomes the reader that
          // we export. Need temporary storage.
          IOBean ioBean = new IOBean();
          Writer writer = ioBean.getWriter();
          ServletResponseWrapper responseWrapper =
          new ServletResponseWrapperForWriter(
          response, new PrintWriter(writer));
          rd = pageContext.getServletContext().getRequestDispatcher(name);
          try {
              rd.include(request, responseWrapper);
              return ioBean.getReader();
          } catch (Exception ex) {
              throw new JspException(ex);
          }
      }
      
      //*********************************************************************
      // Utility methods
          
      private void exposeVariable(Reader reader) {
          if (id != null) {
              pageContext.setAttribute(id, reader);
          }
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/taglib/UsCustomerTag.java
  
  Index: UsCustomerTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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.taglibs.standard.examples.taglib;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import javax.servlet.jsp.jstl.core.*;
  
  import org.apache.taglibs.standard.examples.beans.Customer;
  import org.apache.taglibs.standard.examples.util.*;
  
  /**
   * <p>Tag handler for &lt;usCustomer&gt;
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:02:03 $
   */
  public class UsCustomerTag extends ConditionalTagSupport {
      
      //*********************************************************************
      // Instance Variables
      
      /** Holds value of property customer. */
      private Customer customer;
      
      //*********************************************************************
      // Constructor and lusCustomerecycle management
      
      public UsCustomerTag() {
          super();
          init();
      }
      
      private void init() {
          customer = null;
      }
      
      //*********************************************************************
      // TagSupport methods
      
      public void release() {
          super.release();
          init();
      }
      
      //*********************************************************************
      // ConditionalTagSupport methods
      
      protected boolean condition() throws JspTagException {
          try {
              if (customer == null) {
                  throw new NullAttributeException("usCustomer", "test");
              } else {
                  //System.out.println("country: " + customer.getAddress().getCountry());
                  return (customer.getAddress().getCountry().equalsIgnoreCase("USA"));
              }
          } catch (JspException ex) {
              throw new JspTagException(ex.toString());
          }
      }
      
      //*********************************************************************
      // Accessors
      
      /**
       * Getter for property customer.
       * @return Value of property customer.
       */
      public Customer getCustomer() {
          return customer;
      }
      
      /**
       * Setter for property customer.
       * @param customer New value of property customer.
       */
      public void setCustomer(Customer customer) {
          this.customer = customer;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message