📄 cmsxmltemplate.java
字号:
* @return String or byte[] with the content of this subelement.
* @throws 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, CmsPropertyDefinition.PROPERTY_KEYWORDS);
if (keywords == null) {
keywords = "";
}
return keywords;
}
/**
* gets the caching information for a specific methode.
* @param cms the cms object.
* @param methodName the name of the method for witch the MethodCacheDirectives are wanted.
*/
public CmsMethodCacheDirectives getMethodCacheDirectives(CmsObject cms, String methodName) {
if ("getTitle".equals(methodName) || "getUri".equals(methodName)
|| "getFileUri".equals(methodName) || "getDescription".equals(methodName)
|| "getKeywords".equals(methodName) || "getProperty".equals(methodName)
|| "getPathUri".equals(methodName)) {
CmsMethodCacheDirectives mcd = new CmsMethodCacheDirectives(true);
mcd.setCacheUri(true);
return mcd;
}
if ("getFrameQueryString".equals(methodName) || "getQueryString".equals(methodName)
|| "getRequestIp".equals(methodName) || "getSessionId".equals(methodName)
|| "getUriWithParameter".equals(methodName) || "parameters".equals(methodName)
|| "getStylesheet".equals(methodName)) {
return new CmsMethodCacheDirectives(false);
}
return null;
}
/**
* Reads in the template file and starts the XML parser for the expected
* content type.
* <P>
* Every extending class using not CmsXmlTemplateFile as content type,
* but any derived type should override this method.
*
* @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 the template file
* @throws CmsException if something goes wrong
*/
public CmsXmlTemplateFile getOwnTemplateFile(CmsObject cms, String templateFile,
String elementName, Hashtable parameters, String templateSelector) throws CmsException {
CmsXmlTemplateFile xmlTemplateDocument = new CmsXmlTemplateFile(cms, templateFile);
return xmlTemplateDocument;
}
/**
* Gets the path uri.<p>
*
* @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 getPathUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String path = cms.getRequestContext().getUri();
path = path.substring(0, path.lastIndexOf("/") + 1);
path = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl() + path;
return path.getBytes();
}
/**
* 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 userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
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 (CmsLog.getLog(this).isWarnEnabled()) {
CmsLog.getLog(this).warn("Usermethod getProperty throwed an Exception getting "
+ tagcontent, e);
}
}
if (value == null) {
value = "";
}
return value;
}
/**
* Inserts the correct servlet path 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 userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
public Object getQueryString(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String query = (CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()).getQueryString();
if (query != null && !"".equals(query)) {
query = "?" + query;
}
return query;
}
/**
* Get the IP address of the current request.
* <P>
* This method can be called using <code><METHOD name="getRequestIp"></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 String getRequestIp(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
return (CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()).getRemoteAddr();
}
/**
* Inserts the correct servlet path 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 userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
* @deprecated instead of this method you should use the link tag.
*/
public Object getServletPath(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
return CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl() + "/";
}
/**
* Get the session id. If no session exists, a new one will be created.
* <P>
* This method can be called using <code><METHOD name="getSessionId"></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 String getSessionId(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
return (CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()).getSession(true).getId();
}
/**
* Inserts the correct stylesheet into the layout template.
* <P>
* This method can be called using <code><METHOD name="getStylesheet"></code>
* in the template file.
* <P>
* When using this method follwing parameters should be defined
* either in the page file or in the template file:
* <ul>
* <li><code>root.stylesheet-ie</code></li>
* <li><code>root.stylesheet-ns</code></li>
* </ul>
* These parameters should contain the correct OpenCms path
* for the Internet Explorer and Netscape Navigate
* specific stylesheets.
*
* @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 In case no stylesheet was found (or there were errors accessing the CmsObject)
*/
public String getStylesheet(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String styleSheetUri = null;
try {
styleSheetUri = getStylesheet(cms, tagcontent, null, doc, userObject);
} catch (CmsException e) {
// Happens if no frametemplate is defined, can be ignored
}
if ((styleSheetUri == null) || ("".equals(styleSheetUri))) {
styleSheetUri = getStylesheet(cms, tagcontent, "frametemplate", doc, userObject);
} // The original behaviour is to throw an exception in case no stylesheed could be found
if (styleSheetUri == null) {
styleSheetUri = "";
}
return styleSheetUri;
}
/**
* Inserts the 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 userObject Hashtable with parameters.
* @return String or byte[] with the content of this subelement.
* @throws CmsException if something goes wrong
*/
public Object getTitle(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String title = cms.readProperty(requestedUri, CmsPropertyDefinition.PROPERTY_TITLE);
if (title == null) {
return "";
}
return title;
}
/**
* Inserts the document title into the template, escaping special and non - ASCII characters
* with their HTML number representation (e.g. & becomes &#38;).<p>
*
* This method can be called using <code><METHOD name="getTitleEscaped"></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 getTitleEscaped(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObject) throws CmsException {
String requestedUri = cms.getRequestContext().getUri();
String title = cms.readProperty(requestedUri, CmsPropertyDefinition.PROPERTY_TITLE);
if (title == null) {
return "";
}
return CmsEncoder.escapeHtml(title);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -