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:
19: package org.apache.lenya.cms.publication.templating;
20:
21: import org.apache.excalibur.source.Source;
22: import org.apache.excalibur.source.SourceResolver;
23:
24: /**
25: * Source visitor to obtain the first existing source.
26: *
27: * @version $Id: ExistingSourceResolver.java 487598 2006-12-15 17:01:14Z andreas $
28: */
29: public class ExistingSourceResolver implements VisitingSourceResolver {
30:
31: private Source source;
32:
33: /**
34: * Ctor.
35: */
36: public ExistingSourceResolver() {
37: super ();
38: }
39:
40: /**
41: * @return the first existing source.
42: */
43: public Source getSource() {
44: return this .source;
45: }
46:
47: public void visit(SourceResolver resolver, String sourceUri) {
48: if (this .source == null) {
49: Source source = null;
50: try {
51: source = resolver.resolveURI(sourceUri);
52: if (source.exists()) {
53: this .source = source;
54: }
55: } catch (Exception e) {
56: throw new RuntimeException(e);
57: } finally {
58: if (source != null) {
59: resolver.release(source);
60: }
61: }
62: }
63: }
64:
65: }
|