KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > frontend > templateone > CmsTemplateImprint


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/CmsTemplateImprint.java,v $
3  * Date : $Date: 2005/06/27 23:22:06 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.frontend.templateone;
33
34 import org.opencms.site.CmsSite;
35 import org.opencms.site.CmsSiteManager;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.xml.content.CmsXmlContent;
38
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40 import javax.servlet.http.HttpServletResponse JavaDoc;
41 import javax.servlet.jsp.PageContext JavaDoc;
42
43 /**
44  * Provides methods to build the imprint popup information of the pages of template one.<p>
45  *
46  * @author Andreas Zahner
47  *
48  * @version $Revision: 1.9 $
49  *
50  * @since 6.0.0
51  */

52 public class CmsTemplateImprint extends CmsTemplateBean {
53
54     /** Default file name of the imprint configuration file.<p> */
55     public static final String JavaDoc FILENAME_CONFIGFILE = "imprint";
56
57     /** Name of the property key to set the path to the configuration file.<p> */
58     public static final String JavaDoc PROPERTY_CONFIGFILE = "properties_imprint";
59
60     /** Name of the property key to set the link to the legal notes page.<p> */
61     public static final String JavaDoc PROPERTY_LINK_LEGAL = "link_legalnotes";
62
63     /** Name of the property key to set the link to the privacy policy page.<p> */
64     public static final String JavaDoc PROPERTY_LINK_PRIVACY = "link_privacy";
65
66     /** Stores the imprint configuration.<p> */
67     private CmsXmlContent m_configuration;
68
69     /**
70      * Empty constructor, required for every JavaBean.<p>
71      */

72     public CmsTemplateImprint() {
73
74         super();
75     }
76
77     /**
78      * Constructor, with parameters.<p>
79      *
80      * Use this constructor for the template.<p>
81      *
82      * @param context the JSP page context object
83      * @param req the JSP request
84      * @param res the JSP response
85      */

86     public CmsTemplateImprint(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
87
88         super();
89         init(context, req, res);
90     }
91
92     /**
93      * Returns the html of the email address for the imprint.<p>
94      *
95      * @param className the CSS class name for the table cells
96      * @param localeKey the key name for the localized entry description
97      * @return the html of the email address for the imprint
98      */

99     public String JavaDoc buildEmailEntry(String JavaDoc className, String JavaDoc localeKey) {
100
101         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
102         String JavaDoc nodeValue = getEmail("");
103         if (CmsStringUtil.isNotEmpty(nodeValue)) {
104             // build html if node value is not empty
105
result.append("<tr>\n\t<td class=\"");
106             result.append(className);
107             result.append("\" style=\"white-space: nowrap;\">");
108             result.append(key(localeKey));
109             result.append(":</td>\n\t<td class=\"");
110             result.append(className);
111             result.append("\">");
112             result.append("<a HREF=\"mailto:");
113             result.append(nodeValue);
114             result.append("\">");
115             result.append(nodeValue);
116             result.append("</a></td>\n</tr>");
117         }
118         return result.toString();
119     }
120
121     /**
122      * Builds the html for a single imprint information row.<p>
123      *
124      * If the required information is not configured, the row will not be displayed.<p>
125      *
126      * @param className the CSS class name for the table cells
127      * @param localeKey the key name for the localized entry description
128      * @param nodeName the name of the imprint configuration node
129      * @return the html for a single imprint information row
130      */

131     public String JavaDoc buildImprintEntry(String JavaDoc className, String JavaDoc localeKey, String JavaDoc nodeName) {
132
133         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
134         String JavaDoc nodeValue = "";
135         try {
136             // get value from configuration
137
nodeValue = m_configuration.getStringValue(getCmsObject(), nodeName, getRequestContext().getLocale());
138         } catch (Exception JavaDoc e) {
139             // ignore this exception
140
}
141         if (CmsStringUtil.isNotEmpty(nodeValue)) {
142             // build html if node value is not empty
143
result.append("<tr>\n\t<td class=\"");
144             result.append(className);
145             result.append("\" style=\"white-space: nowrap;\">");
146             result.append(key(localeKey));
147             result.append(":</td>\n\t<td class=\"");
148             result.append(className);
149             result.append("\">");
150             result.append(nodeValue);
151             result.append("</td>\n</tr>");
152         }
153         return result.toString();
154     }
155
156     /**
157      * Returns the value of the specified node name from the imprint configuration.<p>
158      *
159      * @param nodeName the name of the imprint configuration node
160      * @return the value of the specified node name from the imprint configuration
161      */

162     public String JavaDoc getImprintValue(String JavaDoc nodeName) {
163
164         String JavaDoc nodeValue = "";
165         try {
166             // get value from configuration
167
nodeValue = m_configuration.getStringValue(getCmsObject(), nodeName, getRequestContext().getLocale());
168             if (CmsStringUtil.isEmpty(nodeValue)) {
169                 return "";
170             }
171         } catch (Exception JavaDoc e) {
172             // ignore this exception, either configuration is not found or XML value is incorrect
173
}
174         return nodeValue;
175     }
176
177     /**
178      * Returns the substituted link to the legal notes page.<p>
179      *
180      * @return the substituted link to the legal notes page
181      */

182     public String JavaDoc getLinkLegalNotes() {
183
184         String JavaDoc link = property(PROPERTY_LINK_LEGAL, "search", "");
185         if ("".equals(link)) {
186             return "#";
187         } else {
188             return link(link);
189         }
190     }
191
192     /**
193      * Returns the substituted link to the privacy policy page.<p>
194      *
195      * @return the substituted link to the privacy policy page
196      */

197     public String JavaDoc getLinkPrivacy() {
198
199         String JavaDoc link = property(PROPERTY_LINK_PRIVACY, "search", "");
200         if ("".equals(link)) {
201             return "#";
202         } else {
203             return link(link);
204         }
205     }
206
207     /**
208      * Returns the URL of the page to be displayed on the imprint.<p>
209      *
210      * @return the URL of the page
211      */

212     public String JavaDoc getUrl() {
213
214         StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
215         CmsSite site = CmsSiteManager.getCurrentSite(getCmsObject());
216         result.append(site.getUrl());
217         result.append(link(getRequestContext().getUri()));
218         return result.toString();
219     }
220
221     /**
222      * Initialize this bean with the current page context, request and response.<p>
223      *
224      * It is required to call one of the init() methods before you can use the
225      * instance of this bean.
226      *
227      * @param context the JSP page context object
228      * @param req the JSP request
229      * @param res the JSP response
230      */

231     public void init(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
232
233         // call initialization of super class
234
super.init(context, req, res);
235         // set site root
236
String JavaDoc siteRoot = req.getParameter(CmsTemplateBean.PARAM_SITE);
237         if (CmsStringUtil.isNotEmpty(siteRoot)) {
238             getRequestContext().setSiteRoot(siteRoot);
239         }
240         // set uri to file that opened the imprint window
241
String JavaDoc oldUri = getRequestContext().getUri();
242         String JavaDoc uri = req.getParameter(CmsTemplateBean.PARAM_URI);
243         if (uri == null) {
244             uri = oldUri;
245         }
246         getRequestContext().setUri(uri);
247
248         // get configuration file path
249
String JavaDoc configFileName = property(PROPERTY_CONFIGFILE, "search", "");
250         if ("".equals(configFileName)) {
251             configFileName = getConfigPath() + FILENAME_CONFIGFILE;
252         }
253         // collect the configuration data
254
m_configuration = CmsTemplateBean.getConfigurationFile(configFileName, getCmsObject());
255     }
256
257     /**
258      * Returns the email address provided in the imprint configuration.<p>
259      *
260      * @param defaultValue email address used if no email is provided in the configuration.<p>
261      *
262      * @return the email address provided in the imprint configuration
263      */

264     protected String JavaDoc getEmail(String JavaDoc defaultValue) {
265
266         String JavaDoc nodeValue = "";
267         try {
268             // get email value from configuration
269
nodeValue = m_configuration.getStringValue(getCmsObject(), "email", getRequestContext().getLocale());
270         } catch (Exception JavaDoc e) {
271             // ignore this exception
272
}
273         if (CmsStringUtil.isEmpty(nodeValue)) {
274             // no email in configuration, use default value
275
nodeValue = defaultValue;
276         }
277         return nodeValue;
278     }
279
280 }
281
Popular Tags