📄 cmshelptemplatebean.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/help/CmsHelpTemplateBean.java,v $
* Date : $Date: 2006/03/28 07:53:22 $
* Version: $Revision: 1.21 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.workplace.help;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.CmsVfsResourceNotFoundException;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.jsp.CmsJspNavElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsMacroResolver;
import org.opencms.util.CmsPropertyUtils;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.logging.Log;
/**
* The bean that provides methods to build the HTML for the single online help frames.<p>
*
* <h4>Things to know</h4>
* <ul>
* <li>
* Online help will only work with resources of type xmlpage.
* <li>
* Content pages with a property <em>"template-elements"</em> set to a path of a ressource (jsp, page,...)
* will get the content produced by <code>{@link org.opencms.jsp.CmsJspActionElement#getContent(String)}</code>
* appended after their own output. This allows to use jsp's in the online help template.
* </ul>
*
* @author Andreas Zahner
* @author Achim Westermann
*
* @version $Revision: 1.21 $
*
* @since 6.0.0
*/
public class CmsHelpTemplateBean extends CmsDialog {
/** File name of the default help file to load. */
public static final String DEFAULT_HELPFILE = "index.html";
/** File name of the help mappings properties file(s). */
public static final String HELPMAPPINGS_FILENAME = "mappings_"
+ "${"
+ CmsMacroResolver.KEY_REQUEST_LOCALE
+ "}.properties";
/** The name of the help module. */
public static final String MODULE_NAME = "org.opencms.workplace.help";
/** Request parameter name for the buildframe flag parameter. */
public static final String PARAM_BUILDFRAME = "buildframe";
/** Request parameter name for the helpresource uri. */
public static final String PARAM_HELPRESOURCE = "helpresource";
/** Request parameter name for the homelink in head frame. */
public static final String PARAM_HOMELINK = "homelink";
/** Request parameter name for the workplaceresource uri. */
public static final String PARAM_WORKPLACERESOURCE = "workplaceresource";
/** VFS path to the help folder, contains a macro for the Locale which has to be resolved. */
public static final String PATH_HELP = CmsWorkplace.VFS_PATH_LOCALES
+ "${"
+ CmsMacroResolver.KEY_REQUEST_LOCALE
+ "}/help/";
/** Value of the NavInfo property indicating the start folder of the help. */
public static final String PROPERTY_VALUE_HELPSTART = "help.start";
/** Relative RFS path of the help mappings property file(s). */
public static final String RFS_HELPMAPPINGS = "classes/"
+ MODULE_NAME.replace('.', '/')
+ "/"
+ HELPMAPPINGS_FILENAME;
/** Absolute path to used JSP templates. */
public static final String TEMPLATEPATH = CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/jsptemplates/";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsHelpTemplateBean.class);
/** The online project that is switched to whenever body content is processed that should not be exported. */
private CmsProject m_offlineProject;
/** The online project that is switched to whenever body content is processed that shall be exported. */
private CmsProject m_onlineProject;
/** Request parameter for the help build frameset flag. */
private String m_paramBuildframe;
/** Request parameter for the help resource to display. */
private String m_paramHelpresource;
/** Request parameter for the home link to use in the head frame. */
private String m_paramHomelink;
/** Request parameter for the current workplace resource. */
private String m_paramWorkplaceresource;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsHelpTemplateBean(CmsJspActionElement jsp) {
super(jsp);
try {
m_onlineProject = getCms().readProject(CmsProject.ONLINE_PROJECT_ID);
m_offlineProject = jsp.getRequestContext().currentProject();
} catch (CmsException e) {
// failed to get online project
m_onlineProject = getCms().getRequestContext().currentProject();
}
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsHelpTemplateBean(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Returns the java script method to open the online help popup window.<p>
*
* @param locale the current users workplace Locale
* @return the java script method to open the online help popup window
*/
public static String buildOnlineHelpJavaScript(Locale locale) {
StringBuffer result = new StringBuffer(16);
// the online help invoker: pops up the window with url.
result.append("function openOnlineHelp(wpUri) {\n");
result.append("\tif (wpUri == null || wpUri == \"\") {\n");
result.append("\t\tif (top.body.top.body.admin_content != null && top.body.top.body.admin_content.onlineHelpUriCustom != null) {\n");
result.append("\t\t\twpUri = top.body.top.body.admin_content.onlineHelpUriCustom;\n");
result.append("\t\t}\n");
result.append("\t\telse{\n");
result.append("\t\t\tif (top.body != null && top.body.explorer_body != null) {\n");
result.append("\t\t\t\t// determine currently shown explorer item\n");
result.append("\t\t\t\ttry {\n");
result.append("\t\t\t\t\twpUri = top.body.explorer_body.explorer_files.location.pathname;\n");
result.append("\t\t\t\t} catch (e) {}\n");
result.append("\t\t\t} else if (top.body != null && top.body.admin_content != null) {\n");
result.append("\t\t\t\t// determine currently shown administration item\n");
result.append("\t\t\t\tvar parameters = \"\";\n");
result.append("\t\t\t\ttry {\n");
result.append("\t\t\t\t\tparameters = decodeURIComponent(top.body.admin_content.tool_title.location.search);\n");
result.append("\t\t\t\t} catch (e) {\n");
result.append("\t\t\t\t\ttry {\n");
result.append("\t\t\t\t\t\tparameters = decodeURIComponent(top.body.admin_content.location.search);\n");
result.append("\t\t\t\t\t} catch (e) {}\n");
result.append("\t\t\t\t}\n");
result.append("\t\t\t\tvar pathIndex = parameters.lastIndexOf(\"path=\");\n");
result.append("\t\t\t\tif (pathIndex != -1) {\n");
result.append("\t\t\t\t\tparameters = parameters.substring(pathIndex + 5);\n");
result.append("\t\t\t\t\tif (parameters.indexOf(\"&\") != -1) {\n");
result.append("\t\t\t\t\t\tparameters = parameters.substring(0, parameters.indexOf(\"&\"));\n");
result.append("\t\t\t\t\t}\n");
result.append("\t\t\t\t\twpUri = parameters + \"/\";\n");
result.append("\t\t\t\t} else {\n");
result.append("\t\t\t\t\twpUri = \"/administration/\"\n");
result.append("\t\t\t\t}\n");
result.append("\t\t\t} else if(top.body != null) {\n");
result.append("\t\t\t\twpUri = top.body.location.pathname;\n");
result.append("\t\t\t}\n");
result.append("\t\t}\n");
result.append("\t}\n");
result.append("\tif (wpUri==null) {\n");
result.append("\t\twpUri=\"/system/workplace/\";\n");
result.append("\t}\n");
result.append("\twindow.open(\"../locales/");
result.append(locale);
result.append("/help/index.html?").append(PARAM_BUILDFRAME).append("=true");
result.append("&").append(PARAM_WORKPLACERESOURCE).append("=\" + wpUri, \"cmsonlinehelp\", ");
result.append("\"toolbar=no,location=no,directories=no,status=yes,menubar=0,scrollbars=yes,resizable=yes,width=700,height=450\");\n");
result.append("}\n");
String s = result.toString();
return s;
}
/**
* Returns the HTML for the end of the page.<p>
*
* @return the HTML for the end of the page
*/
public String buildHtmlHelpEnd() {
StringBuffer result = new StringBuffer(4);
result.append("</body>\n");
result.append("</html>");
return result.toString();
}
/**
* Returns the HTML for the start of the page.<p>
*
* @param cssFile the CSS file name to use
* @param transitional if true, transitional doctype is used
* @return the HTML for the start of the page
*/
public String buildHtmlHelpStart(String cssFile, boolean transitional) {
StringBuffer result = new StringBuffer(8);
if (transitional) {
result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
} else {
result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
}
result.append("<html>\n");
result.append("<head>\n");
result.append("\t<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8");
result.append("\">\n");
result.append("\t<title>");
if (CmsStringUtil.isNotEmpty(getParamHelpresource())) {
result.append(getJsp().property(
CmsPropertyDefinition.PROPERTY_TITLE,
getParamHelpresource(),
key(Messages.GUI_HELP_FRAMESET_TITLE_0)));
} else {
result.append(key(Messages.GUI_HELP_FRAMESET_TITLE_0));
}
result.append("</title>\n");
result.append("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"");
result.append(getStyleUri(getJsp(), cssFile)).append("\">\n");
result.append("</head>\n");
return result.toString();
}
/**
* Returns the HTML for the body frame of the online help.<p>
*
* @return the HTML for the body frame of the online help
*/
public String displayBody() {
StringBuffer result = new StringBuffer(256);
// change to online project to allow static export
try {
getJsp().getRequestContext().setCurrentProject(m_onlineProject);
result.append(buildHtmlHelpStart("onlinehelp.css", true));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -