1 28 29 package com.opencms.template.cache; 30 31 import org.opencms.file.CmsObject; 32 import org.opencms.main.CmsException; 33 import org.opencms.main.CmsLog; 34 import org.opencms.security.CmsSecurityException; 35 36 import com.opencms.legacy.CmsLegacyException; 37 import com.opencms.legacy.CmsXmlTemplateLoader; 38 import com.opencms.template.A_CmsCacheDirectives; 39 import com.opencms.template.CmsCacheDirectives; 40 import com.opencms.template.I_CmsTemplate; 41 42 import java.util.Hashtable ; 43 44 57 public class CmsElementXml extends A_CmsElement { 58 59 62 public CmsElementXml(String className, String templateName, CmsCacheDirectives cd, int variantCachesize) { 63 init(className, templateName, cd, variantCachesize); 64 } 65 66 75 public CmsElementXml(String className, String templateName, CmsCacheDirectives cd, CmsElementDefinitionCollection defs, int variantCachesize) { 76 init(className, templateName, cd, defs, variantCachesize); 77 } 78 79 89 public byte[] getContent(CmsElementCache elementCache, CmsObject cms, CmsElementDefinitionCollection elDefs, String elementName, Hashtable parameters, String methodParameter) throws CmsException { 90 byte[] result = null; 91 92 CmsElementDefinitionCollection mergedElDefs = new CmsElementDefinitionCollection(elDefs, m_elementDefinitions); 94 95 A_CmsCacheDirectives cd = getCacheDirectives(); 97 98 CmsElementVariant variant = null; 99 100 if(cd.isInternalCacheable()) { 102 103 checkReadAccess(cms); 104 if (cd.isTimeCritical() && (m_timestamp < cd.getTimeout().getLastChange())){ 106 if(this.hasDependenciesVariants()){ 108 CmsXmlTemplateLoader.getOnlineElementCache().getElementLocator().removeElementFromDependencies( 110 mergedElDefs.get(elementName).getDescriptor(), this); 111 } 112 clearVariantCache(); 113 }else{ 114 variant = getVariant(cd.getCacheKey(cms, parameters)); 115 if((variant != null) && variant.isTimeCritical() 116 && variant.getNextTimeout() < System.currentTimeMillis()){ 117 CmsXmlTemplateLoader.getOnlineElementCache().getElementLocator().removeVariantFromDependencies( 119 m_className +"|" + m_templateName +"|" + cd.getCacheKey(cms, parameters), variant); 120 variant = null; 121 } 122 } 123 if(variant != null) { 124 result = resolveVariant(cms, variant, elementCache, mergedElDefs, parameters); 125 } 126 } 127 if(variant == null) { 128 132 I_CmsTemplate templateClass = null; 134 try { 135 templateClass = getTemplateClass(cms, m_className); 136 } catch(Throwable e) { 137 if(CmsLog.getLog(this).isErrorEnabled()) { 138 CmsLog.getLog(this).error("Could not load my template class \"" + m_className + "\"", e); 139 return e.toString().getBytes(); 140 } 141 } 142 143 try { 144 149 parameters.put("_ELDEFS_", mergedElDefs); 156 String templateSelector = null; 157 try{ 158 templateSelector = mergedElDefs.get(elementName).getTemplateSelector(); 159 }catch(Exception e){ 160 } 161 try { 162 String theTemplate = m_templateName; 163 if(theTemplate == null){ 164 try{ 165 theTemplate = mergedElDefs.get("body").getTemplateName(); 166 }catch(Exception exc){ 167 if(CmsLog.getLog(this).isErrorEnabled()) { 168 CmsLog.getLog(this).error("Could not find the body element to get the default template file for " + this.toString(), exc); 169 } 170 } 171 } 172 result = templateClass.getContent(cms, theTemplate, elementName, parameters, templateSelector); 173 } catch(Exception e) { 174 if(e instanceof CmsException) { 175 CmsException ce = (CmsException)e; 176 if(ce instanceof CmsSecurityException) { 177 if(CmsLog.getLog(this).isDebugEnabled()) { 180 CmsLog.getLog(this).debug("Access denied in getContent for template class " + m_className); 181 } 182 } else { 183 if(CmsLog.getLog(this).isWarnEnabled()) { 186 CmsLog.getLog(this).warn("Error in getContent() for template class " + m_className, e); 187 } 188 } 189 throw ce; 190 } else { 191 if(CmsLog.getLog(this).isErrorEnabled()) { 193 CmsLog.getLog(this).error("Non OpenCms error occured in getContent for template class " + m_className, e); 194 } 195 throw new CmsLegacyException(CmsLegacyException.C_UNKNOWN_EXCEPTION, e); 196 } 197 } 198 } 199 catch(CmsException e) { 200 throw e; 202 } 203 } 204 return result; 205 } 206 }
| Popular Tags
|