KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > actions > RedirectAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
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. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.navigation.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28
29 import com.sslexplorer.boot.Util;
30 import com.sslexplorer.core.CoreUtil;
31 import com.sslexplorer.core.actions.DefaultAction;
32 import com.sslexplorer.navigation.forms.RedirectForm;
33 import com.sslexplorer.security.Constants;
34 import com.sslexplorer.security.SessionInfo;
35
36 /**
37  * Simple action that is used to perform visible redirects (i.e. a page is
38  * displayed to the user saying "You will be redirected to ..." or similar).
39  * <p>
40  * A meta refresh is used to perform
41  *
42  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class RedirectAction extends DefaultAction {
45
46     /*
47      * (non-Javadoc)
48      *
49      * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
50      * org.apache.struts.action.ActionForm,
51      * javax.servlet.http.HttpServletRequest,
52      * javax.servlet.http.HttpServletResponse)
53      */

54     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
55                     throws Exception JavaDoc {
56         super.execute(mapping, form, request, response);
57         String JavaDoc forwardTo = (String JavaDoc) request.getAttribute(Constants.REQ_ATTR_FORWARD_TO);
58         if (forwardTo == null) {
59             forwardTo = request.getParameter("forwardTo");
60             if (forwardTo == null) {
61                 throw new Exception JavaDoc("No forwardTo parameter provided.");
62             }
63         }
64         CoreUtil.checkSafeURI(forwardTo);
65         String JavaDoc folder = (String JavaDoc) request.getAttribute(Constants.REQ_ATTR_FOLDER);
66         if (folder == null) {
67             folder = request.getParameter("folder");
68         }
69         String JavaDoc target = (String JavaDoc) request.getAttribute(Constants.REQ_ATTR_TARGET);
70         if (target == null) {
71             target = request.getParameter("target");
72         }
73         ((RedirectForm) form).init(forwardTo, folder, target);
74         
75         // Workaround for IE7 not working with meta refresh tag
76
String JavaDoc execOnLoad = (String JavaDoc) request.getAttribute(Constants.REQ_ATTR_EXEC_ON_LOAD);
77         if (execOnLoad != null) {
78             execOnLoad = execOnLoad + " ; setTimeout('doRedirect()', 3000);";
79         }
80         else {
81             execOnLoad = "javascript: setTimeout('doRedirect()', 3000);";
82         }
83         request.setAttribute(Constants.REQ_ATTR_EXEC_ON_LOAD, execOnLoad);
84         Util.noCache(response);
85         return mapping.findForward("display");
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
92      * org.apache.struts.action.ActionForm,
93      * javax.servlet.http.HttpServletRequest,
94      * javax.servlet.http.HttpServletResponse)
95      */

96     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
97         return SessionInfo.ALL_CONTEXTS;
98     }
99
100 }
Popular Tags