📄 cmsxmltemplate.java
字号:
else {
if(templateFile.hasData("stylesheet")) {
styleNS = templateFile.getDataValue("stylesheet");
}
else {
styleNS = "";
}
}
HttpServletRequest orgReq = (HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest();
String servletPath = cms.getRequestContext().getRequest().getServletUrl() + "/";
// Get the user's browser
String browser = orgReq.getHeader("user-agent");
if(browser == null) {
// the browser is unknown - return the ns-style
return styleNS;
}
if(browser.indexOf("MSIE") > -1) {
return servletPath + styleIE;
}
else {
return servletPath + styleNS;
}
}
/**
* Find the corresponding template class to be loaded.
* this should be defined in the template file of the parent
* template and can be overwritten in the body file.
*
* @param elementName Element name of this template in our parent template.
* @param doc CmsXmlTemplateFile object of our template file including a subtemplate.
* @param parameters Hashtable with all template class parameters.
* @return Name of the class that should generate the output for the included template file.
*/
protected String getTemplateClassName(String elementName, CmsXmlTemplateFile doc, Hashtable parameters) throws CmsException {
String result = null;
if(parameters.containsKey(elementName + "._CLASS_")) {
result = (String)parameters.get(elementName + "._CLASS_");
}else {
if(doc.hasSubtemplateClass(elementName)) {
result = doc.getSubtemplateClass(elementName);
}else {
// Fallback to "body" element
if(parameters.containsKey("body._CLASS_")) {
result = (String)parameters.get("body._CLASS_");
}
}
}
if(result == null){
CmsElementDefinitionCollection elDefs = (CmsElementDefinitionCollection)parameters.get("_ELDEFS_");
if(elDefs != null){
CmsElementDefinition elDef = elDefs.get(elementName);
if(elDef != null){
result = elDef.getClassName();
}
}
}
return result;
}
/**
* Find the corresponding template file to be loaded by the template class.
* this should be defined in the template file of the parent
* template and can be overwritten in the body file.
*
* @param elementName Element name of this template in our parent template.
* @param doc CmsXmlTemplateFile object of our template file including a subtemplate.
* @param parameters Hashtable with all template class parameters.
* @return Name of the template file that should be included.
*/
protected String getTemplateFileName(String elementName, CmsXmlTemplateFile doc, Hashtable parameters) throws CmsException {
String result = null;
if(parameters.containsKey(elementName + "._TEMPLATE_")) {
result = (String)parameters.get(elementName + "._TEMPLATE_");
}else {
if(doc.hasSubtemplateFilename(elementName)) {
result = doc.getSubtemplateFilename(elementName);
}else {
// Fallback to "body" element
if(parameters.containsKey("body._TEMPLATE_")) {
result = (String)parameters.get("body._TEMPLATE_");
}
}
}
if(result == null){
CmsElementDefinitionCollection elDefs = (CmsElementDefinitionCollection)parameters.get("_ELDEFS_");
if(elDefs != null){
CmsElementDefinition elDef = elDefs.get(elementName);
if(elDef != null){
result = elDef.getTemplateName();
}
}
}
return result;
}
/**
* Find the corresponding template selector to be activated.
* This may be defined in the template file of the parent
* template and can be overwritten in the body file.
*
* @param elementName Element name of this template in our parent template.
* @param doc CmsXmlTemplateFile object of our template file including a subtemplate.
* @param parameters Hashtable with all template class parameters.
* @return Name of the class that should generate the output for the included template file.
*/
protected String getTemplateSelector(String elementName, CmsXmlTemplateFile doc, Hashtable parameters) throws CmsException {
if(parameters.containsKey(elementName + "._TEMPLATESELECTOR_")) {
return (String)parameters.get(elementName + "._TEMPLATESELECTOR_");
}
else {
if(doc.hasSubtemplateSelector(elementName)) {
return doc.getSubtemplateSelector(elementName);
}
else {
CmsElementDefinitionCollection elDefs = (CmsElementDefinitionCollection)parameters.get("_ELDEFS_");
if(elDefs != null){
CmsElementDefinition elDef = elDefs.get(elementName);
if(elDef != null){
return elDef.getTemplateSelector();
}
}
return null;
}
}
}
/**
* Inserts the correct document title into the template.
* <P>
* This method can be called using <code><METHOD name="getTitle"></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 userObj Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @exception CmsException
*/
public Object getTitle(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String title = cms.readProperty(requestedUri, C_PROPERTY_TITLE);
if(title == null) {
title = "";
}
return title;
}
/**
* 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 userObj Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @exception CmsException
*/
public Object getDescription(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String description = cms.readProperty(requestedUri, C_PROPERTY_DESCRIPTION);
if(description == null) {
description = "";
}
return description;
}
/**
* Inserts the value of the given property in the template.
* <P>
* This method can be called using <code><METHOD name="getProperty"></code>
* in the template file.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent The name of the property.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObj Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @exception CmsException
*/
public Object getProperty(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String value = "";
try{
value = cms.readProperty(requestedUri, tagcontent);
}catch(Exception e){
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(C_OPENCMS_INFO, "[CmsXmlTemplate] usermethod getProperty throwed an Exception getting "+
tagcontent+": "+e.toString());
}
}
if(value == null) {
value = "";
}
return value;
}
/**
* 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 userObj Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @exception CmsException
*/
public Object getKeywords(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String keywords = cms.readProperty(requestedUri, C_PROPERTY_KEYWORDS);
if(keywords == null) {
keywords = "";
}
return keywords;
}
/**
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent May contain the parameter for framesets to work in the static export.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObj Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @exception CmsException
*/
public Object getUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
String res = cms.getRequestContext().getUri();
if(tagcontent == null || "".equals(tagcontent)){
return (cms.getLinkSubstitution(res)).getBytes();
}else{
return (cms.getLinkSubstitution(res+"?"+tagcontent)).getBytes();
}
}
/**
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Contains the parameter for framesets.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObj Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @exception CmsException
*/
public Object getUriWithParameter(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 = null;
if(cms.getMode() == cms.C_MODUS_EXPORT){
parameters = cms.getRequestContext().getRequest().getParameterNames();
}else{
parameters = ((HttpServletRequest)cms.getRequestContext().getRequest().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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -