KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > help > CmsHelpTemplateBean


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/help/CmsHelpTemplateBean.java,v $
3  * Date : $Date: 2006/03/28 07:53:22 $
4  * Version: $Revision: 1.21 $
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.workplace.help;
33
34 import org.opencms.file.CmsProject;
35 import org.opencms.file.CmsProperty;
36 import org.opencms.file.CmsPropertyDefinition;
37 import org.opencms.file.CmsResource;
38 import org.opencms.file.CmsResourceFilter;
39 import org.opencms.file.CmsVfsResourceNotFoundException;
40 import org.opencms.file.types.CmsResourceTypeXmlPage;
41 import org.opencms.i18n.CmsLocaleManager;
42 import org.opencms.jsp.CmsJspActionElement;
43 import org.opencms.jsp.CmsJspNavElement;
44 import org.opencms.main.CmsException;
45 import org.opencms.main.CmsLog;
46 import org.opencms.main.OpenCms;
47 import org.opencms.util.CmsMacroResolver;
48 import org.opencms.util.CmsPropertyUtils;
49 import org.opencms.util.CmsStringUtil;
50 import org.opencms.workplace.CmsDialog;
51 import org.opencms.workplace.CmsWorkplace;
52 import org.opencms.workplace.CmsWorkplaceSettings;
53
54 import java.io.IOException JavaDoc;
55 import java.util.Iterator JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.Locale JavaDoc;
58 import java.util.Map JavaDoc;
59
60 import javax.servlet.http.HttpServletRequest JavaDoc;
61 import javax.servlet.http.HttpServletResponse JavaDoc;
62 import javax.servlet.jsp.PageContext JavaDoc;
63
64 import org.apache.commons.collections.ExtendedProperties;
65 import org.apache.commons.logging.Log;
66
67 /**
68  * The bean that provides methods to build the HTML for the single online help frames.<p>
69  *
70  * <h4>Things to know</h4>
71  * <ul>
72  * <li>
73  * Online help will only work with resources of type xmlpage.
74  * <li>
75  * Content pages with a property <em>"template-elements"</em> set to a path of a ressource (jsp, page,...)
76  * will get the content produced by <code>{@link org.opencms.jsp.CmsJspActionElement#getContent(String)}</code>
77  * appended after their own output. This allows to use jsp's in the online help template.
78  * </ul>
79  *
80  * @author Andreas Zahner
81  * @author Achim Westermann
82  *
83  * @version $Revision: 1.21 $
84  *
85  * @since 6.0.0
86  */

