📄 cmsxmlcontrolfile.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/template/CmsXmlControlFile.java,v $
* Date : $Date: 2003/01/20 23:59:21 $
* Version: $Revision: 1.28 $
*
* 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 com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.template.cache.CmsElementDefinition;
import com.opencms.template.cache.CmsElementDefinitionCollection;
import com.opencms.util.Utils;
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.28 $ $Date: 2003/01/20 23:59:21 $
*/
public class CmsXmlControlFile extends A_CmsXmlContent implements I_CmsLogChannels {
/**
* Default constructor.
*/
public CmsXmlControlFile() throws CmsException {
super();
}
/**
* 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.
*/
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.
*/
public CmsXmlControlFile(CmsObject cms, String filename) throws CmsException {
super();
init(cms, filename);
}
/**
* Used for setting element definition values.
* Checks if the requested element definition already exists.
* If so, nothing will happen. If not, a corresponding section
* will be created using a hierarchical datablock tag
* <code><ELEMENTDEF name="..."/></code>
*
* @param name Name of the element definition section.
*/
private void createElementDef(String name) {
if(!hasData("ELEMENTDEF." + name)) {
Document doc = getXmlDocument();
Element e = doc.createElement("ELEMENTDEF");
e.setAttribute("name", name);
setData("elementdef." + name, e);
}
}
/**
* 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.
*/
public String getElementClass(String elementName) throws CmsException {
return getDataValue("ELEMENTDEF." + elementName + ".CLASS");
}
/**
* Gets an enumeration of all names of the subelement definition in the
* body file.
* @return Enumeration with of names.
* @throws CmsException
*/
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.
*/
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
*/
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
*/
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 = (Node)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.
*/
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.
*/
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
*/
public String getMasterTemplate() throws CmsException {
String result = getDataValue("mastertemplate");
if(result == null || "".equals(result)) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_CRITICAL, "[CmsXmlControlFile] <MASTERTEMPLATE> tag not found in file " + getAbsoluteFilename() + ".");
A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlControlFile] Document has errors. Removing from cache.");
}
removeFromFileCache();
throw new CmsException("\"MASTERTEMPLATE\" definition tag not found in file " + getAbsoluteFilename() + ".", CmsException.C_XML_TAG_MISSING);
}
return result;
}
/**
* Internal utility method to extract the values of the "name" attribute
* from defined nodes of a given nodelist.
* @param nl NodeList to extract.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -