KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > localizable > ViewLocalizableAction


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.localizable;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.ActionPage;
20 import com.blandware.atleap.model.core.ContentPage;
21 import com.blandware.atleap.model.core.Layout;
22 import com.blandware.atleap.model.core.Localizable;
23 import com.blandware.atleap.service.core.LookupManager;
24 import com.blandware.atleap.webapp.action.core.BaseAction;
25 import com.blandware.atleap.webapp.util.core.WebappConstants;
26 import org.apache.commons.validator.GenericValidator;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionMessages;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 /**
37  * <p>Forward to the page with info about localizable
38  * </p>
39  * <p><a HREF="ViewLocalizableAction.java.htm"><i>View Source</i></a></p>
40  * <p/>
41  *
42  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
43  * @version $Revision: 1.3 $ $Date: 2006/03/10 17:10:26 $
44  * @struts.action path="/core/localizable/view"
45  * roles="core-localizable-view"
46  * validate="false"
47  * @struts.action-forward name="viewLayout"
48  * path="/core/layout/view.do"
49  * redirect="true"
50  * @struts.action-forward name="viewContentPage"
51  * path="/core/contentPage/view.do"
52  * redirect="true"
53  * @struts.action-forward name="viewActionPage"
54  * path="/core/actionPage/view.do"
55  * redirect="true"
56  */

57 public final class ViewLocalizableAction extends BaseAction {
58     /**
59      * @param mapping The ActionMapping used to select this instance
60      * @param form The optional ActionForm bean for this request (if any)
61      * @param request The HTTP request we are proceeding
62      * @param response The HTTP response we are creating
63      * @return an ActionForward instance describing where and how
64      * control should be forwarded, or null if response
65      * has already been completed
66      */

67     public ActionForward execute(ActionMapping mapping, ActionForm form,
68                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
69
70         Long JavaDoc localizableId = null;
71         if ( !GenericValidator.isBlankOrNull(request.getParameter("id")) ) {
72             localizableId = Long.valueOf(request.getParameter("id"));
73         } else {
74             if ( log.isWarnEnabled() ) {
75                 log.warn("Missing localizable ID. Returning to index...");
76             }
77             return mapping.findForward("admin");
78         }
79
80         LookupManager lookupManager = (LookupManager) getBean(Constants.LOOKUP_MANAGER_BEAN);
81         Localizable localizable = lookupManager.retrieveLocalizable(localizableId);
82
83         if ( localizable == null ) {
84             // localizable not found - it might has been deleted
85
ActionMessages errors = new ActionMessages();
86             errors.add("localizableNotFound", new ActionMessage("core.localizable.errors.notFound", localizableId));
87             saveErrors(request, errors);
88             return mapping.findForward("admin");
89         }
90
91         String JavaDoc key = new String JavaDoc();
92         ActionForward forward = null;
93
94         if ( localizable instanceof Layout ) {
95             forward = mapping.findForward("viewLayout");
96             key = WebappConstants.LAYOUT_ID_KEY;
97         } else if ( localizable instanceof ContentPage ) {
98             forward = mapping.findForward("viewContentPage");
99             key = WebappConstants.CONTENT_PAGE_ID_KEY;
100         } else if ( localizable instanceof ActionPage ) {
101             forward = mapping.findForward("viewActionPage");
102             key = WebappConstants.ACTION_PAGE_ID_KEY;
103         }
104
105         request.getSession().setAttribute(key, localizableId);
106
107         // save transaction token in request
108
saveToken(request);
109
110         return forward;
111     }
112 }
Popular Tags