87 public class CmsHelpTemplateBean extends CmsDialog {
88
89     /** File name of the default help file to load. */
90     public static final String JavaDoc DEFAULT_HELPFILE = "index.html";
91
92     /** File name of the help mappings properties file(s). */
93     public static final String JavaDoc HELPMAPPINGS_FILENAME = "mappings_"
94         + "${"
95         + CmsMacroResolver.KEY_REQUEST_LOCALE
96         + "}.properties";
97
98     /** The name of the help module. */
99     public static final String JavaDoc MODULE_NAME = "org.opencms.workplace.help";
100
101     /** Request parameter name for the buildframe flag parameter. */
102     public static final String JavaDoc PARAM_BUILDFRAME = "buildframe";
103
104     /** Request parameter name for the helpresource uri. */
105     public static final String JavaDoc PARAM_HELPRESOURCE = "helpresource";
106
107     /** Request parameter name for the homelink in head frame. */
108     public static final String JavaDoc PARAM_HOMELINK = "homelink";
109
110     /** Request parameter name for the workplaceresource uri. */
111     public static final String JavaDoc PARAM_WORKPLACERESOURCE = "workplaceresource";
112
113     /** VFS path to the help folder, contains a macro for the Locale which has to be resolved. */
114     public static final String JavaDoc PATH_HELP = CmsWorkplace.VFS_PATH_LOCALES
115         + "${"
116         + CmsMacroResolver.KEY_REQUEST_LOCALE
117         + "}/help/";
118
119     /** Value of the NavInfo property indicating the start folder of the help. */
120     public static final String JavaDoc PROPERTY_VALUE_HELPSTART = "help.start";
121
122     /** Relative RFS path of the help mappings property file(s). */
123     public static final String JavaDoc RFS_HELPMAPPINGS = "classes/"
124         + MODULE_NAME.replace('.', '/')
125         + "/"
126         + HELPMAPPINGS_FILENAME;
127
128     /** Absolute path to used JSP templates. */
129     public static final String JavaDoc TEMPLATEPATH = CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/jsptemplates/";
130
131     /** The log object for this class. */
132     private static final Log LOG = CmsLog.getLog(CmsHelpTemplateBean.class);
133
134     /** The online project that is switched to whenever body content is processed that should not be exported. */
135     private CmsProject m_offlineProject;
136
137     /** The online project that is switched to whenever body content is processed that shall be exported. */
138     private CmsProject m_onlineProject;
139
140     /** Request parameter for the help build frameset flag. */
141     private String JavaDoc m_paramBuildframe;
142
143     /** Request parameter for the help resource to display. */
144     private String JavaDoc m_paramHelpresource;
145
146     /** Request parameter for the home link to use in the head frame. */
147     private String JavaDoc m_paramHomelink;
148
149     /** Request parameter for the current workplace resource. */
150     private String JavaDoc m_paramWorkplaceresource;
151
152     /**
153      * Public constructor with JSP action element.<p>
154      *
155      * @param jsp an initialized JSP action element
156      */

157     public CmsHelpTemplateBean(CmsJspActionElement jsp) {
158
159         super(jsp);
160
161         try {
162             m_onlineProject = getCms().readProject(CmsProject.ONLINE_PROJECT_ID);
163             m_offlineProject = jsp.getRequestContext().currentProject();
164         } catch (CmsException e) {
165             // failed to get online project
166
m_onlineProject = getCms().getRequestContext().currentProject();
167         }
168     }
169
170     /**
171      * Public constructor with JSP variables.<p>
172      *
173      * @param context the JSP page context
174      * @param req the JSP request
175      * @param res the JSP response
176      */

177     public CmsHelpTemplateBean(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
178
179         this(new CmsJspActionElement(context, req, res));
180     }
181
182     /**
183      * Returns the java script method to open the online help popup window.<p>
184      *
185      * @param locale the current users workplace Locale
186      * @return the java script method to open the online help popup window
187      */

188     public static String JavaDoc buildOnlineHelpJavaScript(Locale JavaDoc locale) {
189
190         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
191
192         // the online help invoker: pops up the window with url.
193
result.append("function openOnlineHelp(wpUri) {\n");
194         result.append("\tif (wpUri == null || wpUri == \"\") {\n");
195         result.append("\t\tif (top.body.top.body.admin_content != null && top.body.top.body.admin_content.onlineHelpUriCustom != null) {\n");
196         result.append("\t\t\twpUri = top.body.top.body.admin_content.onlineHelpUriCustom;\n");
197         result.append("\t\t}\n");
198         result.append("\t\telse{\n");
199         result.append("\t\t\tif (top.body != null && top.body.explorer_body != null) {\n");
200         result.append("\t\t\t\t// determine currently shown explorer item\n");
201         result.append("\t\t\t\ttry {\n");
202         result.append("\t\t\t\t\twpUri = top.body.explorer_body.explorer_files.location.pathname;\n");
203         result.append("\t\t\t\t} catch (e) {}\n");
204         result.append("\t\t\t} else if (top.body != null && top.body.admin_content != null) {\n");
205         result.append("\t\t\t\t// determine currently shown administration item\n");
206         result.append("\t\t\t\tvar parameters = \"\";\n");
207         result.append("\t\t\t\ttry {\n");
208         result.append("\t\t\t\t\tparameters = decodeURIComponent(top.body.admin_content.tool_title.location.search);\n");
209         result.append("\t\t\t\t} catch (e) {\n");
210         result.append("\t\t\t\t\ttry {\n");
211         result.append("\t\t\t\t\t\tparameters = decodeURIComponent(top.body.admin_content.location.search);\n");
212         result.append("\t\t\t\t\t} catch (e) {}\n");
213         result.append("\t\t\t\t}\n");
214         result.append("\t\t\t\tvar pathIndex = parameters.lastIndexOf(\"path=\");\n");
215         result.append("\t\t\t\tif (pathIndex != -1) {\n");
216         result.append("\t\t\t\t\tparameters = parameters.substring(pathIndex + 5);\n");
217         result.append("\t\t\t\t\tif (parameters.indexOf(\"&\") != -1) {\n");
218         result.append("\t\t\t\t\t\tparameters = parameters.substring(0, parameters.indexOf(\"&\"));\n");
219         result.append("\t\t\t\t\t}\n");
220         result.append("\t\t\t\t\twpUri = parameters + \"/\";\n");
221         result.append("\t\t\t\t} else {\n");
222         result.append("\t\t\t\t\twpUri = \"/administration/\"\n");
223         result.append("\t\t\t\t}\n");
224         result.append("\t\t\t} else if(top.body != null) {\n");
225         result.append("\t\t\t\twpUri = top.body.location.pathname;\n");
226         result.append("\t\t\t}\n");
227         result.append("\t\t}\n");
228         result.append("\t}\n");
229         result.append("\tif (wpUri==null) {\n");
230         result.append("\t\twpUri=\"/system/workplace/\";\n");
231         result.append("\t}\n");
232         result.append("\twindow.open(\"../locales/");
233         result.append(locale);
234         result.append("/help/index.html?").append(PARAM_BUILDFRAME).append("=true");
235         result.append("&").append(PARAM_WORKPLACERESOURCE).append("=\" + wpUri, \"cmsonlinehelp\", ");
236         result.append("\"toolbar=no,location=no,directories=no,status=yes,menubar=0,scrollbars=yes,resizable=yes,width=700,height=450\");\n");
237         result.append("}\n");
238
239         String JavaDoc s = result.toString();
240         return s;
241     }
242
243     /**
244      * Returns the HTML for the end of the page.<p>
245      *
246      * @return the HTML for the end of the page
247      */

248     public String JavaDoc buildHtmlHelpEnd() {
249
250         StringBuffer JavaDoc result = new StringBuffer JavaDoc(4);
251         result.append("</body>\n");
252         result.append("</html>");
253         return result.toString();
254     }
255
256     /**
257      * Returns the HTML for the start of the page.<p>
258      *
259      * @param cssFile the CSS file name to use
260      * @param transitional if true, transitional doctype is used
261      * @return the HTML for the start of the page
262      */

263     public String JavaDoc buildHtmlHelpStart(String JavaDoc cssFile, boolean transitional) {
264
265         StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
266         if (transitional) {
267             result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
268         } else {
269             result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
270         }
271         result.append("<html>\n");
272         result.append("<head>\n");
273         result.append("\t<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8");
274         result.append("\">\n");
275         result.append("\t<title>");
276         if (CmsStringUtil.isNotEmpty(getParamHelpresource())) {
277             result.append(getJsp().property(
278                 CmsPropertyDefinition.PROPERTY_TITLE,
279                 getParamHelpresource(),
280                 key(Messages.GUI_HELP_FRAMESET_TITLE_0)));
281         } else {
282             result.append(key(Messages.GUI_HELP_FRAMESET_TITLE_0));
283         }
284         result.append("</title>\n");
285         result.append("\t<link rel=\"stylesheet\" type=\"text/css\" HREF=\"");
286         result.append(getStyleUri(getJsp(), cssFile)).append("\">\n");
287         result.append("</head>\n");
288         return result.toString();
289     }
290
291     /**
292      * Returns the HTML for the body frame of the online help.<p>
293      *
294      * @return the HTML for the body frame of the online help
295      */

296     public String JavaDoc displayBody() {
297
298         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
299
300         // change to online project to allow static export
301
try {
302             getJsp().getRequestContext().setCurrentProject(m_onlineProject);
303             result.append(buildHtmlHelpStart("onlinehelp.css", true));
304             result.append("<body>\n");
305             result.append("<a name=\"top\"></a>\n");
306             result.append("<table class=\"helpcontent\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
307             result.append("<tr>\n");
308             result.append("\t<td class=\"helpnav\">\n");
309             result.append("\t\t<a class=\"navhelphead\" HREF=\"javascript:top.body.location.href=top.head.homeLink;\">");
310             result.append(key(Messages.GUI_HELP_NAVIGATION_HEAD_0));
311             result.append("</a>\n");
312             result.append(buildHtmlHelpNavigation());
313             result.append("</td>\n");
314             result.append("\t<td class=\"helpcontent\">\n");
315             result.append("\t\t<h1>");
316             result.append(getJsp().property(
317                 CmsPropertyDefinition.PROPERTY_TITLE,
318                 getParamHelpresource(),
319                 key(Messages.GUI_HELP_FRAMESET_TITLE_0)));
320             result.append("</h1>\n");
321             // print navigation if property template-elements is set to sitemap
322
result.append(getJsp().getContent(getParamHelpresource(), "body", getLocale()));
323             try {
324                 // additionally allow appending content of dynamic pages whose path may be specified
325
// as value of property PROPERTY_TEMPLATE_ELEMENTS (currently sitemap.jsp and search.jsp are used)
326
CmsProperty elements = getCms().readPropertyObject(
327                     getParamHelpresource(),
328                     CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS,
329                     false);
330                 if (!elements.isNullProperty()) {
331                     try {
332                         // trigger an exception here as getContent won't throw anything!
333
getJsp().getCmsObject().readFile(elements.getValue());
334                         // Ok, ressource exists: switsch from the online project to turn of static export links.
335
String JavaDoc elementName = elements.getValue();
336                         // check, wether the "dynamic resource" wants to be exported or not:
337
boolean export = false;
338                         CmsProperty exportProp = getCms().readPropertyObject(
339                             elementName,
340                             CmsPropertyDefinition.PROPERTY_EXPORT,
341                             true);
342
343                         if (!exportProp.isNullProperty()) {
344                             export = Boolean.valueOf(exportProp.getValue(CmsStringUtil.FALSE)).booleanValue();
345                         }
346                         if (!export) {
347                             // switch back from online project to avoid export:
348
getJsp().getRequestContext().setCurrentProject(m_offlineProject);
349                         }
350                         result.append(getJsp().getContent(elements.getValue()));
351
352                     } catch (Throwable JavaDoc t) {
353                         CmsVfsResourceNotFoundException e2 = new CmsVfsResourceNotFoundException(
354                             Messages.get().container(
355                                 Messages.GUI_HELP_ERR_CONTENT_APPEND_2,
356                                 this.getParamHelpresource(),
357                                 elements.getValue(),
358                                 CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS),
359                             t);
360                         throw e2;
361                     }
362                 }
363             } catch (CmsException e1) {
364
365                 if (LOG.isErrorEnabled()) {
366                     LOG.error(e1);
367                 }
368                 result.append("<br>\n<div class=\"dialogerror\">");
369                 // getLocale() does not work in this context!?!
370
result.append(e1.getMessageContainer().key(Locale.GERMAN));
371                 result.append("</div>");
372             }
373             result.append("\t</td>\n");
374             result.append("</tr>\n");
375             result.append("</table>\n");
376             result.append(buildHtmlHelpEnd());
377             return result.toString();
378         } finally {
379             getJsp().getRequestContext().setCurrentProject(m_offlineProject);
380         }
381     }
382
383     /**
384      * Returns the HTML for the head frame of the online help.<p>
385      *
386      * @return the HTML for the head frame of the online help
387      */

388     public String JavaDoc displayHead() {
389
390         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
391
392         int buttonStyle = getSettings().getUserSettings().getWorkplaceButtonStyle();
393
394         // change to online project to allow exporting
395
try {
396             getJsp().getRequestContext().setCurrentProject(m_onlineProject);
397             String JavaDoc resourcePath = getJsp().link("/system/modules/" + MODULE_NAME + "/resources/");
398
399             result.append(buildHtmlHelpStart("workplace.css", false));
400             result.append("<body class=\"buttons-head\" unselectable=\"on\">\n");
401             result.append("<script type=\"text/javascript\" SRC=\"");
402             result.append(getJsp().link("/system/modules/org.opencms.workplace.help/resources/search.js"));
403             result.append("\"></script>\n");
404
405             // store home link in JS variable to use it in body frame
406
result.append("<script type=\"text/javascript\">\n<!--\n");
407             result.append("\tvar homeLink = \"");
408             result.append(getParamHomelink());
409             result.append("\";\n\n");
410             result.append("//-->\n</script>\n");
411
412             // search form with invisible elements
413

414             // search index may be attached to resource /system/modules/org.opencms.workplace.help/elements/search.jsp,
415
// property search.index.
416
String JavaDoc index = getJsp().property(
417                 "search.index",
418                 "/system/modules/org.opencms.workplace.help/elements/search.jsp",
419                 "German online help",
420                 false);
421             StringBuffer JavaDoc submitAction = new StringBuffer JavaDoc();
422             submitAction.append("parseSearchQuery(document.forms[\'searchform\'],\'");
423             submitAction.append(
424                 Messages.get().getBundle(getLocale()).key(Messages.GUI_HELP_ERR_SEARCH_WORD_LENGTH_1, new Integer JavaDoc(3))).append(
425                 "\');");
426
427             result.append("<form style=\"margin: 0;\" name=\"searchform\" method=\"post\" action=\"");
428             String JavaDoc searchLink = getJsp().link(
429                 new StringBuffer JavaDoc("/system/modules/org.opencms.workplace.help/elements/search.jsp?").append(
430                     CmsLocaleManager.PARAMETER_LOCALE).append("=").append(getLocale()).toString());
431             result.append(searchLink);
432             result.append("\" target=\"body\"");
433             result.append(" onsubmit=\"");
434             result.append(submitAction.toString());
435             result.append("\">\n");
436             result.append(" <input type=\"hidden\" name=\"action\" value=\"search\" />\n");
437             result.append(" <input type=\"hidden\" name=\"query\" value=\"\" />\n");
438             result.append(" <input type=\"hidden\" name=\"index\" value=\"" + index + "\" />\n");
439             result.append(" <input type=\"hidden\" name=\"searchPage\" value=\"1\" />\n");
440
441             result.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
442             result.append("<tr>\n");
443             result.append("\t<td align=\"left\">\n");
444
445             // display navigation buttons
446
result.append(buttonBar(HTML_START));
447             result.append(buttonBarStartTab(0, 5));
448             result.append(button(
449                 "javascript:history.back();",
450                 null,
451                 "back.png",
452                 org.opencms.search.Messages.GUI_HELP_BUTTON_BACK_0,
453                 buttonStyle,
454                 resourcePath));
455             result.append(button(
456                 "javascript:history.forward();",
457                 null,
458                 "next.png",
459                 org.opencms.search.Messages.GUI_HELP_BUTTON_NEXT_0,
460                 buttonStyle,
461                 resourcePath));
462
463             result.append(button(
464                 "javascript:top.body.location.href='" + getParamHomelink() + "';",
465                 null,
466                 "contents.png",
467                 org.opencms.search.Messages.GUI_HELP_BUTTON_CONTENTS_0,
468                 buttonStyle,
469                 resourcePath));
470             //search
471
result.append("<td style=\"vertical-align: top;\">");
472             result.append("<input type=\"text\" name=\"query2\" class=\"onlineform\" style=\"width: 120px\" value=\"");
473             result.append("");
474             result.append(" \">");
475             result.append("</td>\n");
476
477             result.append(button(
478                 new StringBuffer JavaDoc("javascript:").append(submitAction.toString()).toString(),
479                 null,
480                 null,
481                 org.opencms.search.Messages.GUI_HELP_BUTTON_SEARCH_0,
482                 2,
483                 null));
484
485             result.append(buttonBar(HTML_END));
486
487             result.append("</td>\n");
488             result.append("\t<td align=\"right\" width=\"100%\">\n");
489
490             // display close button
491
result.append(buttonBar(HTML_START));
492             result.append(buttonBarSeparator(5, 0));
493             result.append(button(
494                 "javascript:top.close();",
495                 null,
496                 "close",
497                 org.opencms.search.Messages.GUI_HELP_BUTTON_CLOSE_0,
498                 buttonStyle,
499                 resourcePath));
500             result.append(buttonBar(HTML_END));
501
502             result.append("\t</td>\n");
503             result.append("\t<td>&nbsp;</td>\n");
504             result.append("<td>");
505
506             // display logo
507
result.append("<span style=\"display: block; width: 80px; height: 22px; background-image: url(\'");
508             result.append(getSkinUri());
509             result.append("commons/workplace.png");
510             result.append("\'); \"></span>");
511             result.append("</td>");
512             result.append("</tr>\n");
513             result.append("</table>\n");
514             result.append("</form>\n");
515             result.append(buildHtmlHelpEnd());
516
517             return result.toString();
518         } finally {
519             // set back to offline project
520
getJsp().getRequestContext().setCurrentProject(m_offlineProject);
521         }
522     }
523
524     /**
525      * Generates the HTML for the online help frameset or redirects to the help body, depending on the build frameset flag.<p>
526      *
527      * @return the HTML for the online help frameset or an empty String (redirect)
528      * @throws IOException if redirection fails
529      */

530     public String JavaDoc displayHelp() throws IOException JavaDoc {
531
532         String JavaDoc result = "";
533         // change to online project to allow static export / export links
534
try {
535             getJsp().getRequestContext().setCurrentProject(m_onlineProject);
536
537             if (isBuildFrameset()) {
538                 // build the online help frameset
539
result = displayFrameset();
540             } else {
541                 // redirect to the help body
542
StringBuffer JavaDoc bodyLink = new StringBuffer JavaDoc(8);
543                 bodyLink.append(TEMPLATEPATH);
544                 bodyLink.append("help_body.jsp?");
545                 bodyLink.append(CmsHelpTemplateBean.PARAM_HELPRESOURCE);
546                 bodyLink.append("=");
547                 bodyLink.append(getJsp().getRequestContext().getUri());
548                 bodyLink.append("&");
549                 bodyLink.append(CmsLocaleManager.PARAMETER_LOCALE);
550                 bodyLink.append("=");
551                 bodyLink.append(getLocale());
552                 // add the other parameters too!
553
String JavaDoc bodyLinkWithParams = attachRequestString(bodyLink.toString());
554                 String JavaDoc redirectLink = getJsp().link(bodyLinkWithParams);
555                 // set back to current project
556
getJsp().getResponse().sendRedirect(redirectLink);
557             }
558             return result;
559         } finally {
560             getJsp().getRequestContext().setCurrentProject(m_onlineProject);
561         }
562     }
563
564     /**
565      * Returns the buildframe parameter indicating if the frameset should be generated.<p>
566      *
567      * @return the buildframe parameter indicating if the frameset should be generated
568      */

569     public String JavaDoc getParamBuildframe() {
570
571         return m_paramBuildframe;
572     }
573
574     /**
575      * Returns the helpresource parameter value.<p>
576      *
577      * @return the helpresource parameter value
578      */

579     public String JavaDoc getParamHelpresource() {
580
581         if (m_paramHelpresource == null) {
582             m_paramHelpresource = resolveMacros(PATH_HELP) + DEFAULT_HELPFILE;
583         }
584
585         return m_paramHelpresource;
586     }
587
588     /**
589      * Returns the homelink parameter value.<p>
590      *
591      * @return the homelink parameter value
592      */

593     public String JavaDoc getParamHomelink() {
594
595         return m_paramHomelink;
596     }
597
598     /**
599      * Returns the workplaceresource parameter value.<p>
600      *
601      * @return the workplaceresource parameter value
602      */

603     public String JavaDoc getParamWorkplaceresource() {
604
605         return m_paramWorkplaceresource;
606     }
607
608     /**
609      * Sets the buildframe parameter indicating if the frameset should be generated.<p>
610      *
611      * @param buildframe the buildframe parameter indicating if the frameset should be generated
612      */

613     public void setParamBuildframe(String JavaDoc buildframe) {
614
615         m_paramBuildframe = buildframe;
616     }
617
618     /**
619      * Sets the helpresource parameter value.<p>
620      *
621      * @param helpresource the helpresource parameter value
622      */

623     public void setParamHelpresource(String JavaDoc helpresource) {
624
625         m_paramHelpresource = helpresource;
626     }
627
628     /**
629      * Sets the homelink parameter value.<p>
630      *
631      * @param homelink the homelink parameter value
632      */

633     public void setParamHomelink(String JavaDoc homelink) {
634
635         m_paramHomelink = homelink;
636     }
637
638     /**
639      * Sets the workplaceresource parameter value.<p>
640      *
641      * @param workplaceresource the workplaceresource parameter value
642      */

643     public void setParamWorkplaceresource(String JavaDoc workplaceresource) {
644
645         m_paramWorkplaceresource = workplaceresource;
646     }
647
648     /**
649      * Returns the HTML to build the navigation of the online help folder.<p>
650      *
651      * @return the HTML to build the navigation of the online help folder
652      */

653     protected String JavaDoc buildHtmlHelpNavigation() {
654
655         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
656         // determine current URI
657
String JavaDoc currentUri = getParamHelpresource();
658         // ignore ressources outside content folder: e.g. the search.html which
659
// is in the general help module and not the german or english online help folder.
660
if (currentUri == null || currentUri.indexOf("/workplace/locales/") == -1) {
661             // BUG!: getLocale().getLanguage() -> getCms().getRequestContext().getLocale() returns "en"!
662
//currentUri = "/system/workplace/locales/" + getLocale().getLanguage() + "/help/";
663
currentUri = resolveMacros(PATH_HELP) + DEFAULT_HELPFILE;
664         }
665         // determine level of help start folder
666
int helpLevel = CmsResource.getPathLevel(PATH_HELP);
667
668         // get a list of all pages / subfolders in the help folder
669
List JavaDoc navList = getJsp().getNavigation().getNavigationTreeForFolder(currentUri, helpLevel, 99);
670         Iterator JavaDoc i = navList.iterator();
671
672         while (i.hasNext()) {
673             CmsJspNavElement nav = (CmsJspNavElement)i.next();
674             // calculate level to display
675
int level = nav.getNavTreeLevel() - (helpLevel - 1);
676             if (nav.getResourceName().equals(currentUri)
677                 || (nav.isFolderLink() && currentUri.equals(nav.getResourceName() + "index.html"))) {
678                 result.append("\t\t<span class=\"navhelpcurrent\" style=\"padding-left: ");
679                 result.append(level * 10);
680                 result.append("px; background-position: ");
681                 result.append((level - 1) * 10);
682                 result.append("px 1px;\">");
683                 result.append(nav.getNavText());
684                 result.append("</span><br style=\"clear:left\">\n");
685             } else {
686                 result.append("\t\t<a class=\"navhelp\" style=\"padding-left: ");
687                 result.append(level * 10);
688                 result.append("px; background-position: ");
689                 result.append((level - 1) * 10);
690                 result.append("px 1px;\" HREF=\"");
691                 if (nav.isFolderLink()) {
692                     // append file name to folder links to avoid static export issues
693
result.append(getJsp().link(
694                         "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource="
695                             + nav.getResourceName()
696                             + "index.html&"
697                             + CmsLocaleManager.PARAMETER_LOCALE
698                             + "="
699                             + getLocale()));
700                 } else {
701                     result.append(getJsp().link(
702                         "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource="
703                             + nav.getResourceName()
704                             + "&"
705                             + CmsLocaleManager.PARAMETER_LOCALE
706                             + "="
707                             + getLocale()));
708                     // result.append(getJsp().link(nav.getResourceName()));
709
}
710                 result.append("\">");
711                 result.append(nav.getNavText());
712                 result.append("</a><br style=\"clear:left\">\n");
713             }
714         }
715         return result.toString();
716     }
717
718     /**
719      * Returns the HTML to build the frameset for the online help popup window.<p>
720      *
721      * @return the HTML to build the frameset for the online help popup window
722      */

723     protected String JavaDoc displayFrameset() {
724
725         StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
726         result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
727         result.append("<html>\n");
728         result.append("<head>\n");
729         result.append("\t<title>");
730         result.append(key(Messages.GUI_HELP_FRAMESET_TITLE_0));
731         result.append("</title>\n");
732
733         // script to avoid frameset display errors
734
result.append("<script type=\"text/javascript\">\n<!--\n");
735         result.append("\t if (window.name == \"body\") {\n");
736         result.append("\t\ttop.location.href = \"" + getJsp().link(getJsp().getRequestContext().getUri()) + "\";\n");
737         result.append("\t}\n");
738         result.append("//-->\n</script>\n");
739         result.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n");
740
741         result.append("</head>\n\n");
742         result.append("<frameset rows=\"24,*\" border=\"0\" frameborder=\"0\" framespacing=\"0\">\n");
743         result.append("\t<frame name=\"head\" SRC=\"");
744
745         StringBuffer JavaDoc headLink = new StringBuffer JavaDoc(8);
746         headLink.append(TEMPLATEPATH);
747         headLink.append("help_head.jsp?");
748         headLink.append(CmsLocaleManager.PARAMETER_LOCALE);
749         headLink.append("=");
750         headLink.append(getLocale());
751         headLink.append("&");
752         headLink.append(PARAM_HOMELINK);
753         headLink.append("=");
754         headLink.append(getParamHomelink());
755         result.append(getJsp().link(attachRequestString(headLink.toString())));
756         result.append("\" scrolling=\"no\" noresize>\n");
757         result.append("\t<frame name=\"body\" SRC=\"");
758         StringBuffer JavaDoc bodyLink = new StringBuffer JavaDoc(8);
759         bodyLink.append(TEMPLATEPATH);
760         bodyLink.append("help_body.jsp?");
761         bodyLink.append(CmsHelpTemplateBean.PARAM_HELPRESOURCE);
762         bodyLink.append("=");
763         bodyLink.append(getJsp().getRequestContext().getUri());
764         bodyLink.append("&");
765         bodyLink.append(CmsLocaleManager.PARAMETER_LOCALE);
766         bodyLink.append("=");
767         bodyLink.append(getLocale());
768         result.append(getJsp().link(bodyLink.toString()));
769         result.append("\" scrolling=\"auto\" noresize>\n");
770         result.append("</frameset>\n\n");
771         result.append("<body></body>\n");
772         result.append("</html>");
773
774         return result.toString();
775     }
776
777     /**
778      * Determines the mapped help page for a given workplace resource URI.<p>
779      *
780      * If a mapping information is found, the requested URI is set to the found value.<p>
781      *
782      * If no workplace resource URI is given, nothing is changed.<p>
783      */

784     protected void getMappedHelpUri() {
785
786         try {
787             getJsp().getRequestContext().setCurrentProject(m_onlineProject);
788             if (CmsStringUtil.isNotEmpty(getParamWorkplaceresource())) {
789                 // found a workplace resource parameter, try to get a mapping for it
790
String JavaDoc helpResource = null;
791                 String JavaDoc wpResource = getParamWorkplaceresource();
792                 if (getCms().existsResource(
793                     // todo: get thsis too.
794
resolveMacros(getParamWorkplaceresource()),
795                     CmsResourceFilter.requireType(CmsResourceTypeXmlPage.getStaticTypeId()))) {
796                     // given workplace resource is a page in VFS, use it as start point
797
helpResource = resolveMacros(getParamWorkplaceresource());
798                     setParamHomelink(getJsp().link(helpResource));
799                 } else {
800                     // given workplace resource does not exist, resolve mapping
801
try {
802
803                         // try to read the mappings from the current module
804
String JavaDoc absolutePath = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
805                             resolveMacros(RFS_HELPMAPPINGS));
806                         ExtendedProperties props = CmsPropertyUtils.loadProperties(absolutePath);
807
808                         if (wpResource.startsWith(OpenCms.getSystemInfo().getOpenCmsContext())) {
809                             // remove context from workplace path
810
wpResource = wpResource.substring(OpenCms.getSystemInfo().getOpenCmsContext().length());
811                         }
812                         // determine mapping for workplace resource
813
while (wpResource != null && CmsStringUtil.isEmpty(helpResource)) {
814                             helpResource = props.getString(wpResource, null);
815                             wpResource = CmsResource.getParentFolder(wpResource);
816                         }
817                     } catch (IOException JavaDoc e) {
818                         // no mappings found in module, ignore
819
}
820
821                     if (CmsStringUtil.isEmpty(helpResource)) {
822                         // no mapping found, use default help URI
823
helpResource = DEFAULT_HELPFILE;
824                     }
825                     // create path to the help resource
826
helpResource = resolveMacros(PATH_HELP) + helpResource;
827                     if (!getCms().existsResource(helpResource, CmsResourceFilter.IGNORE_EXPIRATION)) {
828                         helpResource = resolveMacros(PATH_HELP) + DEFAULT_HELPFILE;
829                     }
830                     setParamHomelink(getJsp().link(resolveMacros(PATH_HELP) + DEFAULT_HELPFILE));
831                 }
832                 // set URI to found help page URI
833
getJsp().getRequestContext().setUri(helpResource);
834             }
835
836         } finally {
837             getJsp().getRequestContext().setCurrentProject(m_offlineProject);
838         }
839     }
840
841     /**
842      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
843      */

844     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
845
846         // fill the parameter values in the get/set methods
847
fillParamValues(request);
848
849         // determine initial page to show on frameset generation
850
if (isBuildFrameset()) {
851             // get the mapped URI
852
getMappedHelpUri();
853         }
854     }
855
856     /**
857      * Returns true if the online help frameset has to be generated.<p>
858      *
859      * @return true if the online help frameset has to be generated, otherwise false
860      */

