KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > news > CallCreateNewsItemBodyAction


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.news;
17
18 import com.blandware.atleap.webapp.action.core.BaseAction;
19 import com.blandware.atleap.webapp.form.NewsItemForm;
20 import com.blandware.atleap.webapp.util.core.LocaleUtil;
21 import com.blandware.atleap.webapp.util.core.WebappConstants;
22 import com.blandware.atleap.webapp.util.news.NewsModuleWebConstants;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * <p>Returns page with form to create news item body
33  * </p>
34  * <p><a HREF="CallCreateNewsItemBodyAction.java.htm"><i>View Source</i></a></p>
35  * <p/>
36  *
37  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
38  * @version $Revision: 1.23 $ $Date: 2006/03/10 17:10:31 $
39  * @struts.action path="/news/callCreateItemBody"
40  * input="inputForward"
41  * name="newsItemForm"
42  * validate="false"
43  * roles="news-item-create"
44  * scope="request"
45  * @struts.action-forward name="inputForward"
46  * path=".news.createItem"
47  * @struts.action-forward name="createNewsItemBody"
48  * path=".news.createItemBody"
49  * @struts.action-forward name="listNewsItems"
50  * path="/news/listItems.do"
51  * redirect="true"
52  */

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

63     public ActionForward execute(ActionMapping mapping, ActionForm form,
64                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
65
66         request.getSession().removeAttribute(NewsModuleWebConstants.NEWS_ITEM_SUBMITTED_ACTION_KEY);
67         NewsItemForm newsItemForm = (NewsItemForm) form;
68         String JavaDoc localesMode = newsItemForm.getLocalesMode();
69
70         if ( isBackPressed(request) ) {
71             // First check, may be session has been invalidated and we need to
72
// fill content locales again
73
if (request.getSession().getAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY) == null) {
74                 List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
75                 request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
76             }
77
78             // check 'check all' ckeckbox if needed
79
newsItemForm.setAllCheckedFlagForAnnotationCheckboxes(request, localesMode);
80
81             return mapping.findForward("inputForward");
82         }
83
84         if (isCancelled(request)) {
85             return mapping.findForward("listNewsItems");
86         }
87
88         if ( request.getSession().getAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY) == null ) {
89             List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
90             request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
91         }
92
93         // Check whether user came here not from previous page (or he switched
94
// edit mode/language during creating news item)
95
if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) && newsItemForm.getBodyCheckedBoxes().size() == 0 ) {
96             request.setAttribute("beginPage", mapping.findForward("listNewsItems").getPath());
97             return mapping.findForward("unsatisfiablePage");
98         }
99
100         saveToken(request);
101         return mapping.findForward("createNewsItemBody");
102     }
103 }
Popular Tags