[opencms-dev] Solved: How to make my own CmsXmlNav for page path bar

Salvador Santander dominion.salvador.ext at juntadeandalucia.es
Mon Aug 4 15:23:01 CEST 2003


I've extended the CmsXmlNav and add the method eGetNavPath, wich is the
method getNavPath in OpenCms 5 but modified because this method it's wrong
( at least don't run in opencms 4.6 ). Thanks to Taras Vasylkevych
[t.vasylkevych at inmedias.de] for the idea.

public class PagePathXmlNav extends CmsXmlNav {


public Object eGetNavPath(CmsObject cms, String tagcontent, A_CmsXmlContent
doc, Object userObject) throws CmsException {
        // the result string holding the entire generated navigation path
        String navPath = "";

        // get the template file
        CmsXmlTemplateFile template = (CmsXmlTemplateFile)doc;

        // start absolute from root, or relative from the current folder?
        boolean startAbsolute = true;

        // the depth of the navigation path (= # of navigation levels)
        int requestedNavLevels = 1;

        // include the current folder in the path or not
        boolean includeCurrentFolder = true;

        // the navigation levels where we start and end to calculate the
path
        int startLevel = 0, endLevel = 0;


        // if there is no "naventry" datablock in the template, return an
empty string
        if (!template.hasData("naventry")) {
            template.setData("naventry", "" );
        }

        // if there is no "navcurrent" datablock in the template, use the
"naventry" instead
        if (!template.hasData("navcurrent")) {
            template.setData("navcurrent", template.getData("naventry"));
        }

        // parse the tag content
        if (!"".equals(tagcontent)) {
            StringTokenizer tagContentTokenizer = new StringTokenizer(
tagcontent, "," );

            if (tagContentTokenizer.countTokens()>=3) {
                // start absolute or relative?
                if (tagContentTokenizer.hasMoreTokens()) {
                    startAbsolute =
tagContentTokenizer.nextToken().trim().equalsIgnoreCase("absolute");
                }

                // include the current folder or not?
                if (tagContentTokenizer.hasMoreTokens()) {
                    includeCurrentFolder =
tagContentTokenizer.nextToken().trim().equalsIgnoreCase("this");
                }

                // max. depth
                if (tagContentTokenizer.hasMoreTokens()) {
                    try {
                        requestedNavLevels = Integer.parseInt(
tagContentTokenizer.nextToken() );
                    }
                    catch (Exception e) {
                        // get the requested folder
                        String requestedFolder =
cms.getRequestContext().currentFolder().getAbsolutePath();

                        // calculate the end navigation level in the path
                        endLevel = extractLevel( cms, requestedFolder );

                        requestedNavLevels = endLevel + 1;
                    }
                }
            }
        }

        // get the requested folder
        String requestedFolder =
cms.getRequestContext().currentFolder().getAbsolutePath();

        // calculate the end navigation level in the path
        endLevel = extractLevel( cms, requestedFolder );

        if (includeCurrentFolder) {
            endLevel++;
        }

        // calculate the start navigation level in the path
        if (startAbsolute) {
            startLevel = 1;
        }
        else {
            startLevel = endLevel - requestedNavLevels + 1;
        }

        for (int i = startLevel; i <= endLevel; i++) {
            String currentFolder = extractFolder( cms,i );

            // register the current folder for changes in the beloved
element cache
            Vector vfsDeps = new Vector();
            vfsDeps.add( cms.readFolder(currentFolder) );
            registerVariantDeps(cms, doc.getAbsoluteFilename(), null, null,
(Hashtable)userObject, vfsDeps, null, null);

            // add the current folder as the unique resource
            Vector resources = new Vector();
            resources.addElement( cms.readFolder(currentFolder,false) );

            // build the navigation for the current folder and append to the
path
            String currentNav = buildNav(cms,doc,userObject,resources);
            navPath += currentNav;
        }

        return navPath.getBytes();
    }




More information about the opencms-dev mailing list