1 16 package org.apache.cocoon.components.source.impl; 17 18 import org.apache.avalon.excalibur.pool.Recyclable; 19 import org.apache.excalibur.source.Source; 20 import org.apache.excalibur.source.SourceException; 21 import org.apache.excalibur.source.SourceValidity; 22 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.util.Iterator ; 26 27 34 public final class DelayedRefreshSourceWrapper 35 implements Source { 36 37 private Source source; 38 39 private long delay; 40 41 private long nextCheckTime = 0; 42 43 private long lastModified = 0; 44 45 53 public DelayedRefreshSourceWrapper(Source source, long delay) { 54 this.source = source; 55 this.delay = delay; 56 } 57 58 61 public Source getSource() { 62 return this.source; 63 } 64 65 public final InputStream getInputStream() 66 throws SourceException, IOException { 67 return this.source.getInputStream(); 68 } 69 70 public final String getURI() { 71 return this.source.getURI(); 72 } 73 74 80 public SourceValidity getValidity() { 81 return this.source.getValidity(); 82 } 83 84 87 public String getScheme() { 88 return this.source.getScheme(); 89 } 90 91 95 public boolean exists() { 96 return this.source.exists(); 97 } 98 99 108 public final long getLastModified() { 109 110 if (System.currentTimeMillis() >= nextCheckTime) { 112 this.refresh(); 114 } 115 return this.lastModified; 116 } 117 118 124 public synchronized final void refresh() { 125 126 this.nextCheckTime = System.currentTimeMillis() + this.delay; 127 this.source.refresh(); 129 130 this.lastModified = source.getLastModified(); 132 } 133 134 public final long getContentLength() { 135 return this.source.getContentLength(); 136 } 137 138 143 public String getMimeType() { 144 return this.source.getMimeType(); 145 } 146 147 public final void recycle() { 148 if (this.source instanceof Recyclable) { 149 ((Recyclable)this.source).recycle(); 150 } 151 } 152 153 158 public String getParameter(String name) { 159 return null; 160 } 161 162 167 public long getParameterAsLong(String name) { 168 return 0; 169 } 170 171 176 public Iterator getParameterNames() { 177 return java.util.Collections.EMPTY_LIST.iterator(); 178 179 } 180 181 182 } 183 | Popular Tags |