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: package org.apache.cocoon.components.resolver;
18:
19: import org.apache.excalibur.xml.DefaultEntityResolver;
20:
21: /**
22: * A component that uses catalogs for resolving entities.
23: * This component simply inherits from the excalibur implementation and
24: * adds the context: protocol to each relative uri.
25: *
26: * The catalog is by default loaded from "WEB-INF/entities/catalog".
27: * This can be configured by the "catalog" parameter in the cocoon.xconf:
28: * <entity-resolver>
29: * <parameter name="catalog" value="mycatalog"/>
30: * </entity-resolver>
31: *
32: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
33: * @version CVS $Id: DefaultResolver.java 433543 2006-08-22 06:22:54Z crossley $
34: * @since 2.1
35: */
36: public class DefaultResolver extends DefaultEntityResolver {
37:
38: /**
39: * Parse a catalog
40: */
41: protected void parseCatalog(String uri) {
42: // check for relative URIs
43: // if the URI has ':/' then it's a URI
44: // if the URI starts with '/ it's an absolute (UNIX) path
45: // if the URI has a ':' at position 1, it's an absolute windows path
46: // otherwise we have a relative URI, that is resolved relative
47: // to the context
48: if (uri.indexOf(":/") == -1 && !uri.startsWith("/")
49: && !(uri.length() > 1 && uri.charAt(1) == ':')) {
50: uri = "context://" + uri;
51: }
52: super .parseCatalog(uri);
53: }
54:
55: /**
56: * Default catalog path
57: */
58: protected String defaultCatalog() {
59: return "WEB-INF/entities/catalog";
60: }
61: }
|