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

📄 cmstemplatenavigation.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        // add current entry to temporary Map to create the sub menus
                        subNav.put(resName, navEntries);
                        if (manualConfig) {
                            // for manual configuration, additional information for the xpath is needed for the sub menus
                            subIndex.put(resName, menuIndexes + String.valueOf(i));
                        }
                    } else {
                        // no sub menu present, create common menu entry
                        result.append(">");
                        result.append(ne.getNavText());
                        result.append("</a>");
                    }
                }
            }
            result.append("</div>\n");

            StringBuffer openTag = new StringBuffer(8);
            if ("menu0".equals(prefix) && showAccessibleVersion()) {
                // create div that is displayed for accessible version
                CmsMessages messages = new CmsMessages(CmsTemplateBean.MESSAGE_BUNDLE, getRequestContext().getLocale());
                openTag.append("<div style=\"visibility: hidden; display:none;\">");
                openTag.append("<h3>").append(messages.key("headline.accessible.nav.headline")).append("</h3>");
                openTag.append("<p>").append(messages.key("headline.accessible.nav.text")).append("</p>");
                openTag.append("</div>");
            }
            if (entryPresent) {
                openTag.append("<div class=\"");
                openTag.append(styleClass);
                openTag.append("\" id=\"");
                openTag.append(prefix);
                openTag.append("\" onmouseover=\"menuMouseover(event);\">");
            } else {
                openTag.append("<div style=\"visibility: hidden;\" id=\"");
                openTag.append(prefix);
                openTag.append("\">");
            }
            result.insert(0, openTag);

            // add the sub menus recursively from temporary Map
            Iterator i = subNav.keySet().iterator();
            while (i.hasNext()) {
                String resName = (String)i.next();
                List navEntries = (List)subNav.get(resName);
                String newIndex = menuIndexes;
                if (manualConfig) {
                    // get the xpath information to build the submenus from the XML configuration
                    newIndex = (String)subIndex.get(resName);
                }
                result.append(getMenuNavigation(
                    navEntries,
                    styleClass,
                    prefix + "_" + resName.hashCode(),
                    currentDepth + 1,
                    newIndex));
            }
        }
        return result;
    }

    /**
     * Returns the URI of the page element to include on the left navigation.<p>
     * 
     * @return the URI of the page element to include on the left navigation
     */
    public String getNavLeftElementUri() {

        return m_navLeftElementUri;
    }

    /**
     * Returns the substituted path to the modules resource folder.<p>
     * 
     * @return the substituted path to the modules resource folder
     */
    public String getResourcePath() {

        return m_resPath;
    }

    /**
     * Returns the start folder for navigation and search results.<p>
     * 
     * @return the start folder for navigation and search results
     */
    public String getStartFolder() {

        return m_startFolder;
    }

    /**
     * Initialize this bean with the current page context, request and response.<p>
     * 
     * It is required to call one of the init() methods before you can use the 
     * instance of this bean.
     * 
     * @param context the JSP page context object
     * @param req the JSP request 
     * @param res the JSP response 
     */
    public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        // call initialization of super class
        super.init(context, req, res);
        // initialize members from request
        m_locale = req.getParameter(PARAM_LOCALE);
        if (m_locale == null) {
            m_locale = property(CmsPropertyDefinition.PROPERTY_LOCALE, "search", "en").toLowerCase();
        }
        m_showAccessibleVersion = Boolean.valueOf(req.getParameter(CmsTemplateBean.PARAM_ACCESSIBLE)).booleanValue();
        m_headNavFolder = req.getParameter(PARAM_HEADNAV_FOLDER);
        m_showHeadNavImages = Boolean.valueOf(req.getParameter(PARAM_HEADNAV_IMAGES)).booleanValue();
        m_headNavItemDefaultValue = true;
        m_headNavManual = Boolean.valueOf(req.getParameter(PARAM_HEADNAV_MANUAL)).booleanValue();
        m_headNavMarkCurrent = Boolean.valueOf(req.getParameter(PARAM_HEADNAV_MARKCURRENT)).booleanValue();
        m_headNavMenuClick = Boolean.valueOf(req.getParameter(PARAM_HEADNAV_MENUCLICK)).booleanValue();
        try {
            m_menuDepth = Integer.parseInt(req.getParameter(PARAM_HEADNAV_MENUDEPTH));
        } catch (Exception e) {
            m_menuDepth = 2;
        }
        m_navLeftElementUri = req.getParameter(PARAM_NAVLEFT_ELEMENTURI);
        m_navLeftShowSelected = Boolean.valueOf(req.getParameter(PARAM_NAVLEFT_SHOWSELECTED)).booleanValue();
        m_navLeftShowTree = Boolean.valueOf(req.getParameter(PARAM_NAVLEFT_SHOWTREE)).booleanValue();
        m_resPath = req.getParameter(PARAM_RESPATH);
        m_startFolder = req.getParameter(PARAM_STARTFOLDER);
        m_showMenus = Boolean.valueOf(req.getParameter(PARAM_SHOWMENUS)).booleanValue();
    }

    /**
     * Gets the localized resource string for a given message key.<p>
     * 
     * If the key was not found in the bundle, the return value is
     * <code>"??? " + keyName + " ???"</code>. This will also be returned 
     * if the bundle was not properly initialized first.
     * 
     * @param keyName the key for the desired string 
     * @return the resource string for the given key 
     */
    public String key(String keyName) {

        return messages().key(keyName);
    }

    /**
     * Returns the initialized CmsMessages object to use on the JSP template.<p>
     * 
     * @return the initialized CmsMessages object
     */
    public CmsMessages messages() {

        if (m_messages == null) {
            m_messages = getMessages(CmsTemplateBean.MESSAGE_BUNDLE, getLocale());
        }
        return m_messages;
    }

    /**
     * Sets the default value of the property <code>style_head_nav_showitem</code> in case the property is not set.<p>
     * 
     * @param defaultValue if true, all resources without property value are included in head menu, if false, vice versa
     */
    public void setHeadNavItemDefaultValue(boolean defaultValue) {

        m_headNavItemDefaultValue = defaultValue;
    }

    /**
     * Returns if the accessible version of the page should be shown.<p>
     * 
     * @return true if the accessible version should be shown, otherwise false
     */
    public boolean showAccessibleVersion() {

        return m_showAccessibleVersion;
    }

    /**
     * Returns if the head navigation should use images for the 1st navigation level.<p>
     * 
     * @return true if the head navigation should use images for the 1st navigation level, otherwise false
     */
    public boolean showHeadNavImages() {

        return m_showHeadNavImages;
    }

    /**
     * Returns if the second level navigation menus of the head navigation should be shown.<p>
     * 
     * @return true if the second level navigation menus of the head navigation should be shown
     */
    public boolean showMenus() {

        return m_showMenus;
    }

    /**
     * Returns true if the left navigation include element should be shown.<p>
     * 
     * @return true if the left navigation include element should be shown
     */
    public boolean showNavLeftElement() {

        return (getNavLeftElementUri() != null && !CmsTemplateBean.PROPERTY_VALUE_NONE.equals(getNavLeftElementUri()));
    }

    /**
     * Returns true if the left navigation follows the selection in the head navigation menu.<p>
     * 
     * @return true if the left navigation follows the selection in the head navigation menu
     */
    public boolean showNavLeftSelected() {

        return m_navLeftShowSelected;
    }

    /**
     * Returns true if the left navigation tree should be displayed.<p>
     * 
     * @return true if the left navigation tree should be displayed
     */
    public boolean showNavLeftTree() {

        return m_navLeftShowTree;
    }

    /**
     * Returns the String representation of the default value for the property <code>style_head_nav_showitem</code>.<p>
     * 
     * @return the String representation of the default value for the property <code>style_head_nav_showitem</code>
     */
    private String getHeadNavItemDefaultStringValue() {

        return "" + m_headNavItemDefaultValue;
    }

    /**
     * Checks if a list of navigation entries contains at least one element which is shown in the head navigation.<p>
     * 
     * @param navEntries the navigation elements to check
     * @return true if at least one element of the list should be shown in the head navigation
     */
    private boolean hasSubMenuEntries(List navEntries) {

        for (int i = navEntries.size() - 1; i >= 0; i--) {
            CmsJspNavElement nav = (CmsJspNavElement)navEntries.get(i);
            String showItemProperty = getHeadNavItemDefaultStringValue();
            if (getCmsObject().existsResource(nav.getResourceName())) {
                showItemProperty = property(
                    PROPERTY_HEADNAV_USE,
                    nav.getResourceName(),
                    getHeadNavItemDefaultStringValue());
            } else if (LOG.isWarnEnabled()) {
                LOG.warn(Messages.get().getBundle().key(
                    Messages.LOG_NAVIGATION_CONFIG_ERR_2,
                    nav.getResourceName(),
                    getRequestContext().getUri()));
            }
            if (Boolean.valueOf(showItemProperty).booleanValue()) {
                return true;
            }
        }
        return false;
    }

    /**
     * Determines if the current folder link in the left navigation is the same as the requested uri.<p>
     * 
     * Used to determine if a folder link is marked as "active".<p>
     * 
     * @param navPath the complete path of the current navigation element
     * @param fileUri the requested uri
     * @return true if the folder link is the same as the requested uri, otherwise false
     */
    private boolean isDefaultFile(String navPath, String fileUri) {

        String folderName = CmsResource.getFolderPath(fileUri);
        if (navPath.equals(folderName)) {
            String fileName = CmsResource.getName(fileUri);
            try {
                // check if the "default-file" property was used on the folder
                String defaultFileName = getCmsObject().readPropertyObject(
                    folderName,
                    CmsPropertyDefinition.PROPERTY_DEFAULT_FILE,
                    false).getValue();
                if (defaultFileName != null && fileName.equals(defaultFileName)) {
                    // property was set and the requested file name matches the default file name
                    return true;
                }
            } catch (CmsException e) {
                // ignore exception, reading property failed
            }
            List defaultFileNames = OpenCms.getDefaultFiles();
            for (int i = 0; i < defaultFileNames.size(); i++) {
                String currFileName = (String)defaultFileNames.get(i);
                if (fileName.equals(currFileName)) {
                    return true;
                }
            }
        }

        // current uri does not match
        return false;
    }

    /**
     * Returns true if the head navigation is built manually using a XML content configuration file, otherwise false.<p>
     * 
     * @return true if the head navigation is built manually using a XML content configuration file, otherwise false
     */
    private boolean isHeadNavManual() {

        return m_headNavManual;
    }
}

⌨️ 快捷键说明

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