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.file.CmsRequestContext; 35 import org.opencms.main.CmsException; 36 import org.opencms.main.CmsLog; 37 38 import com.opencms.legacy.CmsLegacyException; 39 import com.opencms.legacy.CmsXmlTemplateLoader; 40 import com.opencms.template.cache.A_CmsElement; 41 import com.opencms.template.cache.CmsElementDump; 42 43 import java.util.Hashtable ; 44 45 55 public class CmsDumpTemplate extends A_CmsTemplate implements I_CmsDumpTemplate { 56 57 58 private static final boolean C_DEBUG = false; 59 60 63 public CmsDumpTemplate() { 64 } 66 67 77 public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) { 78 CmsCacheDirectives result = new CmsCacheDirectives(true); 80 result.setCacheUri(true); 81 return result; 82 83 } 84 85 95 public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters) throws CmsException { 96 if (C_DEBUG && CmsLog.getLog(this).isDebugEnabled()) { 97 CmsLog.getLog(this).debug("Dumping contents of file " + templateFile); 98 } 99 byte[] s = null; 100 try { 101 CmsFile file = cms.readFile(templateFile); 103 s = file.getContents(); 104 } catch (Exception e) { 105 s = null; 106 String errorMessage = "Error while reading file " + templateFile + ": " + e; 107 if (CmsLog.getLog(this).isErrorEnabled()) { 108 CmsLog.getLog(this).error(errorMessage, e); 109 } 110 if (e instanceof CmsException) { 111 throw (CmsException)e; 112 } else { 113 throw new CmsLegacyException(errorMessage, CmsLegacyException.C_UNKNOWN_EXCEPTION); 114 } 115 } 116 return s; 117 } 118 119 130 public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException { 131 132 return getContent(cms, templateFile, elementName, parameters); 134 } 135 136 149 public Object getKey(CmsObject cms, String templateFile, Hashtable parameter, String templateSelector) { 150 CmsRequestContext reqContext = cms.getRequestContext(); 151 return "" + reqContext.currentProject().getId() + ":" + reqContext.addSiteRoot(templateFile); 152 } 153 154 159 public boolean isTemplateCacheSet() { 160 return true; 161 } 162 163 169 public void setTemplateCache(I_CmsTemplateCache c) { 170 } 172 173 183 public boolean shouldReload(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) { 184 return false; 185 } 186 187 199 public A_CmsElement createElement (CmsObject cms, String templateFile, Hashtable parameters) { 200 return new CmsElementDump(getClass().getName(), templateFile, getCacheDirectives(cms, templateFile, null, parameters, null), 201 CmsXmlTemplateLoader.getElementCache().getVariantCachesize()); 202 } 203 } 204 | Popular Tags |