Salome HOME
555b3a0d6a03f8845d36f517b794836a15ad5c7a
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SimanRedirectOnEndOfSessionInterceptor.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-2015
9  *****************************************************************************/
10
11 package org.splat.simer;
12
13 import org.apache.struts2.ServletActionContext;
14
15 import com.opensymphony.xwork2.ActionInvocation;
16
17 /**
18  * Redirect to a globalResult if the session has been invalidated.
19  * 
20  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
21  * 
22  */
23 public class SimanRedirectOnEndOfSessionInterceptor extends
24                 AbstractRedirectAfterLoginInterceptor {
25
26         /**
27          * Serial version UID.
28          */
29         private static final long serialVersionUID = -2669940721820416684L;
30
31         /**
32          * serialVersionUID.
33          */
34
35         /**
36          * globalResultActionName.
37          */
38         private String _globalResultActionName;
39
40         /**
41          * Get the globalResultActionName.
42          * 
43          * @return the globalResultActionName
44          */
45         public String getGlobalResultActionName() {
46                 return _globalResultActionName;
47         }
48
49         /**
50          * Set the globalResultActionName.
51          * 
52          * @param globalResultActionName
53          *            the globalResultActionName to set
54          */
55         public void setGlobalResultActionName(final String globalResultActionName) {
56                 _globalResultActionName = globalResultActionName;
57         }
58         
59         /**
60          * {@inheritDoc}
61          * 
62          * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
63          */
64         public String intercept(final ActionInvocation invocation) throws Exception { //NOPMD: RKV: because of struts invoke() method
65                 String result = super.intercept(invocation);
66                 if (result.equals(getGlobalResult())) { //Redirect happened
67                         ((Action)invocation.getAction()).setMessage("");
68                 }
69                 return result;
70         }
71
72         /**
73          * {@inheritDoc}
74          * 
75          * @see org.splat.simer.AbstractRedirectAfterLoginInterceptor#redirectCondition(com.opensymphony.xwork2.ActionInvocation)
76          */
77         @Override
78         protected boolean redirectCondition(final ActionInvocation invocation)
79                         throws Exception { // NOPMD: RKV: because of struts invoke() method
80                 String action = invocation.getInvocationContext().getName();
81                 boolean doRedirect = (!"index".equals(action));
82                 if (LOG.isDebugEnabled()) {
83                         LOG.debug("Entering redirectCondition Test: " + action);
84                         LOG
85                                         .debug("Do redirection: "
86                                                         + (doRedirect && (ServletActionContext.getRequest()
87                                                                         .getSession().getAttribute(
88                                                                                         Action.USER_RIGHTS) == null)));
89                 }
90                 return (doRedirect && (ServletActionContext.getRequest().getSession()
91                                 .getAttribute(Action.USER_RIGHTS) == null));
92         }
93
94 }