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

📄 cmschnav.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsChnav.java,v $
* Date   : $Date: 2004/01/07 10:57:09 $
* Version: $Revision: 1.11.2.1 $
*
* 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.workplace;

import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsFolder;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.util.Encoder;
import com.opencms.util.Utils;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Template class for displaying the screen for changing the navigation position
 * for folders or pages.<P>
 * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
 *
 * @author Edna Falkenhan
 * @version $Revision: 1.11.2.1 $ $Date: 2004/01/07 10:57:09 $
 */

public class CmsChnav extends CmsWorkplaceDefault implements I_CmsWpConstants,I_CmsConstants {

    final static String C_SESSIONHEADER = "CmsChnav_";

    /**
     * Overwrites the getContent method of the CmsWorkplaceDefault.<br>
     * Gets the content of the new resource page template and processed the data input.
     * @param cms The CmsObject.
     * @param templateFile The new folder template file
     * @param elementName not used
     * @param parameters Parameters of the request and the template.
     * @param templateSelector Selector of the template tag to be displayed.
     * @return Bytearry containing the processed data of the template.
     * @throws Throws CmsException if something goes wrong.
     */

    public byte[] getContent(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {

        // the template to be displayed
        String template = null;
        // get the document to display
        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String navtext = "";

        // clear the session on first call
        String initial = (String)parameters.get("initial");
        if (initial != null){
            clearSession(session);
        }

        // get the lasturl parameter
        String lasturl = getLastUrl(cms, parameters);
        String filename = (String)parameters.get(C_PARA_FILE);
        if(filename == null || "".equals(filename)){
            filename = (String)session.getValue(C_SESSIONHEADER + C_PARA_FILE);
        }
        if(filename != null){
            filename = filename.trim();
            session.putValue(C_SESSIONHEADER + C_PARA_FILE, filename);
        }
        
        CmsResource resource = (CmsResource)cms.readFileHeader(filename);

        // get request parameters
        String navpos = (String)parameters.get(C_PARA_NAVPOS);

        navtext = (String)parameters.get(C_PARA_NAVTEXT);
        if((navtext == null) || ("".equals(navtext))){
            navtext = cms.readProperty(resource.getAbsolutePath(), I_CmsConstants.C_PROPERTY_NAVTEXT);
        }

        // get the current phase of this wizard
        String action = (String)parameters.get("action");
        if(action != null) {
            if("save".equals(action)) {
                try {
                    // update the position
                    updateNavPos(cms, resource, navpos);

                    // update the navigation text
                    if(navtext != null){
                        cms.writeProperty(resource.getAbsolutePath(), I_CmsConstants.C_PROPERTY_NAVTEXT, navtext);
                    }
                    // all done, now we have to clean up our mess
                    clearSession(session);
                } catch(CmsException ex) {
                    session.putValue(C_SESSIONHEADER + C_PARA_NAVPOS, navpos);
                    session.putValue(C_SESSIONHEADER + C_PARA_NAVTEXT, navtext);
                    xmlTemplateDocument.setData("details", Utils.getStackTrace(ex));
                    xmlTemplateDocument.setData("lasturl", lasturl);
                    return startProcessing(cms, xmlTemplateDocument, "", parameters, "error_system");
                }
                // return to filelist
                try {
                    if(lasturl == null || "".equals(lasturl)) {
                        cms.getRequestContext().getResponse().sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
                            + C_WP_EXPLORER_FILELIST);
                    }else {
                        cms.getRequestContext().getResponse().sendRedirect(lasturl);
                    }
                }catch(Exception e) {
                    throw new CmsException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath()
                        + C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, e);
                }
                return null;
            } else if("fromerror".equalsIgnoreCase(action)){
                // error while creating the folder go to firs page and set the stored parameter
                template = null;
                xmlTemplateDocument.setData(C_PARA_NAVPOS, (String)session.getValue(C_SESSIONHEADER +  C_PARA_NAVPOS));
                navtext = (String)session.getValue(C_SESSIONHEADER +  C_PARA_NAVTEXT);
                session.removeValue(C_SESSIONHEADER + C_PARA_NAVPOS);
                session.removeValue(C_SESSIONHEADER + C_PARA_NAVTEXT);
            }
        }
        xmlTemplateDocument.setData("frametitle", resource.getName());
        xmlTemplateDocument.setData(C_PARA_NAVTEXT, Encoder.escapeXml(navtext));

        // process the selected template
        return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
    }

    /**
     * Gets all required navigation information from the files and subfolders of a folder.
     * A file list of all files and folder is created, for all those resources, the navigation
     * property is read. The list is sorted by their navigation position.
     * @param cms The CmsObject.
     * @param filename The Name of the current file.
     * @return Hashtable including three arrays of strings containing the filenames,
     * nicenames and navigation positions.
     * @throws Throws CmsException if something goes wrong.
     */
    private Hashtable getNavData(CmsObject cms, String filename) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        String[] filenames;
        String[] nicenames;
        String[] positions;
        Hashtable storage = new Hashtable();
        CmsFolder folder = null;
        CmsFile file = null;
        String nicename = null;
        String currentFilelist = null;
        int count = 1;
        float max = 0;

        // get the current folder
        currentFilelist = (String)session.getValue(C_PARA_FILELIST);
        if(currentFilelist == null) {
            currentFilelist = cms.rootFolder().getAbsolutePath();
        }

        // get all files and folders in the current filelist.
        Vector files = cms.getFilesInFolder(currentFilelist);
        Vector folders = cms.getSubFolders(currentFilelist);

        // combine folder and file vector
        Vector filefolders = new Vector();
        Enumeration enum = folders.elements();
        while(enum.hasMoreElements()) {
            folder = (CmsFolder)enum.nextElement();
            filefolders.addElement(folder);
        }
        enum = files.elements();
        while(enum.hasMoreElements()) {
            file = (CmsFile)enum.nextElement();
            filefolders.addElement(file);
        }
        if(filefolders.size() > 0) {
            // Create some arrays to store filename, nicename and position for the
            // nav in there. The dimension of this arrays is set to the number of
            // found files and folders plus two more entrys for the first and last
            // element.
            filenames = new String[filefolders.size() + 3];
            nicenames = new String[filefolders.size() + 3];
            positions = new String[filefolders.size() + 3];

            //now check files and folders that are not deleted and include navigation
            // information
            enum = filefolders.elements();
            while(enum.hasMoreElements()) {
                CmsResource res = (CmsResource)enum.nextElement();

⌨️ 快捷键说明

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