husted      02/02/22 02:14:16

  Modified:    contrib/scaffold/src/framework/main/org/apache/scaffold/http
                        SuperForm.java SuperAction.java
                        BaseHelperAction.java
  Added:       contrib/scaffold/src/framework/main/org/apache/scaffold/http
                        SuperServlet.java BlankForm.java
  Log:
  Add SuperServlet to provide invokeAction method [1.0.x compat].
  Updates to SuperForm and SuperAction.  Add BlankForm for use
  with JavaScript buttons.
  
  Revision  Changes    Path
  1.2       +3 -6      
jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperForm.java
  
  Index: SuperForm.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperForm.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SuperForm.java    24 Jan 2002 15:24:50 -0000      1.1
  +++ SuperForm.java    22 Feb 2002 10:14:16 -0000      1.2
  @@ -13,16 +13,14 @@
   
   
   /**
  - * Standard base ActionForm with enhanced functionality.
  + * Enhanced base ActionForm.
    * @author Ted Husted
  - * @version $Revision: 1.1 $ $Date: 2002/01/24 15:24:50 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/22 10:14:16 $
    */
   // public class ScaffoldForm extends ValidatorForm {
   public class SuperForm extends ActionForm {
   
   // --------------------------------------------------- Instance Variables
  -
  -
   // ----------------------------------------------------------- Properties
   
   
  @@ -168,7 +166,6 @@
       }
   
   
  -
   // ----- end SuperForm -----
   
   }
  @@ -179,7 +176,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  
  
  
  1.2       +108 -5    
jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperAction.java
  
  Index: SuperAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SuperAction.java  24 Jan 2002 15:24:50 -0000      1.1
  +++ SuperAction.java  22 Feb 2002 10:14:16 -0000      1.2
  @@ -2,11 +2,14 @@
   
   
   import java.io.IOException;
  +import java.util.List;
  +import java.util.Locale;
   import java.util.Map;
   
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import javax.servlet.http.HttpSession;
   
   import org.apache.struts.action.Action;
   import org.apache.struts.action.ActionError;
  @@ -16,18 +19,115 @@
   import org.apache.struts.action.ActionMapping;
   import org.apache.struts.action.ActionServlet;
   
  +import org.apache.struts.util.MessageResources;
  +
   import org.apache.scaffold.lang.Tokens;
   import org.apache.scaffold.lang.ChainedException;
   
   
   /**
  - * Standard Base Action.
  + * Enhanced base Action.
    * @author Ted Husted
  - * @version $Revision: 1.1 $ $Date: 2002/01/24 15:24:50 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/22 10:14:16 $
    */
   public class SuperAction extends Action {
   
   
  +// ---------------------------------------------------------- Utilities
  +
  +    /**
  +     * Return the framework locale object for the user session
  +     * for given request.
  +     * If no session is set, or if the session has no locale
  +     * set, the default locale is returned.
  +     * @author  Fran�ois Rey (FREY - [EMAIL PROTECTED])
  +     * @author  Eric Bariaux (EBRX - [EMAIL PROTECTED])
  +    **/
  +    protected Locale getLocale(HttpServletRequest request) {
  +        Locale result = null;
  +        HttpSession session = request.getSession();
  +        if (session!=null) {
  +            result = (Locale) session.getAttribute(Action.LOCALE_KEY);
  +            if (result == null) result = Locale.getDefault();
  +        } else {
  +            result = Locale.getDefault();
  +        }
  +        return result;
  +    }
  +
  +
  +    /**
  +     * Set the framework locale object in the session for this request.
  +     * If a session context does not exist, one is created.
  +    **/
  +    protected void setLocale(HttpServletRequest request, Locale locale) {
  +        HttpSession session = request.getSession(true);
  +        session.setAttribute(Action.LOCALE_KEY,locale);
  +    }
  +
  +
  +    /**
  +     * Return the application resources for this web application, if any.
  +    **/
  +    protected MessageResources getMessageResources() {
  +        return servlet.getResources();
  +    }
  +
  +
  +
  +    /**
  +     * Number of replacement parameters permitted in Struts 1.0.
  +     * See also saveConfirm.
  +    **/
  +    private static int CONFIRM_MAX = 5; // (Message Key, plus 1..4)
  +
  +
  +    /**
  +     * Retrieves a base messages and up to four replaceable
  +     * parameters from a List, and adds them as an ActionError.
  +    **/
  +    protected boolean saveMessage(ActionErrors errors, List messages) {
  +        if ((messages==null) || (messages.size()==0)) {
  +            return false;
  +        }
  +        int size = messages.size();
  +            // Struts 1.0 allows up to 4 parameters, 1..4
  +        if (size > CONFIRM_MAX) size = CONFIRM_MAX;
  +        Object[] confirm = new Object[size];
  +        for (int i=0; i<size; i++) {
  +            confirm[i] = messages.get(i);
  +        }
  +        switch (size) {
  +           case 5:
  +                errors.add(ActionErrors.GLOBAL_ERROR,
  +                    new ActionError((String) confirm[0],
  +                        confirm[1],confirm[2],confirm[3],confirm[4]));
  +                break;
  +           case 4:
  +                errors.add(ActionErrors.GLOBAL_ERROR,
  +                    new ActionError((String) confirm[0],
  +                        confirm[1],confirm[2],confirm[3]));
  +                break;
  +           case 3:
  +                errors.add(ActionErrors.GLOBAL_ERROR,
  +                    new ActionError((String) confirm[0],
  +                        confirm[1],confirm[2]));
  +                break;
  +           case 2:
  +                errors.add(ActionErrors.GLOBAL_ERROR,
  +                    new ActionError((String) confirm[0],
  +                        confirm[1]));
  +                break;
  +           case 1:
  +                errors.add(ActionErrors.GLOBAL_ERROR,
  +                    new ActionError((String) confirm[0]));
  +        }
  +        return true;
  +    }
  +
  +
  +// ----------------------------------------------------------- Hotspots
  +
       /**
        * Create and return an ActionErrors object.
        * The default method returns a new, empty object.
  @@ -59,7 +159,8 @@
         * when there is one, or "error" when not.
         * The application must provide an "error" forward.
         * An advanced implementation could check the errors
  -      * and provide different forwardings for different
  +      * and provide different forwardings for different circumstances.
  +      * One possible error may be whether the form is null.
         * @param mapping The ActionMapping used to select this instance
         * @param actionForm The optional ActionForm bean for this request (if any)
         * @param request The HTTP request we are processing
  @@ -196,6 +297,8 @@
       }
   
   
  +// --------------------------------------------------- Ancestor methods
  +
       /**
        * Skeleton perform that calls the other "hotspot" methods in
        * this class in turn. Typically, you can override the other
  @@ -241,9 +344,9 @@
   
   
   /*
  - * $Header: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperAction.java,v
 1.1 2002/01/24 15:24:50 husted Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/01/24 15:24:50 $
  + * $Header: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperAction.java,v
 1.2 2002/02/22 10:14:16 husted Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/22 10:14:16 $
    *
    * ====================================================================
    *
  
  
  
  1.4       +9 -83     
jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/BaseHelperAction.java
  
  Index: BaseHelperAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/BaseHelperAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseHelperAction.java     23 Jan 2002 21:40:52 -0000      1.3
  +++ BaseHelperAction.java     22 Feb 2002 10:14:16 -0000      1.4
  @@ -41,91 +41,13 @@
    * and an error condition is detected.
    * <p>
    * @author Ted Husted
  - * @version $Revision: 1.3 $ $Date: 2002/01/23 21:40:52 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/22 10:14:16 $
   **/
  -public class BaseHelperAction extends Action {
  +public class BaseHelperAction extends SuperAction {
   
   
   // --------------------------------------------------------- Public Methods
   
  -    /**
  -     * Return the locale for the given request. If no session is set,
  -     * or if the session has no locale set, the default locale
  -     * is returned.
  -     * @author  Fran�ois Rey (FREY - [EMAIL PROTECTED])
  -     * @author  Eric Bariaux (EBRX - [EMAIL PROTECTED])
  -    **/
  -    protected Locale getLocale(HttpServletRequest request) {
  -        Locale result = null;
  -        HttpSession session = request.getSession();
  -        if (session!=null) {
  -            result = (Locale) session.getAttribute(Action.LOCALE_KEY);
  -            if (result == null) result = Locale.getDefault();
  -        } else {
  -            result = Locale.getDefault();
  -        }
  -        return result;
  -    }
  -
  -
  -    /**
  -     * Return the application resources for this web application, if any.
  -    **/
  -    public MessageResources getMessageResources() {
  -        return servlet.getResources();
  -    }
  -
  -
  -    /**
  -     * Number of replacement parameters permitted in Struts 1.0.
  -     * See also saveConfirm.
  -    **/
  -    public static int CONFIRM_MAX = 5; // (Message Key, plus 1..4)
  -
  -
  -    /**
  -     * Retrieves a base messages and up to four replaceable
  -     * parameters from a List, and adds them as an ActionError.
  -    **/
  -    protected boolean saveMessage(ActionErrors errors, List messages) {
  -        if ((messages==null) || (messages.size()==0)) {
  -            return false;
  -        }
  -        int size = messages.size();
  -            // Struts 1.0 allows up to 4 parameters, 1..4
  -        if (size > CONFIRM_MAX) size = CONFIRM_MAX;
  -        String[] confirm = new String[size];
  -        for (int i=0; i<size; i++) {
  -            confirm[i] = (String) messages.get(i);
  -        }
  -        switch (size) {
  -           case 5:
  -                errors.add(ActionErrors.GLOBAL_ERROR,
  -                    new ActionError(confirm[0],
  -                        confirm[1],confirm[2],confirm[3],confirm[4]));
  -                break;
  -           case 4:
  -                errors.add(ActionErrors.GLOBAL_ERROR,
  -                    new ActionError(confirm[0],
  -                        confirm[1],confirm[2],confirm[3]));
  -                break;
  -           case 3:
  -                errors.add(ActionErrors.GLOBAL_ERROR,
  -                    new ActionError(confirm[0],
  -                        confirm[1],confirm[2]));
  -                break;
  -           case 2:
  -                errors.add(ActionErrors.GLOBAL_ERROR,
  -                    new ActionError(confirm[0],
  -                        confirm[1]));
  -                break;
  -           case 1:
  -                errors.add(ActionErrors.GLOBAL_ERROR,
  -                    new ActionError(confirm[0]));
  -        }
  -        return true;
  -    }
  -
   
       /**
        * Simple test to render String version of instantiated
  @@ -188,6 +110,10 @@
               return (forward);
           }
   
  +        // Create new token, in case it is needed
  +        resetToken(request);
  +        saveToken(request);
  +
           // This creates a helper for each request.
           // Using data fields in the helper object is thread safe.
           StringTokenizer helperClasses =
  @@ -219,9 +145,9 @@
   
   
   /*
  - * $Header: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/BaseHelperAction.java,v
 1.3 2002/01/23 21:40:52 husted Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/01/23 21:40:52 $
  + * $Header: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/BaseHelperAction.java,v
 1.4 2002/02/22 10:14:16 husted Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/22 10:14:16 $
    *
    * ====================================================================
    *
  
  
  
  1.1                  
jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/SuperServlet.java
  
  Index: SuperServlet.java
  ===================================================================
  package org.apache.scaffold.http;
  
  import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionFormBean;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.action.ActionServlet;
  
  
  /**
   * Enhanced base ActionServlet.
   * @author Ted Husted
   */
  
  // public class SuperServlet extends TilesServlet
  public class SuperServlet extends ActionServlet {
  
  // ---------------------------------------------------------- Utilities
  
      /**
       * Return an instance of the ActionForm associated with the specified
       * path, if any; otherwise return <code>null</code>.
       * May be used to create an ActionForm for InvokeAction.
       *
       * @param name path of the Action using the ActionForm bean
       */
      protected ActionForm createActionForm(String path) {
  
          ActionMapping mapping = findMapping(path);
          String name = mapping.getName();
  
          ActionForm form = null;
  
          ActionFormBean formBean = findFormBean(name);
          if (formBean != null) {
              String className = null;
              className = formBean.getType();
              try {
                  Class clazz = Class.forName(className);
                  form = (ActionForm) clazz.newInstance();
              } catch (Throwable t) {
                  form = null;
              }
          }
  
          return form;
      }
  
  
      /**
       * Directly process the Action perform associated with the
       * given path.
       * Return the <code>ActionForward</code> instance (if any)
       * returned by the called <code>Action</code>.
       * <code>createActionForm</code> may be used to create an
       * ActionForm instance to pass to the Action invoked.
       *
       * @param action The path to the Action to invoke
       * @param form The ActionForm we are processing
       * @param request The servlet request we are processing
       * @param response The servlet response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
      **/
      protected ActionForward invokeAction(
              String path,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response)
          throws IOException, ServletException {
  
          ActionMapping mapping =
              processMapping(path,request);
  
          Action action =
              processActionCreate(mapping,request);
  
          ActionForward forward =
              processActionPerform(
                  action,mapping,form,request,response);
  
          return forward;
      }
  
  // ----- end SuperServlet -----
  
  }
  
  
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 [EMAIL PROTECTED]
   *
   * 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/>.
   *
   */
  
  
  
  1.1                  
jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/BlankForm.java
  
  Index: BlankForm.java
  ===================================================================
  package org.apache.scaffold.http;
  
  import org.apache.struts.validator.action.ValidatorForm;
  
  /**
   * Blank form for useuse with "formless" forms.
   */
  public final class BlankForm extends ValidatorForm {
  
      // blank form
  
  } // end BlankForm
  
  
  /*
   * $Header: 
/home/cvs/jakarta-struts/contrib/scaffold/src/framework/main/org/apache/scaffold/http/BlankForm.java,v
 1.1 2002/02/22 10:14:16 husted Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/22 10:14:16 $
   *
   * ====================================================================
   *
   * 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 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 [EMAIL PROTECTED]
   *
   * 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/>.
   *
   */
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to