1 16 package org.apache.cocoon.components.source; 17 18 import org.apache.cocoon.ProcessingException; 19 import org.apache.cocoon.environment.ModifiableSource; 20 import org.apache.cocoon.environment.Source; 21 import org.apache.cocoon.xml.XMLizable; 22 import org.xml.sax.ContentHandler ; 23 import org.xml.sax.InputSource ; 24 import org.xml.sax.SAXException ; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 29 37 public final class DelayedRefreshSourceWrapper implements Source, ModifiableSource, XMLizable { 38 39 private Source source; 40 41 private long delay; 42 43 private long nextCheckTime = 0; 44 45 private long lastModified = 0; 46 47 private boolean isModifiableSource; 48 49 57 public DelayedRefreshSourceWrapper(Source source, long delay) { 58 this.source = source; 59 this.delay = delay; 60 this.isModifiableSource = source instanceof ModifiableSource; 61 } 62 63 72 public final long getLastModified() { 73 74 if (System.currentTimeMillis() >= nextCheckTime) { 76 this.refresh(); 78 } 79 80 return this.lastModified; 81 } 82 83 89 public synchronized final void refresh() { 90 91 this.nextCheckTime = System.currentTimeMillis() + this.delay; 92 if (this.isModifiableSource) { 94 ((ModifiableSource)this.source).refresh(); 95 } 96 97 this.lastModified = source.getLastModified(); 99 } 100 101 public final long getContentLength() { 102 return this.source.getContentLength(); 103 } 104 105 public final InputStream getInputStream() throws ProcessingException, IOException { 106 return this.source.getInputStream(); 107 } 108 109 public final InputSource getInputSource() throws ProcessingException, IOException { 110 return this.source.getInputSource(); 111 } 112 113 public final String getSystemId() { 114 return this.source.getSystemId(); 115 } 116 117 public final void recycle() { 118 this.source.recycle(); 119 } 120 121 public final void toSAX(ContentHandler handler) throws SAXException { 122 this.source.toSAX(handler); 123 } 124 } 125 | Popular Tags |