KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.util.PartialCollection;
20 import com.blandware.atleap.model.core.Layout;
21 import com.blandware.atleap.service.core.LayoutManager;
22 import com.blandware.atleap.webapp.action.core.BaseAction;
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.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * <p>Returns page with form to create new content page
38  * </p>
39  * <p><a HREF="CallCreateContentPageAction.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.17 $ $Date: 2006/03/10 17:10:20 $
44  * @struts.action path="/core/contentPage/callCreate"
45  * name="contentPageForm"
46  * validate="false"
47  * roles="core-contentPage-create"
48  * @struts.action-forward name="createContentPage"
49  * path=".core.contentPage.create"
50  * @struts.action-forward name="listContentPages"
51  * path="/core/contentPage/list.do"
52  * redirect="true"
53  */

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

64     public ActionForward execute(ActionMapping mapping, ActionForm form,
65                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
66
67         // Populate layout drop-down list
68
LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN);
69         PartialCollection layouts = null;
70         layouts = layoutManager.listLayouts(null);
71
72         if ( layouts != null ) {
73             for ( Iterator JavaDoc i = layouts.iterator(); i.hasNext(); ) {
74                 Layout layout = (Layout) i.next();
75                 if ( layout.getCpDefinition() == null || layout.getCpDefinition().length() == 0 ) {
76                     i.remove();
77                 }
78             }
79         }
80
81         if ( layouts == null || layouts.size() == 0 ) {
82             saveToken(request);
83             ActionMessages errors = new ActionMessages();
84             errors.add("noLayoutFound", new ActionMessage("core.contentPage.errors.noLayoutFound"));
85             saveErrors(request, errors);
86             return mapping.findForward("listContentPages");
87         }
88
89         request.getSession().setAttribute(WebappConstants.LAYOUT_COLLECTION_KEY, layouts);
90
91         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
92         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
93
94         // save transaction token in request
95
saveToken(request);
96         return mapping.findForward("createContentPage");
97     }
98 }
Popular Tags