annotate NGSrich_0.5.5/src/org/jdom/input/SAXBuilder.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 /*--
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 $Id: SAXBuilder.java,v 1.93 2009/07/23 06:26:26 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 All rights reserved.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 modification, are permitted provided that the following conditions
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 are met:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 1. Redistributions of source code must retain the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 notice, this list of conditions, and the following disclaimer.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 2. Redistributions in binary form must reproduce the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 notice, this list of conditions, and the disclaimer that follows
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 these conditions in the documentation and/or other materials
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 provided with the distribution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 3. The name "JDOM" must not be used to endorse or promote products
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 derived from this software without prior written permission. For
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 written permission, please contact <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 4. Products derived from this software may not be called "JDOM", nor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 may "JDOM" appear in their name, without prior written permission
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 from the JDOM Project Management <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 In addition, we request (but do not require) that you include in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 end-user documentation provided with the redistribution and/or in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 software itself an acknowledgement equivalent to the following:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 "This product includes software developed by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 JDOM Project (http://www.jdom.org/)."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 Alternatively, the acknowledgment may be graphical using the logos
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 available at http://www.jdom.org/images/logos.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 SUCH DAMAGE.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 This software consists of voluntary contributions made by many
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 individuals on behalf of the JDOM Project and was originally
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 on the JDOM Project, please see <http://www.jdom.org/>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 package org.jdom.input;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 import java.io.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 import java.lang.reflect.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 import java.net.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 import java.util.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 import org.jdom.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 import org.xml.sax.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 import org.xml.sax.helpers.XMLReaderFactory;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * Builds a JDOM document from files, streams, readers, URLs, or a SAX {@link
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 * org.xml.sax.InputSource} instance using a SAX parser. The builder uses a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 * third-party SAX parser (chosen by JAXP by default, or you can choose
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 * manually) to handle the parsing duties and simply listens to the SAX events
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 * to construct a document. Details which SAX does not provide, such as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 * whitespace outside the root element, are not represented in the JDOM
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 * document. Information about SAX can be found at <a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 * href="http://www.saxproject.org">http://www.saxproject.org</a>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 * Known issues: Relative paths for a {@link DocType} or {@link EntityRef} may
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 * be converted by the SAX parser into absolute paths.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 * @version $Revision: 1.93 $, $Date: 2009/07/23 06:26:26 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 * @author Dan Schaffer
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 * @author Philip Nelson
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 * @author Alex Rosen
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 public class SAXBuilder {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 "@(#) $RCSfile: SAXBuilder.java,v $ $Revision: 1.93 $ $Date: 2009/07/23 06:26:26 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 * Default parser class to use. This is used when no other parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 * is given and JAXP isn't available.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 private static final String DEFAULT_SAX_DRIVER =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 "org.apache.xerces.parsers.SAXParser";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 /** Whether validation should occur */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 private boolean validate;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 /** Whether expansion of entities should occur */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 private boolean expand = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 /** Adapter class to use */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 private String saxDriverClass;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 /** ErrorHandler class to use */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 private ErrorHandler saxErrorHandler = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 /** EntityResolver class to use */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 private EntityResolver saxEntityResolver = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 /** DTDHandler class to use */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 private DTDHandler saxDTDHandler = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 /** XMLFilter instance to use */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 private XMLFilter saxXMLFilter = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 /** The factory for creating new JDOM objects */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 private JDOMFactory factory = new DefaultJDOMFactory();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 /** Whether to ignore ignorable whitespace */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 private boolean ignoringWhite = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 /** Whether to ignore all whitespace content */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 private boolean ignoringBoundaryWhite = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 /** User-specified features to be set on the SAX parser */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 private HashMap features = new HashMap(5);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 /** User-specified properties to be set on the SAX parser */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 private HashMap properties = new HashMap(5);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 /** Whether to use fast parser reconfiguration */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 private boolean fastReconfigure = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 /** Whether to try lexical reporting in fast parser reconfiguration */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 private boolean skipNextLexicalReportingConfig = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 /** Whether to to try entity expansion in fast parser reconfiguration */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 private boolean skipNextEntityExpandConfig = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 * Whether parser reuse is allowed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 * <p>Default: <code>true</code></p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 private boolean reuseParser = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 /** The current SAX parser, if parser reuse has been activated. */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 private XMLReader saxParser = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 * Creates a new SAXBuilder which will attempt to first locate
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 * a parser via JAXP, then will try to use a set of default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 * SAX Drivers. The underlying parser will not validate.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 public SAXBuilder() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 this(false);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 * Creates a new SAXBuilder which will attempt to first locate
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 * a parser via JAXP, then will try to use a set of default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 * SAX Drivers. The underlying parser will validate or not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 * according to the given parameter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 * @param validate <code>boolean</code> indicating if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 * validation should occur.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 public SAXBuilder(boolean validate) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 this.validate = validate;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 * Creates a new SAXBuilder using the specified SAX parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 * The underlying parser will not validate.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 * @param saxDriverClass <code>String</code> name of SAX Driver
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 * to use for parsing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 public SAXBuilder(String saxDriverClass) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 this(saxDriverClass, false);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 * Creates a new SAXBuilder using the specified SAX parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 * The underlying parser will validate or not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 * according to the given parameter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 * @param saxDriverClass <code>String</code> name of SAX Driver
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 * to use for parsing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 * @param validate <code>boolean</code> indicating if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 * validation should occur.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 public SAXBuilder(String saxDriverClass, boolean validate) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 this.saxDriverClass = saxDriverClass;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 this.validate = validate;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 * Returns the driver class assigned in the constructor, or null if none.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 * @return the driver class assigned in the constructor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 public String getDriverClass() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 return saxDriverClass;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 * Returns the current {@link org.jdom.JDOMFactory} in use.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 * @return the factory in use
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 public JDOMFactory getFactory() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 return factory;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 * This sets a custom JDOMFactory for the builder. Use this to build
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 * the tree with your own subclasses of the JDOM classes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 * @param factory <code>JDOMFactory</code> to use
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 public void setFactory(JDOMFactory factory) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 this.factory = factory;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 * Returns whether validation is to be performed during the build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 * @return whether validation is to be performed during the build
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 public boolean getValidation() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 return validate;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 * This sets validation for the builder.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 * @param validate <code>boolean</code> indicating whether validation
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 * should occur.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 public void setValidation(boolean validate) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 this.validate = validate;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 * Returns the {@link ErrorHandler} assigned, or null if none.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 * @return the ErrorHandler assigned, or null if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 public ErrorHandler getErrorHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 return saxErrorHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 * This sets custom ErrorHandler for the <code>Builder</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 * @param errorHandler <code>ErrorHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 public void setErrorHandler(ErrorHandler errorHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 saxErrorHandler = errorHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 * Returns the {@link EntityResolver} assigned, or null if none.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 * @return the EntityResolver assigned
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 public EntityResolver getEntityResolver() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 return saxEntityResolver;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 * This sets custom EntityResolver for the <code>Builder</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 * @param entityResolver <code>EntityResolver</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 public void setEntityResolver(EntityResolver entityResolver) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 saxEntityResolver = entityResolver;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 * Returns the {@link DTDHandler} assigned, or null if none.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 * @return the DTDHandler assigned
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 public DTDHandler getDTDHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 return saxDTDHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294 * This sets custom DTDHandler for the <code>Builder</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 * @param dtdHandler <code>DTDHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 public void setDTDHandler(DTDHandler dtdHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 saxDTDHandler = dtdHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303 * Returns the {@link XMLFilter} used during parsing, or null if none.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 * @return the XMLFilter used during parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 public XMLFilter getXMLFilter() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 return saxXMLFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 * This sets a custom {@link org.xml.sax.XMLFilter} for the builder.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314 * @param xmlFilter the filter to use
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 public void setXMLFilter(XMLFilter xmlFilter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317 saxXMLFilter = xmlFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 * Returns whether element content whitespace is to be ignored during the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322 * build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324 * @return whether element content whitespace is to be ignored during the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 * build
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 public boolean getIgnoringElementContentWhitespace() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 return ignoringWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 * Specifies whether or not the parser should elminate whitespace in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333 * element content (sometimes known as "ignorable whitespace") when
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 * building the document. Only whitespace which is contained within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 * element content that has an element only content model will be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 * eliminated (see XML Rec 3.2.1). For this setting to take effect
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337 * requires that validation be turned on. The default value of this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 * setting is <code>false</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 * @param ignoringWhite Whether to ignore ignorable whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 public void setIgnoringElementContentWhitespace(boolean ignoringWhite) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 this.ignoringWhite = ignoringWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 * Returns whether or not the parser will elminate element content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 * containing only whitespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 * @return <code>boolean</code> - whether only whitespace content will
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351 * be ignored during build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 * @see #setIgnoringBoundaryWhitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 public boolean getIgnoringBoundaryWhitespace() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 return ignoringBoundaryWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360 * Specifies whether or not the parser should elminate boundary whitespace,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361 * a term that indicates whitespace-only text between element tags. This
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362 * feature is a lot like {@link #setIgnoringElementContentWhitespace(boolean)}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 * but this feature is more aggressive and doesn't require validation be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364 * turned on. The {@link #setIgnoringElementContentWhitespace(boolean)}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 * call impacts the SAX parse process while this method impacts the JDOM
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 * build process, so it can be beneficial to turn both on for efficiency.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367 * For implementation efficiency, this method actually removes all
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368 * whitespace-only text() nodes. That can, in some cases (like beteween an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 * element tag and a comment), include whitespace that isn't just boundary
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370 * whitespace. The default is <code>false</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 * @param ignoringBoundaryWhite Whether to ignore whitespace-only text
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373 * noes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 public void setIgnoringBoundaryWhitespace(boolean ignoringBoundaryWhite) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376 this.ignoringBoundaryWhite = ignoringBoundaryWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380 * Returns whether the contained SAX parser instance is reused across
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 * multiple parses. The default is true.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383 * @return whether the contained SAX parser instance is reused across
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 * multiple parses
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386 public boolean getReuseParser() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 return reuseParser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 * Specifies whether this builder shall reuse the same SAX parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392 * when performing subsequent parses or allocate a new parser for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393 * each parse. The default value of this setting is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394 * <code>true</code> (parser reuse).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 * <strong>Note</strong>: As SAX parser instances are not thread safe,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 * the parser reuse feature should not be used with SAXBuilder instances
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398 * shared among threads.</p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400 * @param reuseParser Whether to reuse the SAX parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 public void setReuseParser(boolean reuseParser) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403 this.reuseParser = reuseParser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 this.saxParser = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408 * Specifies whether this builder will do fast reconfiguration of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409 * underlying SAX parser when reuseParser is true. This improves
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 * performance in cases where SAXBuilders are reused and lots of small
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 * documents are frequently parsed. This avoids attempting to set features
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412 * on the SAX parser each time build() is called which result in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 * SaxNotRecognizedExceptions. This should ONLY be set for builders where
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 * this specific case is an issue. The default value of this setting is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 * <code>false</code> (no fast reconfiguration). If reuseParser is false,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416 * calling this has no effect.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 * @param fastReconfigure Whether to do a fast reconfiguration of the parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420 public void setFastReconfigure(boolean fastReconfigure) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 if (this.reuseParser) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 this.fastReconfigure = fastReconfigure;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 * This sets a feature on the SAX parser. See the SAX documentation for .
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428 * more information.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431 * NOTE: SAXBuilder requires that some particular features of the SAX parser be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 * set up in certain ways for it to work properly. The list of such features
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433 * may change in the future. Therefore, the use of this method may cause
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 * parsing to break, and even if it doesn't break anything today it might
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 * break parsing in a future JDOM version, because what JDOM parsers require
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436 * may change over time. Use with caution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439 * @param name The feature name, which is a fully-qualified URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440 * @param value The requested state of the feature (true or false).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 public void setFeature(String name, boolean value) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 // Save the specified feature for later.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 * This sets a property on the SAX parser. See the SAX documentation for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 * more information.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 * NOTE: SAXBuilder requires that some particular properties of the SAX parser be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 * set up in certain ways for it to work properly. The list of such properties
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 * may change in the future. Therefore, the use of this method may cause
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454 * parsing to break, and even if it doesn't break anything today it might
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455 * break parsing in a future JDOM version, because what JDOM parsers require
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456 * may change over time. Use with caution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 * @param name The property name, which is a fully-qualified URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 * @param value The requested value for the property.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 public void setProperty(String name, Object value) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463 // Save the specified property for later.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 properties.put(name, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 * input source.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 * @param in <code>InputSource</code> to read from
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
474 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
475 * from being fully parsed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
476 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
477 public Document build(InputSource in)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
478 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
479 SAXHandler contentHandler = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
480
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
481 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
482 // Create and configure the content handler.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
483 contentHandler = createContentHandler();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
484 configureContentHandler(contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
485
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
486 XMLReader parser = this.saxParser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
487 if (parser == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
488 // Create and configure the parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
489 parser = createParser();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
490
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
491 // Install optional filter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
492 if (saxXMLFilter != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
493 // Connect filter chain to parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
494 XMLFilter root = saxXMLFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
495 while (root.getParent() instanceof XMLFilter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
496 root = (XMLFilter)root.getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
497 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
498 root.setParent(parser);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
499
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
500 // Read from filter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
501 parser = saxXMLFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
502 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
503
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
504 // Configure parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
505 configureParser(parser, contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
506
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
507 if (reuseParser) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
508 this.saxParser = parser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
509 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
510 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
511 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
512 // Reset content handler as SAXHandler instances cannot
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
513 // be reused
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
514 configureParser(parser, contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
515 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
516
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
517 // Parse the document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
518 parser.parse(in);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
519
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
520 return contentHandler.getDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
521 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
522 catch (SAXParseException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
523 Document doc = contentHandler.getDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
524 if (doc.hasRootElement() == false) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
525 doc = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
526 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
527
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
528 String systemId = e.getSystemId();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
529 if (systemId != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
530 throw new JDOMParseException("Error on line " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
531 e.getLineNumber() + " of document " + systemId, e, doc);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
532 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
533 throw new JDOMParseException("Error on line " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
534 e.getLineNumber(), e, doc);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
535 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
536 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
537 catch (SAXException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
538 throw new JDOMParseException("Error in building: " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
539 e.getMessage(), e, contentHandler.getDocument());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
540 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
541 finally {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
542 // Explicitly nullify the handler to encourage GC
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
543 // It's a stack var so this shouldn't be necessary, but it
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
544 // seems to help on some JVMs
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
545 contentHandler = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
546 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
547 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
548
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
549 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
550 * This creates the SAXHandler that will be used to build the Document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
551 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
552 * @return <code>SAXHandler</code> - resultant SAXHandler object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
553 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
554 protected SAXHandler createContentHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
555 SAXHandler contentHandler = new SAXHandler(factory);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
556 return contentHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
557 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
558
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
559 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
560 * This configures the SAXHandler that will be used to build the Document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
561 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
562 * The default implementation simply passes through some configuration
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
563 * settings that were set on the SAXBuilder: setExpandEntities() and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
564 * setIgnoringElementContentWhitespace().
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
565 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
566 * @param contentHandler The SAXHandler to configure
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
567 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
568 protected void configureContentHandler(SAXHandler contentHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
569 // Setup pass through behavior
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
570 contentHandler.setExpandEntities(expand);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
571 contentHandler.setIgnoringElementContentWhitespace(ignoringWhite);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
572 contentHandler.setIgnoringBoundaryWhitespace(ignoringBoundaryWhite);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
573 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
574
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
575 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
576 * This creates the XMLReader to be used for reading the XML document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
577 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
578 * The default behavior is to (1) use the saxDriverClass, if it has been
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
579 * set, (2) try to obtain a parser from JAXP, if it is available, and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
580 * (3) if all else fails, use a hard-coded default parser (currently
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
581 * the Xerces parser). Subclasses may override this method to determine
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
582 * the parser to use in a different way.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
583 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
584 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
585 * @return <code>XMLReader</code> - resultant XMLReader object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
586 * @throws org.jdom.JDOMException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
587 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
588 protected XMLReader createParser() throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
589 XMLReader parser = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
590 if (saxDriverClass != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
591 // The user knows that they want to use a particular class
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
592 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
593 parser = XMLReaderFactory.createXMLReader(saxDriverClass);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
594
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
595 // Configure parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
596 setFeaturesAndProperties(parser, true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
597 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
598 catch (SAXException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
599 throw new JDOMException("Could not load " + saxDriverClass, e);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
600 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
601 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
602 // Try using JAXP...
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
603 // Note we need JAXP 1.1, and if JAXP 1.0 is all that's
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
604 // available then the getXMLReader call fails and we skip
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
605 // to the hard coded default parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
606 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
607 // Get factory class and method.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
608 Class factoryClass =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
609 Class.forName("org.jdom.input.JAXPParserFactory");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
610
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
611 Method createParser =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
612 factoryClass.getMethod("createParser",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
613 new Class[] { boolean.class, Map.class, Map.class });
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
614
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
615 // Create SAX parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
616 parser = (XMLReader)createParser.invoke(null,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
617 new Object[] { validate ? Boolean.TRUE : Boolean.FALSE,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
618 features, properties });
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
619
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
620 // Configure parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
621 setFeaturesAndProperties(parser, false);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
622 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
623 catch (JDOMException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
624 throw e;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
625 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
626 catch (NoClassDefFoundError e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
627 // The class loader failed to resolve the dependencies
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
628 // of org.jdom.input.JAXPParserFactory. This probably means
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
629 // that no JAXP parser is present in its class path.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
630 // => Ignore and try allocating default SAX parser instance.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
631 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
632 catch (Exception e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
633 // Ignore and try allocating default SAX parser instance.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
634 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
635 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
636
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
637 // Check to see if we got a parser yet, if not, try to use a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
638 // hard coded default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
639 if (parser == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
640 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
641 parser = XMLReaderFactory.createXMLReader(DEFAULT_SAX_DRIVER);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
642 // System.out.println("using default " + DEFAULT_SAX_DRIVER);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
643 saxDriverClass = parser.getClass().getName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
644
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
645 // Configure parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
646 setFeaturesAndProperties(parser, true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
647 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
648 catch (SAXException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
649 throw new JDOMException("Could not load default SAX parser: "
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
650 + DEFAULT_SAX_DRIVER, e);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
651 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
652 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
653
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
654 return parser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
655 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
656
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
657 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
658 * This configures the XMLReader to be used for reading the XML document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
659 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
660 * The default implementation sets various options on the given XMLReader,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
661 * such as validation, DTD resolution, entity handlers, etc., according
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
662 * to the options that were set (e.g. via <code>setEntityResolver</code>)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
663 * and set various SAX properties and features that are required for JDOM
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
664 * internals. These features may change in future releases, so change this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
665 * behavior at your own risk.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
666 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
667 * @param parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
668 * @param contentHandler
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
669 * @throws org.jdom.JDOMException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
670 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
671 protected void configureParser(XMLReader parser, SAXHandler contentHandler)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
672 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
673
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
674 // Setup SAX handlers.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
675
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
676 parser.setContentHandler(contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
677
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
678 if (saxEntityResolver != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
679 parser.setEntityResolver(saxEntityResolver);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
680 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
681
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
682 if (saxDTDHandler != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
683 parser.setDTDHandler(saxDTDHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
684 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
685 parser.setDTDHandler(contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
686 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
687
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
688 if (saxErrorHandler != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
689 parser.setErrorHandler(saxErrorHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
690 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
691 parser.setErrorHandler(new BuilderErrorHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
692 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
693
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
694 // If fastReconfigure is enabled and we failed in the previous attempt
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
695 // in configuring lexical reporting, then we skip this step. This
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
696 // saves the work of repeated exception handling on each parse.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
697 if (!skipNextLexicalReportingConfig) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
698 boolean success = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
699
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
700 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
701 parser.setProperty("http://xml.org/sax/handlers/LexicalHandler",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
702 contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
703 success = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
704 } catch (SAXNotSupportedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
705 // No lexical reporting available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
706 } catch (SAXNotRecognizedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
707 // No lexical reporting available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
708 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
709
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
710 // Some parsers use alternate property for lexical handling (grr...)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
711 if (!success) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
712 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
713 parser.setProperty("http://xml.org/sax/properties/lexical-handler",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
714 contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
715 success = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
716 } catch (SAXNotSupportedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
717 // No lexical reporting available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
718 } catch (SAXNotRecognizedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
719 // No lexical reporting available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
720 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
721 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
722
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
723 // If unable to configure this property and fastReconfigure is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
724 // enabled, then setup to avoid this code path entirely next time.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
725 if (!success && fastReconfigure) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
726 skipNextLexicalReportingConfig = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
727 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
728 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
729
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
730 // If fastReconfigure is enabled and we failed in the previous attempt
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
731 // in configuring entity expansion, then skip this step. This
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
732 // saves the work of repeated exception handling on each parse.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
733 if (!skipNextEntityExpandConfig) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
734 boolean success = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
735
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
736 // Try setting the DeclHandler if entity expansion is off
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
737 if (!expand) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
738 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
739 parser.setProperty("http://xml.org/sax/properties/declaration-handler",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
740 contentHandler);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
741 success = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
742 } catch (SAXNotSupportedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
743 // No lexical reporting available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
744 } catch (SAXNotRecognizedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
745 // No lexical reporting available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
746 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
747 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
748
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
749 /* If unable to configure this property and fastReconfigure is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
750 * enabled, then setup to avoid this code path entirely next time.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
751 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
752 if (!success && fastReconfigure) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
753 skipNextEntityExpandConfig = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
754 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
755 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
756 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
757
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
758 private void setFeaturesAndProperties(XMLReader parser,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
759 boolean coreFeatures)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
760 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
761 // Set any user-specified features on the parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
762 Iterator iter = features.keySet().iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
763 while (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
764 String name = (String)iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
765 Boolean value = (Boolean)features.get(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
766 internalSetFeature(parser, name, value.booleanValue(), name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
767 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
768
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
769 // Set any user-specified properties on the parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
770 iter = properties.keySet().iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
771 while (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
772 String name = (String)iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
773 internalSetProperty(parser, name, properties.get(name), name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
774 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
775
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
776 if (coreFeatures) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
777 // Set validation.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
778 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
779 internalSetFeature(parser,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
780 "http://xml.org/sax/features/validation",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
781 validate, "Validation");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
782 } catch (JDOMException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
783 // If validation is not supported, and the user is requesting
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
784 // that we don't validate, that's fine - don't throw an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
785 // exception.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
786 if (validate)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
787 throw e;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
788 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
789
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
790 // Setup some namespace features.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
791 internalSetFeature(parser,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
792 "http://xml.org/sax/features/namespaces",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
793 true, "Namespaces");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
794 internalSetFeature(parser,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
795 "http://xml.org/sax/features/namespace-prefixes",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
796 true, "Namespace prefixes");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
797 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
798
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
799 // Set entity expansion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
800 // Note SAXHandler can work regardless of how this is set, but when
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
801 // entity expansion it's worth it to try to tell the parser not to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
802 // even bother with external general entities.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
803 // Apparently no parsers yet support this feature.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
804 // XXX It might make sense to setEntityResolver() with a resolver
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
805 // that simply ignores external general entities
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
806 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
807 if (parser.getFeature("http://xml.org/sax/features/external-general-entities") != expand) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
808 parser.setFeature("http://xml.org/sax/features/external-general-entities", expand);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
809 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
810 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
811 catch (SAXNotRecognizedException e) { /* Ignore... */ }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
812 catch (SAXNotSupportedException e) { /* Ignore... */ }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
813 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
814
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
815 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
816 * Tries to set a feature on the parser. If the feature cannot be set,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
817 * throws a JDOMException describing the problem.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
818 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
819 private void internalSetFeature(XMLReader parser, String feature,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
820 boolean value, String displayName) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
821 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
822 parser.setFeature(feature, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
823 } catch (SAXNotSupportedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
824 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
825 displayName + " feature not supported for SAX driver " + parser.getClass().getName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
826 } catch (SAXNotRecognizedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
827 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
828 displayName + " feature not recognized for SAX driver " + parser.getClass().getName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
829 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
830 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
831
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
832 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
833 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
834 * Tries to set a property on the parser. If the property cannot be set,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
835 * throws a JDOMException describing the problem.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
836 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
837 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
838 private void internalSetProperty(XMLReader parser, String property,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
839 Object value, String displayName) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
840 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
841 parser.setProperty(property, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
842 } catch (SAXNotSupportedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
843 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
844 displayName + " property not supported for SAX driver " + parser.getClass().getName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
845 } catch (SAXNotRecognizedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
846 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
847 displayName + " property not recognized for SAX driver " + parser.getClass().getName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
848 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
849 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
850
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
851 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
852 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
853 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
854 * input stream.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
855 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
856 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
857 * @param in <code>InputStream</code> to read from
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
858 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
859 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
860 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
861 * from being fully parsed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
862 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
863 public Document build(InputStream in)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
864 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
865 return build(new InputSource(in));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
866 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
867
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
868 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
869 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
870 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
871 * filename.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
872 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
873 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
874 * @param file <code>File</code> to read from
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
875 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
876 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
877 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
878 * from being fully parsed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
879 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
880 public Document build(File file)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
881 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
882 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
883 URL url = fileToURL(file);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
884 return build(url);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
885 } catch (MalformedURLException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
886 throw new JDOMException("Error in building", e);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
887 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
888 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
889
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
890 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
891 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
892 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
893 * URL.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
894 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
895 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
896 * @param url <code>URL</code> to read from.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
897 * @return <code>Document</code> - resultant Document object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
898 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
899 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
900 * from being fully parsed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
901 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
902 public Document build(URL url)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
903 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
904 String systemID = url.toExternalForm();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
905 return build(new InputSource(systemID));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
906 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
907
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
908 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
909 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
910 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
911 * input stream.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
912 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
913 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
914 * @param in <code>InputStream</code> to read from.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
915 * @param systemId base for resolving relative URIs
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
916 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
917 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
918 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
919 * from being fully parsed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
920 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
921 public Document build(InputStream in, String systemId)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
922 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
923
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
924 InputSource src = new InputSource(in);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
925 src.setSystemId(systemId);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
926 return build(src);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
927 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
928
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
929 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
930 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
931 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
932 * Reader. It's the programmer's responsibility to make sure
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
933 * the reader matches the encoding of the file. It's often easier
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
934 * and safer to use an InputStream rather than a Reader, and to let the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
935 * parser auto-detect the encoding from the XML declaration.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
936 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
937 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
938 * @param characterStream <code>Reader</code> to read from
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
939 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
940 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
941 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
942 * from being fully parsed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
943 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
944 public Document build(Reader characterStream)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
945 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
946 return build(new InputSource(characterStream));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
947 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
948
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
949 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
950 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
951 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
952 * Reader. It's the programmer's responsibility to make sure
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
953 * the reader matches the encoding of the file. It's often easier
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
954 * and safer to use an InputStream rather than a Reader, and to let the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
955 * parser auto-detect the encoding from the XML declaration.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
956 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
957 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
958 * @param characterStream <code>Reader</code> to read from.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
959 * @param systemId base for resolving relative URIs
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
960 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
961 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
962 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
963 * from being fully parsed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
964 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
965 public Document build(Reader characterStream, String systemId)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
966 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
967
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
968 InputSource src = new InputSource(characterStream);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
969 src.setSystemId(systemId);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
970 return build(src);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
971 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
972
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
973 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
974 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
975 * This builds a document from the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
976 * URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
977 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
978 * @param systemId URI for the input
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
979 * @return <code>Document</code> resultant Document object
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
980 * @throws JDOMException when errors occur in parsing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
981 * @throws IOException when an I/O error prevents a document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
982 * from being fully parsed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
983 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
984 public Document build(String systemId)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
985 throws JDOMException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
986 return build(new InputSource(systemId));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
987 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
988
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
989 // /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
990 // * Imitation of File.toURL(), a JDK 1.2 method, reimplemented
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
991 // * here to work with JDK 1.1.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
992 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
993 // * @see java.io.File
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
994 // *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
995 // * @param f the file to convert
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
996 // * @return the file path converted to a file: URL
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
997 // */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
998 // protected URL fileToURL(File f) throws MalformedURLException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
999 // String path = f.getAbsolutePath();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1000 // if (File.separatorChar != '/') {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1001 // path = path.replace(File.separatorChar, '/');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1002 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1003 // if (!path.startsWith("/")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1004 // path = "/" + path;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1005 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1006 // if (!path.endsWith("/") && f.isDirectory()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1007 // path = path + "/";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1008 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1009 // return new URL("file", "", path);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1010 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1012 /** Custom File.toUrl() implementation to handle special chars in file names
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1013 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1014 * @param file file object whose path will be converted
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1015 * @return URL form of the file, with special characters handled
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1016 * @throws MalformedURLException if there's a problem constructing a URL
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1017 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1018 private static URL fileToURL(File file) throws MalformedURLException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1019 StringBuffer buffer = new StringBuffer();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1020 String path = file.getAbsolutePath();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1021
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1022 // Convert non-URL style file separators
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1023 if (File.separatorChar != '/') {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1024 path = path.replace(File.separatorChar, '/');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1025 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1026
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1027 // Make sure it starts at root
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1028 if (!path.startsWith("/")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1029 buffer.append('/');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1030 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1031
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1032 // Copy, converting URL special characters as we go
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1033 int len = path.length();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1034 for (int i = 0; i < len; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1035 char c = path.charAt(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1036 if (c == ' ')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1037 buffer.append("%20");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1038 else if (c == '#')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1039 buffer.append("%23");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1040 else if (c == '%')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1041 buffer.append("%25");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1042 else if (c == '&')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1043 buffer.append("%26");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1044 else if (c == ';')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1045 buffer.append("%3B");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1046 else if (c == '<')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1047 buffer.append("%3C");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1048 else if (c == '=')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1049 buffer.append("%3D");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1050 else if (c == '>')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1051 buffer.append("%3E");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1052 else if (c == '?')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1053 buffer.append("%3F");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1054 else if (c == '~')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1055 buffer.append("%7E");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1056 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1057 buffer.append(c);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1058 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1059
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1060 // Make sure directories end with slash
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1061 if (!path.endsWith("/") && file.isDirectory()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1062 buffer.append('/');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1063 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1064
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1065 // Return URL
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1066 return new URL("file", "", buffer.toString());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1067 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1068
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1069 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1070 * Returns whether or not entities are being expanded into normal text
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1071 * content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1072 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1073 * @return whether entities are being expanded
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1074 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1075 public boolean getExpandEntities() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1076 return expand;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1077 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1078
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1079 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1080 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1081 * This sets whether or not to expand entities for the builder.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1082 * A true means to expand entities as normal content. A false means to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1083 * leave entities unexpanded as <code>EntityRef</code> objects. The
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1084 * default is true.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1085 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1086 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1087 * When this setting is false, the internal DTD subset is retained; when
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1088 * this setting is true, the internal DTD subset is not retained.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1089 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1090 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1091 * Note that Xerces (at least up to 1.4.4) has a bug where entities
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1092 * in attribute values will be misreported if this flag is turned off,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1093 * resulting in entities to appear within element content. When turning
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1094 * entity expansion off either avoid entities in attribute values, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1095 * use another parser like Crimson.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1096 * http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6111
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1097 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1098 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1099 * @param expand <code>boolean</code> indicating whether entity expansion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1100 * should occur.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1101 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1102 public void setExpandEntities(boolean expand) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1103 this.expand = expand;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1104 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1105 }