01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.cocoon.source;
19:
20: import org.apache.excalibur.source.SourceValidity;
21:
22: /**
23: * Validity for repository sources.
24: */
25: public class RepositorySourceValidity implements SourceValidity {
26:
27: private static final long serialVersionUID = 1L;
28:
29: private String sourceUri;
30: private long lastModified;
31:
32: /**
33: * @param source The source this validity is for.
34: */
35: public RepositorySourceValidity(RepositorySource source) {
36: this .sourceUri = source.getSourceURI();
37: this .lastModified = source.getLastModified();
38: }
39:
40: public int isValid() {
41: return SourceValidity.UNKNOWN;
42: }
43:
44: public int isValid(SourceValidity validity) {
45: if (validity instanceof RepositorySourceValidity) {
46: RepositorySourceValidity repoValidity = (RepositorySourceValidity) validity;
47: String repoValidityUri = repoValidity.getSourceURI();
48:
49: if (!repoValidityUri.equals(this .sourceUri)) {
50: throw new RuntimeException("Wrong source URI: ["
51: + repoValidityUri + "] instead of ["
52: + this .sourceUri + "]!");
53: }
54: if (this .lastModified >= repoValidity.getLastModified()) {
55: return SourceValidity.VALID;
56: } else {
57: return SourceValidity.INVALID;
58: }
59: } else {
60: return SourceValidity.INVALID;
61: }
62: }
63:
64: protected long getLastModified() {
65: return this .lastModified;
66: }
67:
68: protected String getSourceURI() {
69: return this.sourceUri;
70: }
71:
72: }
|