001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.caching;
018:
019: import org.apache.excalibur.source.Source;
020: import org.apache.cocoon.environment.SourceResolver;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: /**
027: * A validation object used in CachingCIncludeTransformer
028: *
029: * @deprecated Use the Avalon Excalibur SourceValidity implementations instead
030: * @author <a href="mailto:maciejka@tiger.com.pl">Maciek Kaminski</a>
031: * @version CVS $Id: IncludeCacheValidity.java 433543 2006-08-22 06:22:54Z crossley $
032: */
033: public final class IncludeCacheValidity implements CacheValidity {
034:
035: private List sources;
036: private List timeStamps;
037:
038: private boolean isNew;
039:
040: private SourceResolver resolver;
041:
042: public IncludeCacheValidity(SourceResolver resolver) {
043: this .resolver = resolver;
044: sources = new ArrayList();
045: timeStamps = new ArrayList();
046: isNew = true;
047: }
048:
049: public boolean isNew() {
050: return isNew;
051: }
052:
053: public void setIsNew2False() {
054: isNew = false;
055: resolver = null;
056: }
057:
058: public void add(String source, long timeStamp) {
059: this .sources.add(source);
060: this .timeStamps.add(new Long(timeStamp));
061: }
062:
063: public boolean isValid(CacheValidity validity) {
064: if (validity instanceof IncludeCacheValidity) {
065: SourceResolver otherResolver = ((IncludeCacheValidity) validity).resolver;
066:
067: for (Iterator i = sources.iterator(), j = timeStamps
068: .iterator(); i.hasNext();) {
069: String src = ((String) i.next());
070: long timeStamp = ((Long) j.next()).longValue();
071: Source otherSource = null;
072: try {
073: otherSource = otherResolver.resolveURI(src);
074: if (otherSource.getLastModified() != timeStamp
075: || timeStamp == 0)
076: return false;
077: } catch (Exception e) {
078: return false;
079: } finally {
080: otherResolver.release(otherSource);
081: }
082: }
083: return true;
084: }
085: return false;
086: }
087:
088: public String toString() {
089: StringBuffer b = new StringBuffer("Include Validity[");
090: for (Iterator i = sources.iterator(), j = timeStamps.iterator(); i
091: .hasNext();) {
092: b.append('{');
093: b.append(i.next());
094: b.append(':');
095: b.append(j.next());
096: b.append('}');
097: if (i.hasNext())
098: b.append(':');
099: }
100: b.append(']');
101: return b.toString();
102: }
103: }
|