+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 10.01.2013
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.simer;
+
+import org.splat.log.AppLogger;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.Interceptor;
+
+/**
+ * The interceptor that redirect to a page after login.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ *
+ */
+public abstract class AbstractRedirectAfterLoginInterceptor implements
+ Interceptor {
+
+ /**
+ * the logger.
+ */
+ protected final static AppLogger LOG = AppLogger
+ .getLogger(AbstractRedirectAfterLoginInterceptor.class);
+
+ /**
+ * The global result.
+ */
+ private String _globalResult;
+
+ /**
+ * Get the globalResult.
+ *
+ * @return the globalResult
+ */
+ public String getGlobalResult() {
+ return _globalResult;
+ }
+
+ /**
+ * Set the globalResult.
+ *
+ * @param globalResult
+ * the globalResult to set
+ */
+ public void setGlobalResult(final String globalResult) {
+ _globalResult = globalResult;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
+ */
+ public void destroy() {
+ LOG.debug("RedirectAfterLoginInterceptor destroyed.");
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
+ */
+ public void init() {
+ LOG.debug("RedirectAfterLoginInterceptor initialized.");
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
+ */
+ public String intercept(final ActionInvocation invocation) throws Exception { //NOPMD: RKV: because of struts invoke() method
+ LOG.debug("RedirectAfterLoginInterceptor before rendering.");
+
+ String result = getGlobalResult();
+
+ if (redirectCondition(invocation)) {
+ LOG.debug("RedirectAfterLoginInterceptor Redirection Needed");
+ } else {
+ result = invocation.invoke();
+ }
+ LOG.debug("RedirectAfterLoginInterceptor after rendering.");
+ return result;
+ }
+
+ /**
+ * Return true if it must to redirect on the global result.
+ *
+ * @param invocation
+ * the Invocation
+ * @return boolean true if we need to redirect to the global result
+ * @throws Exception
+ * exception
+ */
+ protected abstract boolean redirectCondition(
+ final ActionInvocation invocation) throws Exception; //NOPMD: RKV: because of struts invoke() method
+
+}