01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.deployment.resolver;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
24: import org.xml.sax.InputSource;
25:
26: import java.net.URI;
27:
28: public class WarFileBasedURIResolver extends DefaultURIResolver {
29:
30: protected static final Log log = LogFactory
31: .getLog(WarFileBasedURIResolver.class);
32:
33: private ClassLoader classLoader;
34:
35: public WarFileBasedURIResolver(ClassLoader classLoader) {
36: this .classLoader = classLoader;
37: }
38:
39: public InputSource resolveEntity(String targetNamespace,
40: String schemaLocation, String baseUri) {
41: //no issue with
42: if (isAbsolute(schemaLocation)) {
43: return super .resolveEntity(targetNamespace, schemaLocation,
44: baseUri);
45: } else {
46: //validate
47: if ((baseUri == null || "".equals(baseUri))
48: && schemaLocation.startsWith("..")) {
49: throw new RuntimeException(
50: "Unsupported schema location " + schemaLocation);
51: }
52:
53: URI lastImportLocation = URI.create(baseUri).resolve(
54: schemaLocation);
55: String searchingStr = lastImportLocation.toString();
56: return new InputSource(classLoader
57: .getResourceAsStream(searchingStr));
58: }
59: }
60: }
|