861     protected boolean isBuildFrameset() {
862
863         return Boolean.valueOf(getParamBuildframe()).booleanValue();
864     }
865
866     /**
867      * @param ressourceName a name of a ressource
868      * @return The given ressources name with additional request parameter concatenations of the
869      * current request on this <code>CmsDialog</code>
870      *
871      */

872     private String JavaDoc attachRequestString(String JavaDoc ressourceName) {
873
874         StringBuffer JavaDoc result = new StringBuffer JavaDoc(ressourceName);
875         boolean firstParam = true;
876         if (ressourceName.indexOf('?') == -1) {
877             // no params in uri yet?
878
result.append('?');
879         } else {
880             firstParam = false;
881         }
882         Map.Entry JavaDoc entry;
883         Iterator JavaDoc it = getJsp().getRequest().getParameterMap().entrySet().iterator();
884         String JavaDoc[] values = null;
885         while (it.hasNext()) {
886             if (values == null) {
887                 // first iteration: check if params before so an & has to be used.
888
if (!firstParam) {
889                     result.append('&');
890                 }
891             } else {
892                 result.append("&");
893             }
894             entry = (Map.Entry JavaDoc)it.next();
895             result.append(entry.getKey().toString()).append('=');
896             values = (String JavaDoc[])entry.getValue();
897             for (int i = 0; i < values.length; i++) {
898                 result.append(values[i]);
899                 if (i + 1 < values.length) {
900                     result.append(',');
901                 }
902             }
903         }
904         return result.toString();
905     }
906
907 }
Popular Tags