1 16 package org.apache.cocoon.caching; 17 18 import org.apache.excalibur.source.Source; 19 import org.apache.cocoon.environment.SourceResolver; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 26 33 public final class IncludeCacheValidity implements CacheValidity { 34 35 private List sources; 36 private List timeStamps; 37 38 private boolean isNew; 39 40 private SourceResolver resolver; 41 42 public IncludeCacheValidity(SourceResolver resolver) { 43 this.resolver = resolver; 44 sources = new ArrayList (); 45 timeStamps = new ArrayList (); 46 isNew = true; 47 } 48 49 public boolean isNew() { 50 return isNew; 51 } 52 53 public void setIsNew2False() { 54 isNew = false; 55 resolver = null; 56 } 57 58 public void add(String source, long timeStamp) { 59 this.sources.add(source); 60 this.timeStamps.add(new Long (timeStamp)); 61 } 62 63 public boolean isValid(CacheValidity validity) { 64 if (validity instanceof IncludeCacheValidity) { 65 SourceResolver otherResolver = ((IncludeCacheValidity) validity).resolver; 66 67 for(Iterator i = sources.iterator(), j = timeStamps.iterator(); i.hasNext();) { 68 String src = ((String )i.next()); 69 long timeStamp = ((Long )j.next()).longValue(); 70 Source otherSource = null; 71 try { 72 otherSource = otherResolver.resolveURI(src); 73 if(otherSource.getLastModified() != timeStamp || 74 timeStamp == 0) 75 return false; 76 } catch (Exception e) { 77 return false; 78 } finally { 79 otherResolver.release(otherSource); 80 } 81 } 82 return true; 83 } 84 return false; 85 } 86 87 public String toString() { 88 StringBuffer b = new StringBuffer ("Include Validity["); 89 for(Iterator i = sources.iterator(), j = timeStamps.iterator(); i.hasNext();) { 90 b.append('{'); 91 b.append(i.next()); 92 b.append(':'); 93 b.append(j.next()); 94 b.append('}'); 95 if(i.hasNext()) b.append(':'); 96 } 97 b.append(']'); 98 return b.toString(); 99 } 100 } 101 | Popular Tags |