⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmshelptemplatebean.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

    /**
     * Sets the buildframe parameter indicating if the frameset should be generated.<p>
     *
     * @param buildframe the buildframe parameter indicating if the frameset should be generated
     */
    public void setParamBuildframe(String buildframe) {

        m_paramBuildframe = buildframe;
    }

    /**
     * Sets the helpresource parameter value.<p>
     *
     * @param helpresource the helpresource parameter value
     */
    public void setParamHelpresource(String helpresource) {

        m_paramHelpresource = helpresource;
    }

    /**
     * Sets the homelink parameter value.<p>
     *
     * @param homelink the homelink parameter value
     */
    public void setParamHomelink(String homelink) {

        m_paramHomelink = homelink;
    }

    /**
     * Sets the workplaceresource parameter value.<p>
     *
     * @param workplaceresource the workplaceresource parameter value
     */
    public void setParamWorkplaceresource(String workplaceresource) {

        m_paramWorkplaceresource = workplaceresource;
    }

    /**
     * Returns the HTML to build the navigation of the online help folder.<p>
     * 
     * @return the HTML to build the navigation of the online help folder
     */
    protected String buildHtmlHelpNavigation() {

        StringBuffer result = new StringBuffer(512);
        // determine current URI
        String currentUri = getParamHelpresource();
        // ignore ressources outside content folder: e.g. the search.html which 
        // is in the general help module and not the german or english online help folder.
        if (currentUri == null || currentUri.indexOf("/workplace/locales/") == -1) {
            // BUG!: getLocale().getLanguage() -> getCms().getRequestContext().getLocale() returns "en"!
            //currentUri = "/system/workplace/locales/" + getLocale().getLanguage() + "/help/";
            currentUri = resolveMacros(PATH_HELP) + DEFAULT_HELPFILE;
        }
        // determine level of help start folder
        int helpLevel = CmsResource.getPathLevel(PATH_HELP);

        // get a list of all pages / subfolders in the help folder
        List navList = getJsp().getNavigation().getNavigationTreeForFolder(currentUri, helpLevel, 99);
        Iterator i = navList.iterator();

        while (i.hasNext()) {
            CmsJspNavElement nav = (CmsJspNavElement)i.next();
            // calculate level to display
            int level = nav.getNavTreeLevel() - (helpLevel - 1);
            if (nav.getResourceName().equals(currentUri)
                || (nav.isFolderLink() && currentUri.equals(nav.getResourceName() + "index.html"))) {
                result.append("\t\t<span class=\"navhelpcurrent\" style=\"padding-left: ");
                result.append(level * 10);
                result.append("px; background-position: ");
                result.append((level - 1) * 10);
                result.append("px 1px;\">");
                result.append(nav.getNavText());
                result.append("</span><br style=\"clear:left\">\n");
            } else {
                result.append("\t\t<a class=\"navhelp\" style=\"padding-left: ");
                result.append(level * 10);
                result.append("px; background-position: ");
                result.append((level - 1) * 10);
                result.append("px 1px;\" href=\"");
                if (nav.isFolderLink()) {
                    // append file name to folder links to avoid static export issues
                    result.append(getJsp().link(
                        "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource="
                            + nav.getResourceName()
                            + "index.html&"
                            + CmsLocaleManager.PARAMETER_LOCALE
                            + "="
                            + getLocale()));
                } else {
                    result.append(getJsp().link(
                        "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource="
                            + nav.getResourceName()
                            + "&"
                            + CmsLocaleManager.PARAMETER_LOCALE
                            + "="
                            + getLocale()));
                    //                    result.append(getJsp().link(nav.getResourceName()));
                }
                result.append("\">");
                result.append(nav.getNavText());
                result.append("</a><br style=\"clear:left\">\n");
            }
        }
        return result.toString();
    }

    /**
     * Returns the HTML to build the frameset for the online help popup window.<p>
     * 
     * @return the HTML to build the frameset for the online help popup window
     */
    protected String displayFrameset() {

        StringBuffer result = new StringBuffer(8);
        result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
        result.append("<html>\n");
        result.append("<head>\n");
        result.append("\t<title>");
        result.append(key(Messages.GUI_HELP_FRAMESET_TITLE_0));
        result.append("</title>\n");

        // script to avoid frameset display errors
        result.append("<script type=\"text/javascript\">\n<!--\n");
        result.append("\t if (window.name == \"body\") {\n");
        result.append("\t\ttop.location.href = \"" + getJsp().link(getJsp().getRequestContext().getUri()) + "\";\n");
        result.append("\t}\n");
        result.append("//-->\n</script>\n");
        result.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n");

        result.append("</head>\n\n");
        result.append("<frameset rows=\"24,*\" border=\"0\" frameborder=\"0\" framespacing=\"0\">\n");
        result.append("\t<frame name=\"head\" src=\"");

        StringBuffer headLink = new StringBuffer(8);
        headLink.append(TEMPLATEPATH);
        headLink.append("help_head.jsp?");
        headLink.append(CmsLocaleManager.PARAMETER_LOCALE);
        headLink.append("=");
        headLink.append(getLocale());
        headLink.append("&");
        headLink.append(PARAM_HOMELINK);
        headLink.append("=");
        headLink.append(getParamHomelink());
        result.append(getJsp().link(attachRequestString(headLink.toString())));
        result.append("\" scrolling=\"no\" noresize>\n");
        result.append("\t<frame name=\"body\" src=\"");
        StringBuffer bodyLink = new StringBuffer(8);
        bodyLink.append(TEMPLATEPATH);
        bodyLink.append("help_body.jsp?");
        bodyLink.append(CmsHelpTemplateBean.PARAM_HELPRESOURCE);
        bodyLink.append("=");
        bodyLink.append(getJsp().getRequestContext().getUri());
        bodyLink.append("&");
        bodyLink.append(CmsLocaleManager.PARAMETER_LOCALE);
        bodyLink.append("=");
        bodyLink.append(getLocale());
        result.append(getJsp().link(bodyLink.toString()));
        result.append("\" scrolling=\"auto\" noresize>\n");
        result.append("</frameset>\n\n");
        result.append("<body></body>\n");
        result.append("</html>");

        return result.toString();
    }

    /**
     * Determines the mapped help page for a given workplace resource URI.<p>
     * 
     * If a mapping information is found, the requested URI is set to the found value.<p>
     * 
     * If no workplace resource URI is given, nothing is changed.<p>
     */
    protected void getMappedHelpUri() {

        try {
            getJsp().getRequestContext().setCurrentProject(m_onlineProject);
            if (CmsStringUtil.isNotEmpty(getParamWorkplaceresource())) {
                // found a workplace resource parameter, try to get a mapping for it
                String helpResource = null;
                String wpResource = getParamWorkplaceresource();
                if (getCms().existsResource(
                    // todo: get thsis too.
                    resolveMacros(getParamWorkplaceresource()),
                    CmsResourceFilter.requireType(CmsResourceTypeXmlPage.getStaticTypeId()))) {
                    // given workplace resource is a page in VFS, use it as start point
                    helpResource = resolveMacros(getParamWorkplaceresource());
                    setParamHomelink(getJsp().link(helpResource));
                } else {
                    // given workplace resource does not exist, resolve mapping
                    try {

                        // try to read the mappings from the current module
                        String absolutePath = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
                            resolveMacros(RFS_HELPMAPPINGS));
                        ExtendedProperties props = CmsPropertyUtils.loadProperties(absolutePath);

                        if (wpResource.startsWith(OpenCms.getSystemInfo().getOpenCmsContext())) {
                            // remove context from workplace path
                            wpResource = wpResource.substring(OpenCms.getSystemInfo().getOpenCmsContext().length());
                        }
                        // determine mapping for workplace resource
                        while (wpResource != null && CmsStringUtil.isEmpty(helpResource)) {
                            helpResource = props.getString(wpResource, null);
                            wpResource = CmsResource.getParentFolder(wpResource);
                        }
                    } catch (IOException e) {
                        // no mappings found in module, ignore              
                    }

                    if (CmsStringUtil.isEmpty(helpResource)) {
                        // no mapping found, use default help URI
                        helpResource = DEFAULT_HELPFILE;
                    }
                    // create path to the help resource
                    helpResource = resolveMacros(PATH_HELP) + helpResource;
                    if (!getCms().existsResource(helpResource, CmsResourceFilter.IGNORE_EXPIRATION)) {
                        helpResource = resolveMacros(PATH_HELP) + DEFAULT_HELPFILE;
                    }
                    setParamHomelink(getJsp().link(resolveMacros(PATH_HELP) + DEFAULT_HELPFILE));
                }
                // set URI to found help page URI
                getJsp().getRequestContext().setUri(helpResource);
            }

        } finally {
            getJsp().getRequestContext().setCurrentProject(m_offlineProject);
        }
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        // fill the parameter values in the get/set methods
        fillParamValues(request);

        // determine initial page to show on frameset generation
        if (isBuildFrameset()) {
            // get the mapped URI
            getMappedHelpUri();
        }
    }

    /**
     * Returns true if the online help frameset has to be generated.<p>
     * 
     * @return true if the online help frameset has to be generated, otherwise false
     */
    protected boolean isBuildFrameset() {

        return Boolean.valueOf(getParamBuildframe()).booleanValue();
    }

    /**
     * @param ressourceName a name of a ressource
     * @return The given ressources name with additional request parameter concatenations of the 
     *         current request on this <code>CmsDialog</code> 
     * 
     */
    private String attachRequestString(String ressourceName) {

        StringBuffer result = new StringBuffer(ressourceName);
        boolean firstParam = true;
        if (ressourceName.indexOf('?') == -1) {
            // no params in uri yet?
            result.append('?');
        } else {
            firstParam = false;
        }
        Map.Entry entry;
        Iterator it = getJsp().getRequest().getParameterMap().entrySet().iterator();
        String[] values = null;
        while (it.hasNext()) {
            if (values == null) {
                // first iteration: check if params before so an & has to be used.
                if (!firstParam) {
                    result.append('&');
                }
            } else {
                result.append("&");
            }
            entry = (Map.Entry)it.next();
            result.append(entry.getKey().toString()).append('=');
            values = (String[])entry.getValue();
            for (int i = 0; i < values.length; i++) {
                result.append(values[i]);
                if (i + 1 < values.length) {
                    result.append(',');
                }
            }
        }
        return result.toString();
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -