📄 cmsxmltemplate.java
字号:
// First build our own cache directives.
CmsCacheDirectives result = new CmsCacheDirectives(true);
Vector para = new Vector();
para.add("cmsframe");
result.setCacheParameters(para);
return result;
}
/**
* Gets the content of a given template file and its subtemplates
* with the given parameters. The default section in the template file
* will be used.
* <P>
* Parameters are stored in a hashtable and can derive from
* <UL>
* <LI>Template file of the parent template</LI>
* <LI>Body file clicked by the user</LI>
* <LI>URL parameters</LI>
* </UL>
* Paramter names must be in "elementName.parameterName" format.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template
* @param parameters Hashtable with all template class parameters.
* @return Content of the template and all subtemplates.
* @throws CmsException if something goes wrong
*/
public byte[] getContent(CmsObject cms, String templateFile, String elementName,
Hashtable parameters) throws CmsException {
return getContent(cms, templateFile, elementName, parameters, null);
}
/**
* Gets the content of a defined section in a given template file and its subtemplates
* with the given parameters.
*
* @see #getContent(CmsObject, String, String, Hashtable, String)
* @param cms CmsObject Object for accessing system resources.
* @param templateFile Filename of the template file.
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return Content of the template and all subtemplates.
* @throws CmsException if something goes wrong
*/
public byte[] getContent(CmsObject cms, String templateFile, String elementName,
Hashtable parameters, String templateSelector) throws CmsException {
if (CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
CmsLog.getLog(this).debug("[CmsXmlTemplate] getting content of element "
+ ((elementName == null) ? "<root>" : elementName));
CmsLog.getLog(this).debug("[CmsXmlTemplate] template file is: " + templateFile);
CmsLog.getLog(this).debug("[CmsXmlTemplate] selected template section is: "
+ ((templateSelector == null) ? "<default>" : templateSelector));
}
CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
if (templateSelector == null || "".equals(templateSelector)) {
templateSelector = (String)parameters.get(C_FRAME_SELECTOR);
}
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
}
/**
* Inserts the correct document description into the template.
* <P>
* This method can be called using <code><METHOD name="getDescription"></code>
* in the template file.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
public Object getDescription(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String description = cms.readProperty(requestedUri, CmsPropertyDefinition.PROPERTY_DESCRIPTION);
if (description == null) {
description = "";
}
return description;
}
public Object getEncoding(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
return cms.getRequestContext().getEncoding();
}
/**
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
public Object getFileUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String uri = cms.getRequestContext().getUri();
return uri.substring(uri.lastIndexOf("/") + 1);
}
/**
* Gets the QueryString for CmsFrameTemplates.
* <P>
* This method can be called using <code><METHOD name="getCmsQueryString"></code>
* in the template file.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
public Object getFrameQueryString(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String query = new String();
// get the parameternames of the original request and get the values from the userObject
try {
Enumeration parameters = (CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()).getParameterNames();
StringBuffer paramQuery = new StringBuffer();
while (parameters.hasMoreElements()) {
String name = (String)parameters.nextElement();
String value = (String)((Hashtable)userObject).get(name);
if (value != null && !"".equals(value)) {
paramQuery.append(name + "=" + value + "&");
}
}
if (paramQuery.length() > 0) {
// add the parameters to the query string
query = paramQuery.substring(0, paramQuery.length() - 1).toString();
}
} catch (Exception exc) {
exc.printStackTrace();
}
// get the name of the frame and parameters
String frame = "", param = "";
if (!tagcontent.equals("")) {
if (!tagcontent.startsWith("&")) {
if (tagcontent.indexOf(",") != -1) {
frame = tagcontent.substring(0, tagcontent.indexOf(","));
param = tagcontent.substring(tagcontent.indexOf(",") + 1);
} else {
frame = tagcontent;
}
} else {
param = tagcontent;
}
}
query = (query == null ? "" : query);
if (!query.equals("")) {
if (query.indexOf("cmsframe=") != -1) {
int start = query.indexOf("cmsframe=");
int end = query.indexOf("&", start);
String cmsframe = "";
if (end != -1) {
cmsframe = query.substring(start + 9, end);
} else {
cmsframe = query.substring(start + 9);
}
if (!cmsframe.equals("plain")) {
if (!frame.equals("")) {
if (end != -1) {
query = query.substring(0, start + 9) + frame + query.substring(end);
} else {
query = query.substring(0, start + 9) + frame;
}
} else {
if (end != -1) {
query = query.substring(0, start) + query.substring(end + 1);
} else {
query = query.substring(0, start);
}
}
}
} else {
if (!tagcontent.equals("")) {
query = query + "&cmsframe=" + frame;
}
}
if (!query.equals("")) {
query = "?" + query;
}
} else {
if (!frame.equals("")) {
query = "?cmsframe=" + frame;
}
}
if (!query.equals("")) {
query = query + param;
} else {
query = "?" + param.substring(param.indexOf("&") + 1);
}
if (query.trim().equals("?") || query.trim().equals("&") || query.trim().equals("?&")
|| query.trim().equals("??")) {
query = "";
}
return query;
}
/**
* Gets the target for a link.
* <P>
* This method can be called using <code><METHOD name="getCmsFrame"></code>
* in the template file.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
public Object getFrameTarget(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String target = "";
String cmsframe = (String)((Hashtable)userObject).get("cmsframe");
cmsframe = (cmsframe == null ? "" : cmsframe);
if (cmsframe.equals("plain")) {
target = "";
} else {
if (tagcontent.equals("")) {
target = "target=_top";
} else {
target = "target=" + tagcontent;
}
}
return target;
}
/**
* Gets the key that should be used to cache the results of
* <EM>this</EM> template class.
* <P>
* Since our results may depend on the used template file,
* the parameters and the requested body document, we must
* build a complex key using this three arguments.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return key that can be used for caching
*/
public Object getKey(CmsObject cms, String templateFile, Hashtable parameters,
String templateSelector) {
CmsRequestContext reqContext = cms.getRequestContext();
String result = "" + reqContext.currentProject().getId() + ":"
+ reqContext.currentUser().getName() + reqContext.getUri()
+ reqContext.addSiteRoot(templateFile);
Enumeration keys = parameters.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
result = result + key + parameters.get(key);
}
result = result + templateSelector;
return result;
}
/**
* Inserts the correct document keyword into the template.
* <P>
* This method can be called using <code><METHOD name="getKeywords"></code>
* in the template file.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObject Hashtable with parameters.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -