You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by fe...@apache.org on 2004/02/27 06:15:48 UTC

cvs commit: jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/util IOBean.java ServletResponseWrapperForWriter.java Util.java

felipeal    2004/02/26 21:15:48

  Added:       standard/examples/src/org/apache/taglibs/standard/examples/beans
                        Address.java Customer.java Customers.java
               standard/examples/src/org/apache/taglibs/standard/examples/i18n
                        Resources.java Resources_de.java Resources_fr.java
                        Resources_it.java
               standard/examples/src/org/apache/taglibs/standard/examples/startup
                        Init.java
               standard/examples/src/org/apache/taglibs/standard/examples/util
                        IOBean.java ServletResponseWrapperForWriter.java
                        Util.java
  Log:
  fixing jsptl/standard issue
  
  Revision  Changes    Path
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/beans/Address.java
  
  Index: Address.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.beans;
  
  /**
   * Object that represents a Customer.
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  
  public class Address {
      
      //*********************************************************************
      // Instance variables
      
      /** Holds value of property line1. */
      private String line1;
      
      /** Holds value of property line2. */
      private String line2;
      
      /** Holds value of property city. */
      private String city;
      
      /** Holds value of property zip. */
      private String zip;
  
      /** Holds value of property state. */
      private String state;
      
      /** Holds value of property country. */
      private String country;
      
      //*********************************************************************
      // Constructor
      
      public Address(String line1, String line2, String city,
      String state, String zip, String country) {
          setLine1(line1);
          setLine2(line2);
          setCity(city);
          setState(state);
          setZip(zip);
          setCountry(country);
      }
      
      //*********************************************************************
      // Accessors
      
      /** Getter for property line1.
       * @return Value of property line1.
       */
      public String getLine1() {
          return line1;
      }
      
      /** Setter for property line1.
       * @param line1 New value of property line1.
       */
      public void setLine1(String line1) {
          this.line1 = line1;
      }
      
      /** Getter for property line2.
       * @return Value of property line2.
       */
      public String getLine2() {
          return line2;
      }
      
      /** Setter for property line2.
       * @param line2 New value of property line2.
       */
      public void setLine2(String line2) {
          this.line2 = line2;
      }
      
      /** Getter for property city.
       * @return Value of property city.
       */
      public String getCity() {
          return city;
      }
      
      /** Setter for property city.
       * @param city New value of property city.
       */
      public void setCity(String city) {
          this.city = city;
      }
      
      /** Getter for property zip.
       * @return Value of property zip.
       */
      public String getZip() {
          return zip;
      }
      
      /** Setter for property zip.
       * @param zip New value of property zip.
       */
      public void setZip(String zip) {
          this.zip = zip;
      }
      
      /** Getter for property country.
       * @return Value of property country.
       */
      public String getCountry() {
          return country;
      }
      
      /** Setter for property country.
       * @param country New value of property country.
       */
      public void setCountry(String country) {
          this.country = country;
      }
      
      /** Getter for property state.
       * @return Value of property state.
       */
      public String getState() {
          return state;
      }
      
      /** Setter for property state.
       * @param state New value of property state.
       */
      public void setState(String state) {
          this.state = state;
      }
      
      //*********************************************************************
      // Utility Methods
      
      /**
       * Return a String representation of this object.
       */
      public String toString() {
          StringBuffer sb = new StringBuffer();
          sb.append(line1).append(" ");
          sb.append(city).append(" ");
          sb.append(country);
          return (sb.toString());
      } 
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/beans/Customer.java
  
  Index: Customer.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.beans;
  
  import java.util.Date;
  import java.text.*;
  
  /**
   * Object that represents a Customer.
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  
  public class Customer {
      
      //*********************************************************************
      // Instance variables
      
      /** Holds value of property key. */
      int key;
      
      /** Holds value of property lastName. */
      private String lastName;
      
      /** Holds value of property firstName. */
      private String firstName;
      
      /** Holds value of property birthDate. */
      private Date birthDate;
      
      /** Holds value of property address. */
      private Address address;
         
      /** Holds value of property phoneHome. */
      private String phoneHome;
      
      /** Holds value of property phoneCell. */
      private String phoneCell;
      
      static DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
      
      //*********************************************************************
      // Constructors
      
      public Customer() {}
      
      public Customer(int key,
      String lastName,
      String firstName,
      Date birthDate,
      Address address,
      String phoneHome,
      String phoneCell) {
          init(key, lastName, firstName, birthDate, address, phoneHome, phoneCell);
      }
      
      public void init(int key,
      String lastName,
      String firstName,
      Date birthDate,
      Address address,
      String phoneHome,
      String phoneCell) {
          setKey(key);
          setLastName(lastName);
          setFirstName(firstName);
          setBirthDate(birthDate);
          setAddress(address);
          setPhoneHome(phoneHome);
          setPhoneCell(phoneCell);
      }
      
      //*********************************************************************
      // Properties
      
      /**
       * Getter for property key.
       * @return Value of property key.
       */
      public int getKey() {
          return key;
      }
      
      /**
       * Setter for property key.
       * @param key New value of property key.
       */
      public void setKey(int key) {
          this.key = key;
      }
      
      /**
       * Getter for property lastName.
       * @return Value of property lastName.
       */
      public String getLastName() {
          return lastName;
      }
      
      /**
       * Setter for property lastName.
       * @param lastName New value of property lastName.
       */
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
      
      /**
       * Getter for property firstName.
       * @return Value of property firstName.
       */
      public String getFirstName() {
          return firstName;
      }
      
      /**
       * Setter for property firstName.
       * @param firstName New value of property firstName.
       */
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      
      /**
       * Getter for property birthDate.
       * @return Value of property birthDate.
       */
      public Date getBirthDate() {
          return birthDate;
      }
      
      /**
       * Setter for property birthDate.
       * @param birthDate New value of property birthDate.
       */
      public void setBirthDate(Date birthDate) {
          this.birthDate = birthDate;
      }
      
      /**
       * Getter for property address.
       * @return Value of property address.
       */
      public Address getAddress() {
          return address;
      }
      
      /**
       * Setter for property address.
       * @param address New value of property address.
       */
      public void setAddress(Address address) {
          this.address = address;
      }
      
      /**
       * Getter for property phoneHome.
       * @return Value of property phoneHome.
       */
      public String getPhoneHome() {
          return phoneHome;
      }
      
      /**
       * Setter for property phoneHome.
       * @param phoneHome New value of property phoneHome.
       */
      public void setPhoneHome(String phoneHome) {
          this.phoneHome = phoneHome;
      }
      
      /**
       * Getter for property phoneCell.
       * @return Value of property phoneCell.
       */
      public String getPhoneCell() {
          return phoneCell;
      }
      
      /**
       * Setter for property phoneCell.
       * @param phoneCell New value of property phoneCell.
       */
      public void setPhoneCell(String phoneCell) {
          this.phoneCell = phoneCell;
      }
      
      //*********************************************************************
      // Utility Methods
      
      /**
       * Return a String representation of this object.
       */
      public String toString() {
          StringBuffer sb = new StringBuffer();
          sb.append("[").append(key).append("] ");
          sb.append(getLastName()).append(", ");
          sb.append(getFirstName()).append("  ");
          sb.append(df.format(getBirthDate())).append("  ");
          sb.append(getAddress()).append("  ");
          if(getPhoneHome() != null) sb.append(getPhoneHome()).append("  ");
          if(getPhoneCell() != null) sb.append(getPhoneCell());
          return (sb.toString());
      }
  }
  
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/beans/Customers.java
  
  Index: Customers.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.beans;
  
  import java.util.*;
  import java.text.*;
  
  /**
   * Customers Datastore.
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  
  public class Customers {
      
      //*********************************************************************
      // Instance variables
      
      private static Vector customers = new Vector();
      private static int nextSeqNo = 0;
      
      //*********************************************************************
      // Datastore operations
      
      public static void create(
      String lastName,
      String firstName,
      String birthDate,
      String line1,
      String line2,
      String city,
      String state,
      String zip,
      String country) {
          create(lastName, firstName, birthDate, line1, line2, city, state, zip,
          country, null, null);
      }
      
      /**
       *  Create new customer
       */
      public static void create(
      String lastName,
      String firstName,
      String birthDate,
      String line1,
      String line2,
      String city,
      String state,
      String zip,
      String country,
      String phoneHome,
      String phoneCell) {
          Customer customer =
          new Customer(++nextSeqNo, lastName, firstName,
          genDate(birthDate), genAddress(line1, line2, city, state, zip, country),
          phoneHome, phoneCell);
          customers.add(customer);
      }
      
      /**
       * Find all customers
       */
      public static Collection findAll() {
          return customers;
      }
      
      //*********************************************************************
      // Utility methods
      
      private static Date genDate(String dateString) {
          DateFormat df = new SimpleDateFormat("M/d/y");
          Date date;
          try {
              date = df.parse(dateString);
          } catch (Exception ex) {
              date = null;
          }
          return date;
      }
      
      private static Address genAddress(String line1, String line2, String city,
      String state, String zip, String country) {
          return new Address(line1, line2, city, state, zip, country);
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/i18n/Resources.java
  
  Index: Resources.java
  ===================================================================
  package org.apache.taglibs.standard.examples.i18n;
  
  import java.util.*;
  
  public class Resources extends ListResourceBundle {
      private static Object[][] contents;
  
      static {
  	contents = new Object[][] {
  	    { "greetingMorning", "Good Morning!" },
  	    { "greetingEvening", "Good Evening!" },
  	    { "serverInfo", "Name/Version of Servlet Container: {0}, "
  	                    + "Java Version: {1}" },
  	    { "currentTime", "Current time: {0}" },
  	    { "com.acme.labels.cancel", "Cancel" },
  	    { "java.lang.ArithmeticException", "division by 0" }
  	};
      }
  
      public Object[][] getContents() {
  	return contents;
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/i18n/Resources_de.java
  
  Index: Resources_de.java
  ===================================================================
  package org.apache.taglibs.standard.examples.i18n;
  
  import java.util.*;
  
  public class Resources_de extends ListResourceBundle {
      private static Object[][] contents;
  
      static {
  	contents = new Object[][] {
  	    { "greetingMorning", "Guten Morgen!" },
  	    { "greetingEvening", "Guten Abend!" },
  	    { "serverInfo", "Name/Version des Servlet Containers: {0}, "
  	                    + "Java Version: {1}" },
  	    { "currentTime", "Heutiges Datum und Uhrzeit: {0}" },
  	    { "com.acme.labels.cancel", "Abbrechen" },
  	    { "java.lang.ArithmeticException", "/ durch 0" }
  	};
      }
  
      public Object[][] getContents() {
  	return contents;
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/i18n/Resources_fr.java
  
  Index: Resources_fr.java
  ===================================================================
  package org.apache.taglibs.standard.examples.i18n;
  
  import java.util.*;
  
  public class Resources_fr extends ListResourceBundle {
      private static Object[][] contents;
  
      static {
  	contents = new Object[][] {
  	    { "greetingMorning", "Bonjour!!" },
  	    { "greetingEvening", "Bonsoir!" },
  	    { "serverInfo", "Nom/Version du Servlet Container: {0}, "
  	                    + "Version Java: {1}" },
  	    { "currentTime", "Nous sommes le: {0}" },
  	    { "com.acme.labels.cancel", "Annuler" },
  	    { "java.lang.ArithmeticException", "division par 0" }
  	};
      }
  
      public Object[][] getContents() {
  	return contents;
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/i18n/Resources_it.java
  
  Index: Resources_it.java
  ===================================================================
  package org.apache.taglibs.standard.examples.i18n;
  
  import java.util.*;
  
  public class Resources_it extends ListResourceBundle {
      private static Object[][] contents;
  
      static {
  	contents = new Object[][] {
  	    { "greetingMorning", "Buon giorno!" }
  	};
      }
  
      public Object[][] getContents() {
  	return contents;
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/startup/Init.java
  
  Index: Init.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.startup;
  
  import java.util.*;
  
  import javax.servlet.*;
  import org.apache.taglibs.standard.examples.beans.*;
  
  /**
   * Initialization class. Builds all the data structures
   * used in the "examples" webapp.
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  public class Init implements ServletContextListener {
      
      //*********************************************************************
      // ServletContextListener methods
      
      // recovers the one context parameter we need
      public void contextInitialized(ServletContextEvent sce) {
          //p("contextInitialized");
          init(sce);
      }
      
      public void contextDestroyed(ServletContextEvent sce) {
          //p("contextInitialized");
      }
      
      //*********************************************************************
      // Initializations
      
      private void init(ServletContextEvent sce) {
          /*
           *  Customers
           */
          Customers.create("Richard", "Maurice", "5/15/35",
          "123 Chemin Royal", "Appt. #301",
          "Montreal", "QC", "H3J 9R9", "Canada");
          Customers.create("Mikita", "Stan", "12/25/47",
          "45 Fisher Blvd", "Suite 203",
          "Chicago", "IL", "65982", "USA", "(320)876-9784", null);
          Customers.create("Gilbert", "Rod", "3/11/51",
          "123 Main Street", "",
          "New-York City", "NY", "19432", "USA");
          Customers.create("Howe", "Gordie", "7/25/46",
          "7654 Wings Street", "",
          "Detroit", "MG", "07685", "USA", "(465)675-0761", "(465)879-9802");
          Customers.create("Sawchuk", "Terrie", "11/05/46",
          "12 Maple Leafs Avenue", "",
          "Toronto", "ON", "M5C 1Z1", "Canada");
          sce.getServletContext().setAttribute("customers", Customers.findAll());
  
  	/**
  	 * Array of primitives (int)
  	 */
  	int[] intArray = new int[] {10, 20, 30, 40, 50};
          sce.getServletContext().setAttribute("intArray", intArray);
  
  	/**
  	 * Array of Objects (String)
  	 */
  	String[] stringArray = new String[] {
  	    "A first string",
  	    "La deuxieme string",
  	    "Ella troisiemo stringo",
  	};
          sce.getServletContext().setAttribute("stringArray", stringArray);
  
  	/**
          * String-keyed Map
          */
          Hashtable stringMap = new Hashtable();
          sce.getServletContext().setAttribute("stringMap", stringMap);
          stringMap.put("one", "uno");
          stringMap.put("two", "dos");
          stringMap.put("three", "tres");
          stringMap.put("four", "cuatro");
          stringMap.put("five", "cinco");
          stringMap.put("six", "seis");
          stringMap.put("seven", "siete");
          stringMap.put("eight", "ocho");
          stringMap.put("nine", "nueve");
          stringMap.put("ten", "diez");
  
          /**
           * Integer-keyed Map
  	 */
  	// we use a Hashtable so we can get an Enumeration easily, below
          Hashtable numberMap = new Hashtable();
  	sce.getServletContext().setAttribute("numberMap", numberMap);
  	numberMap.put(new Integer(1), "uno");
  	numberMap.put(new Integer(2), "dos");
  	numberMap.put(new Integer(3), "tres");
  	numberMap.put(new Integer(4), "cuatro");
  	numberMap.put(new Integer(5), "cinco");
  	numberMap.put(new Integer(6), "seis");
  	numberMap.put(new Integer(7), "siete");
  	numberMap.put(new Integer(8), "ocho");
  	numberMap.put(new Integer(9), "nueve");
  	numberMap.put(new Integer(10), "diez");
  
  	/**
  	 * Enumeration
  	 */
  	Enumeration enum = numberMap.keys();
  	// don't use 'enum' for attribute name because it is a 
  	// reserved word in EcmaScript.
          sce.getServletContext().setAttribute("enumeration", enum);
  
  	/**
  	 * Message arguments for parametric replacement
  	 */
  	Object[] serverInfoArgs =
  	    new Object[] {
  		sce.getServletContext().getServerInfo(),
  		System.getProperty("java.version")
  	    };
  	sce.getServletContext().setAttribute("serverInfoArgs", serverInfoArgs);
      }
      
      //*********************************************************************
      // Initializations
      
      private void p(String s) {
          System.out.println("[Init] " + s);
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/util/IOBean.java
  
  Index: IOBean.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.util;
  
  import java.io.*;
  import javax.servlet.jsp.JspException;
  
  /**
   * <p>String repository for Reader/Writer.
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  public class IOBean {
      StringWriter stringWriter = null;
      String content = null;
  
      public Reader getReader() throws JspException {
  	//p("getReader()");
  	if (content == null) {
  	    if (stringWriter == null) {
  		throw new JspException(
  		    "content must first be added to the bean via the writer");
  	    }
  	    content = stringWriter.toString();
  	}
  	return new StringReader(content);
      }
  
      public Writer getWriter() {
  	//p("getWriter()");
  	content = null;
  	stringWriter = new StringWriter();
  	return stringWriter;
      }
  
      public void release() {
  	stringWriter = null;
  	content = null;
      }
  
      private void p(String s) {
  	System.out.println("[IOBean] " + s);
      }
  }
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/util/ServletResponseWrapperForWriter.java
  
  Index: ServletResponseWrapperForWriter.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.util;
  
  import java.io.PrintWriter;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.servlet.jsp.*;
  
  /**
   * ServletResponseWrapper used for the the generation of 
   * semi-dynamic pages.
   * <p>
   * This 'wrapped' response object is passed as the second argument 
   * to the internal RequestDispatcher.include(). It channels
   * all output text into the PrintWriter specified in the
   * constructor (which is associated with the file where the
   * output of the JSP page has to be saved).
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  public class ServletResponseWrapperForWriter
      extends HttpServletResponseWrapper
  {
      /**
       * The writer that will get all the output of the response.
       */
      PrintWriter writer;
  
      public ServletResponseWrapperForWriter(ServletResponse response, 
  					   PrintWriter writer) 
      {
  	super((HttpServletResponse)response);
  	this.writer = writer;
      }
  
      /**
       * Returns the Writer associated with the response.
       */
      public java.io.PrintWriter getWriter()
  	throws java.io.IOException 
      {
  	return writer;
      }
  }
  
  
  
  
  1.1                  jakarta-taglibs/standard/examples/src/org/apache/taglibs/standard/examples/util/Util.java
  
  Index: Util.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.util;
  
  import java.io.*;
  import javax.servlet.jsp.*;
  
  /**
   * <p>Utility class for examples webapp.
   *
   * @author Pierre Delisle
   * @version $Revision: 1.1 $ $Date: 2004/02/27 05:15:47 $
   */
  public class Util {
  
      public static Writer castToWriter(Object obj) throws JspException {
          if (obj instanceof OutputStream) {
              return new OutputStreamWriter((OutputStream)obj);
          } else if (obj instanceof Writer) {
              return (Writer)obj;
              /*@@@
          } else if (obj instanceof String) {
              return new StringWriter();
               */
          }
          throw new JspException("Invalid type '" + obj.getClass().getName() +
  			       "' for castToWriter()");
      }
      
      public static Reader castToReader(Object obj) throws JspException {
          if (obj instanceof InputStream) {
              return new InputStreamReader((InputStream)obj);
          } else if (obj instanceof Reader) {
              return (Reader)obj;
          } else if (obj instanceof String) {
              return new StringReader((String)obj);
          }
          throw new JspException("Invalid type '" + obj.getClass().getName() +
  			       "' for castToReader()");
      }
  }
  
  
  
  

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