KickJava   Java API By Example, From Geeks To Geeks.

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


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

53 public final class CallCreateNewsItemAction 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         NewsItemForm newsItemForm = (NewsItemForm) form;
67
68         request.getSession().removeAttribute(NewsModuleWebConstants.NEWS_ITEM_SUBMITTED_ACTION_KEY);
69
70         List contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
71         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
72
73         // fill in publication and expiration date
74
Locale locale = getLocale(request);
75         if ( GenericValidator.isBlankOrNull(newsItemForm.getPublicationDate()) ) {
76             newsItemForm.setPublicationDate(DateUtil.formatDate(new Date(), locale));
77         }
78
79         if ( GenericValidator.isBlankOrNull(newsItemForm.getExpirationDate()) ) {
80             Calendar cal = Calendar.getInstance(locale);
81             cal.add(Calendar.YEAR, 1);
82             newsItemForm.setExpirationDate(DateUtil.formatDate(cal.getTime(), locale));
83         }
84
85         String JavaDoc localesMode = newsItemForm.getLocalesMode();
86         if ( !"current".equalsIgnoreCase(localesMode) && !"all".equalsIgnoreCase(localesMode) ) {
87             localesMode = "selected";
88         }
89         newsItemForm.setLocalesMode(localesMode);
90
91         // mark all locales as checked
92
Map annotationCheckedBoxes = newsItemForm.getAnnotationCheckedBoxes();
93         for (Iterator i = contentLocales.iterator(); i.hasNext();) {
94             ContentLocale contentLocale = (ContentLocale) i.next();
95             annotationCheckedBoxes.put(contentLocale.getIdentifier(), Boolean.TRUE);
96         }
97
98         // check 'check all' ckeckbox
99
if ("selected".equalsIgnoreCase(localesMode)) {
100             request.setAttribute(WebappConstants.SELECT_ALL_LOCALES_CHECKBOX_IS_CHECKED, Boolean.TRUE);
101         }
102
103         // save transaction token in request
104
saveToken(request);
105         return mapping.findForward("createNewsItem");
106     }
107 }
Popular Tags