You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/08/23 07:45:19 UTC

cvs commit: jakarta-turbine-3/src/tool/org/apache/turbine/tool IntakeTool.java

jmcnally    01/08/22 22:45:19

  Modified:    src/java/org/apache/turbine/services/intake/model Field.java
                        FileItemField.java Group.java
               src/java/org/apache/turbine/services/intake/validator
                        DefaultValidator.java FileValidator.java
               src/tool/org/apache/turbine/tool IntakeTool.java
  Added:       src/java/org/apache/turbine/services/intake Intake.java
  Log:
  removed intake dependence on RunData
  
  moved most of IntakeTool's functionality into a class inside the service hierarchy.  IntakeTool extends Intake.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-3/src/java/org/apache/turbine/services/intake/Intake.java
  
  Index: Intake.java
  ===================================================================
  package org.apache.turbine.services.intake;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" 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",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   */
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import org.apache.fulcrum.Log;
  import org.apache.fulcrum.pool.Recyclable;
  import org.apache.torque.om.Retrievable;
  import org.apache.turbine.RunData;
  import org.apache.turbine.ParameterParser;
  import org.apache.turbine.services.intake.model.Group;
  import org.apache.turbine.services.intake.TurbineIntake;
  import org.apache.turbine.services.pull.ApplicationTool;
  
  /**
   * The main class through which Intake is accessed.
   *
   * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
   * @version $Id: Intake.java,v 1.1 2001/08/23 05:45:18 jmcnally Exp $
   */
  public class Intake
      implements Recyclable
  {
      public static final String DEFAULT_KEY = "_0";
      private HashMap groups;
      private ParameterParser pp;
  
      /** The cache of PullHelpers. **/
      private Map pullMap;
  
      public Intake()
      {
          String[] groupNames = TurbineIntake.getGroupNames();
          groups = new HashMap((int)(1.25*groupNames.length + 1));
          pullMap = new HashMap((int)(1.25*groupNames.length + 1));
          // omToolKey = TurbineResources.getString("tool.intake.om");
  
          for (int i=groupNames.length-1; i>=0; i--)
          {
              pullMap.put(groupNames[i], new PullHelper(groupNames[i]));
          }
      }
  
      /**
       * Prepares intake for a single request
       */
      public void init(ParameterParser pp)
      {
          this.pp = pp;
          String[] groupKeys = pp.getStrings("intake-grp");
          String[] groupNames = null;
          if ( groupKeys == null || groupKeys.length == 0 )
          {
              groupNames = TurbineIntake.getGroupNames();
          }
          else
          {
              groupNames = new String[groupKeys.length];
              for ( int i=groupKeys.length-1; i>=0; i-- )
              {
                  groupNames[i] = TurbineIntake.getGroupName(groupKeys[i]);
              }
  
          }
  
          for (int i=groupNames.length-1; i>=0; i--)
          {
              try
              {
                  List foundGroups = TurbineIntake.getGroup(groupNames[i])
                      .getObjects(pp);
  
                  if ( foundGroups != null )
                  {
                      Iterator iter = foundGroups.iterator();
                      while (iter.hasNext())
                      {
                          Group group = (Group)iter.next();
                          groups.put(group.getObjectKey(), group);
                      }
                  }
              }
              catch(Exception e)
              {
                  Log.error(e);
              }
          }
      }
  
      /**
       * A convenience method to write out the hidden form fields
       * that notify intake of the relevant groups.  It should be used
       * only in templates with 1 form.  In multiform templates, the groups
       * that are relevant for each form need to be declared using
       * $intake.newForm() and $intake.declareGroup($group) for the relevant
       * groups in the form.
       *
       */
      public String declareGroups()
      {
          allGroupsSB.setLength(0);
          Iterator i = groups.values().iterator();
          while ( i.hasNext() )
          {
              declareGroup( (Group)i.next(), allGroupsSB );
          }
          return allGroupsSB.toString();
      }
  
      HashMap declaredGroups = new HashMap();
      StringBuffer allGroupsSB = new StringBuffer(256);
      StringBuffer groupSB = new StringBuffer(128);
  
      /**
       * A convenience method to write out the hidden form fields
       * that notify intake of the group.
       */
      public String declareGroup(Group group)
      {
          groupSB.setLength(0);
          declareGroup(group, groupSB);
          return groupSB.toString();
      }
  
      /**
       * xhtml valid hidden input field(s) that notifies intake of the
       * group's presence.
       */
      public void declareGroup(Group group, StringBuffer sb)
      {
          if ( !declaredGroups.containsKey(group.getIntakeGroupName()) )
          {
              declaredGroups.put(group.getIntakeGroupName(), null);
              sb.append("<input type=\"hidden\" name=\"")
                .append("intake-grp\" value=\"")
                .append(group.getGID())
                .append("\"></input>\n");
          }
          group.appendHtmlFormInput(sb);
      }
  
      public void newForm()
      {
          declaredGroups.clear();
          Iterator i = groups.values().iterator();
          while ( i.hasNext() )
          {
               ((Group)i.next()).resetDeclared();
          }
      }
  
  
      /**
       * Inner class to present a nice interface to the template designer
       */
      public class PullHelper
      {
          String groupName;
  
          private PullHelper(String groupName)
          {
              this.groupName = groupName;
          }
  
          public Group getDefault()
              throws Exception
          {
              return setKey(DEFAULT_KEY);
          }
  
          public Group setKey(String key)
              throws Exception
          {
              return setKey(key, true);
          }
  
          public Group setKey(String key, boolean create)
              throws Exception
          {
              Group g = null;
  
              String inputKey = TurbineIntake.getGroupKey(groupName) + key;
              if ( groups.containsKey(inputKey))
              {
                  g = (Group)groups.get(inputKey);
              }
              else if (create)
              {
                  g = TurbineIntake.getGroup(groupName);
                  groups.put(inputKey, g);
                  g.init(key, pp);
              }
  
              return g;
          }
  
  
          public Group mapTo(Retrievable obj)
              throws Exception
          {
              Group g = null;
  
              try
              {
                  String inputKey = TurbineIntake.getGroupKey(groupName)
                      + obj.getQueryKey();
                  if ( groups.containsKey(inputKey))
                  {
                      g = (Group)groups.get(inputKey);
                  }
                  else
                  {
                      g = TurbineIntake.getGroup(groupName);
                      groups.put(inputKey, g);
                  }
                  return g.init(obj);
              }
              catch(Exception e)
              {
                  Log.error(e);
              }
  
              return null;
          }
      }
  
  
      public Object get(String groupName)
          throws Exception
      {
          return pullMap.get(groupName);
      }
  
      public boolean isAllValid()
      {
          boolean allValid = true;
          Iterator iter = groups.values().iterator();
          while (iter.hasNext())
          {
              Group group = (Group)iter.next();
              allValid &= group.isAllValid();
          }
          return allValid;
      }
  
      public Group get(String groupName, String key)
          throws Exception
      {
          return ((PullHelper)get(groupName)).setKey(key);
      }
  
      public Group get(String groupName, String key, boolean create)
          throws Exception
      {
          return ((PullHelper)get(groupName)).setKey(key, create);
      }
  
      /**
       * Removes group.  Primary use is to remove a group that has
       * been processed by an action and is no longer appropriate
       * in the view (screen).
       */
      public void remove(Group group)
      {
          groups.remove(group.getObjectKey());
          group.removeFromRequest();
          TurbineIntake.releaseGroup(group);
      }
  
      /**
       * Removes all groups.  Primary use is to remove groups that have
       * been processed by an action and are no longer appropriate
       * in the view (screen).
       */
      public void removeAll()
      {
          Object[] allGroups = groups.values().toArray();
          for (int i=allGroups.length-1; i>=0; i-- )
          {
              Group group = (Group)allGroups[i];
              remove(group);
          }
      }
  
  
      // ****************** Recyclable implementation ************************
  
      private boolean disposed;
  
      /**
       * Recycles the object for a new client. Recycle methods with
       * parameters must be added to implementing object and they will be
       * automatically called by pool implementations when the object is
       * taken from the pool for a new client. The parameters must
       * correspond to the parameters of the constructors of the object.
       * For new objects, constructors can call their corresponding recycle
       * methods whenever applicable.
       * The recycle methods must call their super.
       */
      public void recycle()
      {
          disposed = false;
      }
  
      /**
       * Disposes the object after use. The method is called
       * when the object is returned to its pool.
       * The dispose method must call its super.
       */
      public void dispose()
      {
          Iterator iter = groups.values().iterator();
          while ( iter.hasNext() )
          {
              Group g = (Group)iter.next();
              TurbineIntake.releaseGroup(g);
          }
  
          groups.clear();
          declaredGroups.clear();
          pp = null;
  
          disposed = true;
      }
  
      /**
       * Checks whether the recyclable has been disposed.
       * @return true, if the recyclable is disposed.
       */
      public boolean isDisposed()
      {
          return disposed;
      }
  
  
  }
  
  
  
  
  
  
  
  
  
  1.3       +7 -9      jakarta-turbine-3/src/java/org/apache/turbine/services/intake/model/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/intake/model/Field.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Field.java	2001/08/22 16:53:29	1.2
  +++ Field.java	2001/08/23 05:45:18	1.3
  @@ -58,7 +58,6 @@
   import java.lang.reflect.Method;
   import org.apache.regexp.RE;
   import org.apache.turbine.ParameterParser;
  -import org.apache.turbine.RunData;
   import org.apache.torque.om.Retrievable;
   import org.apache.turbine.services.intake.TurbineIntake;
   import org.apache.turbine.services.intake.xmlmodel.Rule;
  @@ -74,7 +73,7 @@
    * Base class for Intake generated input processing classes.
    *
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
  - * @version $Id: Field.java,v 1.2 2001/08/22 16:53:29 jmcnally Exp $
  + * @version $Id: Field.java,v 1.3 2001/08/23 05:45:18 jmcnally Exp $
    */
   public abstract class Field
   {
  @@ -110,7 +109,7 @@
       private Object[] valArray; // for reflection
   
       /** The object containing the request data */
  -    protected RunData data;
  +    protected ParameterParser pp;
   
       /**
        * Constructs a field based on data in the xml specification
  @@ -181,17 +180,16 @@
        * if a value has been supplied for this field.  if so, the value
        * is validated.
        *
  -     * @param data a <code>RunData</code> value
  +     * @param pp a <code>ParameterParser</code> value
        * @return a <code>Field</code> value
        * @exception ServiceException if an error occurs
        */
  -    public Field init(RunData data)
  +    public Field init(ParameterParser pp)
           throws ServiceException
       {
  -        this.data = data;
  +        this.pp = pp;
           valid_flag = true;
   
  -        ParameterParser pp = data.getParameters();
           if ( pp.containsKey(getKey()) && pp.getString(getKey()) != null )
           {
               set_flag = true;
  @@ -282,7 +280,7 @@
        */
       public void removeFromRequest()
       {
  -        data.getParameters().remove(getKey());
  +        pp.remove(getKey());
       }
   
   
  @@ -293,7 +291,7 @@
        */
       public void dispose()
       {
  -        data = null;
  +        pp = null;
           initialized = false;
           set_flag = false;
           valid_flag = false;
  
  
  
  1.2       +3 -5      jakarta-turbine-3/src/java/org/apache/turbine/services/intake/model/FileItemField.java
  
  Index: FileItemField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/intake/model/FileItemField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileItemField.java	2001/08/16 04:41:39	1.1
  +++ FileItemField.java	2001/08/23 05:45:18	1.2
  @@ -58,7 +58,6 @@
   import org.apache.turbine.services.intake.xmlmodel.Rule;
   import org.apache.turbine.services.intake.xmlmodel.XmlField;
   import org.apache.turbine.ParameterParser;
  -import org.apache.turbine.RunData;
   import org.apache.turbine.services.intake.validator.Validator;
   import org.apache.turbine.services.intake.validator.FileValidator;
   // import org.apache.turbine.services.intake.validator.InitableByConstraintMap;
  @@ -93,17 +92,16 @@
        * if a value has been supplied for this field.  if so, the value
        * is validated.
        *
  -     * @param data a <code>RunData</code> value
  +     * @param pp a <code>ParameterParser</code> value
        * @return a <code>Field</code> value
        * @exception ServiceException if an error occurs
        */
  -    public Field init(RunData data)
  +    public Field init(ParameterParser pp)
           throws ServiceException
       {
  -        this.data = data;
  +        this.pp = pp;
           valid_flag = true;
   
  -        ParameterParser pp = data.getParameters();
           if ( pp.containsKey(getKey()) )
           {
               set_flag = true;
  
  
  
  1.2       +12 -14    jakarta-turbine-3/src/java/org/apache/turbine/services/intake/model/Group.java
  
  Index: Group.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/intake/model/Group.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Group.java	2001/08/16 04:41:40	1.1
  +++ Group.java	2001/08/23 05:45:18	1.2
  @@ -65,7 +65,6 @@
   import org.apache.turbine.services.intake.xmlmodel.XmlField;
   import org.apache.turbine.services.intake.xmlmodel.XmlGroup;
   import org.apache.turbine.ParameterParser;
  -import org.apache.turbine.RunData;
   import org.apache.fulcrum.ServiceException;
   import org.apache.fulcrum.pool.Recyclable;
   
  @@ -120,7 +119,7 @@
       /**
        * The object containing the request data
        */
  -    protected RunData data;
  +    protected ParameterParser pp;
   
       /**
        * A flag to help prevent duplicate hidden fields declaring this group.
  @@ -176,14 +175,14 @@
       }
   
       /**
  -     * Initializes the default Group with parameters from RunData.
  +     * Initializes the default Group using parameters.
        *
  -     * @param data a <code>RunData</code> value
  +     * @param pp a <code>ParameterParser</code> value
        * @return this Group
        */
  -    public Group init(RunData data) throws ServiceException
  +    public Group init(ParameterParser pp) throws ServiceException
       {
  -        return init(NEW, data);
  +        return init(NEW, pp);
       }
   
       /**
  @@ -193,14 +192,14 @@
        * @param data a <code>RunData</code> value
        * @return this Group
        */
  -    public Group init(String key, RunData data)
  +    public Group init(String key, ParameterParser pp)
           throws ServiceException
       {
           this.oid = key;
  -        this.data = data;
  +        this.pp = pp;
           for (int i=fieldsArray.length-1; i>=0; i--)
           {
  -            fieldsArray[i].init(data);
  +            fieldsArray[i].init(pp);
           }
           return this;
       }
  @@ -311,17 +310,17 @@
        * @return an <code>ArrayList</code> value
        * @exception ServiceException if an error occurs
        */
  -    public ArrayList getObjects(RunData data)
  +    public ArrayList getObjects(ParameterParser pp)
           throws ServiceException
       {
           ArrayList objs = null;
  -        String[] oids = data.getParameters().getStrings(gid);
  +        String[] oids = pp.getStrings(gid);
           if (oids != null)
           {
               objs = new ArrayList(oids.length);
               for (int i=oids.length-1; i>=0; i--)
               {
  -                objs.add( TurbineIntake.getGroup(name).init(oids[i], data) );
  +                objs.add( TurbineIntake.getGroup(name).init(oids[i], pp) );
               }
           }
           return objs;
  @@ -414,7 +413,6 @@
        */
       public void removeFromRequest()
       {
  -        ParameterParser pp = data.getParameters();
           String[] groups = pp.getStrings(gid);
           if ( groups != null )
           {
  @@ -499,7 +497,7 @@
       public void dispose()
       {
           oid = null;
  -        data = null;
  +        pp = null;
           for (int i=fieldsArray.length-1; i>=0; i--)
           {
               fieldsArray[i].dispose();
  
  
  
  1.2       +1 -10     jakarta-turbine-3/src/java/org/apache/turbine/services/intake/validator/DefaultValidator.java
  
  Index: DefaultValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/intake/validator/DefaultValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultValidator.java	2001/08/16 04:41:41	1.1
  +++ DefaultValidator.java	2001/08/23 05:45:19	1.2
  @@ -54,17 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  -import java.lang.reflect.Method;
   import java.util.Map;
   import org.apache.regexp.RE;
  -import org.apache.torque.om.Retrievable;
  -import org.apache.turbine.services.intake.TurbineIntake;
  -import org.apache.turbine.services.intake.xmlmodel.Rule;
  -import org.apache.turbine.services.intake.xmlmodel.XmlField;
  -import org.apache.turbine.services.intake.xmlmodel.XmlGroup;
  -import org.apache.fulcrum.Log;
  -import org.apache.turbine.ParameterParser;
  -import org.apache.turbine.RunData;
   import org.apache.fulcrum.ServiceException;
   
   /**
  @@ -81,7 +72,7 @@
    * This validator can serve as the base class for more specific validators
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id: DefaultValidator.java,v 1.1 2001/08/16 04:41:41 jvanzyl Exp $
  + * @version $Id: DefaultValidator.java,v 1.2 2001/08/23 05:45:19 jmcnally Exp $
    */
   public class DefaultValidator
       implements Validator, InitableByConstraintMap
  
  
  
  1.2       +1 -10     jakarta-turbine-3/src/java/org/apache/turbine/services/intake/validator/FileValidator.java
  
  Index: FileValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/java/org/apache/turbine/services/intake/validator/FileValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileValidator.java	2001/08/16 04:41:41	1.1
  +++ FileValidator.java	2001/08/23 05:45:19	1.2
  @@ -54,17 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  -import java.lang.reflect.Method;
   import java.util.Map;
   import org.apache.regexp.RE;
  -import org.apache.torque.om.Retrievable;
  -import org.apache.turbine.services.intake.TurbineIntake;
  -import org.apache.turbine.services.intake.xmlmodel.Rule;
  -import org.apache.turbine.services.intake.xmlmodel.XmlField;
  -import org.apache.turbine.services.intake.xmlmodel.XmlGroup;
  -import org.apache.fulcrum.Log;
  -import org.apache.turbine.ParameterParser;
  -import org.apache.turbine.RunData;
   import org.apache.fulcrum.ServiceException;
   import org.apache.fulcrum.upload.FileItem;
   
  @@ -82,7 +73,7 @@
    * This validator can serve as the base class for more specific validators
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id: FileValidator.java,v 1.1 2001/08/16 04:41:41 jvanzyl Exp $
  + * @version $Id: FileValidator.java,v 1.2 2001/08/23 05:45:19 jmcnally Exp $
    */
   public class FileValidator
       implements Validator, InitableByConstraintMap
  
  
  
  1.2       +6 -318    jakarta-turbine-3/src/tool/org/apache/turbine/tool/IntakeTool.java
  
  Index: IntakeTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-3/src/tool/org/apache/turbine/tool/IntakeTool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IntakeTool.java	2001/08/16 04:41:50	1.1
  +++ IntakeTool.java	2001/08/23 05:45:19	1.2
  @@ -54,161 +54,32 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.ArrayList;
  -import java.util.Collection;
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.Map;
  -import org.apache.fulcrum.Log;
  -import org.apache.fulcrum.pool.Recyclable;
  -import org.apache.torque.om.Retrievable;
   import org.apache.turbine.RunData;
  -import org.apache.turbine.ParameterParser;
  -import org.apache.turbine.services.intake.model.Group;
  -import org.apache.turbine.services.intake.TurbineIntake;
  +import org.apache.turbine.services.intake.Intake;
   import org.apache.turbine.services.pull.ApplicationTool;
   
   /**
    * A Pull tool to make intake objects available to a template
    *
    * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
  - * @version $Id: IntakeTool.java,v 1.1 2001/08/16 04:41:50 jvanzyl Exp $
  + * @version $Id: IntakeTool.java,v 1.2 2001/08/23 05:45:19 jmcnally Exp $
    */
  -public class IntakeTool
  -    implements ApplicationTool, Recyclable
  +public class IntakeTool extends Intake
  +    implements ApplicationTool
   {
  -    public static final String DEFAULT_KEY = "_0";
  -    private HashMap groups;
  -    private RunData data;
  -    // private boolean allValid;
  -    // private String omToolKey;
  -    // private OMTool omTool;
  -
  -    /** The cache of PullHelpers. **/
  -    private Map pullMap = new HashMap();
  -
       public IntakeTool()
       {
  -        String[] groupNames = TurbineIntake.getGroupNames();
  -        groups = new HashMap((int)(1.25*groupNames.length + 1));
  -        pullMap = new HashMap((int)(1.25*groupNames.length + 1));
  -        // omToolKey = TurbineResources.getString("tool.intake.om");
  -
  -        for (int i=groupNames.length-1; i>=0; i--)
  -        {
  -            pullMap.put(groupNames[i], new PullHelper(groupNames[i]));
  -        }
  +        super();
       }
   
       /**
        * Prepares intake for a single request
        */
       public void init(Object runData)
  -    {
  -        data = (RunData)runData;
  -
  -        String[] groupKeys = data.getParameters().getStrings("intake-grp");
  -        String[] groupNames = null;
  -        if ( groupKeys == null || groupKeys.length == 0 )
  -        {
  -            groupNames = TurbineIntake.getGroupNames();
  -        }
  -        else
  -        {
  -            groupNames = new String[groupKeys.length];
  -            for ( int i=groupKeys.length-1; i>=0; i-- )
  -            {
  -                groupNames[i] = TurbineIntake.getGroupName(groupKeys[i]);
  -            }
  -
  -        }
  -
  -        for (int i=groupNames.length-1; i>=0; i--)
  -        {
  -            try
  -            {
  -                List foundGroups = TurbineIntake.getGroup(groupNames[i])
  -                    .getObjects(data);
  -
  -                if ( foundGroups != null )
  -                {
  -                    Iterator iter = foundGroups.iterator();
  -                    while (iter.hasNext())
  -                    {
  -                        Group group = (Group)iter.next();
  -                        groups.put(group.getObjectKey(), group);
  -                    }
  -                }
  -            }
  -            catch(Exception e)
  -            {
  -                Log.error(e);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * A convenience method to write out the hidden form fields
  -     * that notify intake of the relevant groups.  It should be used
  -     * only in templates with 1 form.  In multiform templates, the groups
  -     * that are relevant for each form need to be declared using
  -     * $intake.newForm() and $intake.declareGroup($group) for the relevant
  -     * groups in the form.
  -     *
  -     */
  -    public String declareGroups()
  -    {
  -        allGroupsSB.setLength(0);
  -        Iterator i = groups.values().iterator();
  -        while ( i.hasNext() )
  -        {
  -            declareGroup( (Group)i.next(), allGroupsSB );
  -        }
  -        return allGroupsSB.toString();
  -    }
  -
  -    HashMap declaredGroups = new HashMap();
  -    StringBuffer allGroupsSB = new StringBuffer(256);
  -    StringBuffer groupSB = new StringBuffer(128);
  -
  -    /**
  -     * A convenience method to write out the hidden form fields
  -     * that notify intake of the group.
  -     */
  -    public String declareGroup(Group group)
  -    {
  -        groupSB.setLength(0);
  -        declareGroup(group, groupSB);
  -        return groupSB.toString();
  -    }
  -
  -    /**
  -     * xhtml valid hidden input field(s) that notifies intake of the
  -     * group's presence.
  -     */
  -    public void declareGroup(Group group, StringBuffer sb)
       {
  -        if ( !declaredGroups.containsKey(group.getIntakeGroupName()) )
  -        {
  -            declaredGroups.put(group.getIntakeGroupName(), null);
  -            sb.append("<input type=\"hidden\" name=\"")
  -              .append("intake-grp\" value=\"")
  -              .append(group.getGID())
  -              .append("\"></input>\n");
  -        }
  -        group.appendHtmlFormInput(sb);
  +        super.init( ((RunData)runData).getParameters() );
       }
   
  -    public void newForm()
  -    {
  -        declaredGroups.clear();
  -        Iterator i = groups.values().iterator();
  -        while ( i.hasNext() )
  -        {
  -             ((Group)i.next()).resetDeclared();
  -        }
  -    }
   
       /**
        * Implementation of ApplicationTool interface is not needed for this
  @@ -218,189 +89,6 @@
       {
           // empty
       }
  -
  -    /**
  -     * Inner class to present a nice interface to the template designer
  -     */
  -    public class PullHelper
  -    {
  -        String groupName;
  -
  -        private PullHelper(String groupName)
  -        {
  -            this.groupName = groupName;
  -        }
  -
  -        public Group getDefault()
  -            throws Exception
  -        {
  -            return setKey(DEFAULT_KEY);
  -        }
  -
  -        public Group setKey(String key)
  -            throws Exception
  -        {
  -            return setKey(key, true);
  -        }
  -
  -        public Group setKey(String key, boolean create)
  -            throws Exception
  -        {
  -            Group g = null;
  -
  -            String inputKey = TurbineIntake.getGroupKey(groupName) + key;
  -            if ( groups.containsKey(inputKey))
  -            {
  -                g = (Group)groups.get(inputKey);
  -            }
  -            else if (create)
  -            {
  -                g = TurbineIntake.getGroup(groupName);
  -                groups.put(inputKey, g);
  -                g.init(key, data);
  -            }
  -
  -            return g;
  -        }
  -
  -
  -        public Group mapTo(Retrievable obj)
  -            throws Exception
  -        {
  -            Group g = null;
  -
  -            try
  -            {
  -                String inputKey = TurbineIntake.getGroupKey(groupName)
  -                    + obj.getQueryKey();
  -                if ( groups.containsKey(inputKey))
  -                {
  -                    g = (Group)groups.get(inputKey);
  -                }
  -                else
  -                {
  -                    g = TurbineIntake.getGroup(groupName);
  -                    groups.put(inputKey, g);
  -                }
  -                return g.init(obj);
  -            }
  -            catch(Exception e)
  -            {
  -                Log.error(e);
  -            }
  -
  -            return null;
  -        }
  -    }
  -
  -
  -    public Object get(String groupName)
  -        throws Exception
  -    {
  -        return pullMap.get(groupName);
  -    }
  -
  -    public boolean isAllValid()
  -    {
  -        boolean allValid = true;
  -        Iterator iter = groups.values().iterator();
  -        while (iter.hasNext())
  -        {
  -            Group group = (Group)iter.next();
  -            allValid &= group.isAllValid();
  -        }
  -        return allValid;
  -    }
  -
  -    public Group get(String groupName, String key)
  -        throws Exception
  -    {
  -        return ((PullHelper)get(groupName)).setKey(key);
  -    }
  -
  -    public Group get(String groupName, String key, boolean create)
  -        throws Exception
  -    {
  -        return ((PullHelper)get(groupName)).setKey(key, create);
  -    }
  -
  -    /**
  -     * Removes group.  Primary use is to remove a group that has
  -     * been processed by an action and is no longer appropriate
  -     * in the view (screen).
  -     */
  -    public void remove(Group group)
  -    {
  -        groups.remove(group.getObjectKey());
  -        group.removeFromRequest();
  -        TurbineIntake.releaseGroup(group);
  -    }
  -
  -    /**
  -     * Removes all groups.  Primary use is to remove groups that have
  -     * been processed by an action and are no longer appropriate
  -     * in the view (screen).
  -     */
  -    public void removeAll()
  -    {
  -        Object[] allGroups = groups.values().toArray();
  -        for (int i=allGroups.length-1; i>=0; i-- )
  -        {
  -            Group group = (Group)allGroups[i];
  -            remove(group);
  -        }
  -    }
  -
  -
  -    // ****************** Recyclable implementation ************************
  -
  -    private boolean disposed;
  -
  -    /**
  -     * Recycles the object for a new client. Recycle methods with
  -     * parameters must be added to implementing object and they will be
  -     * automatically called by pool implementations when the object is
  -     * taken from the pool for a new client. The parameters must
  -     * correspond to the parameters of the constructors of the object.
  -     * For new objects, constructors can call their corresponding recycle
  -     * methods whenever applicable.
  -     * The recycle methods must call their super.
  -     */
  -    public void recycle()
  -    {
  -        disposed = false;
  -    }
  -
  -    /**
  -     * Disposes the object after use. The method is called
  -     * when the object is returned to its pool.
  -     * The dispose method must call its super.
  -     */
  -    public void dispose()
  -    {
  -        Iterator iter = groups.values().iterator();
  -        while ( iter.hasNext() )
  -        {
  -            Group g = (Group)iter.next();
  -            TurbineIntake.releaseGroup(g);
  -        }
  -
  -        groups.clear();
  -        declaredGroups.clear();
  -        data = null;
  -
  -        disposed = true;
  -    }
  -
  -    /**
  -     * Checks whether the recyclable has been disposed.
  -     * @return true, if the recyclable is disposed.
  -     */
  -    public boolean isDisposed()
  -    {
  -        return disposed;
  -    }
  -
   
   }
   
  
  
  

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