[opencms-dev] Suggestion for OpenCms cms:navigation => an option for Visibility

Sandrine Prousteau s.prousteau at eurelis.com
Tue Dec 18 11:50:48 CET 2012


Hi
I'd like to suggest to add some options on the cms:navigation tag.


I found that there is "Visibility" option in the code, to list with or without "Hidden in navigation" pages.
I had to create a page with 2 menus : one on the left, one on the main column. The menu on the left displaying the tree in the site section should not display some special pages,  but the menu on the main column should display theses special pages (in the current folder level).
To do this, I set the special pages as "Hidden in navigation", and must have created a custom function to list the pages I wanted on right (this function in a mix of getNavigationForFolder(int level) and getNavigationForFolder(String folder,  Visibility visibility,  CmsResourceFilter resourceFilter) ) : 

It should be great if we have an tag attribute to manage level AND visibilities options!!


public java.util.List<CmsJspNavElement> getNavigationForFolder(
        org.opencms.file.CmsObject cms,
        int level,
        org.opencms.jsp.CmsJspNavBuilder.Visibility visibility,
        org.opencms.file.CmsResourceFilter resourceFilter) {

       org.apache.commons.logging.Log LOG = org.opencms.main.CmsLog.getLog(org.opencms.main.OpenCms.class);

        String folder = org.opencms.util.CmsFileUtil.removeTrailingSeparator(/*org.opencms.file.CmsResource.getFolderPath(*/cms.getRequestContext().getUri()/*)*/);
        LOG.debug("getNavigationForFolder : folder = " + folder);
        // If level is one just use root folder
     		org.opencms.jsp.CmsJspNavBuilder builder = new org.opencms.jsp.CmsJspNavBuilder(cms);
     		String finalfolder = folder;
        if (level == 0) {
        	finalfolder = "/";
          //  return builder.getNavigationForFolder("/");
        }
        String navfolder = org.opencms.file.CmsResource.getPathPart(folder, level);
        LOG.debug("getNavigationForFolder : navfolder = " + navfolder + " with level = " + level) ;
     		// If navigation folder found use it to build navigation
        if (navfolder != null) {
        	finalfolder = navfolder;
          //  return builder.getNavigationForFolder(navfolder);
        }
        LOG.debug("getNavigationForFolder : finalfolder = " + finalfolder);
        
        java.util.List<CmsJspNavElement> result = new java.util.ArrayList<CmsJspNavElement>();

        java.util.List<org.opencms.file.CmsResource> resources;
        try {

            resources = cms.getResourcesInFolder(finalfolder, resourceFilter);
        } catch (Exception e) {
            // should never happen
            return java.util.Collections.<CmsJspNavElement> emptyList();
        }
        boolean includeAll = visibility == org.opencms.jsp.CmsJspNavBuilder.Visibility.all;
        boolean includeHidden = visibility == org.opencms.jsp.CmsJspNavBuilder.Visibility.includeHidden;
        for (org.opencms.file.CmsResource r : resources) {
            CmsJspNavElement element = builder.getNavigationForResource(cms.getSitePath(r), resourceFilter);
            if ((element != null)
                && (includeAll || (element.isInNavigation() && (includeHidden || !element.isHiddenNavigationEntry())))) {
                result.add(element);
            }
        }
        java.util.Collections.sort(result);
        return result;
    }




Sandrine




More information about the opencms-dev mailing list