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

📄 cmsxmlnav.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/CmsXmlNav.java,v $
* Date   : $Date: 2005/06/27 23:22:23 $
* Version: $Revision: 1.4 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.defaults;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.workplace.CmsWorkplace;

import com.opencms.legacy.CmsLegacyException;
import com.opencms.legacy.CmsXmlTemplateLoader;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsCacheDirectives;
import com.opencms.template.CmsXmlTemplateFile;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * This class builds the default Navigation.
 *
 * @author Alexander Kandzior
 * @author Waruschan Babachan
 * @author Thomas Weckert
 * @version $Revision: 1.4 $ $Date: 2005/06/27 23:22:23 $
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public class CmsXmlNav extends A_CmsNavBase {

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */
    public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return true;
    }



    /**
     * Builds the navigation.<p>
     *
     * @param cms CmsObject Object for accessing system resources
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document
     * @param resources a vector that contains the elements of navigation
     * @param userObject Hashtable with parameters
     * @return String that contains the navigation
     * @throws CmsException if something goes wrong
     */
    protected String buildNav(CmsObject cms, A_CmsXmlContent doc, Object userObject, List resources)
        throws CmsException {

        // get uri, currentfolder,servletpath and template file
        String requestedUri = cms.getRequestContext().getUri();
        // String currentFolder=cms.readPath(cms.getRequestContext().currentFolder());
        // String servletPath = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl();
        CmsXmlTemplateFile template=(CmsXmlTemplateFile)doc;
        StringBuffer result = new StringBuffer();
        int size = resources.size();

        String navLink[] = new String[size];
        String navText[] = new String[size];
        float navPos[] = new float[size];
        // extract the navigation according to navigation position and nav text
        int max=extractNav(cms, resources, navLink, navText, navPos);
        // The arrays folderNames and folderTitles now contain all folders
        // that should appear in the nav.
        // Loop through all folders and generate output
        for (int i=0; i<max; i++) {
            template.setData("navtext", navText[i]);
            template.setData("navcount", new Integer(i+1).toString());
            template.setData("navlevel", new Integer(extractLevel(cms, navLink[i])).toString());
            // check whether it is a folder or file
            String link="";
            if (navLink[i].endsWith("/")) {
                // read the property of folder to find the link file.
                String navIndex=cms.readProperty(navLink[i], C_PROPERTY_NAVINDEX);
                // if there is not defined a property then take C_NAVINDEX constant
                if (navIndex==null) {
                    navIndex=C_NAVINDEX;
                }
                try {
                    cms.readFile(navLink[i] + navIndex);
                    link=navLink[i] + navIndex;
                    template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, navLink[i] + navIndex));
                } catch (CmsException e) {
                    template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, requestedUri));
                }
            } else {
                try {
                    cms.readFile(navLink[i]);
                    link=navLink[i];
                    template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, navLink[i]));
                } catch (CmsException e) {
                    template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, requestedUri));
                }
            }
            // Check if nav is current nav
            //if (navLink[i].equals(currentFolder) || navLink[i].equals(requestedUri)) {
            if (link.equals(requestedUri)) {
                result.append(template.getProcessedDataValue("navcurrent", this, userObject));
            } else {
                result.append(template.getProcessedDataValue("naventry", this, userObject));
            }
        }
        return result.toString();
    }
    
    /**
     * Builds the navigation that could be closed or opened.<p>
     *
     * @param cms CmsObject Object for accessing system resources
     * @param template Reference to the CmsXmTemplateFile object of the initiating XLM document
     * @param resources a vector that contains the elements of navigation
     * @param userObject Hashtable with parameters
     * @param requestedUri The absolute path of current requested file
     * @param currentFolder The currenet folder
     * @param servletPath The absolute path of servlet
     * @param level An Integer that shows how many folders must be displayed.
     * @param count the nav count
     * @return String that contains the navigation
     * @throws CmsException if soemthing goes wrong
     */
    protected String buildNavFold(CmsObject cms, CmsXmlTemplateFile template, Object userObject, List resources, String requestedUri, String currentFolder, String servletPath, int level, int[] count)
        throws CmsException {

        StringBuffer result = new StringBuffer();
        // arrays of navigation position, text and link
        int size = resources.size();
        String navLink[] = new String[size];
        String navText[] = new String[size];
        float navPos[] = new float[size];
        // extract the navigation according
        int max=extractNav(cms, resources, navLink, navText, navPos);
        if (max>0) {
            result.append(template.getProcessedDataValue("navstart", this, userObject));
            for (int i=0; i<max; i++) {
                count[0]++;
                template.setData("navtext", navText[i]);
                template.setData("navcount", new Integer(count[0]).toString());
                // this part is to set the level starting from specified level given as tagcontent
                // there it must be make a difference between extracted level and the given level
                int extractedLevel=extractLevel(cms, navLink[i]);
                template.setData("navlevel", new Integer(extractedLevel).toString());
                /*int rightLevel=extractedLevel;
                if (level!=0) {
                    rightLevel=(extractedLevel-level);
                    if (rightLevel>=0) {
                        rightLevel++;
                    }
                }
                template.setData("navlevel", new Integer(rightLevel).toString());*/
                String link="";
                // check whether the link is folder
                if (navLink[i].endsWith("/")) {
                    // read the property of link file
                    String navIndex=cms.readProperty(navLink[i], C_PROPERTY_NAVINDEX);
                    // if the property is not defined then take C_NAVINDEX constant
                    if (navIndex==null) {
                        navIndex=C_NAVINDEX;
                    }
                    // read the file, if the file does'nt exist then write the uri as a link
                    try {
                        cms.readFile(navLink[i] + navIndex);
                        link=navLink[i] + navIndex;
                        template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, navLink[i] + navIndex));
                    } catch (CmsException e) {
                        link=requestedUri;
                        template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, requestedUri));
                    }
                } else {
                    // read the file, if the file does'nt exist then write the uri as a link
                    try {
                        cms.readFile(navLink[i]);
                        link=navLink[i];
                        template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, navLink[i]));
                    } catch (CmsException e) {
                        link=requestedUri;
                        template.setData("navlink", OpenCms.getLinkManager().substituteLink(cms, requestedUri));
                    }
                }
                // Check if nav is current nav
                if (link.equals(requestedUri)) {
                    result.append(template.getProcessedDataValue("navcurrent", this, userObject));
                } else {
                    result.append(template.getProcessedDataValue("naventry", this, userObject));
                }
                // if the folder was clicked
                if (requestedUri.indexOf(navLink[i])!=-1) {
                    List all=cms.getSubFolders(navLink[i]);
                    List files=cms.getFilesInFolder(navLink[i]);
                    // register this folder for changes (if it is a folder!)
                    if (navLink[i].endsWith("/")) {
                        Vector vfsDeps = new Vector();
                        vfsDeps.add(cms.readFolder(navLink[i]));
                        registerVariantDeps(cms, template.getAbsoluteFilename(), null, null,
                                        (Hashtable)userObject, vfsDeps, null, null);
                    }
                    ((ArrayList)all).ensureCapacity(all.size() + files.size());
                    Iterator e = files.iterator();
                    while (e.hasNext()) {
                        all.add(e.next());
                    }
                    result.append(buildNavFold(cms, template, userObject, all, requestedUri, currentFolder, servletPath, level, count));
                }
            }
            result.append(template.getProcessedDataValue("navend", this, userObject));
        }

        return result.toString();

    }

    /**
     * Builds the tree of navigation.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param template Reference to the CmsXmTemplateFile object of the initiating XML document
     * @param resources a vector that contains the elements of navigation
     * @param userObject Hashtable with parameters
     * @param requestedUri The absolute path of current requested file
     * @param currentFolder The currenet folder
     * @param servletPath The absolute path of servlet
     * @param level The starting level
     * @param depth An Integer that shows how many folders must be displayed
     * @param depthIsNull a boolean that determines whether the depth is given in tagcontent
     * @param count the nav count
     * @return String that contains the navigation
     * @throws CmsException if something goes wrong
     */
    protected String buildNavTree(CmsObject cms, CmsXmlTemplateFile template, Object userObject, List resources, String requestedUri, String currentFolder, String servletPath, int level, int depth, boolean depthIsNull, int[] count)
        throws CmsException {

        StringBuffer result = new StringBuffer();
        // define some array for link,text and position of
        // the elements of navigation

⌨️ 快捷键说明

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