📄 cmsxmltemplatefile.java
字号:
A_OpenCms.log(C_OPENCMS_STREAMING, getClassName() + "Disabled streaming mode for file: " + getAbsoluteFilename());
}
}
String datablockName = this.getTemplateDatablockName(templateSelector);
if(datablockName == null && (templateSelector.toLowerCase().equals("script"))) {
return "";
}
A_OpenCms.log(C_OPENCMS_DEBUG, "DAO [" + getClassName() + "][getProcessedTemplateContent()] templateSelector=" + templateSelector);
return getProcessedDataValue(datablockName, callingObject, parameters, os);
}
/**
* Gets the processed data of the appropriate <code><TEMPLATE></code> section of
* this workplace template file.
* <P>
* In contrast to <code>getProcessedElementContent()</code> the <code><ELEMENT></code>
* tags will NOT be resolved during this loop. Instead, a new element cache variant
* containing links to these elements will be created.
*
* @param callingObject reference to the calling object. Used to look up user methods while processing.
* @param parameters hashtable containing all user parameters.
* @param elementName Element name of this template in our parent template.
* @param templateSelector Name of the template section or null if the default section is requested.
* @return New variant for the element cache.
* @throws CmsException
*/
public CmsElementVariant generateElementCacheVariant(Object callingObject, Hashtable parameters, String elementName, String templateSelector) throws CmsException {
CmsElementVariant result = new CmsElementVariant();
String datablockName = this.getTemplateDatablockName(templateSelector);
if(datablockName == null && (templateSelector.toLowerCase().equals("script"))) {
return result;
}
Element domEl = getProcessedData(datablockName, callingObject, parameters, null);
StringBuffer buf = new StringBuffer();
for(Node n = domEl.getFirstChild(); n != null; n = treeWalker(domEl, n)) {
if(n.getNodeType() == Node.ELEMENT_NODE && "element".equalsIgnoreCase(n.getNodeName())) {
// This is an <ELEMENT> tag. First get the name of this element
String elName = ((Element)n).getAttribute("name");
if(elName != null && !"".equalsIgnoreCase(elName)) {
// If there is something in the string buffer, store is now!
if(buf.length() > 0) {
result.add(buf.toString());
buf = new StringBuffer();
}
// Create new CmsElementLink
CmsElementLink link = new CmsElementLink(elName);
result.add(link);
}
} else if (n.getNodeType() == Node.ELEMENT_NODE && "method".equalsIgnoreCase(n.getNodeName())) {
// this is a left over <METHOD> tag.
String methodName = ((Element)n).getAttribute("name");
String tagcontent = getTagValue((Element)n);
if(methodName != null && !"".equals(methodName)){
//if there is something in the buffer store it now
if(buf.length() > 0) {
result.add(buf.toString());
buf = new StringBuffer();
}
// create the new methode link
CmsMethodLink methodLink = new CmsMethodLink(methodName, tagcontent);
result.add(methodLink);
// remove the tagcontent if necessary
if(tagcontent != null && !"".equals(tagcontent)){
n = treeWalker(domEl, n);
}
}
} else if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) {
buf.append(n.getNodeValue());
}
}
// Store pending buffer content
if(buf.length() > 0) {
result.add(buf.toString());
}
return result;
}
public String getSectionTitle(String sectionName) throws CmsException {
String datablockName = getTemplateDatablockName(sectionName);
String result = null;
try {
Element data = getData(datablockName);
result = data.getAttribute("title");
}
catch(Exception e) {
// The given section doesn't exist. Ignore.
result = "";
}
return result;
}
/**
* Gets the template class of a given subelement definition.
* @param elementName Name of the subelement.
* @return Name of the template class.
*/
public String getSubtemplateClass(String name) throws CmsException {
String className = getDataValue("ELEMENTDEF." + name + ".CLASS");
return className;
}
/**
* 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 getSubtemplateFilename(String name) throws CmsException {
String className = getDataValue("ELEMENTDEF." + name + ".TEMPLATE");
return className;
}
/**
* Gets the template selector of the master template file of a given subelement definition.
* @param elementName Name of the subelement.
* @return Filename of the template file.
*/
public String getSubtemplateSelector(String name) throws CmsException {
String templateSelector = getDataValue("ELEMENTDEF." + name + ".TEMPLATESELECTOR");
return templateSelector;
}
/**
* Gets the data of the appropriate <code><TEMPLATE></code> section of
* this workplace template file.
* <P>
* The correct datablock name for the template datablock will be taken
* from <code>getTemplateDatablockName</code>.
*
* @param callingObject reference to the calling object. Used to look up user methods while processing.
* @param parameters hashtable containing all user parameters.
* @param templateSelector Name of the template section or null if the default section is requested.
* @return Processed template data.
* @throws CmsException
*/
public String getTemplateContent(Object callingObject, Hashtable parameters, String templateSelector) throws CmsException {
String datablockName = this.getTemplateDatablockName(templateSelector);
return getDataValue(datablockName);
}
/**
* Utility method to get the correct datablock name for a given selector.<BR>
* If no selector is given or the selected section is not found, the template section
* with no name will be returned. If even this is not found the section named "default"
* will be returned.
*
* @param templateSelector Name of the template section or null if the default section is requested.
* @return Appropriate name of the template datablock.
* @throws CmsException
*/
private String getTemplateDatablockName(String templateSelector) throws CmsException {
String templateDatablockName = null;
if(templateSelector != null && !"".equals(templateSelector)) {
if(hasData("template." + templateSelector)) {
templateDatablockName = "template." + templateSelector;
}else {
if((I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) && (!"script".equals(templateSelector))) {
A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "cannot load selected template file section " + templateSelector + " in template file " + getFilename() + ". Fallback to default section.");
}
}
}
if(templateDatablockName == null && (!"script".equals(templateSelector))) {
if(hasData("TEMPLATE")) {
templateDatablockName = "TEMPLATE";
}else {
if(hasData("TEMPLATE.default")) {
templateDatablockName = "TEMPLATE.default";
}else {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "template definition file " + getAbsoluteFilename() + " is corrupt. cannot find default section.");
}
throw new CmsException("Corrupt template file " + getAbsoluteFilename() + ". Cannot find default section.", CmsException.C_XML_TAG_MISSING);
}
}
}
return templateDatablockName;
}
/**
* Utility method to get the correct edit-datablock name for a given selector.<BR>
* If no selector is given or the selected section is not found, the template section
* with no name will be returned. If even this is not found the section named "default"
* will be returned.
*
* @param templateSelector Name of the template section or null if the default section is requested.
* @return Appropriate name of the template datablock.
* @throws CmsException
*/
private String getEditTemplateDatablockName(String templateSelector) throws CmsException {
String templateDatablockName = null;
if(templateSelector != null && !"".equals(templateSelector)) {
if(hasData(C_EDIT_TEMPLATE + "." + templateSelector)) {
templateDatablockName = C_EDIT_TEMPLATE + "." + templateSelector;
}else {
if((I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) && (!"script".equals(templateSelector))) {
A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "cannot load selected template file section " + templateSelector + " in template file " + getFilename() + ". Fallback to default section.");
}
}
}
if(templateDatablockName == null && (!"script".equals(templateSelector))) {
if(hasData(C_EDIT_TEMPLATE)) {
templateDatablockName = C_EDIT_TEMPLATE;
}else {
if(hasData(C_EDIT_TEMPLATE + ".default")) {
templateDatablockName = C_EDIT_TEMPLATE + ".default";
}else{
// no default section. file seems to be an old one without the edittemplate section
// so create it.
setData(C_EDIT_TEMPLATE , (String)null);
templateDatablockName = C_EDIT_TEMPLATE;
}
}
}
return templateDatablockName;
}
/**
* Gets the expected tagname for the XML documents of this content type
* @return Expected XML tagname.
*/
public String getXmlDocumentTagName() {
return "XMLTEMPLATE";
}
/**
* Handling of the <CODE><ELEMENT></CODE> tags.
* Calls the user method <code>elementTag</code> that has to be
* defined in the XML template class.
*
* @param n XML element containing the <code><PROCESS></code> tag.
* @param callingObject Reference to the object requesting the node processing.
* @param userObj Customizable user object that will be passed through to handling and user methods.
* @return Result of user method <code>templateElement()</code>.
* @throws CmsException
*/
public Object handleElementTag(Element n, Object callingObject, Object userObj) throws CmsException {
String tagcontent = n.getAttribute("name");
return callUserMethod("templateElement", tagcontent, callingObject, userObj, false);
}
/**
* Checks if this Template owns a datablock with the given key.
* @param key Datablock key to be checked.
* @return true if a datablock is found, false otherwise.
*/
public boolean hasData(String key) {
return super.hasData(key);
}
/**
* Checks if the section with the given name is defined
* in this XML template file.
* @param name Name of the requested section.
* @return <code>true</code> if a section exists, <code>false</code> otherwise.
*/
public boolean hasSection(String name) {
return hasData("template." + name);
}
/**
* Check if there is the template class of a given subelement defined.
* @param elementName Name of the subelement.
* @return <code>true</code>, if defined, <code>false</code> otherwise
*/
public boolean hasSubtemplateClass(String name) throws CmsException {
return hasData("ELEMENTDEF." + name + ".CLASS");
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -