View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.control.action;
16  
17  import org.figure8.join.control.JoinAction;
18  import org.figure8.join.control.form.ScriptLogForm;
19  import org.figure8.join.util.ScriptLogAccessorProxy;
20  import org.figure8.join.util.LogUtil;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  import java.util.List;
30  /**
31   * Struts action for managing the retrieval of script log infos.
32   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
33   * @version $Revision: 1.1 $
34   *
35   * @struts.action path="/scriptLog" name="scriptLogForm"
36   *                scope="request" parameter="op" validate="true"
37   *                input="/pages/mainpage.jsp?body=/jsp/scriptlogs.jsp"
38   * @struts.action-forward name="Box" path="/jsp/scriptlogs.jsp"
39   */
40  public class ScriptLogActions extends JoinAction{
41  
42     // Static -------------------------------------------------------------------
43  
44     /** Get a commons logger. */
45     private static final Log log = LogUtil.getLog(ScriptLogActions.class);
46  
47     /** Operation code for retrieving script logs using the script criterion */
48     public static final String SCRIPT_OP = "getByScript";
49     /** Operation code for retrieving script logs using the entity criterion */
50     public static final String ENTITY_OP = "getByEntity";
51  
52     /**
53      * The request scope attribute under which the retrieved script logs
54      * list is stored.
55      */
56     public static final String SCRIPT_LOGS_KEY = "scriptLogs";
57  
58  
59     // Constructors -------------------------------------------------------------
60  
61     /** Creates a new instance of ScriptLogActions */
62     public ScriptLogActions(){
63     }
64  
65  
66     // Implementation of JoinAction ---------------------------------------------
67  
68     /**
69      *
70      * @param operation String representing the operation to invoke on Action
71      * @param mapping Mapping between forwards name and path for this action
72      * @param form The form object containing request parameters
73      * @param request The servlet container request wrapper
74      * @param response The servlet container response wrapper
75      * @return A forward to the next view to render and display
76      * @throws Exception such as InfraStructureExceptions ...
77      */
78     public ActionForward doExecute(String operation, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
79             throws Exception{
80        // Trace operation to execute.
81        log.debug("doExecute() called for '" + operation + "' operation");
82  
83        if (form instanceof ScriptLogForm){
84           // Get the script log form, proxy and prepare a result.
85           ScriptLogForm sForm = (ScriptLogForm)form;
86           ScriptLogAccessorProxy proxy = ScriptLogAccessorProxy.getInstance();
87           List scriptLogs = null;
88  
89           if (SCRIPT_OP.equals(operation)){
90              log.info("Retrieving script log infos for script '" + sForm.getScriptName() + "' and category " + sForm.getScriptCategory());
91              scriptLogs = proxy.getScriptLogInfos(sForm.getScriptName(), sForm.getScriptCategory());
92           }
93           else if (ENTITY_OP.equals(operation)){
94              log.info("Retrieving script log infos for entity " + sForm.getEntityClass() + "#" + sForm.getEntityId());
95              scriptLogs = proxy.getScriptLogInfos(sForm.getEntityId(), sForm.getEntityClass());
96           }
97  
98           // Store list into request before forwarding.
99           request.setAttribute(SCRIPT_LOGS_KEY, scriptLogs);
100          return mapping.findForward("Box");
101       }
102       // This should not happen...
103       return null;
104    }
105 }
106