01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package com.icesoft.jasper.xmlparser;
18:
19: import com.icesoft.jasper.Constants;
20: import com.icesoft.jasper.compiler.Localizer;
21: import org.xml.sax.EntityResolver;
22: import org.xml.sax.InputSource;
23: import org.xml.sax.SAXException;
24:
25: import java.io.InputStream;
26:
27: public class CachedEntityResolver implements EntityResolver {
28: public InputSource resolveEntity(String publicId, String systemId)
29: throws SAXException {
30: for (int i = 0; i < Constants.CACHED_DTD_PUBLIC_IDS.length; i++) {
31: String cachedDtdPublicId = Constants.CACHED_DTD_PUBLIC_IDS[i];
32: if (cachedDtdPublicId.equals(publicId)) {
33: String resourcePath = Constants.CACHED_DTD_RESOURCE_PATHS[i];
34: InputStream input = this .getClass()
35: .getResourceAsStream(resourcePath);
36: if (input == null) {
37: throw new SAXException(Localizer.getMessage(
38: "jsp.error.internal.filenotfound",
39: resourcePath));
40: }
41: InputSource isrc = new InputSource(input);
42: return isrc;
43: }
44: }
45: ParserUtils.log.error(Localizer.getMessage(
46: "jsp.error.parse.xml.invalidPublicId", publicId));
47: return null;
48: }
49: }
|