1 28 29 30 package com.opencms.template; 31 32 import org.opencms.file.CmsFile; 33 import org.opencms.file.CmsObject; 34 import org.opencms.main.CmsException; 35 import org.opencms.main.CmsLog; 36 37 import com.opencms.core.I_CmsResponse; 38 import com.opencms.legacy.CmsLegacyException; 39 import com.opencms.legacy.CmsXmlTemplateLoader; 40 41 import java.util.Hashtable ; 42 43 52 public class CmsRootTemplate { 53 54 71 public byte[] getMasterTemplate(CmsObject cms, I_CmsTemplate templateClass, CmsFile masterTemplate, com.opencms.template.I_CmsTemplateCache cache, Hashtable parameters) throws CmsException { 72 byte[] result; 73 74 String masterTemplateUri = cms.getSitePath(masterTemplate); 75 CmsCacheDirectives cd = templateClass.collectCacheDirectives(cms, masterTemplateUri, com.opencms.core.I_CmsConstants.C_ROOT_TEMPLATE_NAME, parameters, null); 77 78 89 90 Object cacheKey = templateClass.getKey(cms, masterTemplateUri, parameters, null); 91 boolean cacheable = cd.isInternalCacheable(); 92 93 I_CmsResponse resp = CmsXmlTemplateLoader.getResponse(cms.getRequestContext()); 94 95 if (!resp.containsHeader("Cache-Control")) { 97 98 if (cd.isProxyPublicCacheable() || cd.isProxyPrivateCacheable()) { 101 102 resp.setHeader("Cache-Control", "max-age=300"); 104 if (cd.isProxyPrivateCacheable()) { 105 resp.addHeader("Cache-Control", "private"); 106 } 107 108 109 } else { 110 resp.setHeader("Cache-Control", "no-cache"); 113 resp.setHeader("Pragma", "no-cache"); 115 } 116 } 117 118 if (cacheable && cache.has(cacheKey) && !templateClass.shouldReload(cms, masterTemplateUri, com.opencms.core.I_CmsConstants.C_ROOT_TEMPLATE_NAME, parameters, null)) { 119 result = cache.get(cacheKey); 120 } else { 121 try { 122 result = templateClass.getContent(cms, masterTemplateUri, com.opencms.core.I_CmsConstants.C_ROOT_TEMPLATE_NAME, parameters); 123 } catch (CmsException e) { 124 cache.clearCache(cacheKey); 125 if (CmsLog.getLog(this).isWarnEnabled() && (e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_USER)) { 126 127 CmsLog.getLog(this).warn("Could not get contents of master template " + masterTemplate.getName(), e); 128 } 129 throw e; 130 } 131 if (cacheable) { 132 cache.put(cacheKey, result); 133 } 134 } 135 return result; 136 } 137 } 138 | Popular Tags |