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

📄 cmsjspnavbuilder.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Each of the nav elements in the list has the {@link CmsJspNavElement#getNavTreeLevel()} set
     * to the level it belongs to. Use this information to distinguish between the nav levels.<p>
     * 
     * @param cms context provider for the current request
     * @param folder the selected folder
     * @param startlevel the start level
     * @param endlevel the end level
     * @return a sorted list of nav elements with the nav tree level property set 
     */
    public static List getNavigationTreeForFolder(CmsObject cms, String folder, int startlevel, int endlevel) {

        folder = CmsResource.getFolderPath(folder);
        // Make sure start and end level make sense
        if (endlevel < startlevel) {
            return Collections.EMPTY_LIST;
        }
        int currentlevel = CmsResource.getPathLevel(folder);
        if (currentlevel < endlevel) {
            endlevel = currentlevel;
        }
        if (startlevel == endlevel) {
            return getNavigationForFolder(cms, CmsResource.getPathPart(folder, startlevel), startlevel);
        }

        ArrayList result = new ArrayList();
        float parentcount = 0;

        for (int i = startlevel; i <= endlevel; i++) {
            String currentfolder = CmsResource.getPathPart(folder, i);
            List entries = getNavigationForFolder(cms, currentfolder);
            // Check for parent folder
            if (parentcount > 0) {
                for (int it = 0; it < entries.size(); it++) {
                    CmsJspNavElement e = (CmsJspNavElement)entries.get(it);
                    e.setNavPosition(e.getNavPosition() + parentcount);
                }
            }
            // Add new entries to result
            result.addAll(entries);
            Collections.sort(result);
            // Finally spread the values of the nav items so that there is enough room for further items.
            float pos = 0;
            int count = 0;
            String nextfolder = CmsResource.getPathPart(folder, i + 1);
            parentcount = 0;
            for (int it = 0; it < result.size(); it++) {
                pos = 10000 * (++count);
                CmsJspNavElement e = (CmsJspNavElement)result.get(it);
                e.setNavPosition(pos);
                if (e.getResourceName().startsWith(nextfolder)) {
                    parentcount = pos;
                }
            }
            if (parentcount == 0) {
                parentcount = pos;
            }
        }
        return result;
    }

    /**
     * This method builds a complete navigation tree with entries of all branches 
     * from the specified folder.<p>
     * 
     * For an unlimited depth of the navigation (i.e. no endLevel), set the endLevel to
     * a value &lt; 0.<p>
     * 
     * 
     * @param cms the current CmsJspActionElement.
     * @param folder the root folder of the navigation tree.
     * @param endLevel the end level of the navigation.
     * @return ArrayList of CmsJspNavElement, in depth first order.
     */
    public static List getSiteNavigation(CmsObject cms, String folder, int endLevel) {

        // check if a specific end level was given, if not, build the complete navigation
        boolean noLimit = false;
        if (endLevel < 0) {
            noLimit = true;
        }
        ArrayList list = new ArrayList();
        // get the navigation for this folder
        List curnav = getNavigationForFolder(cms, folder);
        // loop through all nav entrys
        for (int i = 0; i < curnav.size(); i++) {
            CmsJspNavElement ne = (CmsJspNavElement)curnav.get(i);
            // add the naventry to the result list
            list.add(ne);
            // check if naventry is a folder and below the max level -> if so, get the navigation from this folder as well
            if (ne.isFolderLink() && (noLimit || (ne.getNavTreeLevel() < endLevel))) {
                List subnav = getSiteNavigation(cms, ne.getResourceName(), endLevel);
                // copy the result of the subfolder to the result list
                list.addAll(subnav);
            }
        }
        return list;
    }

    /**
     * Returns all subfolders of a channel, or an empty array if 
     * the folder does not exist or has no subfolders.<p>
     * 
     * @param channel the channel to look for subfolders in
     * @return an unsorted list of CmsResources
     */
    public List getChannelSubFolders(String channel) {

        return getChannelSubFolders(m_cms, channel);
    }

    /**
     * Returns all subfolders of a sub channel that has 
     * the given parent channel, or an empty array if 
     * that combination does not exist or has no subfolders.<p>
     * 
     * @param parentChannel the parent channel
     * @param subChannel the sub channel
     * @return an unsorted list of CmsResources
     */
    public List getChannelSubFolders(String parentChannel, String subChannel) {

        return getChannelSubFolders(m_cms, parentChannel, subChannel);
    }

    /**
     * Returns all subfolders of a channel, 
     * sorted by "Title" property ascending, or an empty array if 
     * the folder does not exist or has no subfolders.
     * 
     * @param channel the parent channel
     * @param subChannel the sub channel
     * @return a sorted list of CmsResources
     */
    public List getChannelSubFoldersSortTitleAsc(String channel, String subChannel) {

        return getChannelSubFoldersSortTitleAsc(m_cms, channel, subChannel);
    }

    /**
     * Build a "bread crump" path navigation to the current folder.<p>
     * 
     * @return ArrayList sorted list of navigation elements
     * @see #getNavigationBreadCrumb(String, int, int, boolean) 
     */
    public List getNavigationBreadCrumb() {

        return getNavigationBreadCrumb(m_requestUriFolder, 0, -1, true);
    }

    /**
     * Build a "bread crump" path navigation to the current folder.<p>
     * 
     * @param startlevel the start level, if negative, go down |n| steps from selected folder
     * @param currentFolder include the selected folder in navigation or not
     * @return ArrayList sorted list of navigation elements
     * @see #getNavigationBreadCrumb(String, int, int, boolean) 
     */
    public List getNavigationBreadCrumb(int startlevel, boolean currentFolder) {

        return getNavigationBreadCrumb(m_requestUriFolder, startlevel, -1, currentFolder);
    }

    /**
     * Build a "bread crump" path navigation to the current folder.<p>
     * 
     * @param startlevel the start level, if negative, go down |n| steps from selected folder
     * @param endlevel the end level, if -1, build navigation to selected folder
     * @return ArrayList sorted list of navigation elements
     * @see #getNavigationBreadCrumb(String, int, int, boolean) 
     */
    public List getNavigationBreadCrumb(int startlevel, int endlevel) {

        return getNavigationBreadCrumb(m_requestUriFolder, startlevel, endlevel, true);
    }

    /** 
     * Build a "bread crump" path navigation to the given folder.<p>
     * 
     * The startlevel marks the point where the navigation starts from, if negative, 
     * the count of steps to go down from the given folder.
     * The endlevel is the maximum level of the navigation path, set it to -1 to build the
     * complete navigation to the given folder.
     * You can include the given folder in the navigation by setting currentFolder to true,
     * otherwise false.<p> 
     * 
     * @param folder the selected folder
     * @param startlevel the start level, if negative, go down |n| steps from selected folder
     * @param endlevel the end level, if -1, build navigation to selected folder
     * @param currentFolder include the selected folder in navigation or not
     * @return ArrayList sorted list of navigation elements
     */
    public List getNavigationBreadCrumb(String folder, int startlevel, int endlevel, boolean currentFolder) {

        ArrayList result = new ArrayList();

        int level = CmsResource.getPathLevel(folder);
        // decrease folder level if current folder is not displayed
        if (!currentFolder) {
            level -= 1;
        }
        // check current level and change endlevel if it is higher or -1
        if (level < endlevel || endlevel == -1) {
            endlevel = level;
        }

        // if startlevel is negative, display only |startlevel| links
        if (startlevel < 0) {
            startlevel = endlevel + startlevel + 1;
            if (startlevel < 0) {
                startlevel = 0;
            }
        }

        // create the list of navigation elements     
        for (int i = startlevel; i <= endlevel; i++) {
            String navFolder = CmsResource.getPathPart(folder, i);
            CmsJspNavElement e = getNavigationForResource(navFolder);
            // add element to list
            result.add(e);
        }

        return result;
    }

    /**
     * Collect all navigation elements from the files of the folder of the current request URI,
     * navigation elements are of class CmsJspNavElement.<p>
     *
     * @return a sorted (ascending to nav position) ArrayList of navigation elements.
     */
    public List getNavigationForFolder() {

        return getNavigationForFolder(m_cms, m_requestUriFolder);
    }

    /** 
     * Build a navigation for the folder that is either minus levels up 
     * from of the folder of the current request URI, or that is plus levels down from the 
     * root folder towards the current request URI.<p> 
     * 
     * If level is set to zero the root folder is used by convention.<p>
     * 
     * @param level if negative, walk this many levels up, if positive, walk this many 
     * levels down from root folder 
     * @return a sorted (ascending to nav position) ArrayList of navigation elements
     */
    public List getNavigationForFolder(int level) {

        return getNavigationForFolder(m_cms, m_requestUriFolder, level);
    }

    /**
     * Collect all navigation elements from the files in the given folder,
     * navigation elements are of class CmsJspNavElement.<p>
     *
     * @param folder the selected folder
     * @return A sorted (ascending to nav position) ArrayList of navigation elements.
     */
    public List getNavigationForFolder(String folder) {

        return getNavigationForFolder(m_cms, folder);
    }

    /** 
     * Build a navigation for the folder that is either minus levels up 
     * from the given folder, or that is plus levels down from the 
     * root folder towards the given folder.<p> 
     * 
     * If level is set to zero the root folder is used by convention.<p>
     * 
     * @param folder the selected folder
     * @param level if negative, walk this many levels up, if positive, walk this many 
     * levels down from root folder 
     * @return a sorted (ascending to nav position) ArrayList of navigation elements
     */
    public List getNavigationForFolder(String folder, int level) {

        return getNavigationForFolder(m_cms, folder, level);
    }

    /**
     * Returns a CmsJspNavElement for the resource of the current request URI.<p>
     *  
     * @return CmsJspNavElement a CmsJspNavElement for the resource of the current request URI
     */
    public CmsJspNavElement getNavigationForResource() {

        return getNavigationForResource(m_cms, m_requestUri);
    }

    /**
     * Returns a CmsJspNavElement for the named resource.<p>
     * 
     * @param resource the resource name to get the nav information for, 
     * must be a full path name, e.g. "/docs/index.html".
     * @return CmsJspNavElement a CmsJspNavElement for the given resource
     */
    public CmsJspNavElement getNavigationForResource(String resource) {

        return getNavigationForResource(m_cms, resource);
    }

    /**
     * Builds a tree navigation for the folders between the provided start and end level.<p>
     * 
     * @param startlevel the start level
     * @param endlevel the end level
     * @return a sorted list of nav elements with the nav tree level property set 
     * @see #getNavigationTreeForFolder(CmsObject, String, int, int)
     */
    public List getNavigationTreeForFolder(int startlevel, int endlevel) {

        return getNavigationTreeForFolder(m_cms, m_requestUriFolder, startlevel, endlevel);
    }

    /**
     * Builds a tree navigation for the folders between the provided start and end level.<p>
     * 
     * @param folder the selected folder
     * @param startlevel the start level
     * @param endlevel the end level
     * @return a sorted list of nav elements with the nav tree level property set 
     * @see #getNavigationTreeForFolder(CmsObject, String, int, int) 
     */
    public List getNavigationTreeForFolder(String folder, int startlevel, int endlevel) {

        return getNavigationTreeForFolder(m_cms, folder, startlevel, endlevel);
    }

    /**
     * This method builds a complete site navigation tree with entries of all branches.<p>
     *
     * @see #getSiteNavigation(CmsObject, String, int)
     * 
     * @return ArrayList of CmsJspNavElement, in depth first order.
     */
    public List getSiteNavigation() {

        return getSiteNavigation(m_cms, "/", -1);
    }

    /**
     * This method builds a complete navigation tree with entries of all branches 
     * from the specified folder.<p>
     * 
     * @see #getSiteNavigation(CmsObject, String, int)
     * 
     * @param folder folder the root folder of the navigation tree.
     * @param endLevel the end level of the navigation.
     * @return ArrayList of CmsJspNavElement, in depth first order.
     */
    public List getSiteNavigation(String folder, int endLevel) {

        return getSiteNavigation(m_cms, folder, endLevel);
    }

    /**
     * Initiliazes this bean.<p>
     * 
     * @param cms context provider for the current request
     */
    public void init(CmsObject cms) {

        m_cms = cms;
        m_requestUri = m_cms.getRequestContext().getUri();
        m_requestUriFolder = CmsResource.getFolderPath(m_requestUri);
    }
}

⌨️ 快捷键说明

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