KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > taglib > MailForm


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.taglib;
24
25 import java.io.*;
26 import java.text.*;
27 import java.util.*;
28 import javax.servlet.*;
29 import javax.servlet.jsp.*;
30 import org.meshcms.core.*;
31 import org.meshcms.util.*;
32
33 /**
34  * Creates a mail form if a recipient has been specified for the page being
35  * viewed. If the editor is active, this tag writes the form field needed to
36  * specify the recipient address.
37  */

38 public final class MailForm extends AbstractTag {
39   public void writeTag() throws IOException, JspException {
40     String JavaDoc email = getPage().getProperty(PageAssembler.EMAIL_PARAM);
41
42     if (Utils.checkAddress(email)) {
43       try {
44         Path mailModulePath = webSite.getAdminModulesPath().add("mail");
45         String JavaDoc location = "meshcmsmailformtag";
46         ModuleDescriptor md = new ModuleDescriptor();
47         md.setLocation(location);
48         md.setArgument(email);
49         md.setModulePath(mailModulePath);
50         md.setPagePath(pagePath);
51         String JavaDoc moduleCode = "meshcmsmodule_" + location;
52         request.setAttribute(moduleCode, md);
53         pageContext.include("/" + webSite.getServedPath(mailModulePath) + "/" +
54             SiteMap.MODULE_INCLUDE_FILE + "?modulecode=" + moduleCode);
55       } catch (ServletException ex) {
56         throw new JspException(ex);
57       }
58     } else {
59       getOut().write(" ");
60     }
61   }
62
63   public void writeEditTag() throws IOException, JspException {
64     final String JavaDoc uniqueHash = Integer.toString(new Object JavaDoc().hashCode());
65     final String JavaDoc tagIdPrefix = "meshcmsmodule_mail_"+ uniqueHash +"_";
66     final String JavaDoc idCont = tagIdPrefix +"cont";
67     final String JavaDoc idElem = tagIdPrefix +"elem";
68     final String JavaDoc idIcon = tagIdPrefix +"icon";
69     final boolean isEditorModulesCollapsed = webSite.getConfiguration().isEditorModulesCollapsed();
70
71     Locale locale = WebUtils.getPageLocale(pageContext);
72     ResourceBundle bundle = ResourceBundle.getBundle("org/meshcms/webui/Locales", locale);
73
74     String JavaDoc email = getPage().getProperty(PageAssembler.EMAIL_PARAM);
75
76     Writer w = getOut();
77
78     if (isEditorModulesCollapsed) {
79       MessageFormat formatter = new MessageFormat("", locale);
80         w.write("<div id=\""+ idCont +"\" class='meshcmsfieldlabel' " +
81             " style=\"cursor:pointer;\" onclick=\"javascript:editor_moduleShow('"+ idCont +"','"+ idElem +"','"+ idIcon +"');\">" +
82             "<img alt=\"\" SRC=\"" + afp + "/images/tree_plus.gif\" id=\""+ idIcon +"\" />\n");
83         Object JavaDoc[] args = { bundle.getString("editorMailTitle"), email != null ? bundle.getString("editorMailTitle") : bundle.getString("editorNoTemplate"),
84                 Utils.noNull(email), "" };
85         formatter.applyPattern(bundle.getString("editorModuleLocExt"));
86         w.write("<label for=\""+ idElem +"\">"+ formatter.format(args) +"</label>");
87         w.write("</div>");
88     }
89
90     w.write("<fieldset "+ (isEditorModulesCollapsed ? "style=\"display:none;\"" : "") +
91             "class='meshcmseditor' id=\""+ idElem +"\">\n");
92     w.write("<legend>" + bundle.getString("editorMailTitle") + "</legend>\n");
93     w.write("<div class='meshcmsfieldlabel'>" + bundle.getString("editorMail") + "</div>\n");
94     w.write("<div class='meshcmsfield'><img alt=\"\" SRC='" + afp +
95       "/images/clear_field.gif' onclick=\"javascript:editor_clr('" +
96       PageAssembler.EMAIL_PARAM + "');\" style='vertical-align:middle;' /><input type='text' id='" +
97       PageAssembler.EMAIL_PARAM + "' name='" +
98       PageAssembler.EMAIL_PARAM + "' value=\"" +
99       Utils.noNull(email) + "\" style='width: 12em;' /></div>\n");
100     w.write("</fieldset>");
101   }
102 }
103
Popular Tags