1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 // ResolvingXMLReader.java - An XMLReader that performs catalog resolution
6
7 /*
8 * Copyright 2001-2004 The Apache Software Foundation or its licensors,
9 * as applicable.
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24 package com.sun.org.apache.xml.internal.resolver.tools;
25
26 import org.xml.sax;
27
28 import javax.xml.parsers;
29
30 import com.sun.org.apache.xml.internal.resolver;
31
32 /**
33 * A SAX XMLReader that performs catalog-based entity resolution.
34 *
35 * <p>This class implements a SAX XMLReader that performs entity resolution
36 * using the CatalogResolver. The actual, underlying parser is obtained
37 * from a SAXParserFactory.</p>
38 * </p>
39 *
40 * @see CatalogResolver
41 * @see org.xml.sax.XMLReader
42 *
43 * @author Norman Walsh
44 * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
45 *
46 */
47 public class ResolvingXMLReader extends ResolvingXMLFilter {
48 /** Make the parser Namespace aware? */
49 public static boolean namespaceAware = true;
50
51 /** Make the parser validating? */
52 public static boolean validating = false;
53
54 /**
55 * Construct a new reader from the JAXP factory.
56 *
57 * <p>In order to do its job, a ResolvingXMLReader must in fact be
58 * a filter. So the only difference between this code and the filter
59 * code is that the constructor builds a new reader.</p>
60 */
61 public ResolvingXMLReader() {
62 super();
63 SAXParserFactory spf = SAXParserFactory.newInstance();
64 spf.setNamespaceAware(namespaceAware);
65 spf.setValidating(validating);
66 try {
67 SAXParser parser = spf.newSAXParser();
68 setParent(parser.getXMLReader());
69 } catch (Exception ex) {
70 ex.printStackTrace();
71 }
72 }
73
74 /**
75 * Construct a new reader from the JAXP factory.
76 *
77 * <p>In order to do its job, a ResolvingXMLReader must in fact be
78 * a filter. So the only difference between this code and the filter
79 * code is that the constructor builds a new reader.</p>
80 */
81 public ResolvingXMLReader(CatalogManager manager) {
82 super(manager);
83 SAXParserFactory spf = SAXParserFactory.newInstance();
84 spf.setNamespaceAware(namespaceAware);
85 spf.setValidating(validating);
86 try {
87 SAXParser parser = spf.newSAXParser();
88 setParent(parser.getXMLReader());
89 } catch (Exception ex) {
90 ex.printStackTrace();
91 }
92 }
93 }