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

📄 cmsxmlnav.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/defaults/CmsXmlNav.java,v $
* Date   : $Date: 2002/01/02 10:20:21 $
* Version: $Revision: 1.37 $
*
* 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 com.opencms.file.*;
import com.opencms.core.*;
import com.opencms.util.*;
import com.opencms.template.*;

import javax.servlet.*;
import javax.servlet.http.*;

import java.util.*;

/**
 * This class builds the default Navigation.
 *
 * @author Alexander Kandzior
 * @author Waruschan Babachan
 * @version $Revision: 1.37 $ $Date: 2002/01/02 10:20:21 $
 */
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.
     *
     * @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 userObj Hashtable with parameters.
     * @return String that contains the navigation.
     */
    protected String buildNav(CmsObject cms, A_CmsXmlContent doc,Object userObject, Vector resources)
        throws CmsException {

        // get uri, currentfolder,servletpath and template file
        String requestedUri = cms.getRequestContext().getUri();
        String currentFolder=cms.getRequestContext().currentFolder().getAbsolutePath();
        String servletPath = cms.getRequestContext().getRequest().getServletUrl();
        CmsXmlTemplateFile template=(CmsXmlTemplateFile)doc;
        StringBuffer result = new StringBuffer();
        LinkSubstitution ls = new LinkSubstitution();
        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
            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);
                    template.setData("navlink", ls.getLinkSubstitution(cms, navLink[i] + navIndex));
                } catch (CmsException e) {
                    template.setData("navlink", ls.getLinkSubstitution(cms, requestedUri));
                }
            } else {
                try {
                    cms.readFile(navLink[i]);
                    template.setData("navlink", ls.getLinkSubstitution(cms, navLink[i]));
                } catch (CmsException e) {
                    template.setData("navlink", ls.getLinkSubstitution(cms, requestedUri));
                }
            }
            // Check if nav is current nav
            if (navLink[i].equals(currentFolder) || navLink[i].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.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param doc Reference to the CmsXmTemplateFile object of the initiating XLM document.
     * @param resources a vector that contains the elements of navigation.
     * @param userObj 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 depth An Integer that shows how many folders must be displayed.
     * @return String that contains the navigation.
     */
    protected String buildNavFold(CmsObject cms, CmsXmlTemplateFile template, Object userObject, Vector resources, String requestedUri, String currentFolder, String servletPath,int level,int[] count)
        throws CmsException {

        StringBuffer result = new StringBuffer();
        LinkSubstitution ls = new LinkSubstitution();
        // 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]);
                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", ls.getLinkSubstitution(cms, navLink[i] + navIndex));
                    } catch (CmsException e) {
                        link=requestedUri;
                        template.setData("navlink", ls.getLinkSubstitution(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", ls.getLinkSubstitution(cms, navLink[i]));
                    } catch (CmsException e) {
                        link=requestedUri;
                        template.setData("navlink", ls.getLinkSubstitution(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) {
                    Vector all=cms.getSubFolders(navLink[i]);
                    Vector files=cms.getFilesInFolder(navLink[i]);
                    all.ensureCapacity(all.size() + files.size());
                    Enumeration e = files.elements();
                    while (e.hasMoreElements()) {
                        all.addElement(e.nextElement());
                    }
                    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 doc Reference to the CmsXmTemplateFile object of the initiating XML document.
     * @param resources a vector that contains the elements of navigation.
     * @param userObj 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
     * @return String that contains the navigation.
     */
    protected String buildNavTree(CmsObject cms, CmsXmlTemplateFile template, Object userObject, Vector resources, String requestedUri, String currentFolder, String servletPath,int level,int depth,boolean depthIsNull,int[] count)
        throws CmsException {

        StringBuffer result = new StringBuffer();
        LinkSubstitution ls = new LinkSubstitution();
        // define some array for link,text and position of
        // the elements of navigation
        int size = resources.size();
        String navLink[] = new String[size];
        String navText[] = new String[size];
        float navPos[] = new float[size];
        // extract the navigation from the given resources, i.e. it will be showed
        // if the elements of that resources must be showed in navigation, i.e.
        // wheather navigation Text und navigation position are defined for an element
        int max=extractNav(cms,resources,navLink,navText,navPos);
        // check wheather there is some elements
        if (max>0) {
            result.append(template.getProcessedDataValue("navstart", this, userObject));
            for(int i=0; i<max; i++) {
                // set the templates
                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]);
                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 a folder
                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!=null && navIndex.equals(""))) {
                        navIndex=C_NAVINDEX;
                    }
                    // check whether the file exist, if not then the link is current uri
                    try {
                        cms.readFile(navLink[i] + navIndex);
                        link=navLink[i] + navIndex;
                        template.setData("navlink", ls.getLinkSubstitution(cms, navLink[i] + navIndex));
                    } catch (CmsException e) {
                        link=requestedUri;
                        template.setData("navlink", ls.getLinkSubstitution(cms, requestedUri));
                    }
                } else {
                    // check whether the file exist, if not then the link is current uri
                    try {
                        cms.readFile(navLink[i]);
                        link=navLink[i];
                        template.setData("navlink", ls.getLinkSubstitution(cms, navLink[i]));
                    } catch (CmsException e) {
                        link=requestedUri;
                        template.setData("navlink", ls.getLinkSubstitution(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));
                }
                // redurce the depth and test if it is now zero or is the depth
                // given as tagcontent or not.
                // if the depth is not given in tagcontent then the depth variable must be ignored
                // the user don't want to give depth otherwise the depth must be considered
                // because it must not be exceeded the limit that user has defined.
                depth--;
                if (depthIsNull || (depthIsNull==false && depth>=0)) {
                    if (navLink[i].endsWith("/")) {
                        Vector all=cms.getSubFolders(navLink[i]);
                        Vector files=cms.getFilesInFolder(navLink[i]);
                        all.ensureCapacity(all.size() + files.size());
                        Enumeration e = files.elements();
                        while (e.hasMoreElements()) {
                            all.addElement(e.nextElement());
                        }

⌨️ 快捷键说明

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