0001: /*
0002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/help/CmsHelpTemplateBean.java,v $
0003: * Date : $Date: 2008-02-27 12:05:53 $
0004: * Version: $Revision: 1.24 $
0005: *
0006: * This library is part of OpenCms -
0007: * the Open Source Content Management System
0008: *
0009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
0010: *
0011: * This library is free software; you can redistribute it and/or
0012: * modify it under the terms of the GNU Lesser General Public
0013: * License as published by the Free Software Foundation; either
0014: * version 2.1 of the License, or (at your option) any later version.
0015: *
0016: * This library is distributed in the hope that it will be useful,
0017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019: * Lesser General Public License for more details.
0020: *
0021: * For further information about Alkacon Software GmbH, please see the
0022: * company website: http://www.alkacon.com
0023: *
0024: * For further information about OpenCms, please see the
0025: * project website: http://www.opencms.org
0026: *
0027: * You should have received a copy of the GNU Lesser General Public
0028: * License along with this library; if not, write to the Free Software
0029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030: */
0031:
0032: package org.opencms.workplace.help;
0033:
0034: import org.opencms.file.CmsProject;
0035: import org.opencms.file.CmsProperty;
0036: import org.opencms.file.CmsPropertyDefinition;
0037: import org.opencms.file.CmsResource;
0038: import org.opencms.file.CmsResourceFilter;
0039: import org.opencms.file.CmsVfsResourceNotFoundException;
0040: import org.opencms.file.types.CmsResourceTypeXmlPage;
0041: import org.opencms.i18n.CmsLocaleManager;
0042: import org.opencms.jsp.CmsJspActionElement;
0043: import org.opencms.jsp.CmsJspNavElement;
0044: import org.opencms.main.CmsException;
0045: import org.opencms.main.CmsLog;
0046: import org.opencms.main.OpenCms;
0047: import org.opencms.security.CmsRole;
0048: import org.opencms.security.CmsRoleViolationException;
0049: import org.opencms.util.CmsMacroResolver;
0050: import org.opencms.util.CmsPropertyUtils;
0051: import org.opencms.util.CmsStringUtil;
0052: import org.opencms.workplace.CmsDialog;
0053: import org.opencms.workplace.CmsWorkplace;
0054: import org.opencms.workplace.CmsWorkplaceSettings;
0055:
0056: import java.io.IOException;
0057: import java.util.Iterator;
0058: import java.util.List;
0059: import java.util.Locale;
0060: import java.util.Map;
0061:
0062: import javax.servlet.http.HttpServletRequest;
0063: import javax.servlet.http.HttpServletResponse;
0064: import javax.servlet.jsp.PageContext;
0065:
0066: import org.apache.commons.collections.ExtendedProperties;
0067: import org.apache.commons.logging.Log;
0068:
0069: /**
0070: * The bean that provides methods to build the HTML for the single online help frames.<p>
0071: *
0072: * <h4>Things to know</h4>
0073: * <ul>
0074: * <li>
0075: * Online help will only work with resources of type xmlpage.
0076: * <li>
0077: * Content pages with a property <em>"template-elements"</em> set to a path of a ressource (jsp, page,...)
0078: * will get the content produced by <code>{@link org.opencms.jsp.CmsJspActionElement#getContent(String)}</code>
0079: * appended after their own output. This allows to use jsp's in the online help template.
0080: * </ul>
0081: *
0082: * @author Andreas Zahner
0083: * @author Achim Westermann
0084: *
0085: * @version $Revision: 1.24 $
0086: *
0087: * @since 6.0.0
0088: */
0089: public class CmsHelpTemplateBean extends CmsDialog {
0090:
0091: /** File name of the default help file to load. */
0092: public static final String DEFAULT_HELPFILE = "index.html";
0093:
0094: /** File name of the help mappings properties file(s). */
0095: public static final String HELPMAPPINGS_FILENAME = "mappings_"
0096: + "${" + CmsMacroResolver.KEY_REQUEST_LOCALE
0097: + "}.properties";
0098:
0099: /** The name of the help module. */
0100: public static final String MODULE_NAME = "org.opencms.workplace.help";
0101:
0102: /** Request parameter name for the buildframe flag parameter. */
0103: public static final String PARAM_BUILDFRAME = "buildframe";
0104:
0105: /** Request parameter name for the helpresource uri. */
0106: public static final String PARAM_HELPRESOURCE = "helpresource";
0107:
0108: /** Request parameter name for the homelink in head frame. */
0109: public static final String PARAM_HOMELINK = "homelink";
0110:
0111: /** Request parameter name for the workplaceresource uri. */
0112: public static final String PARAM_WORKPLACERESOURCE = "workplaceresource";
0113:
0114: /** VFS path to the help folder, contains a macro for the Locale which has to be resolved. */
0115: public static final String PATH_HELP = CmsWorkplace.VFS_PATH_LOCALES
0116: + "${" + CmsMacroResolver.KEY_REQUEST_LOCALE + "}/help/";
0117:
0118: /** Value of the NavInfo property indicating the start folder of the help. */
0119: public static final String PROPERTY_VALUE_HELPSTART = "help.start";
0120:
0121: /** Relative RFS path of the help mappings property file(s). */
0122: public static final String RFS_HELPMAPPINGS = "classes/"
0123: + MODULE_NAME.replace('.', '/') + "/"
0124: + HELPMAPPINGS_FILENAME;
0125:
0126: /** Absolute path to used JSP templates. */
0127: public static final String TEMPLATEPATH = CmsWorkplace.VFS_PATH_MODULES
0128: + MODULE_NAME + "/jsptemplates/";
0129:
0130: /** The log object for this class. */
0131: private static final Log LOG = CmsLog
0132: .getLog(CmsHelpTemplateBean.class);
0133:
0134: /** The online project that is switched to whenever body content is processed that should not be exported. */
0135: private CmsProject m_offlineProject;
0136:
0137: /** The online project that is switched to whenever body content is processed that shall be exported. */
0138: private CmsProject m_onlineProject;
0139:
0140: /** Request parameter for the help build frameset flag. */
0141: private String m_paramBuildframe;
0142:
0143: /** Request parameter for the help resource to display. */
0144: private String m_paramHelpresource;
0145:
0146: /** Request parameter for the home link to use in the head frame. */
0147: private String m_paramHomelink;
0148:
0149: /** Request parameter for the current workplace resource. */
0150: private String m_paramWorkplaceresource;
0151:
0152: /**
0153: * Public constructor with JSP action element.<p>
0154: *
0155: * @param jsp an initialized JSP action element
0156: */
0157: public CmsHelpTemplateBean(CmsJspActionElement jsp) {
0158:
0159: super (jsp);
0160:
0161: try {
0162: m_onlineProject = getCms().readProject(
0163: CmsProject.ONLINE_PROJECT_ID);
0164: m_offlineProject = jsp.getRequestContext().currentProject();
0165: } catch (CmsException e) {
0166: // failed to get online project
0167: m_onlineProject = getCms().getRequestContext()
0168: .currentProject();
0169: }
0170: }
0171:
0172: /**
0173: * Public constructor with JSP variables.<p>
0174: *
0175: * @param context the JSP page context
0176: * @param req the JSP request
0177: * @param res the JSP response
0178: */
0179: public CmsHelpTemplateBean(PageContext context,
0180: HttpServletRequest req, HttpServletResponse res) {
0181:
0182: this (new CmsJspActionElement(context, req, res));
0183: }
0184:
0185: /**
0186: * Returns the java script method to open the online help popup window.<p>
0187: *
0188: * @param locale the current users workplace Locale
0189: * @return the java script method to open the online help popup window
0190: */
0191: public static String buildOnlineHelpJavaScript(Locale locale) {
0192:
0193: StringBuffer result = new StringBuffer(16);
0194:
0195: // the online help invoker: pops up the window with url.
0196: result.append("function openOnlineHelp(wpUri) {\n");
0197: result.append("\tif (wpUri == null || wpUri == \"\") {\n");
0198: result
0199: .append("\t\tif (top.body.top.body.admin_content != null && top.body.top.body.admin_content.onlineHelpUriCustom != null) {\n");
0200: result
0201: .append("\t\t\twpUri = top.body.top.body.admin_content.onlineHelpUriCustom;\n");
0202: result.append("\t\t}\n");
0203: result.append("\t\telse{\n");
0204: result
0205: .append("\t\t\tif (top.body != null && top.body.explorer_body != null) {\n");
0206: result
0207: .append("\t\t\t\t// determine currently shown explorer item\n");
0208: result.append("\t\t\t\ttry {\n");
0209: result
0210: .append("\t\t\t\t\twpUri = top.body.explorer_body.explorer_files.location.pathname;\n");
0211: result.append("\t\t\t\t} catch (e) {}\n");
0212: result
0213: .append("\t\t\t} else if (top.body != null && top.body.admin_content != null) {\n");
0214: result
0215: .append("\t\t\t\t// determine currently shown administration item\n");
0216: result.append("\t\t\t\tvar parameters = \"\";\n");
0217: result.append("\t\t\t\ttry {\n");
0218: result
0219: .append("\t\t\t\t\tparameters = decodeURIComponent(top.body.admin_content.tool_title.location.search);\n");
0220: result.append("\t\t\t\t} catch (e) {\n");
0221: result.append("\t\t\t\t\ttry {\n");
0222: result
0223: .append("\t\t\t\t\t\tparameters = decodeURIComponent(top.body.admin_content.location.search);\n");
0224: result.append("\t\t\t\t\t} catch (e) {}\n");
0225: result.append("\t\t\t\t}\n");
0226: result
0227: .append("\t\t\t\tvar pathIndex = parameters.lastIndexOf(\"path=\");\n");
0228: result.append("\t\t\t\tif (pathIndex != -1) {\n");
0229: result
0230: .append("\t\t\t\t\tparameters = parameters.substring(pathIndex + 5);\n");
0231: result
0232: .append("\t\t\t\t\tif (parameters.indexOf(\"&\") != -1) {\n");
0233: result
0234: .append("\t\t\t\t\t\tparameters = parameters.substring(0, parameters.indexOf(\"&\"));\n");
0235: result.append("\t\t\t\t\t}\n");
0236: result.append("\t\t\t\t\twpUri = parameters + \"/\";\n");
0237: result.append("\t\t\t\t} else {\n");
0238: result.append("\t\t\t\t\twpUri = \"/administration/\"\n");
0239: result.append("\t\t\t\t}\n");
0240: result.append("\t\t\t} else if(top.body != null) {\n");
0241: result.append("\t\t\t\twpUri = top.body.location.pathname;\n");
0242: result.append("\t\t\t}\n");
0243: result.append("\t\t}\n");
0244: result.append("\t}\n");
0245: result.append("\tif (wpUri==null) {\n");
0246: result.append("\t\twpUri=\"/system/workplace/\";\n");
0247: result.append("\t}\n");
0248: result.append("\twindow.open(\"../locales/");
0249: result.append(locale);
0250: result.append("/help/index.html?").append(PARAM_BUILDFRAME)
0251: .append("=true");
0252: result.append("&").append(PARAM_WORKPLACERESOURCE).append(
0253: "=\" + wpUri, \"cmsonlinehelp\", ");
0254: result
0255: .append("\"toolbar=no,location=no,directories=no,status=yes,menubar=0,scrollbars=yes,resizable=yes,width=700,height=450\");\n");
0256: result.append("}\n");
0257:
0258: String s = result.toString();
0259: return s;
0260: }
0261:
0262: /**
0263: * Returns the HTML for the end of the page.<p>
0264: *
0265: * @return the HTML for the end of the page
0266: */
0267: public String buildHtmlHelpEnd() {
0268:
0269: StringBuffer result = new StringBuffer(4);
0270: result.append("</body>\n");
0271: result.append("</html>");
0272: return result.toString();
0273: }
0274:
0275: /**
0276: * Returns the HTML for the start of the page.<p>
0277: *
0278: * @param cssFile the CSS file name to use
0279: * @param transitional if true, transitional doctype is used
0280: * @return the HTML for the start of the page
0281: */
0282: public String buildHtmlHelpStart(String cssFile,
0283: boolean transitional) {
0284:
0285: StringBuffer result = new StringBuffer(8);
0286: if (transitional) {
0287: result
0288: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
0289: } else {
0290: result
0291: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
0292: }
0293: result.append("<html>\n");
0294: result.append("<head>\n");
0295: result
0296: .append("\t<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8");
0297: result.append("\">\n");
0298: result.append("\t<title>");
0299: if (CmsStringUtil.isNotEmpty(getParamHelpresource())) {
0300: result.append(getJsp().property(
0301: CmsPropertyDefinition.PROPERTY_TITLE,
0302: getParamHelpresource(),
0303: key(Messages.GUI_HELP_FRAMESET_TITLE_0)));
0304: } else {
0305: result.append(key(Messages.GUI_HELP_FRAMESET_TITLE_0));
0306: }
0307: result.append("</title>\n");
0308: result
0309: .append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"");
0310: result.append(getStyleUri(getJsp(), cssFile)).append("\">\n");
0311: result.append("</head>\n");
0312: return result.toString();
0313: }
0314:
0315: /**
0316: * Returns the HTML for the body frame of the online help.<p>
0317: *
0318: * @return the HTML for the body frame of the online help
0319: */
0320: public String displayBody() {
0321:
0322: StringBuffer result = new StringBuffer(256);
0323:
0324: // change to online project to allow static export
0325: try {
0326: getJsp().getRequestContext().setCurrentProject(
0327: m_onlineProject);
0328: result.append(buildHtmlHelpStart("onlinehelp.css", true));
0329: result.append("<body>\n");
0330: result.append("<a name=\"top\"></a>\n");
0331: result
0332: .append("<table class=\"helpcontent\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
0333: result.append("<tr>\n");
0334: result.append("\t<td class=\"helpnav\">\n");
0335: result
0336: .append("\t\t<a class=\"navhelphead\" href=\"javascript:top.body.location.href=top.head.homeLink;\">");
0337: result.append(key(Messages.GUI_HELP_NAVIGATION_HEAD_0));
0338: result.append("</a>\n");
0339: result.append(buildHtmlHelpNavigation());
0340: result.append("</td>\n");
0341: result.append("\t<td class=\"helpcontent\">\n");
0342: result.append("\t\t<h1>");
0343: result.append(getJsp().property(
0344: CmsPropertyDefinition.PROPERTY_TITLE,
0345: getParamHelpresource(),
0346: key(Messages.GUI_HELP_FRAMESET_TITLE_0)));
0347: result.append("</h1>\n");
0348: // print navigation if property template-elements is set to sitemap
0349: result.append(getJsp().getContent(getParamHelpresource(),
0350: "body", getLocale()));
0351: try {
0352: // additionally allow appending content of dynamic pages whose path may be specified
0353: // as value of property PROPERTY_TEMPLATE_ELEMENTS (currently sitemap.jsp and search.jsp are used)
0354: CmsProperty elements = getCms()
0355: .readPropertyObject(
0356: getParamHelpresource(),
0357: CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS,
0358: false);
0359: if (!elements.isNullProperty()) {
0360: try {
0361: // trigger an exception here as getContent won't throw anything!
0362: getJsp().getCmsObject().readFile(
0363: elements.getValue());
0364: // Ok, ressource exists: switsch from the online project to turn of static export links.
0365: String elementName = elements.getValue();
0366: // check, wether the "dynamic resource" wants to be exported or not:
0367: boolean export = false;
0368: CmsProperty exportProp = getCms()
0369: .readPropertyObject(
0370: elementName,
0371: CmsPropertyDefinition.PROPERTY_EXPORT,
0372: true);
0373:
0374: if (!exportProp.isNullProperty()) {
0375: export = Boolean
0376: .valueOf(
0377: exportProp
0378: .getValue(CmsStringUtil.FALSE))
0379: .booleanValue();
0380: }
0381: if (!export) {
0382: // switch back from online project to avoid export:
0383: getJsp()
0384: .getRequestContext()
0385: .setCurrentProject(m_offlineProject);
0386: }
0387: result.append(getJsp().getContent(
0388: elements.getValue()));
0389:
0390: } catch (Throwable t) {
0391: CmsVfsResourceNotFoundException e2 = new CmsVfsResourceNotFoundException(
0392: Messages
0393: .get()
0394: .container(
0395: Messages.GUI_HELP_ERR_CONTENT_APPEND_2,
0396: this
0397: .getParamHelpresource(),
0398: elements.getValue(),
0399: CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS),
0400: t);
0401: throw e2;
0402: }
0403: }
0404: } catch (CmsException e1) {
0405:
0406: if (LOG.isErrorEnabled()) {
0407: LOG.error(e1);
0408: }
0409: result.append("<br>\n<div class=\"dialogerror\">");
0410: // getLocale() does not work in this context!?!
0411: result.append(e1.getMessageContainer().key(
0412: Locale.GERMAN));
0413: result.append("</div>");
0414: }
0415: result.append("\t</td>\n");
0416: result.append("</tr>\n");
0417: result.append("</table>\n");
0418: result.append(buildHtmlHelpEnd());
0419: return result.toString();
0420: } finally {
0421: getJsp().getRequestContext().setCurrentProject(
0422: m_offlineProject);
0423: }
0424: }
0425:
0426: /**
0427: * Returns the HTML for the head frame of the online help.<p>
0428: *
0429: * @return the HTML for the head frame of the online help
0430: */
0431: public String displayHead() {
0432:
0433: StringBuffer result = new StringBuffer(2048);
0434:
0435: int buttonStyle = getSettings().getUserSettings()
0436: .getWorkplaceButtonStyle();
0437:
0438: // change to online project to allow exporting
0439: try {
0440: getJsp().getRequestContext().setCurrentProject(
0441: m_onlineProject);
0442: String resourcePath = getJsp().link(
0443: "/system/modules/" + MODULE_NAME + "/resources/");
0444:
0445: result.append(buildHtmlHelpStart("workplace.css", false));
0446: result
0447: .append("<body class=\"buttons-head\" unselectable=\"on\">\n");
0448: result.append("<script type=\"text/javascript\" src=\"");
0449: result
0450: .append(getJsp()
0451: .link(
0452: "/system/modules/org.opencms.workplace.help/resources/search.js"));
0453: result.append("\"></script>\n");
0454:
0455: // store home link in JS variable to use it in body frame
0456: result.append("<script type=\"text/javascript\">\n<!--\n");
0457: result.append("\tvar homeLink = \"");
0458: result.append(getParamHomelink());
0459: result.append("\";\n\n");
0460: result.append("//-->\n</script>\n");
0461:
0462: // search form with invisible elements
0463:
0464: // search index may be attached to resource /system/modules/org.opencms.workplace.help/elements/search.jsp,
0465: // property search.index.
0466: String index = getJsp()
0467: .property(
0468: "search.index",
0469: "/system/modules/org.opencms.workplace.help/elements/search.jsp",
0470: "German online help", false);
0471: StringBuffer submitAction = new StringBuffer();
0472: submitAction
0473: .append("parseSearchQuery(document.forms[\'searchform\'],\'");
0474: submitAction.append(
0475: Messages.get().getBundle(getLocale()).key(
0476: Messages.GUI_HELP_ERR_SEARCH_WORD_LENGTH_1,
0477: new Integer(3))).append("\');");
0478:
0479: result
0480: .append("<form style=\"margin: 0;\" name=\"searchform\" method=\"post\" action=\"");
0481: String searchLink = getJsp()
0482: .link(
0483: new StringBuffer(
0484: "/system/modules/org.opencms.workplace.help/elements/search.jsp?")
0485: .append(
0486: CmsLocaleManager.PARAMETER_LOCALE)
0487: .append("=").append(getLocale())
0488: .toString());
0489: result.append(searchLink);
0490: result.append("\" target=\"body\"");
0491: result.append(" onsubmit=\"");
0492: result.append(submitAction.toString());
0493: result.append("\">\n");
0494: result
0495: .append(" <input type=\"hidden\" name=\"action\" value=\"search\" />\n");
0496: result
0497: .append(" <input type=\"hidden\" name=\"query\" value=\"\" />\n");
0498: result
0499: .append(" <input type=\"hidden\" name=\"index\" value=\""
0500: + index + "\" />\n");
0501: result
0502: .append(" <input type=\"hidden\" name=\"searchPage\" value=\"1\" />\n");
0503:
0504: result
0505: .append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
0506: result.append("<tr>\n");
0507: result.append("\t<td align=\"left\">\n");
0508:
0509: // display navigation buttons
0510: result.append(buttonBar(HTML_START));
0511: result.append(buttonBarStartTab(0, 5));
0512: result.append(button("javascript:history.back();", null,
0513: "back.png",
0514: org.opencms.search.Messages.GUI_HELP_BUTTON_BACK_0,
0515: buttonStyle, resourcePath));
0516: result.append(button("javascript:history.forward();", null,
0517: "next.png",
0518: org.opencms.search.Messages.GUI_HELP_BUTTON_NEXT_0,
0519: buttonStyle, resourcePath));
0520:
0521: result
0522: .append(button(
0523: "javascript:top.body.location.href='"
0524: + getParamHomelink() + "';",
0525: null,
0526: "contents.png",
0527: org.opencms.search.Messages.GUI_HELP_BUTTON_CONTENTS_0,
0528: buttonStyle, resourcePath));
0529: //search
0530: result.append("<td style=\"vertical-align: top;\">");
0531: result
0532: .append("<input type=\"text\" name=\"query2\" class=\"onlineform\" style=\"width: 120px\" value=\"");
0533: result.append("");
0534: result.append(" \">");
0535: result.append("</td>\n");
0536:
0537: result
0538: .append(button(
0539: new StringBuffer("javascript:").append(
0540: submitAction.toString()).toString(),
0541: null,
0542: null,
0543: org.opencms.search.Messages.GUI_HELP_BUTTON_SEARCH_0,
0544: 2, null));
0545:
0546: result.append(buttonBar(HTML_END));
0547:
0548: result.append("</td>\n");
0549: result.append("\t<td align=\"right\" width=\"100%\">\n");
0550:
0551: // display close button
0552: result.append(buttonBar(HTML_START));
0553: result.append(buttonBarSeparator(5, 0));
0554: result
0555: .append(button(
0556: "javascript:top.close();",
0557: null,
0558: "close",
0559: org.opencms.search.Messages.GUI_HELP_BUTTON_CLOSE_0,
0560: buttonStyle, resourcePath));
0561: result.append(buttonBar(HTML_END));
0562:
0563: result.append("\t</td>\n");
0564: result.append("\t<td> </td>\n");
0565: result.append("<td>");
0566:
0567: // display logo
0568: result
0569: .append("<span style=\"display: block; width: 80px; height: 22px; background-image: url(\'");
0570: result.append(getSkinUri());
0571: result.append("commons/workplace.png");
0572: result.append("\'); \"></span>");
0573: result.append("</td>");
0574: result.append("</tr>\n");
0575: result.append("</table>\n");
0576: result.append("</form>\n");
0577: result.append(buildHtmlHelpEnd());
0578:
0579: return result.toString();
0580: } finally {
0581: // set back to offline project
0582: getJsp().getRequestContext().setCurrentProject(
0583: m_offlineProject);
0584: }
0585: }
0586:
0587: /**
0588: * Generates the HTML for the online help frameset or redirects to the help body, depending on the build frameset flag.<p>
0589: *
0590: * @return the HTML for the online help frameset or an empty String (redirect)
0591: * @throws IOException if redirection fails
0592: */
0593: public String displayHelp() throws IOException {
0594:
0595: String result = "";
0596: // change to online project to allow static export / export links
0597: try {
0598: getJsp().getRequestContext().setCurrentProject(
0599: m_onlineProject);
0600:
0601: if (isBuildFrameset()) {
0602: // build the online help frameset
0603: result = displayFrameset();
0604: } else {
0605: // redirect to the help body
0606: StringBuffer bodyLink = new StringBuffer(8);
0607: bodyLink.append(TEMPLATEPATH);
0608: bodyLink.append("help_body.jsp?");
0609: bodyLink.append(CmsHelpTemplateBean.PARAM_HELPRESOURCE);
0610: bodyLink.append("=");
0611: bodyLink.append(getJsp().getRequestContext().getUri());
0612: bodyLink.append("&");
0613: bodyLink.append(CmsLocaleManager.PARAMETER_LOCALE);
0614: bodyLink.append("=");
0615: bodyLink.append(getLocale());
0616: // add the other parameters too!
0617: String bodyLinkWithParams = attachRequestString(bodyLink
0618: .toString());
0619: String redirectLink = getJsp().link(bodyLinkWithParams);
0620: // set back to current project
0621: getJsp().getResponse().sendRedirect(redirectLink);
0622: }
0623: return result;
0624: } finally {
0625: getJsp().getRequestContext().setCurrentProject(
0626: m_onlineProject);
0627: }
0628: }
0629:
0630: /**
0631: * Returns the buildframe parameter indicating if the frameset should be generated.<p>
0632: *
0633: * @return the buildframe parameter indicating if the frameset should be generated
0634: */
0635: public String getParamBuildframe() {
0636:
0637: return m_paramBuildframe;
0638: }
0639:
0640: /**
0641: * Returns the helpresource parameter value.<p>
0642: *
0643: * @return the helpresource parameter value
0644: */
0645: public String getParamHelpresource() {
0646:
0647: if (m_paramHelpresource == null) {
0648: m_paramHelpresource = resolveMacros(PATH_HELP)
0649: + DEFAULT_HELPFILE;
0650: }
0651:
0652: return m_paramHelpresource;
0653: }
0654:
0655: /**
0656: * Returns the homelink parameter value.<p>
0657: *
0658: * @return the homelink parameter value
0659: */
0660: public String getParamHomelink() {
0661:
0662: return m_paramHomelink;
0663: }
0664:
0665: /**
0666: * Returns the workplaceresource parameter value.<p>
0667: *
0668: * @return the workplaceresource parameter value
0669: */
0670: public String getParamWorkplaceresource() {
0671:
0672: return m_paramWorkplaceresource;
0673: }
0674:
0675: /**
0676: * Sets the buildframe parameter indicating if the frameset should be generated.<p>
0677: *
0678: * @param buildframe the buildframe parameter indicating if the frameset should be generated
0679: */
0680: public void setParamBuildframe(String buildframe) {
0681:
0682: m_paramBuildframe = buildframe;
0683: }
0684:
0685: /**
0686: * Sets the helpresource parameter value.<p>
0687: *
0688: * @param helpresource the helpresource parameter value
0689: */
0690: public void setParamHelpresource(String helpresource) {
0691:
0692: m_paramHelpresource = helpresource;
0693: }
0694:
0695: /**
0696: * Sets the homelink parameter value.<p>
0697: *
0698: * @param homelink the homelink parameter value
0699: */
0700: public void setParamHomelink(String homelink) {
0701:
0702: m_paramHomelink = homelink;
0703: }
0704:
0705: /**
0706: * Sets the workplaceresource parameter value.<p>
0707: *
0708: * @param workplaceresource the workplaceresource parameter value
0709: */
0710: public void setParamWorkplaceresource(String workplaceresource) {
0711:
0712: m_paramWorkplaceresource = workplaceresource;
0713: }
0714:
0715: /**
0716: * Returns the HTML to build the navigation of the online help folder.<p>
0717: *
0718: * @return the HTML to build the navigation of the online help folder
0719: */
0720: protected String buildHtmlHelpNavigation() {
0721:
0722: StringBuffer result = new StringBuffer(512);
0723: // determine current URI
0724: String currentUri = getParamHelpresource();
0725: // ignore ressources outside content folder: e.g. the search.html which
0726: // is in the general help module and not the german or english online help folder.
0727: if ((currentUri == null)
0728: || (currentUri.indexOf("/workplace/locales/") == -1)) {
0729: // BUG!: getLocale().getLanguage() -> getCms().getRequestContext().getLocale() returns "en"!
0730: //currentUri = "/system/workplace/locales/" + getLocale().getLanguage() + "/help/";
0731: currentUri = resolveMacros(PATH_HELP) + DEFAULT_HELPFILE;
0732: }
0733: // determine level of help start folder
0734: int helpLevel = CmsResource.getPathLevel(PATH_HELP);
0735:
0736: // get a list of all pages / subfolders in the help folder
0737: List navList = getJsp().getNavigation()
0738: .getNavigationTreeForFolder(currentUri, helpLevel, 99);
0739: Iterator i = navList.iterator();
0740:
0741: while (i.hasNext()) {
0742: CmsJspNavElement nav = (CmsJspNavElement) i.next();
0743: // calculate level to display
0744: int level = nav.getNavTreeLevel() - (helpLevel - 1);
0745: if (nav.getResourceName().equals(currentUri)
0746: || (nav.isFolderLink() && currentUri.equals(nav
0747: .getResourceName()
0748: + "index.html"))) {
0749: result
0750: .append("\t\t<span class=\"navhelpcurrent\" style=\"padding-left: ");
0751: result.append(level * 10);
0752: result.append("px; background-position: ");
0753: result.append((level - 1) * 10);
0754: result.append("px 1px;\">");
0755: result.append(nav.getNavText());
0756: result.append("</span><br style=\"clear:left\">\n");
0757: } else {
0758: result
0759: .append("\t\t<a class=\"navhelp\" style=\"padding-left: ");
0760: result.append(level * 10);
0761: result.append("px; background-position: ");
0762: result.append((level - 1) * 10);
0763: result.append("px 1px;\" href=\"");
0764: if (nav.isFolderLink()) {
0765: // append file name to folder links to avoid static export issues
0766: result
0767: .append(getJsp()
0768: .link(
0769: "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource="
0770: + nav
0771: .getResourceName()
0772: + "index.html&"
0773: + CmsLocaleManager.PARAMETER_LOCALE
0774: + "=" + getLocale()));
0775: } else {
0776: result
0777: .append(getJsp()
0778: .link(
0779: "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource="
0780: + nav
0781: .getResourceName()
0782: + "&"
0783: + CmsLocaleManager.PARAMETER_LOCALE
0784: + "=" + getLocale()));
0785: // result.append(getJsp().link(nav.getResourceName()));
0786: }
0787: result.append("\">");
0788: result.append(nav.getNavText());
0789: result.append("</a><br style=\"clear:left\">\n");
0790: }
0791: }
0792: return result.toString();
0793: }
0794:
0795: /**
0796: * @see org.opencms.workplace.CmsWorkplace#checkRole()
0797: */
0798: protected void checkRole() throws CmsRoleViolationException {
0799:
0800: // needed since these pages are static exported
0801: if (!OpenCms.getDefaultUsers().isUserExport(
0802: getCms().getRequestContext().currentUser().getName())) {
0803: // only for users that are not the export user
0804: OpenCms.getRoleManager().checkRole(getCms(),
0805: CmsRole.WORKPLACE_USER);
0806: }
0807: }
0808:
0809: /**
0810: * Returns the HTML to build the frameset for the online help popup window.<p>
0811: *
0812: * @return the HTML to build the frameset for the online help popup window
0813: */
0814: protected String displayFrameset() {
0815:
0816: StringBuffer result = new StringBuffer(8);
0817: result
0818: .append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
0819: result.append("<html>\n");
0820: result.append("<head>\n");
0821: result.append("\t<title>");
0822: result.append(key(Messages.GUI_HELP_FRAMESET_TITLE_0));
0823: result.append("</title>\n");
0824:
0825: // script to avoid frameset display errors
0826: result.append("<script type=\"text/javascript\">\n<!--\n");
0827: result.append("\t if (window.name == \"body\") {\n");
0828: result.append("\t\ttop.location.href = \""
0829: + getJsp().link(getJsp().getRequestContext().getUri())
0830: + "\";\n");
0831: result.append("\t}\n");
0832: result.append("//-->\n</script>\n");
0833: result
0834: .append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n");
0835:
0836: result.append("</head>\n\n");
0837: result
0838: .append("<frameset rows=\"24,*\" border=\"0\" frameborder=\"0\" framespacing=\"0\">\n");
0839: result.append("\t<frame name=\"head\" src=\"");
0840:
0841: StringBuffer headLink = new StringBuffer(8);
0842: headLink.append(TEMPLATEPATH);
0843: headLink.append("help_head.jsp?");
0844: headLink.append(CmsLocaleManager.PARAMETER_LOCALE);
0845: headLink.append("=");
0846: headLink.append(getLocale());
0847: headLink.append("&");
0848: headLink.append(PARAM_HOMELINK);
0849: headLink.append("=");
0850: headLink.append(getParamHomelink());
0851: result.append(getJsp().link(
0852: attachRequestString(headLink.toString())));
0853: result.append("\" scrolling=\"no\" noresize>\n");
0854: result.append("\t<frame name=\"body\" src=\"");
0855: StringBuffer bodyLink = new StringBuffer(8);
0856: bodyLink.append(TEMPLATEPATH);
0857: bodyLink.append("help_body.jsp?");
0858: bodyLink.append(CmsHelpTemplateBean.PARAM_HELPRESOURCE);
0859: bodyLink.append("=");
0860: bodyLink.append(getJsp().getRequestContext().getUri());
0861: bodyLink.append("&");
0862: bodyLink.append(CmsLocaleManager.PARAMETER_LOCALE);
0863: bodyLink.append("=");
0864: bodyLink.append(getLocale());
0865: result.append(getJsp().link(bodyLink.toString()));
0866: result.append("\" scrolling=\"auto\" noresize>\n");
0867: result.append("</frameset>\n\n");
0868: result.append("<body></body>\n");
0869: result.append("</html>");
0870:
0871: return result.toString();
0872: }
0873:
0874: /**
0875: * Determines the mapped help page for a given workplace resource URI.<p>
0876: *
0877: * If a mapping information is found, the requested URI is set to the found value.<p>
0878: *
0879: * If no workplace resource URI is given, nothing is changed.<p>
0880: */
0881: protected void getMappedHelpUri() {
0882:
0883: try {
0884: getJsp().getRequestContext().setCurrentProject(
0885: m_onlineProject);
0886: if (CmsStringUtil.isNotEmpty(getParamWorkplaceresource())) {
0887: // found a workplace resource parameter, try to get a mapping for it
0888: String helpResource = null;
0889: String wpResource = getParamWorkplaceresource();
0890: if (getCms().existsResource(
0891: // todo: get thsis too.
0892: resolveMacros(getParamWorkplaceresource()),
0893: CmsResourceFilter
0894: .requireType(CmsResourceTypeXmlPage
0895: .getStaticTypeId()))) {
0896: // given workplace resource is a page in VFS, use it as start point
0897: helpResource = resolveMacros(getParamWorkplaceresource());
0898: setParamHomelink(getJsp().link(helpResource));
0899: } else {
0900: // given workplace resource does not exist, resolve mapping
0901: try {
0902:
0903: // try to read the mappings from the current module
0904: String absolutePath = OpenCms
0905: .getSystemInfo()
0906: .getAbsoluteRfsPathRelativeToWebInf(
0907: resolveMacros(RFS_HELPMAPPINGS));
0908: ExtendedProperties props = CmsPropertyUtils
0909: .loadProperties(absolutePath);
0910:
0911: if (wpResource.startsWith(OpenCms
0912: .getSystemInfo().getOpenCmsContext())) {
0913: // remove context from workplace path
0914: wpResource = wpResource.substring(OpenCms
0915: .getSystemInfo()
0916: .getOpenCmsContext().length());
0917: }
0918: // determine mapping for workplace resource
0919: while ((wpResource != null)
0920: && CmsStringUtil.isEmpty(helpResource)) {
0921: helpResource = props.getString(wpResource,
0922: null);
0923: wpResource = CmsResource
0924: .getParentFolder(wpResource);
0925: }
0926: } catch (IOException e) {
0927: // no mappings found in module, ignore
0928: }
0929:
0930: if (CmsStringUtil.isEmpty(helpResource)) {
0931: // no mapping found, use default help URI
0932: helpResource = DEFAULT_HELPFILE;
0933: }
0934: // create path to the help resource
0935: helpResource = resolveMacros(PATH_HELP)
0936: + helpResource;
0937: if (!getCms().existsResource(helpResource,
0938: CmsResourceFilter.IGNORE_EXPIRATION)) {
0939: helpResource = resolveMacros(PATH_HELP)
0940: + DEFAULT_HELPFILE;
0941: }
0942: setParamHomelink(getJsp()
0943: .link(
0944: resolveMacros(PATH_HELP)
0945: + DEFAULT_HELPFILE));
0946: }
0947: // set URI to found help page URI
0948: getJsp().getRequestContext().setUri(helpResource);
0949: }
0950:
0951: } finally {
0952: getJsp().getRequestContext().setCurrentProject(
0953: m_offlineProject);
0954: }
0955: }
0956:
0957: /**
0958: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
0959: */
0960: protected void initWorkplaceRequestValues(
0961: CmsWorkplaceSettings settings, HttpServletRequest request) {
0962:
0963: // fill the parameter values in the get/set methods
0964: fillParamValues(request);
0965:
0966: // determine initial page to show on frameset generation
0967: if (isBuildFrameset()) {
0968: // get the mapped URI
0969: getMappedHelpUri();
0970: }
0971: }
0972:
0973: /**
0974: * Returns true if the online help frameset has to be generated.<p>
0975: *
0976: * @return true if the online help frameset has to be generated, otherwise false
0977: */
0978: protected boolean isBuildFrameset() {
0979:
0980: return Boolean.valueOf(getParamBuildframe()).booleanValue();
0981: }
0982:
0983: /**
0984: * @param ressourceName a name of a ressource
0985: * @return The given ressources name with additional request parameter concatenations of the
0986: * current request on this <code>CmsDialog</code>
0987: *
0988: */
0989: private String attachRequestString(String ressourceName) {
0990:
0991: StringBuffer result = new StringBuffer(ressourceName);
0992: boolean firstParam = true;
0993: if (ressourceName.indexOf('?') == -1) {
0994: // no params in uri yet?
0995: result.append('?');
0996: } else {
0997: firstParam = false;
0998: }
0999: Map.Entry entry;
1000: Iterator it = getJsp().getRequest().getParameterMap()
1001: .entrySet().iterator();
1002: String[] values = null;
1003: while (it.hasNext()) {
1004: if (values == null) {
1005: // first iteration: check if params before so an & has to be used.
1006: if (!firstParam) {
1007: result.append('&');
1008: }
1009: } else {
1010: result.append("&");
1011: }
1012: entry = (Map.Entry) it.next();
1013: result.append(entry.getKey().toString()).append('=');
1014: values = (String[]) entry.getValue();
1015: for (int i = 0; i < values.length; i++) {
1016: result.append(values[i]);
1017: if (i + 1 < values.length) {
1018: result.append(',');
1019: }
1020: }
1021: }
1022: return result.toString();
1023: }
1024:
1025: }
|