📄 cmsxmlcontrolfile.java
字号:
* @param tag Name of the tag whose "name" attribute should be extracted
* @param unnamedAllowed Indicates if unnamed tags are allowed or an exception should
* be thrown.
* @return Enumeration of all "name" attributes.
* @throws CmsException
*/
private Enumeration getNamesFromNodeList(NodeList nl, String tag, boolean unnamedAllowed) throws CmsException {
int numElements = nl.getLength();
Vector collectNames = new Vector();
for(int i = 0;i < numElements;i++) {
Node n = (Node)nl.item(i);
if(n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().toLowerCase().equals(tag.toLowerCase())) {
String name = ((Element)n).getAttribute("name");
if(name == null || "".equals(name)) {
// unnamed element found.
if(unnamedAllowed) {
name = "(default)";
}
else {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_CRITICAL, "[CmsXmlControlFile] unnamed <" + n.getNodeName() + "> found in OpenCms control file " + getAbsoluteFilename() + ".");
}
throw new CmsException("Unnamed \"" + n.getNodeName() + "\" found in OpenCms control file " + getAbsoluteFilename() + ".", CmsException.C_XML_TAG_MISSING);
}
}
collectNames.addElement(name);
}
}
return collectNames.elements();
}
/**
* Gets the value of a single parameter of the master template.
* @param parameterName Name of the requested parameter.
*/
public String getParameter(String parameterName) throws CmsException {
return getDataValue("PARAMETER." + parameterName);
}
/**
* Gets an enumeration of all parameter names of the master template.
* @return Enumeration of all names.
* @throws CmsException
*/
public Enumeration getParameterNames() throws CmsException {
NodeList parameterTags = getXmlDocument().getDocumentElement().getChildNodes();
return getNamesFromNodeList(parameterTags, "PARAMETER", false);
}
/**
* Gets the template class defined in the body file.
* @return Name of the template class.
* @throws CmsException
*/
public String getTemplateClass() throws CmsException {
String result = getDataValue("class");
// checking the value is not required here.
// the launcher takes another class if no classname was found here
return result;
}
/**
* Gets the expected tagname for the XML documents of this content type
* @return Expected XML tagname.
*/
public String getXmlDocumentTagName() {
return "PAGE";
}
/**
* Checks if the body file contains a definition of the
* template class name for a given subelement definition.
* @param elementName Name of the subelement.
* @return <code>true<code> if a definition exists, <code>false</code> otherwise.
*/
public boolean isElementClassDefined(String elementName) {
return this.hasData("ELEMENTDEF." + elementName + ".CLASS");
}
/**
* Checks if the body file contains a definition of the
* template file name for a given subelement definition.
* @param elementName Name of the subelement.
* @return <code>true<code> if a definition exists, <code>false</code> otherwise.
*/
public boolean isElementTemplateDefined(String elementName) {
return this.hasData("ELEMENTDEF." + elementName + ".TEMPLATE");
}
/**
* Checks if the body file contains a definition of the
* template selector for a given subelement definition.
* @param elementName Name of the subelement.
* @return <code>true<code> if a definition exists, <code>false</code> otherwise.
*/
public boolean isElementTemplSelectorDefined(String elementName) {
return this.hasData("ELEMENTDEF." + elementName + ".TEMPLATESELECTOR");
}
/**
* Sets the template class of a given subelement definition.
* @param elementName Name of the subelement.
* @param classname Classname to be set.
*/
public void setElementClass(String elementName, String classname) {
createElementDef(elementName);
setData("ELEMENTDEF." + elementName + ".CLASS", classname);
}
/**
* Set the value of a single parameter of a given subelement definition.
* @param elementName Name of the subelement.
* @param parameterName Name of the requested parameter.
* @param parameterValue Value to be set
*/
public void setElementParameter(String elementName, String parameterName, String parameterValue) throws CmsException {
createElementDef(elementName);
if(!hasData("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName)) {
Document doc = getXmlDocument();
Element e = doc.createElement("PARAMETER");
e.setAttribute("name", parameterName);
e.appendChild(doc.createTextNode(parameterValue));
setData("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName, e);
}
else {
setData("ELEMENTDEF." + elementName + ".PARAMETER." + parameterName, parameterValue);
}
}
/**
* Sets the filename of the master template file of a given subelement definition.
* @param elementName Name of the subelement.
* @param filename Filename to be set.
*/
public void setElementTemplate(String elementName, String filename) {
createElementDef(elementName);
setData("ELEMENTDEF." + elementName + ".TEMPLATE", filename);
}
/**
* Sets the filename of the master template file of a given subelement definition.
* @param elementName Name of the subelement.
* @param templateSelector Template selector to be set.
*/
public void setElementTemplSelector(String elementName, String templateSelector) {
createElementDef(elementName);
setData("ELEMENTDEF." + elementName + ".TEMPLATESELECTOR", templateSelector);
}
/**
* Sets the filename of the master template file defined in
* the body file.
* @param template Filename of the template file.
* @throws CmsException
*/
public void setMasterTemplate(String template) {
setData("masterTemplate", template);
}
/**
* Set the value of a single parameter of the master template.
* @param parameterName Name of the requested parameter.
* @param parameterValue Value to be set
*/
public void setParameter(String parameterName, String parameterValue) throws CmsException {
if(!hasData("PARAMETER." + parameterName)) {
Document doc = getXmlDocument();
Element e = doc.createElement("PARAMETER");
e.setAttribute("name", parameterName);
e.appendChild(doc.createTextNode(parameterValue));
setData("PARAMETER." + parameterName, e);
}
else {
setData("PARAMETER." + parameterName, parameterValue);
}
}
/**
* Set the template class used for the master Template
* @param templateClass Name of the template class.
*/
public void setTemplateClass(String templateClass) {
setData("class", templateClass);
}
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 = "com.opencms.template.CmsXmlTemplate";
}
if(elementTemplate != null){
elementTemplate = Utils.mergeAbsolutePath(getAbsoluteFilename(), elementTemplate);
}
result.add(new CmsElementDefinition(elementName, elementClass, elementTemplate, elementTs, elementParameters));
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -