📄 cmsxmltemplate.java
字号:
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.
* @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, C_PROPERTY_KEYWORDS);
if(keywords == null) {
keywords = "";
}
return keywords;
}
public Object getEncoding(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
return cms.getRequestContext().getEncoding();
}
public Object setEncoding(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
if((tagcontent != null) && !"".equals(tagcontent)){
cms.getRequestContext().setEncoding(tagcontent.trim());
}
return "";
}
/**
* @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.
* @throws 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.
* @throws 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() == CmsObject.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
query = paramQuery.substring(0,paramQuery.length()-1).toString();
}
} catch (Exception exc){
exc.printStackTrace();
}
// get the parameters in the tagcontent
if((tagcontent != null) && (!"".equals(tagcontent))){
if(tagcontent.startsWith("?")){
tagcontent = tagcontent.substring(1);
}
query = tagcontent +"&" + query;
}
return getUri(cms, query, doc, userObject);
}
/**
* Indicates if the current template class is able to stream it's results
* directly to the response oputput stream.
* <P>
* Classes must not set this feature, if they might throw special
* exception that cause HTTP errors (e.g. 404/Not Found), or if they
* might send HTTP redirects.
* <p>
* If a class sets this feature, it has to check the
* isStreaming() property of the RequestContext. If this is set
* to <code>true</code> the results must be streamed directly
* to the output stream. If it is <code>false</code> the results
* must not be streamed.
* <P>
* Complex classes that are able top include other subtemplates
* have to check the streaming ability of their subclasses here!
*
* @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 <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
*/
public boolean isStreamable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
return true;
}
/**
* Collect caching informations from the current template class.
* <P>
* Complex classes that are able to include other subtemplates
* have to check the streaming ability of their subclasses here!
*
* @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 <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
*/
public CmsCacheDirectives collectCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
// Frist build our own cache directives.
boolean isCacheable = isCacheable(cms, templateFile, elementName, parameters, templateSelector);
boolean isProxyPrivateCacheable = isProxyPrivateCacheable(cms, templateFile, elementName, parameters, templateSelector);
boolean isProxyPublicCacheable = isProxyPublicCacheable(cms, templateFile, elementName, parameters, templateSelector);
boolean isExportable = isExportable(cms, templateFile, elementName, parameters, templateSelector);
boolean isStreamable = isStreamable(cms, templateFile, elementName, parameters, templateSelector);
CmsCacheDirectives result = new CmsCacheDirectives(isCacheable, isProxyPrivateCacheable, isProxyPublicCacheable, isExportable, isStreamable);
// Collect all subelements of this page
CmsXmlTemplateFile doc = null;
Vector subtemplates = null;
try {
doc = this.getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
doc.init(cms, templateFile);
subtemplates = doc.getAllSubElements();
// Loop through all subelements and get their cache directives
int numSubtemplates = subtemplates.size();
for(int i = 0;i < numSubtemplates;i++) {
String elName = (String)subtemplates.elementAt(i);
String className = null;
String templateName = null;
className = getTemplateClassName(elName, doc, parameters);
templateName = getTemplateFileName(elName, doc, parameters);
if(className != null) {
I_CmsTemplate templClass = (I_CmsTemplate)CmsTemplateClassManager.getClassInstance(cms, className);
CmsCacheDirectives cd2 = templClass.collectCacheDirectives(cms, templateName, elName, parameters, null);
/*System.err.println("* INT PUB PRV EXP STR");
debugPrint(elementName, result.m_cd);
System.err.println(" ");
debugPrint(elName, cd2.m_cd);
System.err.println(" " + templClass.getClass());
System.err.println("* -------------------");*/
//result.merge(templClass.collectCacheDirectives(cms, templateName, elName, parameters, null));
result.merge(cd2);
/*debugPrint(elementName, result.m_cd);
System.err.println(" ");
System.err.println("* ");*/
} else {
// This template file includes a subelement not exactly defined.
// The name of it's template class is missing at the moment, so
// we cannot say anything about the cacheablility.
// Set it to false.
return new CmsCacheDirectives(false);
}
}
}
catch(CmsException e) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_INFO, getClassName() + "Cannot determine cache directives for my template file " + templateFile + " (" + e + "). ");
A_OpenCms.log(C_OPENCMS_INFO, getClassName() + "Resuming normal operation, setting cacheability to false.");
return new CmsCacheDirectives(false);
}
}
return result;
}
/**
* gets the caching information from the current template class.
*
* @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 <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
*/
public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
// 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 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;
}
/**
* Tests, if the template cache is setted.
* @return <code>true</code> if setted, <code>false</code> otherwise.
*/
public final boolean isTemplateCacheSet() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -