1 28 29 package com.opencms.template; 30 31 import org.opencms.file.CmsObject; 32 import org.opencms.file.CmsRequestContext; 33 34 import com.opencms.legacy.CmsXmlTemplateLoader; 35 import com.opencms.template.cache.CmsTimeout; 36 37 import java.util.Enumeration ; 38 import java.util.Hashtable ; 39 import java.util.Vector ; 40 41 49 50 public abstract class A_CmsCacheDirectives { 51 52 53 protected int m_cd; 54 55 57 private boolean m_user; 59 private boolean m_group; 61 private boolean m_uri; 63 private Vector m_cacheParameter; 65 66 private Vector m_dynamicParameter; 68 69 private boolean m_renewAfterEveryPublish; 71 72 73 protected CmsTimeout m_timeout; 74 75 protected boolean m_timecheck; 76 77 78 protected boolean m_userSetProxyPrivate; 79 80 protected boolean m_userSetProxyPublic; 81 82 protected boolean m_userSetExport; 83 84 85 86 public static final int C_CACHE_INTERNAL = 1; 87 88 public static final int C_CACHE_PROXY_PRIVATE = 2; 89 90 public static final int C_CACHE_PROXY_PUBLIC = 4; 91 92 public static final int C_CACHE_EXPORT = 8; 93 94 public static final int C_CACHE_STREAM = 16; 95 96 101 public boolean isInternalCacheable() { 102 return (m_cd & C_CACHE_INTERNAL) == C_CACHE_INTERNAL; 103 } 104 105 110 public boolean isUserPartOfKey() { 111 return m_group || m_user; 112 } 113 118 public boolean isParameterPartOfKey() { 119 return (m_cacheParameter != null) && (!m_cacheParameter.isEmpty()); 120 } 121 122 127 public CmsTimeout getTimeout() { 128 return m_timeout; 129 } 130 131 136 public boolean isTimeCritical() { 137 return m_timecheck; 138 } 139 140 144 public abstract void setTimeout(CmsTimeout timeout); 145 146 151 public void renewAfterEveryPublish() { 152 m_renewAfterEveryPublish = true; 153 } 154 155 160 public void noAutoRenewAfterPublish() { 161 m_renewAfterEveryPublish = false; 162 } 163 164 170 public boolean shouldRenew() { 171 return m_renewAfterEveryPublish; 172 } 173 174 181 public String getCacheKey(CmsObject cms, Hashtable parameters) { 182 183 if (! this.isInternalCacheable()) { 184 return null; 185 } 186 if (parameters == null) { 187 parameters = new Hashtable (); 188 } 189 if ((m_dynamicParameter != null) && (!m_dynamicParameter.isEmpty())) { 191 for (int i=0; i < m_dynamicParameter.size(); i++) { 192 String testparameter = (String )m_dynamicParameter.elementAt(i); 193 if (parameters.containsKey(testparameter)) { 194 return null; 195 } 196 } 197 } 198 CmsRequestContext reqContext = cms.getRequestContext(); 199 String groupKey = ""; 200 209 String scheme = "http"; 212 try { 213 scheme = (CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()).getScheme(); 214 } catch (Exception e) { 215 } 217 String key = "key_"+scheme+"_"; 218 if (m_uri) { 219 key += reqContext.getUri(); 220 } 221 if (m_user) { 222 key += reqContext.currentUser().getName(); 223 } 224 key += groupKey; 225 if ((m_cacheParameter != null) && (!m_cacheParameter.isEmpty())) { 226 for (int i=0; i < m_cacheParameter.size(); i++) { 227 String para = (String )m_cacheParameter.elementAt(i); 228 if (parameters.containsKey(para)) { 229 key += (String )parameters.get(para); 230 } 231 } 232 } 233 if (key.equals("")) { 234 return null; 235 } 236 String elementName = (String )parameters.get("_ELEMENT_"); 238 if (elementName == null) { 239 elementName = com.opencms.core.I_CmsConstants.C_ROOT_TEMPLATE_NAME; 241 } 242 Enumeration paramKeys = parameters.keys(); 243 while (paramKeys.hasMoreElements()) { 244 String paramKey = (String ) paramKeys.nextElement(); 245 if (paramKey.startsWith(elementName)) { 246 key += paramKey + "=" + parameters.get(paramKey) + ";"; 247 } 248 } 249 return key; 250 } 251 252 257 public void setCacheGroups(boolean groupCache) { 258 m_group = groupCache; 259 } 260 261 267 public void setCacheGroups(Vector groupNames) { 268 groupNames.hashCode(); 272 } 273 274 279 public void setCacheUser(boolean userCache) { 280 m_user = userCache; 281 } 283 284 289 public void setCacheUri(boolean uriCache) { 290 m_uri = uriCache; 291 m_renewAfterEveryPublish = true; 292 } 293 294 300 public void setCacheParameters(Vector parameterNames) { 301 m_cacheParameter = parameterNames; 302 } 303 304 309 public void setNoCacheParameters(Vector parameterNames) { 310 m_dynamicParameter = parameterNames; 311 } 312 313 322 protected void setExternalCaching(boolean internal, boolean proxyPriv, boolean proxyPub, boolean export, boolean stream) { 323 m_cd = 0; 324 m_cd |= internal?C_CACHE_INTERNAL:0; 325 m_cd |= proxyPriv?C_CACHE_PROXY_PRIVATE:0; 326 m_cd |= proxyPub?C_CACHE_PROXY_PUBLIC:0; 327 m_cd |= export?C_CACHE_EXPORT:0; 328 m_cd |= stream?C_CACHE_STREAM:0; 329 } 330 331 338 public void merge(A_CmsCacheDirectives cd) { 339 m_cd &= cd.m_cd; 340 } 341 342 347 public boolean isProxyPrivateCacheable() { 348 return (m_cd & C_CACHE_PROXY_PRIVATE) == C_CACHE_PROXY_PRIVATE; 349 } 350 351 356 public boolean isProxyPublicCacheable() { 357 return (m_cd & C_CACHE_PROXY_PUBLIC) == C_CACHE_PROXY_PUBLIC; 358 } 359 360 365 public boolean isExportable() { 366 return (m_cd & C_CACHE_EXPORT) == C_CACHE_EXPORT; 367 } 368 369 374 public boolean isStreamable() { 375 return (m_cd & C_CACHE_STREAM) == C_CACHE_STREAM; 376 } 377 378 383 public boolean userSetProxyPrivate() { 384 return m_userSetProxyPrivate; 385 } 386 391 public boolean userSetProxyPublic() { 392 return m_userSetProxyPublic; 393 } 394 398 public boolean userSetExport() { 399 return m_userSetExport; 400 } 401 402 403 }
| Popular Tags
|