KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > editMode > SwitchEditModeAction


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.core.editMode;
17
18 import com.blandware.atleap.webapp.action.core.BaseAction;
19 import com.blandware.atleap.webapp.util.core.WebappConstants;
20 import org.apache.struts.action.ActionForm;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.action.ActionMapping;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import javax.servlet.http.HttpSession JavaDoc;
27
28 /**
29  * <p>Switches edit mode on or off
30  * </p>
31  * <p><a HREF="SwitchEditModeAction.java.htm"><i>View Source</i></a></p>
32  * <p/>
33  *
34  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
35  * @version $Revision: 1.2 $ $Date: 2006/03/10 17:10:23 $
36  * @struts.action path="/core/switchEditMode"
37  * scope="request"
38  * validate="false"
39  * roles="core-editMode-switch"
40  */

41 public final class SwitchEditModeAction extends BaseAction {
42     /**
43      * @param mapping The ActionMapping used to select this instance
44      * @param form The optional ActionForm bean for this request (if any)
45      * @param request The HTTP request we are proceeding
46      * @param response The HTTP response we are creating
47      * @return an ActionForward instance describing where and how
48      * control should be forwarded, or null if response
49      * has already been completed
50      */

51     public ActionForward execute(ActionMapping mapping, ActionForm form,
52                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
53
54         HttpSession JavaDoc session = request.getSession();
55         if ( session.getAttribute(WebappConstants.SITE_EDIT_MODE_ENABLED_KEY) == null ) {
56             // edit mode is disabled - turn it on
57
session.setAttribute(WebappConstants.SITE_EDIT_MODE_ENABLED_KEY, Boolean.TRUE);
58         } else {
59             // edit mode is enabled - turn it off
60
session.removeAttribute(WebappConstants.SITE_EDIT_MODE_ENABLED_KEY);
61         }
62
63         // return to page we are from
64

65         String JavaDoc redirectUrl = request.getParameter("redirectUrl");
66
67         if ( redirectUrl != null && redirectUrl.trim().length() != 0 ) {
68             ActionForward redirect = new ActionForward();
69             redirect.setRedirect(true);
70             redirect.setPath(redirectUrl);
71             return redirect;
72         } else {
73             return mapping.findForward("admin");
74         }
75     }
76
77 }
Popular Tags