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