1 16 package org.apache.cocoon.generation; 17 18 import org.apache.avalon.framework.component.Recomposable; 19 import org.apache.avalon.framework.component.ComponentManager; 20 import org.apache.avalon.framework.component.ComponentException; 21 22 import org.apache.cocoon.caching.CacheValidity; 23 import org.apache.cocoon.caching.Cacheable; 24 import org.apache.cocoon.caching.CacheableProcessingComponent; 25 import org.apache.cocoon.components.language.generator.CompiledComponent; 26 import org.apache.cocoon.environment.Request; 27 28 import org.apache.excalibur.source.SourceValidity; 29 import org.apache.excalibur.source.impl.validity.NOPValidity; 30 31 import org.xml.sax.SAXException ; 32 import org.xml.sax.helpers.AttributesImpl ; 33 34 import java.io.File ; 35 import java.io.Serializable ; 36 37 44 public abstract class AbstractServerPage 45 extends ServletGenerator 46 implements CompiledComponent, CacheableProcessingComponent, Cacheable, Recomposable { 47 61 62 63 protected long dateCreated = -1L; 64 65 protected File [] dependencies = null; 66 67 71 public void recompose(ComponentManager manager) throws ComponentException { 72 this.manager = manager; 73 } 74 75 81 public boolean modifiedSince(long date) { 82 if (date == 0 || dateCreated < date) { 83 return true; 84 } 85 86 for (int i = 0; i < dependencies.length; i++) { 87 if (dateCreated < dependencies[i].lastModified()) { 88 return true; 89 } 90 } 91 92 return false; 93 } 94 95 104 public boolean hasContentChanged(Request request) { 105 return true; 106 } 107 108 116 public Serializable getKey() { 117 return null; 118 } 119 120 129 public SourceValidity getValidity() { 130 if (hasContentChanged(request)) 131 return null; 132 else 133 return NOPValidity.SHARED_INSTANCE; 134 } 135 136 138 145 protected void attribute(AttributesImpl attr, String name, String value) { 146 attr.addAttribute("", name, name, "CDATA", value); 147 } 148 149 155 protected void start(String name, AttributesImpl attr) throws SAXException { 156 this.contentHandler.startElement("", name, name, attr); 157 attr.clear(); 158 } 159 160 165 protected void end(String name) throws SAXException { 166 this.contentHandler.endElement("", name, name); 167 } 168 169 174 protected void characters(String data) throws SAXException { 175 this.contentHandler.characters(data.toCharArray(), 0, data.length()); 176 } 177 178 183 protected void comment(String data) throws SAXException { 184 this.lexicalHandler.comment(data.toCharArray(), 0, data.length()); 185 } 186 187 195 public long generateKey() { 196 return 0; 197 } 198 199 206 public CacheValidity generateValidity() { 207 if (hasContentChanged(request)) 208 return null; 209 else 210 return NOPCacheValidity.CACHE_VALIDITY; 211 } 212 213 } 214 215 219 final class NOPCacheValidity 220 implements CacheValidity { 221 222 public static final CacheValidity CACHE_VALIDITY = new NOPCacheValidity(); 223 224 public boolean isValid(CacheValidity validity) { 225 return validity instanceof NOPCacheValidity; 226 } 227 228 public String toString() { 229 return "NOP Validity"; 230 } 231 } | Popular Tags |