KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > contentField > ListContentFieldsAction


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.contentField;
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.form.ContentFieldForm;
26 import com.blandware.atleap.webapp.util.core.WebappConstants;
27 import org.apache.commons.validator.GenericValidator;
28 import org.apache.struts.action.*;
29
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 /**
34  * <p>Forward to the page with list of content fields
35  * </p>
36  * <p><a HREF="ListContentFieldsAction.java.htm"><i>View Source</i></a></p>
37  * <p/>
38  *
39  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
40  * @version $Revision: 1.17 $ $Date: 2006/03/16 11:09:40 $
41  * @struts.action path="/core/contentField/list"
42  * name="contentFieldForm"
43  * validate="false"
44  * roles="core-contentField-list"
45  * @struts.action-forward name="viewLayout"
46  * path="/core/layout/view.do"
47  * redirect="true"
48  * @struts.action-forward name="viewContentPage"
49  * path="/core/contentPage/view.do"
50  * redirect="true"
51  * @struts.action-forward name="viewActionPage"
52  * path="/core/actionPage/view.do"
53  * redirect="true"
54  */

55 public final class ListContentFieldsAction 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
68
69         Long JavaDoc ownerId = null;
70         ContentFieldForm contentFieldForm = (ContentFieldForm) form;
71         if ( !GenericValidator.isBlankOrNull(contentFieldForm.getOwnerId()) ) {
72             ownerId = Long.valueOf(contentFieldForm.getOwnerId());
73         } else if ( request.getAttribute(WebappConstants.OWNER_ID_KEY) != null ) {
74             ownerId = (Long JavaDoc) request.getAttribute(WebappConstants.OWNER_ID_KEY);
75         } else if ( request.getSession().getAttribute(WebappConstants.OWNER_ID_KEY) != null ) {
76             ownerId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.OWNER_ID_KEY);
77         } else {
78             if ( log.isWarnEnabled() ) {
79                 log.warn("Missing owner ID. Returning to index...");
80             }
81             return mapping.findForward("admin");
82         }
83
84         LookupManager lookupManager = (LookupManager) getBean(Constants.LOOKUP_MANAGER_BEAN);
85         Localizable owner = lookupManager.retrieveLocalizable(ownerId);
86
87         if ( owner == null ) {
88             // owner not found - it might has been deleted
89
ActionMessages errors = new ActionMessages();
90             errors.add("ownerNotFound", new ActionMessage("core.contentField.errors.ownerNotFound"));
91             saveErrors(request, errors);
92             return mapping.findForward("admin");
93         }
94
95         String JavaDoc key = new String JavaDoc();
96         ActionForward forward = null;
97
98         if ( owner instanceof Layout ) {
99             forward = mapping.findForward("viewLayout");
100             key = WebappConstants.LAYOUT_ID_KEY;
101         } else if ( owner instanceof ContentPage ) {
102             forward = mapping.findForward("viewContentPage");
103             key = WebappConstants.CONTENT_PAGE_ID_KEY;
104         } else if ( owner instanceof ActionPage ) {
105             forward = mapping.findForward("viewActionPage");
106             key = WebappConstants.ACTION_PAGE_ID_KEY;
107         } else {
108             // TODO: temporary plug. fix it
109
forward = mapping.findForward("admin");
110         }
111
112         request.getSession().setAttribute(key, ownerId);
113
114         // save transaction token in request
115
saveToken(request);
116         return forward;
117     }
118 }
Popular Tags