KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > jasper > xmlparser > CachedEntityResolver


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
22 import org.xml.sax.InputSource JavaDoc;
23 import org.xml.sax.SAXException JavaDoc;
24
25 import java.io.InputStream JavaDoc;
26
27 public class CachedEntityResolver implements EntityResolver JavaDoc {
28     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
29             throws SAXException JavaDoc {
30         for (int i = 0; i < Constants.CACHED_DTD_PUBLIC_IDS.length; i++) {
31             String JavaDoc cachedDtdPublicId = Constants.CACHED_DTD_PUBLIC_IDS[i];
32             if (cachedDtdPublicId.equals(publicId)) {
33                 String JavaDoc resourcePath = Constants.CACHED_DTD_RESOURCE_PATHS[i];
34                 InputStream JavaDoc input =
35                         this.getClass().getResourceAsStream(resourcePath);
36                 if (input == null) {
37                     throw new SAXException JavaDoc(
38                             Localizer.getMessage(
39                                     "jsp.error.internal.filenotfound",
40                                     resourcePath));
41                 }
42                 InputSource JavaDoc isrc = new InputSource JavaDoc(input);
43                 return isrc;
44             }
45         }
46         ParserUtils.log.error(Localizer.getMessage(
47                 "jsp.error.parse.xml.invalidPublicId",
48                 publicId));
49         return null;
50     }
51 }
52
53
Popular Tags