commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject cvs commit: jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader ActionHelper.java ActionHelperBase.java CommandAction.java
Date Sat, 27 Mar 2004 18:21:30 GMT
husted      2004/03/27 10:21:30

  Modified:    chain/apps/mailreader build.xml
               chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader
                        ActionHelper.java ActionHelperBase.java
                        CommandAction.java
  Log:
  Extend design of CommandAction
  
  Revision  Changes    Path
  1.2       +5 -0      jakarta-commons-sandbox/chain/apps/mailreader/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	25 Mar 2004 12:35:00 -0000	1.1
  +++ build.xml	27 Mar 2004 18:21:30 -0000	1.2
  @@ -20,6 +20,11 @@
          <param name="maven.goal" value="war:webapp" />
        </antcall>
      </target>
  +    <target description="Test classes" name="test">
  +      <antcall target="maven">
  +        <param name="maven.goal" value="test" />
  +      </antcall>
  +    </target>
     <target description="Build webapp documentation" name="site">
       <antcall target="maven">
         <param name="maven.goal" value="site" />
  
  
  
  1.2       +4 -2      jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ActionHelper.java
  
  Index: ActionHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ActionHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionHelper.java	27 Mar 2004 03:56:20 -0000	1.1
  +++ ActionHelper.java	27 Mar 2004 18:21:30 -0000	1.2
  @@ -114,6 +114,8 @@
        */
       public Locale getLocale();
   
  +    public void setLocale(Locale locale);
  +
       /**
        * <p>
        * The transaction token stored in this session, if it is used.
  
  
  
  1.2       +5 -8      jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ActionHelperBase.java
  
  Index: ActionHelperBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ActionHelperBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionHelperBase.java	27 Mar 2004 03:56:20 -0000	1.1
  +++ ActionHelperBase.java	27 Mar 2004 18:21:30 -0000	1.2
  @@ -19,7 +19,6 @@
    */
   package org.apache.commons.chain.mailreader;
   
  -import org.apache.commons.chain.impl.ContextBase;
   import org.apache.struts.Globals;
   import org.apache.struts.action.*;
   import org.apache.struts.upload.MultipartRequestWrapper;
  @@ -135,15 +134,14 @@
        * Do not call other methods without setting these first!
        * This is also called by the convenience constructor.
        *
  -     * @param application - The associated ServletContext.
        * @param request - The associated HTTP request.
        * @param response - The associated HTTP response.
        */
       public void setResources(
  -            ServletContext application,
               HttpServletRequest request,
               HttpServletResponse response) {
   
  +        ServletContext application = request.getSession().getServletContext();
           setApplication(application);
           setRequest(request);
           setResponse(response);
  @@ -154,12 +152,11 @@
       }
   
       public ActionHelperBase(
  -            ServletContext application,
               HttpServletRequest request,
               HttpServletResponse response) {
   
           super();
  -        this.setResources(application, request, response);
  +        this.setResources(request, response);
       }
   
   
  
  
  
  1.3       +88 -6     jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/CommandAction.java
  
  Index: CommandAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/CommandAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CommandAction.java	27 Mar 2004 03:58:02 -0000	1.2
  +++ CommandAction.java	27 Mar 2004 18:21:30 -0000	1.3
  @@ -1,12 +1,15 @@
   package org.apache.commons.chain.mailreader;
   
  -import org.apache.struts.action.Action;
  -import org.apache.struts.action.ActionForm;
  -import org.apache.struts.action.ActionForward;
  -import org.apache.struts.action.ActionMapping;
  +import org.apache.struts.action.*;
  +import org.apache.commons.chain.Catalog;
  +import org.apache.commons.chain.Context;
  +import org.apache.commons.chain.impl.ContextBase;
  +import org.apache.commons.chain.mailreader.commands.MailReader;
  +import org.apache.commons.chain.mailreader.commands.MailReaderBase;
   
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import java.util.Locale;
   
   /**
    * <p>
  @@ -26,9 +29,88 @@
    */
   public class CommandAction extends Action {
   
  -    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest
httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
  +    /**
  +     * <p>
  +     * Return the default {@link org.apache.commons.chain.Catalog}.
  +     * </p>
  +     * @return Default Catalog
  +     * @throws java.lang.UnsupportedOperationException if ControllerContext is
  +     * null.
  +     */
  +    public Catalog getCatalog(HttpServletRequest request){
   
  -        throw new RuntimeException("TODO: Implement CommandAction");
  +        return (Catalog) request.getSession().getServletContext().getAttribute(Catalog.CATALOG_KEY);
  +
  +    }
  +
  +    public ViewContext getContext(ActionHelper helper, ActionForm form) {
  +
  +        Locale locale = helper.getLocale();
  +        Context input = getInput(form);
  +        return new MailReaderBase(locale,input);
  +
  +    }
  +
  +
  +    public Context getInput(ActionForm form) {
  +        DynaActionForm dyna = (DynaActionForm) form;
  +        return new ContextBase(dyna.getMap());
  +    }
  +
  +    public void conformInput(ActionHelper helper, ViewContext context) {
  +        Context input = context.getInput();
  +        ActionMapping mapping = helper.getMapping();
  +        HttpServletRequest request = helper.getRequest();
  +        String formScope = mapping.getScope();
  +        String name = mapping.getName();
  +        if (helper.isRequestScope()) request.setAttribute(name,input);
  +        else request.getSession().setAttribute(name,input);
  +    }
  +
  +    public void conformState(ActionHelper helper, ViewContext context) {
  +        helper.setLocale(context.getLocale());
       }
   
  +    public ActionForward findSuccess(ActionMapping mapping) {
  +        return mapping.findForward("success");
  +    }
  +
  +    public ActionForward execute(ActionMapping mapping,
  +                                 ActionForm form,
  +                                 HttpServletRequest request,
  +                                 HttpServletResponse response) throws Exception {
  +
  +        // create ActionHelper
  +        ActionHelper helper = new ActionHelperBase(request,response);
  +        // return execute(helper); // ContextAction
  +
  +        // TODO: obtain database reference
  +        // forward = preCommand(helper); if (forward!=null) return forward;
  +
  +        // create mailreader context, using ActionHelper methods
  +        ViewContext context = getContext(helper,form);
  +
  +        // execute command
  +        String name = mapping.getName();
  +        boolean stop = getCatalog(request).getCommand(name).execute(context);
  +
  +        // update state from mailreader context
  +        conformInput(helper,context);
  +        conformState(helper,context);
  +
  +        // TODO: Expose any output
  +        // TODO: Expose any status messages,
  +        // TODO: Expose any error messages and find input
  +        // location = postCommand(helper,context);
  +
  +        // find success
  +        return helper.findSuccess();
  +    }
  +
  +    // ModuleContext -> state for a module (mappings, messages) : ReadOnly
  +    // ClientContext -> runtime input for this request/client (locale,form) : ReadWrite
  +    // ActionContext -> ClientState, ModuleState
  +
  +    // StrutsContext -> state for entire Struts application : ReadWrite
  +    // StrutsContext.createActionContext(request);
   }
  
  
  

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


Mime
View raw message