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

📄 cmsxmlcontrolfile.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/CmsXmlControlFile.java,v $
 * Date   : $Date: 2005/06/27 23:22:20 $
 * Version: $Revision: 1.5 $
 *
 * 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.template;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.importexport.CmsCompatibleCheck;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.staticexport.CmsLinkManager;

import com.opencms.legacy.CmsLegacyException;
import com.opencms.template.cache.CmsElementDefinition;
import com.opencms.template.cache.CmsElementDefinitionCollection;

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

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Content definition for "clickable" and user requestable XML body files.
 *
 * @author Alexander Lucas
 * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:20 $
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public class CmsXmlControlFile extends A_CmsXmlContent {

    /**
     * Default constructor.
     */
    public CmsXmlControlFile() {

        super();
    }

    /**
     * Constructor for creating a new object containing the content
     * of the given filename.
     *
     * @param cms CmsObject object for accessing system resources.
     * @param file name of the body file that shoul be read.
     * @throws CmsException if something goes wrong
     */
    public CmsXmlControlFile(CmsObject cms, CmsFile file)
    throws CmsException {

        super();
        init(cms, file);
    }

    /**
     * Constructor for creating a new object containing the content
     * of the given filename.
     *
     * @param cms CmsObject object for accessing system resources.
     * @param filename name of the body file that shoul be read.
     * @throws CmsException if something goes wrong
     */
    public CmsXmlControlFile(CmsObject cms, String filename)
    throws CmsException {

        super();
        init(cms, filename);
    }

    /**
     * Constructor for creating a new object containing the given content
     * for the given filename.
     *
     * @param cms for accessing system resources
     * @param filename name of the file that shoul be stored in this XML file cache
     * @param content XML file to parse
     * @throws CmsException if something goes wrong
     */
    public CmsXmlControlFile(CmsObject cms, String filename, String content)
    throws CmsException {

        super();
        init(cms, filename, content);
    }

    /**
     * Gets a description of this content type.
     * @return Content type description.
     */
    public String getContentDescription() {

        return "OpenCms XML page file";
    }

    /**
     * Gets the template class of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Name of the template class.
     * @throws CmsException if something goes wrong
     */
    public String getElementClass(String elementName) throws CmsException {

        return getDataValue("ELEMENTDEF." + elementName + ".CLASS");
    }

    /**
     * Gets a collection of element definitions.<p>
     * 
     * @return a collection of element definitions
     * @throws CmsException if something goes wrong
     */
    public CmsElementDefinitionCollection getElementDefinitionCollection() throws CmsException {

        CmsElementDefinitionCollection result = new CmsElementDefinitionCollection();
        Enumeration elementDefinitions = getElementDefinitions();
        while (elementDefinitions.hasMoreElements()) {
            String elementName = (String)elementDefinitions.nextElement();

            String elementClass = null;
            String elementTemplate = null;
            String elementTs = null;
            if (isElementClassDefined(elementName)) {
                elementClass = getElementClass(elementName);
            }
            if (isElementTemplateDefined(elementName)) {
                elementTemplate = getElementTemplate(elementName);
            }
            if (isElementTemplSelectorDefined(elementName)) {
                elementTs = getElementTemplSelector(elementName);
            }
            Hashtable elementParameters = getElementParameters(elementName);
            if (elementClass == null) {
                elementClass = CmsCompatibleCheck.XML_CONTROL_DEFAULT_CLASS;
            }
            if (elementTemplate != null) {
                elementTemplate = CmsLinkManager.getAbsoluteUri(elementTemplate, getAbsoluteFilename());
            }
            result.add(new CmsElementDefinition(
                elementName,
                elementClass,
                elementTemplate,
                elementTs,
                elementParameters));
        }
        return result;
    }

    /**
     * Gets an enumeration of all names of the subelement definition in the
     * body file.
     * @return Enumeration with of names.
     * @throws CmsException if something goes wrong
     */
    public Enumeration getElementDefinitions() throws CmsException {

        NodeList elementDefTags = getXmlDocument().getDocumentElement().getChildNodes();
        return getNamesFromNodeList(elementDefTags, "ELEMENTDEF", false);
    }

    /**
     * Gets the value of a single parameter of a given subelement definition.
     * @param elementName Name of the subelement.
     * @param parameterName Name of the requested parameter.
     * @return the element parameter value
     * @throws CmsException if something goes wrong
     */
    public String getElementParameter(String elementName, String parameterName) throws CmsException {

        return getDataValue("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName);
    }

    /**
     * Gets an enumeration of all parameter names of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Enumeration of all names.
     * @throws CmsException if something goes wrong
     */
    public Enumeration getElementParameterNames(String elementName) throws CmsException {

        Element elementDefinition = getData("elementdef." + elementName);
        NodeList parameterTags = elementDefinition.getChildNodes();
        return getNamesFromNodeList(parameterTags, "PARAMETER", false);
    }

    /**
     * Get a hashtable containing all parameters and thies values of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Enumeration of all names.
     * @throws CmsException if something goes wrong
     */
    public Hashtable getElementParameters(String elementName) throws CmsException {

        Hashtable result = new Hashtable();
        Element elementDefinition = getData("elementdef." + elementName);
        NodeList parameterTags = elementDefinition.getChildNodes();

        int numElements = parameterTags.getLength();
        for (int i = 0; i < numElements; i++) {
            Node n = parameterTags.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().toLowerCase().equals("parameter")) {
                String name = ((Element)n).getAttribute("name");
                if (name != null && !"".equals(name)) {
                    result.put(name, getTagValue((Element)n));
                }
            }
        }
        return result;
    }

    /**
     * Gets the filename of the master template file of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Filename of the template file.
     * @throws CmsException if something goes wrong
     */
    public String getElementTemplate(String elementName) throws CmsException {

        //return getDataValue("ELEMENTDEF." + elementName + ".TEMPLATE");
        String result = getDataValue("ELEMENTDEF." + elementName + ".TEMPLATE");
        return result;
    }

    /**
     * Gets the filename of the master template file of a given subelement definition.
     * @param elementName Name of the subelement.
     * @return Filename of the template file.
     * @throws CmsException if something goes wrong
     */
    public String getElementTemplSelector(String elementName) throws CmsException {

        return getDataValue("ELEMENTDEF." + elementName + ".TEMPLATESELECTOR");
    }

    /**
     * Gets the filename of the master template file defined in
     * the body file.
     * @return Filename of the template file.
     * @throws CmsException if something goes wrong
     */
    public String getMasterTemplate() throws CmsException {

        String result = getDataValue("mastertemplate");
        if (result == null || "".equals(result)) {
            if (CmsLog.getLog(this).isErrorEnabled()) {
                CmsLog.getLog(this).error("<MASTERTEMPLATE> tag not found in file " + getAbsoluteFilename());
            }
            removeFromFileCache();
            throw new CmsLegacyException("\"MASTERTEMPLATE\" definition tag not found in file "

⌨️ 快捷键说明

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