Salome HOME
Remove the scenario functionality is implemented
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / AbstractRedirectAfterLoginInterceptor.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   10.01.2013
6  * @author         $Author$
7  * @version        $Revision$
8  * @copyright      OPEN CASCADE 2012
9  *****************************************************************************/
10
11 package org.splat.simer;
12
13 import org.splat.log.AppLogger;
14
15 import com.opensymphony.xwork2.ActionInvocation;
16 import com.opensymphony.xwork2.interceptor.Interceptor;
17
18 /**
19  * The interceptor that redirect to a page after login.
20  * 
21  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
22  * 
23  */
24 public abstract class AbstractRedirectAfterLoginInterceptor implements
25                 Interceptor {
26
27         /**
28          * the logger.
29          */
30         protected final static AppLogger LOG = AppLogger
31                         .getLogger(AbstractRedirectAfterLoginInterceptor.class);
32
33         /**
34          * The global result.
35          */
36         private String _globalResult;
37
38         /**
39          * Get the globalResult.
40          * 
41          * @return the globalResult
42          */
43         public String getGlobalResult() {
44                 return _globalResult;
45         }
46
47         /**
48          * Set the globalResult.
49          * 
50          * @param globalResult
51          *            the globalResult to set
52          */
53         public void setGlobalResult(final String globalResult) {
54                 _globalResult = globalResult;
55         }
56
57         /**
58          * {@inheritDoc}
59          * 
60          * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
61          */
62         public void destroy() {
63                 LOG.debug("RedirectAfterLoginInterceptor destroyed.");
64         }
65
66         /**
67          * {@inheritDoc}
68          * 
69          * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
70          */
71         public void init() {
72                 LOG.debug("RedirectAfterLoginInterceptor initialized.");
73         }
74
75         /**
76          * {@inheritDoc}
77          * 
78          * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
79          */
80         public String intercept(final ActionInvocation invocation) throws Exception { //NOPMD: RKV: because of struts invoke() method
81                 LOG.debug("RedirectAfterLoginInterceptor before rendering.");
82
83                 String result = getGlobalResult();
84
85                 if (redirectCondition(invocation)) {
86                         LOG.debug("RedirectAfterLoginInterceptor Redirection Needed");
87                 } else {
88                         result = invocation.invoke();
89                 }
90                 LOG.debug("RedirectAfterLoginInterceptor after rendering.");
91                 return result;
92         }
93
94         /**
95          * Return true if it must to redirect on the global result.
96          * 
97          * @param invocation
98          *            the Invocation
99          * @return boolean true if we need to redirect to the global result
100          * @throws Exception
101          *             exception
102          */
103         protected abstract boolean redirectCondition(
104                         final ActionInvocation invocation) throws Exception; //NOPMD: RKV: because of struts invoke() method
105
106 }