📄 cmsxmltemplatefile.java
字号:
if(n.getNodeType() == n.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 a processed datablock from the datablock hashtable.
*
* @param tag Key for the datablocks hashtable.
* @return Processed datablock for the given key.
* @exception CmsException
*/
public Element getProcessedData(String tag) throws CmsException {
return super.getProcessedData(tag);
}
/**
* Gets a processed datablock from the datablock hashtable.
*
* @param tag Key for the datablocks hashtable.
* @param callingObject Object that should be used to look up user methods.
* @return Processed datablock for the given key.
* @exception CmsException
*/
public Element getProcessedData(String tag, Object callingObject) throws CmsException {
return super.getProcessedData(tag, callingObject);
}
/**
* Gets a processed datablock from the datablock hashtable.
* <P>
* The userObj Object is passed to all called user methods.
* By using this, the initiating class can pass customized data to its methods.
*
* @param tag Key for the datablocks hashtable.
* @param callingObject Object that should be used to look up user methods.
* @param userObj any object that should be passed to user methods
* @return Processed datablock for the given key.
* @exception CmsException
*/
public Element getProcessedData(String tag, Object callingObject, Object userObj) throws CmsException {
return super.getProcessedData(tag, callingObject, userObj);
}
/**
* Gets the text and CDATA content of a processed datablock from the
* datablock hashtable.
*
* @param tag Key for the datablocks hashtable.
* @return Processed datablock for the given key.
* @exception CmsException
*/
public String getProcessedDataValue(String tag) throws CmsException {
return super.getProcessedDataValue(tag);
}
/**
* Gets the text and CDATA content of a processed datablock from the
* datablock hashtable.
*
* @param tag Key for the datablocks hashtable.
* @param callingObject Object that should be used to look up user methods.
* @return Processed datablock for the given key.
* @exception CmsException
*/
public String getProcessedDataValue(String tag, Object callingObject) throws CmsException {
return super.getProcessedDataValue(tag, callingObject);
}
/**
* Gets the text and CDATA content of a processed datablock from the
* datablock hashtable.
* <P>
* The userObj Object is passed to all called user methods.
* By using this, the initiating class can pass customized data to its methods.
*
* @param tag Key for the datablocks hashtable.
* @param callingObject Object that should be used to look up user methods.
* @param userObj any object that should be passed to user methods
* @return Processed datablock for the given key.
* @exception CmsException
*/
public String getProcessedDataValue(String tag, Object callingObject, Object userObj) throws CmsException {
return super.getProcessedDataValue(tag, callingObject, userObj);
}
/**
* Gets the text and CDATA content of a processed datablock from the
* datablock hashtable. An eventually given output stream is user for streaming
* the generated result directly to the response output stream while processing.
* <P>
* The userObj Object is passed to all called user methods.
* By using this, the initiating class can pass customized data to its methods.
*
* @param tag Key for the datablocks hashtable.
* @param callingObject Object that should be used to look up user methods.
* @param userObj any object that should be passed to user methods
* @param stream OutputStream that may be used for directly streaming the results or null.
* @return Processed datablock for the given key.
* @exception CmsException
*/
public String getProcessedDataValue(String tag, Object callingObject, Object userObj, OutputStream stream) throws CmsException {
return super.getProcessedDataValue(tag, callingObject, userObj, stream);
}
/**
* Gets the processed data of the default <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.
* @return Processed template data.
* @exception CmsException
* @see #getTemplateDatablockName
*/
public String getProcessedTemplateContent(Object callingObject, Hashtable parameters) throws CmsException {
return getProcessedTemplateContent(callingObject, parameters, null);
}
/**
* Gets the processed 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.
* @exception CmsException
* @see #getTemplateDatablockName
*/
public String getProcessedTemplateContent(Object callingObject, Hashtable parameters, String templateSelector) throws CmsException {
OutputStream os = null;
if(m_cms.getRequestContext().isStreaming()) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_STREAMING, getClassName() + "Entering streaming mode for file: " + getAbsoluteFilename());
}
try {
os = m_cms.getRequestContext().getResponse().getOutputStream();
} catch (Exception e) {
throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, e);
}
} else {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
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 "";
}
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.
* @exception CmsException
* @see #getProcessedElementContent
*/
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() == n.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().getBytes());
buf = new StringBuffer();
}
// Create new CmsElementLink
CmsElementLink link = new CmsElementLink(elName);
result.add(link);
}
} else if (n.getNodeType() == n.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().getBytes());
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() == n.TEXT_NODE || n.getNodeType() == n.CDATA_SECTION_NODE) {
buf.append(n.getNodeValue());
}
}
// Store pending buffer content
if(buf.length() > 0) {
result.add(buf.toString().getBytes());
}
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.
* @exception CmsException
* @see #getTemplateDatablockName
*/
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.
* @exception 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.
* @exception CmsException
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -