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.validation.jaxp;
18:
19: import org.apache.cocoon.components.validation.impl.ValidationResolver;
20: import org.apache.commons.lang.exception.NestableRuntimeException;
21: import org.apache.excalibur.source.SourceResolver;
22: import org.w3c.dom.DOMError;
23: import org.w3c.dom.ls.LSException;
24: import org.w3c.dom.ls.LSInput;
25: import org.w3c.dom.ls.LSResourceResolver;
26: import org.xml.sax.EntityResolver;
27: import org.xml.sax.InputSource;
28:
29: /**
30: * <p>An implementation of the {@link LSResourceResolver} interface based on the
31: * generic {@link ValidationResolver} to supply to JAXP schema factories.</p>
32: *
33: */
34: public class JaxpResolver extends ValidationResolver implements
35: LSResourceResolver {
36:
37: /**
38: * <p>Create a new {@link JaxpResolver} instance.</p>
39: */
40: public JaxpResolver(SourceResolver sourceResolver,
41: EntityResolver entityResolver) {
42: super (sourceResolver, entityResolver);
43: }
44:
45: /**
46: * <p>Resolve a resource into a {@link LSInput} from the provided location
47: * information.</p>
48: *
49: * <p>This method will obtain a {@link InputSource} instance invoking the
50: * {@link ValidationResolver#resolveEntity(String, String, String)} method
51: * return it wrapped in a {@link JaxpInput} instance.</p>
52: *
53: * @param type the type of the resource being resolved.
54: * @param namespace the namespace of the resource being resolved.
55: * @param systemId the system identifier of the resource being resolved.
56: * @param publicId the public identifier of the resource being resolved.
57: * @param base the base uri against wich relative resolution should happen.
58: * @return a <b>non null</b> {@link LSInput} instance.
59: * @throws LSException wrapping another {@link Exception}.
60: */
61: public LSInput resolveResource(String type, String namespace,
62: String systemId, String publicId, String base)
63: throws LSException {
64: try {
65: final InputSource source = this .resolveEntity(base,
66: publicId, systemId);
67: return new JaxpInput(source);
68: } catch (Exception exception) {
69: String message = "Exception resolving resource " + systemId;
70: Throwable err = new LSException(
71: DOMError.SEVERITY_FATAL_ERROR, message);
72: throw new NestableRuntimeException(message, err);
73: }
74: }
75: }
|