View Javadoc
1   /*
2    * 
3    * $Revision: 1.11 $
4    * $Date: 2005/03/15 21:16:21 $
5    *
6    * ====================================================================
7    * struts-it
8    * Copyright (C) 2004-2005 - Manfred Wolff and the strutsit community
9    * 
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   * 
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   * 
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   * Projekt       : struts-it solutions for webbased projects
23   * Part          : demo application for the struts-it architecture
24   * Created       : 26.02.2005 mwolff
25   */
26  package org.struts.velocity.demo.login;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.apache.struts.action.ActionMessage;
31  import org.apache.struts.action.ActionMessages;
32  import org.struts.velocity.demo.util.Constants;
33  import org.strutsit.architecture.context.StrutsitContext;
34  import org.strutsit.architecture.hibernate.HibernateContext;
35  import org.strutsit.architecture.service.Service;
36  import org.strutsit.architecture.struts.StrutsitAction;
37  import org.strutsit.architecture.struts.StrutsitActionBase;
38  
39  /***
40   * Demonstrates:
41   *         <ul>
42   *         <li>How to use Action-Messages under Velocity</li>
43   *         <li>How to go back to the input form</li>
44   *         </ul>
45   * 
46   * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff</a>
47   * @since JDK 1.4
48   * @version $Revision: 1.11 $
49   * 
50   */
51  public class LogonAction extends StrutsitActionBase implements StrutsitAction {
52  
53      // the logger for this class
54      private static Log log = LogFactory.getLog(LogonAction.class);
55  
56      /***
57       * Execute-Methods for Struts-It Actions.
58       * 
59       * @param context The Context for this usecase
60       * @return true, if the request is fulfilled. In this case the context has
61       *         to return the next step. False, if the request is not fulfilled
62       *         yet.
63       */
64      public boolean execute(StrutsitContext context) throws Exception {
65  
66          // Cast the service to the proper type
67          HibernateContext hibContext = (HibernateContext) context;
68  
69          // Gets a service out of the HiveMind Registry
70          Service service = getService("org.struts.velocity.demo.service.LoginService");
71  
72          // Puts an action into the context
73          hibContext.setAction(Constants.LOGIN_COMPARE_PASSWD);
74  
75          // Executes the service
76          service.execute(hibContext);
77  
78          if (hibContext.getResult() == false) {
79              ActionMessages messages = new ActionMessages();
80              messages.add("", new ActionMessage("error.nameOrPassword"));
81              // reset the form
82              hibContext.resetForm();
83              saveMessages(hibContext.getRequest(), messages);
84              // return to input page
85              setInput(context);
86          } else {
87              setSucceeded(context);
88          }
89          hibContext.resetForm();
90          hibContext.release();
91          return true;
92      }
93  
94      /***
95       * Gets the corresponded use case for this action.
96       * 
97       * @return
98       */
99      public String getUseCase() {
100         return ("login");
101     }
102 }
103