KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentPage > ViewContentPageAction


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.contentPage;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.model.core.ContentPage;
20 import com.blandware.atleap.service.core.PageManager;
21 import com.blandware.atleap.webapp.action.core.BaseAction;
22 import com.blandware.atleap.webapp.form.ContentPageForm;
23 import com.blandware.atleap.webapp.util.core.LocaleUtil;
24 import com.blandware.atleap.webapp.util.core.WebappConstants;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionMessage;
29 import org.apache.struts.action.ActionMessages;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33 import java.util.List JavaDoc;
34
35 /**
36  * <p>Exposes bean to request to view its properties on JSP page (content page
37  * is to be viewed)
38  * </p>
39  * <p><a HREF="ViewContentPageAction.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.18 $ $Date: 2006/03/10 17:10:21 $
44  * @struts.action path="/core/contentPage/view"
45  * name="contentPageForm"
46  * scope="request"
47  * validate="false"
48  * roles="core-contentPage-view"
49  * @struts.action-forward name="viewContentPage"
50  * path=".core.contentPage.view"
51  * @struts.action-forward name="listContentPages"
52  * path="/core/contentPage/list.do"
53  * redirect="true"
54  */

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

65     public ActionForward execute(ActionMapping mapping, ActionForm form,
66                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
67         ContentPageForm contentPageForm = (ContentPageForm) form;
68         Long JavaDoc contentPageId = null;
69         if ( contentPageForm.getId() != null ) {
70             contentPageId = Long.valueOf(contentPageForm.getId());
71         } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_PAGE_ID_KEY) != null ) {
72             contentPageId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.CONTENT_PAGE_ID_KEY);
73         } else {
74             if ( log.isWarnEnabled() ) {
75                 log.warn("Missing content page ID. Returning to list...");
76             }
77             return mapping.findForward("listContentPages");
78         }
79
80         PageManager contentPageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN);
81         ContentPage contentPage = contentPageManager.retrieveContentPage(contentPageId);
82         if ( contentPage == null ) {
83             // content page not found. it might be deleted by someone else
84
ActionMessages errors = new ActionMessages();
85             errors.add("contentPageNotFound", new ActionMessage("core.contentPage.errors.notFound"));
86             saveErrors(request, errors);
87             return mapping.findForward("listContentPages");
88         }
89
90         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
91
92         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
93
94         // save owner ID in session
95
request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, contentPage.getId());
96         
97         request.setAttribute("contentPage", contentPage);
98         saveToken(request);
99         return mapping.findForward("viewContentPage");
100     }
101 }
Popular Tags