KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > core > mailTemplate > ViewMailTemplateAction


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.mailTemplate;
17
18 import com.blandware.atleap.common.Constants;
19 import com.blandware.atleap.common.util.ConvertUtil;
20 import com.blandware.atleap.model.core.MailTemplate;
21 import com.blandware.atleap.service.core.MailTemplateManager;
22 import com.blandware.atleap.webapp.action.core.BaseAction;
23 import com.blandware.atleap.webapp.form.MailTemplateForm;
24 import com.blandware.atleap.webapp.util.core.LocaleUtil;
25 import com.blandware.atleap.webapp.util.core.WebappConstants;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30 import org.apache.struts.action.ActionMessages;
31
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * <p>Exposes bean to request to view its properties on JSP template (mail
38  * template is to be viewed)
39  * </p>
40  * <p><a HREF="ViewMailTemplateAction.java.htm"><i>View Source</i></a></p>
41  * <p/>
42  *
43  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
44  * @version $Revision: 1.7 $ $Date: 2006/03/10 17:10:27 $
45  * @struts.action path="/core/mailTemplate/view"
46  * name="mailTemplateForm"
47  * scope="request"
48  * validate="false"
49  * roles="core-mailTemplate-view"
50  * @struts.action-forward name="viewMailTemplate"
51  * path=".core.mailTemplate.view"
52  * @struts.action-forward name="listMailTemplates"
53  * path="/core/mailTemplate/list.do"
54  * redirect="true"
55  */

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

66     public ActionForward execute(ActionMapping mapping, ActionForm form,
67                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68         MailTemplateForm mailTemplateForm = (MailTemplateForm) form;
69         Long JavaDoc mailTemplateId = null;
70         if ( mailTemplateForm.getId() != null ) {
71             mailTemplateId = Long.valueOf(mailTemplateForm.getId());
72         } else if ( request.getSession().getAttribute(WebappConstants.MAIL_TEMPLATE_ID_KEY) != null ) {
73             mailTemplateId = (Long JavaDoc) request.getSession().getAttribute(WebappConstants.MAIL_TEMPLATE_ID_KEY);
74         } else {
75             if ( log.isWarnEnabled() ) {
76                 log.warn("Missing mail template ID. Returning to list...");
77             }
78             return mapping.findForward("listMailTemplates");
79         }
80
81         MailTemplateManager mailTemplateManager = (MailTemplateManager) getBean(Constants.MAIL_TEMPLATE_MANAGER_BEAN);
82         MailTemplate mailTemplate = mailTemplateManager.retrieveMailTemplate(mailTemplateId);
83
84         if ( mailTemplate == null ) {
85             // mail template not found. it might be deleted by someone else
86
ActionMessages errors = new ActionMessages();
87             errors.add("mailTemplateNotFound", new ActionMessage("core.mailTemplate.errors.notFound"));
88             saveErrors(request, errors);
89             return mapping.findForward("listMailTemplates");
90         }
91
92         request.setAttribute("mailTemplate", mailTemplate);
93
94         
95
96         // export available variables to session
97

98         if ( mailTemplate.getAvailableVariables() != null && !mailTemplate.getAvailableVariables().isEmpty() ) {
99             request.getSession().setAttribute(WebappConstants.MAIL_TEMPLATE_AVAIALABLE_VARIABLES_KEY, ConvertUtil.convertListToString(mailTemplate.getAvailableVariables(), ", "));
100         } else {
101             request.getSession().removeAttribute(WebappConstants.MAIL_TEMPLATE_AVAIALABLE_VARIABLES_KEY);
102         }
103
104         List JavaDoc contentLocales = LocaleUtil.getInstance(servlet.getServletContext()).getAvailableLocales();
105
106         request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
107
108         return mapping.findForward("viewMailTemplate");
109     }
110 }
Popular Tags