annotate NGSrich_0.5.5/src/org/jdom/output/SAXOutputter.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: SAXOutputter.java,v 1.40 2007/11/10 05:29:01 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.output;
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.util.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 import org.jdom.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 import org.xml.sax.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 import org.xml.sax.ext.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 import org.xml.sax.helpers.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * Outputs a JDOM document as a stream of SAX2 events.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 * Most ContentHandler callbacks are supported. Both
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 * <code>ignorableWhitespace()</code> and <code>skippedEntity()</code> have not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 * been implemented. The <code>{@link JDOMLocator}</code> class returned by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 * <code>{@link #getLocator}</code> exposes the current node being operated
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 * upon.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 * At this time, it is not possible to access notations and unparsed entity
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 * references in a DTD from JDOM. Therefore, <code>DTDHandler</code> callbacks
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 * have not been implemented yet.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 * The <code>ErrorHandler</code> callbacks have not been implemented, since
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 * these are supposed to be invoked when the document is parsed and at this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 * point the document exists in memory and is known to have no errors. </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 * @version $Revision: 1.40 $, $Date: 2007/11/10 05:29:01 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 * @author Fred Trimble
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 * @author Bradley S. Huffman
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 public class SAXOutputter {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 "@(#) $RCSfile: SAXOutputter.java,v $ $Revision: 1.40 $ $Date: 2007/11/10 05:29:01 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 /** Shortcut for SAX namespaces core feature */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 private static final String NAMESPACES_SAX_FEATURE =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 "http://xml.org/sax/features/namespaces";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 /** Shortcut for SAX namespace-prefixes core feature */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 private static final String NS_PREFIXES_SAX_FEATURE =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 "http://xml.org/sax/features/namespace-prefixes";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 /** Shortcut for SAX validation core feature */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 private static final String VALIDATION_SAX_FEATURE =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 "http://xml.org/sax/features/validation";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 /** Shortcut for SAX-ext. lexical handler property */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 private static final String LEXICAL_HANDLER_SAX_PROPERTY =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 "http://xml.org/sax/properties/lexical-handler";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 /** Shortcut for SAX-ext. declaration handler property */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 private static final String DECL_HANDLER_SAX_PROPERTY =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 "http://xml.org/sax/properties/declaration-handler";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 * Shortcut for SAX-ext. lexical handler alternate property.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 * Although this property URI is not the one defined by the SAX
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 * "standard", some parsers use it instead of the official one.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 private static final String LEXICAL_HANDLER_ALT_PROPERTY =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 "http://xml.org/sax/handlers/LexicalHandler";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 /** Shortcut for SAX-ext. declaration handler alternate property */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 private static final String DECL_HANDLER_ALT_PROPERTY =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 "http://xml.org/sax/handlers/DeclHandler";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 * Array to map JDOM attribute type (as entry index) to SAX
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 * attribute type names.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 private static final String[] attrTypeToNameMap = new String[] {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 "CDATA", // Attribute.UNDEFINED_ATTRIBUTE, as per SAX 2.0 spec.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 "CDATA", // Attribute.CDATA_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 "ID", // Attribute.ID_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 "IDREF", // Attribute.IDREF_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 "IDREFS", // Attribute.IDREFS_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 "ENTITY", // Attribute.ENTITY_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 "ENTITIES", // Attribute.ENTITIES_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 "NMTOKEN", // Attribute.NMTOKEN_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 "NMTOKENS", // Attribute.NMTOKENS_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 "NOTATION", // Attribute.NOTATION_TYPE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 "NMTOKEN", // Attribute.ENUMERATED_TYPE, as per SAX 2.0 spec.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 };
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 /** registered <code>ContentHandler</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 private ContentHandler contentHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 /** registered <code>ErrorHandler</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 private ErrorHandler errorHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 /** registered <code>DTDHandler</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 private DTDHandler dtdHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 /** registered <code>EntityResolver</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 private EntityResolver entityResolver;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 /** registered <code>LexicalHandler</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 private LexicalHandler lexicalHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 /** registered <code>DeclHandler</code> */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 private DeclHandler declHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 * Whether to report attribute namespace declarations as xmlns attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 * Defaults to <code>false</code> as per SAX specifications.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 * @see <a href="http://www.megginson.com/SAX/Java/namespaces.html">
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 * SAX namespace specifications</a>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 private boolean declareNamespaces = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 * Whether to report DTD events to DeclHandlers and LexicalHandlers.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 * Defaults to <code>true</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 private boolean reportDtdEvents = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 * A SAX Locator that points at the JDOM node currently being
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 * outputted.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 private JDOMLocator locator = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 * This will create a <code>SAXOutputter</code> without any
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 * registered handler. The application is then responsible for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 * registering them using the <code>setXxxHandler()</code> methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 public SAXOutputter() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 * This will create a <code>SAXOutputter</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 * specified <code>ContentHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 * @param contentHandler contains <code>ContentHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 * callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 public SAXOutputter(ContentHandler contentHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 this(contentHandler, null, null, null, null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 * This will create a <code>SAXOutputter</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 * specified SAX2 handlers. At this time, only <code>ContentHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 * and <code>EntityResolver</code> are supported.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 * @param contentHandler contains <code>ContentHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 * callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 * @param errorHandler contains <code>ErrorHandler</code> callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 * @param dtdHandler contains <code>DTDHandler</code> callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 * @param entityResolver contains <code>EntityResolver</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 * callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 public SAXOutputter(ContentHandler contentHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 ErrorHandler errorHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 DTDHandler dtdHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 EntityResolver entityResolver) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 this(contentHandler, errorHandler, dtdHandler, entityResolver, null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 * This will create a <code>SAXOutputter</code> with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 * specified SAX2 handlers. At this time, only <code>ContentHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 * and <code>EntityResolver</code> are supported.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 * @param contentHandler contains <code>ContentHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 * callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 * @param errorHandler contains <code>ErrorHandler</code> callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 * @param dtdHandler contains <code>DTDHandler</code> callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 * @param entityResolver contains <code>EntityResolver</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 * callback methods
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 * @param lexicalHandler contains <code>LexicalHandler</code> callbacks.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 public SAXOutputter(ContentHandler contentHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 ErrorHandler errorHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 DTDHandler dtdHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 EntityResolver entityResolver,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 LexicalHandler lexicalHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 this.contentHandler = contentHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 this.errorHandler = errorHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 this.dtdHandler = dtdHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 this.entityResolver = entityResolver;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 this.lexicalHandler = lexicalHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 * This will set the <code>ContentHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 * @param contentHandler contains <code>ContentHandler</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 * callback methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 public void setContentHandler(ContentHandler contentHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 this.contentHandler = contentHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 * Returns the registered <code>ContentHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 * @return the current <code>ContentHandler</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 * <code>null</code> if none was registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 public ContentHandler getContentHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265 return this.contentHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 * This will set the <code>ErrorHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 * @param errorHandler contains <code>ErrorHandler</code> callback methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 public void setErrorHandler(ErrorHandler errorHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274 this.errorHandler = errorHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 * Return the registered <code>ErrorHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 * @return the current <code>ErrorHandler</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 * <code>null</code> if none was registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 public ErrorHandler getErrorHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 return this.errorHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 * This will set the <code>DTDHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 * @param dtdHandler contains <code>DTDHandler</code> callback methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292 public void setDTDHandler(DTDHandler dtdHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 this.dtdHandler = dtdHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 * Return the registered <code>DTDHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 * @return the current <code>DTDHandler</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 * <code>null</code> if none was registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 public DTDHandler getDTDHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303 return this.dtdHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 * This will set the <code>EntityResolver</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 * @param entityResolver contains EntityResolver callback methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 public void setEntityResolver(EntityResolver entityResolver) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 this.entityResolver = entityResolver;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 * Return the registered <code>EntityResolver</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 * @return the current <code>EntityResolver</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319 * <code>null</code> if none was registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 public EntityResolver getEntityResolver() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322 return this.entityResolver;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326 * This will set the <code>LexicalHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 * @param lexicalHandler contains lexical callback methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 public void setLexicalHandler(LexicalHandler lexicalHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 this.lexicalHandler = lexicalHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 * Return the registered <code>LexicalHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337 * @return the current <code>LexicalHandler</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 * <code>null</code> if none was registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 public LexicalHandler getLexicalHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 return this.lexicalHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 * This will set the <code>DeclHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 * @param declHandler contains declaration callback methods.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 public void setDeclHandler(DeclHandler declHandler) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 this.declHandler = declHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 * Return the registered <code>DeclHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 * @return the current <code>DeclHandler</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 * <code>null</code> if none was registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359 public DeclHandler getDeclHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360 return this.declHandler;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364 * Returns whether attribute namespace declarations shall be reported as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 * "xmlns" attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367 * @return whether attribute namespace declarations shall be reported as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368 * "xmlns" attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370 public boolean getReportNamespaceDeclarations() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 return declareNamespaces;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 * This will define whether attribute namespace declarations shall be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376 * reported as "xmlns" attributes. This flag defaults to <code>false</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 * and behaves as the "namespace-prefixes" SAX core feature.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 * @param declareNamespaces whether attribute namespace declarations
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380 * shall be reported as "xmlns" attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 public void setReportNamespaceDeclarations(boolean declareNamespaces) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383 this.declareNamespaces = declareNamespaces;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 * Returns whether DTD events will be reported.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389 * @return whether DTD events will be reported
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 public boolean getReportDTDEvents() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392 return reportDtdEvents;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 * This will define whether to report DTD events to SAX DeclHandlers
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 * and LexicalHandlers if these handlers are registered and the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398 * document to output includes a DocType declaration.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400 * @param reportDtdEvents whether to notify DTD events.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 public void setReportDTDEvents(boolean reportDtdEvents) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403 this.reportDtdEvents = reportDtdEvents;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 * This will set the state of a SAX feature.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409 * All XMLReaders are required to support setting to true and to false.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412 * SAXOutputter currently supports the following SAX core features:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 * <dl>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 * <dt><code>http://xml.org/sax/features/namespaces</code></dt>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 * <dd><strong>description:</strong> <code>true</code> indicates
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416 * namespace URIs and unprefixed local names for element and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 * attribute names will be available</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 * <dd><strong>access:</strong> read/write, but always
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419 * <code>true</code>!</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420 * <dt><code>http://xml.org/sax/features/namespace-prefixes</code></dt>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 * <dd><strong>description:</strong> <code>true</code> indicates
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 * XML 1.0 names (with prefixes) and attributes (including xmlns*
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 * attributes) will be available</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424 * <dd><strong>access:</strong> read/write</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425 * <dt><code>http://xml.org/sax/features/validation</code></dt>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426 * <dd><strong>description:</strong> controls whether SAXOutputter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 * is reporting DTD-related events; if <code>true</code>, the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428 * DocType internal subset will be parsed to fire DTD events</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429 * <dd><strong>access:</strong> read/write, defaults to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430 * <code>true</code></dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431 * </dl>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 * @param name <code>String</code> the feature name, which is a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 * fully-qualified URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436 * @param value <code>boolean</code> the requested state of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 * feature (true or false).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439 * @throws SAXNotRecognizedException when SAXOutputter does not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440 * recognize the feature name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 * @throws SAXNotSupportedException when SAXOutputter recognizes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 * the feature name but cannot set the requested value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 public void setFeature(String name, boolean value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 throws SAXNotRecognizedException, SAXNotSupportedException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446 if (NS_PREFIXES_SAX_FEATURE.equals(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 // Namespace prefix declarations.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 this.setReportNamespaceDeclarations(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 if (NAMESPACES_SAX_FEATURE.equals(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 if (value != true) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 // Namespaces feature always supported by SAXOutputter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454 throw new SAXNotSupportedException(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456 // Else: true is OK!
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 if (VALIDATION_SAX_FEATURE.equals(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 // Report DTD events.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461 this.setReportDTDEvents(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 // Not a supported feature.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 throw new SAXNotRecognizedException(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 * This will look up the value of a SAX feature.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
474 * @param name <code>String</code> the feature name, which is a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
475 * fully-qualified URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
476 * @return <code>boolean</code> the current state of the feature
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
477 * (true or false).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
478 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
479 * @throws SAXNotRecognizedException when SAXOutputter does not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
480 * recognize the feature name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
481 * @throws SAXNotSupportedException when SAXOutputter recognizes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
482 * the feature name but determine its value at this time.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
483 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
484 public boolean getFeature(String name)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
485 throws SAXNotRecognizedException, SAXNotSupportedException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
486 if (NS_PREFIXES_SAX_FEATURE.equals(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
487 // Namespace prefix declarations.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
488 return (this.declareNamespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
489 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
490 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
491 if (NAMESPACES_SAX_FEATURE.equals(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
492 // Namespaces feature always supported by SAXOutputter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
493 return (true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
494 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
495 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
496 if (VALIDATION_SAX_FEATURE.equals(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
497 // Report DTD events.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
498 return (this.reportDtdEvents);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
499 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
500 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
501 // Not a supported feature.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
502 throw new SAXNotRecognizedException(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
503 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
504 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
505 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
506 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
507
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
508 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
509 * This will set the value of a SAX property.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
510 * This method is also the standard mechanism for setting extended
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
511 * handlers.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
512 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
513 * SAXOutputter currently supports the following SAX properties:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
514 * <dl>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
515 * <dt><code>http://xml.org/sax/properties/lexical-handler</code></dt>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
516 * <dd><strong>data type:</strong>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
517 * <code>org.xml.sax.ext.LexicalHandler</code></dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
518 * <dd><strong>description:</strong> An optional extension handler for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
519 * lexical events like comments.</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
520 * <dd><strong>access:</strong> read/write</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
521 * <dt><code>http://xml.org/sax/properties/declaration-handler</code></dt>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
522 * <dd><strong>data type:</strong>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
523 * <code>org.xml.sax.ext.DeclHandler</code></dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
524 * <dd><strong>description:</strong> An optional extension handler for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
525 * DTD-related events other than notations and unparsed entities.</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
526 * <dd><strong>access:</strong> read/write</dd>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
527 * </dl>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
528 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
529 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
530 * @param name <code>String</code> the property name, which is a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
531 * fully-qualified URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
532 * @param value <code>Object</code> the requested value for the property.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
533 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
534 * @throws SAXNotRecognizedException when SAXOutputter does not recognize
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
535 * the property name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
536 * @throws SAXNotSupportedException when SAXOutputter recognizes the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
537 * property name but cannot set the requested value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
538 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
539 public void setProperty(String name, Object value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
540 throws SAXNotRecognizedException, SAXNotSupportedException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
541 if ((LEXICAL_HANDLER_SAX_PROPERTY.equals(name)) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
542 (LEXICAL_HANDLER_ALT_PROPERTY.equals(name))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
543 this.setLexicalHandler((LexicalHandler)value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
544 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
545 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
546 if ((DECL_HANDLER_SAX_PROPERTY.equals(name)) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
547 (DECL_HANDLER_ALT_PROPERTY.equals(name))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
548 this.setDeclHandler((DeclHandler)value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
549 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
550 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
551 throw new SAXNotRecognizedException(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
552 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
553 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
554 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
555
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
556 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
557 * This will look up the value of a SAX property.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
558 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
559 * @param name <code>String</code> the property name, which is a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
560 * fully-qualified URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
561 * @return <code>Object</code> the current value of the property.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
562 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
563 * @throws SAXNotRecognizedException when SAXOutputter does not recognize
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
564 * the property name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
565 * @throws SAXNotSupportedException when SAXOutputter recognizes the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
566 * property name but cannot determine its value at this time.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
567 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
568 public Object getProperty(String name)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
569 throws SAXNotRecognizedException, SAXNotSupportedException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
570 if ((LEXICAL_HANDLER_SAX_PROPERTY.equals(name)) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
571 (LEXICAL_HANDLER_ALT_PROPERTY.equals(name))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
572 return this.getLexicalHandler();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
573 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
574 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
575 if ((DECL_HANDLER_SAX_PROPERTY.equals(name)) ||
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
576 (DECL_HANDLER_ALT_PROPERTY.equals(name))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
577 return this.getDeclHandler();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
578 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
579 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
580 throw new SAXNotRecognizedException(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
581 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
582 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
583 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
584
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
585
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
586 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
587 * This will output the <code>JDOM Document</code>, firing off the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
588 * SAX events that have been registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
589 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
590 * @param document <code>JDOM Document</code> to output.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
591 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
592 * @throws JDOMException if any error occurred.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
593 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
594 public void output(Document document) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
595 if (document == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
596 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
597 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
598
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
599 // contentHandler.setDocumentLocator()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
600 documentLocator(document);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
601
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
602 // contentHandler.startDocument()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
603 startDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
604
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
605 // Fire DTD events
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
606 if (this.reportDtdEvents) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
607 dtdEvents(document);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
608 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
609
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
610 // Handle root element, as well as any root level
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
611 // processing instructions and comments
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
612 Iterator i = document.getContent().iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
613 while (i.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
614 Object obj = i.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
615
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
616 // update locator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
617 locator.setNode(obj);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
618
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
619 if (obj instanceof Element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
620 // process root element and its content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
621 element(document.getRootElement(), new NamespaceStack());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
622 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
623 else if (obj instanceof ProcessingInstruction) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
624 // contentHandler.processingInstruction()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
625 processingInstruction((ProcessingInstruction) obj);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
626 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
627 else if (obj instanceof Comment) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
628 // lexicalHandler.comment()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
629 comment(((Comment) obj).getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
630 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
631 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
632
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
633 // contentHandler.endDocument()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
634 endDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
635 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
636
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
637 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
638 * This will output a list of JDOM nodes as a document, firing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
639 * off the SAX events that have been registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
640 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
641 * <strong>Warning</strong>: This method may output ill-formed XML
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
642 * documents if the list contains top-level objects that are not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
643 * legal at the document level (e.g. Text or CDATA nodes, multiple
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
644 * Element nodes, etc.). Thus, it should only be used to output
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
645 * document portions towards ContentHandlers capable of accepting
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
646 * such ill-formed documents (such as XSLT processors).</p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
647 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
648 * @param nodes <code>List</code> of JDOM nodes to output.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
649 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
650 * @throws JDOMException if any error occurred.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
651 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
652 * @see #output(org.jdom.Document)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
653 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
654 public void output(List nodes) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
655 if ((nodes == null) || (nodes.size() == 0)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
656 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
657 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
658
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
659 // contentHandler.setDocumentLocator()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
660 documentLocator(null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
661
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
662 // contentHandler.startDocument()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
663 startDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
664
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
665 // Process node list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
666 elementContent(nodes, new NamespaceStack());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
667
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
668 // contentHandler.endDocument()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
669 endDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
670 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
671
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
672 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
673 * This will output a single JDOM element as a document, firing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
674 * off the SAX events that have been registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
675 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
676 * @param node the <code>Element</code> node to output.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
677 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
678 * @throws JDOMException if any error occurred.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
679 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
680 public void output(Element node) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
681 if (node == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
682 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
683 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
684
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
685 // contentHandler.setDocumentLocator()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
686 documentLocator(null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
687
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
688 // contentHandler.startDocument()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
689 startDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
690
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
691 // Output node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
692 elementContent(node, new NamespaceStack());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
693
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
694 // contentHandler.endDocument()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
695 endDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
696 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
697
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
698 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
699 * This will output a list of JDOM nodes as a fragment of an XML
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
700 * document, firing off the SAX events that have been registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
701 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
702 * <strong>Warning</strong>: This method does not call the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
703 * {@link ContentHandler#setDocumentLocator},
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
704 * {@link ContentHandler#startDocument} and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
705 * {@link ContentHandler#endDocument} callbacks on the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
706 * {@link #setContentHandler ContentHandler}. The user shall
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
707 * invoke these methods directly prior/after outputting the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
708 * document fragments.</p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
709 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
710 * @param nodes <code>List</code> of JDOM nodes to output.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
711 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
712 * @throws JDOMException if any error occurred.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
713 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
714 * @see #outputFragment(org.jdom.Content)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
715 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
716 public void outputFragment(List nodes) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
717 if ((nodes == null) || (nodes.size() == 0)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
718 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
719 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
720
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
721 // Output node list as a document fragment.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
722 elementContent(nodes, new NamespaceStack());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
723 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
724
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
725 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
726 * This will output a single JDOM nodes as a fragment of an XML
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
727 * document, firing off the SAX events that have been registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
728 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
729 * <strong>Warning</strong>: This method does not call the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
730 * {@link ContentHandler#setDocumentLocator},
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
731 * {@link ContentHandler#startDocument} and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
732 * {@link ContentHandler#endDocument} callbacks on the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
733 * {@link #setContentHandler ContentHandler}. The user shall
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
734 * invoke these methods directly prior/after outputting the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
735 * document fragments.</p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
736 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
737 * @param node the <code>Content</code> node to output.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
738 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
739 * @throws JDOMException if any error occurred.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
740 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
741 * @see #outputFragment(java.util.List)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
742 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
743 public void outputFragment(Content node) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
744 if (node == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
745 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
746 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
747
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
748 // Output single node as a document fragment.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
749 elementContent(node, new NamespaceStack());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
750 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
751
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
752 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
753 * This parses a DTD declaration to fire the related events towards
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
754 * the registered handlers.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
755 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
756 * @param document <code>JDOM Document</code> the DocType is to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
757 * process.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
758 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
759 private void dtdEvents(Document document) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
760 DocType docType = document.getDocType();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
761
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
762 // Fire DTD-related events only if handlers have been registered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
763 if ((docType != null) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
764 ((dtdHandler != null) || (declHandler != null))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
765
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
766 // Build a dummy XML document that only references the DTD...
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
767 String dtdDoc = new XMLOutputter().outputString(docType);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
768
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
769 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
770 // And parse it to fire DTD events.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
771 createDTDParser().parse(new InputSource(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
772 new StringReader(dtdDoc)));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
773
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
774 // We should never reach this point as the document is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
775 // ill-formed; it does not have any root element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
776 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
777 catch (SAXParseException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
778 // Expected exception: There's no root element in document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
779 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
780 catch (SAXException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
781 throw new JDOMException("DTD parsing error", e);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
782 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
783 catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
784 throw new JDOMException("DTD parsing error", e);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
785 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
786 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
787 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
788
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
789 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
790 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
791 * This method tells you the line of the XML file being parsed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
792 * For an in-memory document, it's meaningless. The location
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
793 * is only valid for the current parsing lifecycle, but
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
794 * the document has already been parsed. Therefore, it returns
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
795 * -1 for both line and column numbers.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
796 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
797 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
798 * @param document JDOM <code>Document</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
799 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
800 private void documentLocator(Document document) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
801 locator = new JDOMLocator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
802 String publicID = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
803 String systemID = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
804
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
805 if (document != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
806 DocType docType = document.getDocType();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
807 if (docType != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
808 publicID = docType.getPublicID();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
809 systemID = docType.getSystemID();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
810 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
811 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
812 locator.setPublicId(publicID);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
813 locator.setSystemId(systemID);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
814 locator.setLineNumber(-1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
815 locator.setColumnNumber(-1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
816
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
817 contentHandler.setDocumentLocator(locator);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
818 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
819
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
820 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
821 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
822 * This method is always the second method of all callbacks in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
823 * all handlers to be invoked (setDocumentLocator is always first).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
824 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
825 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
826 private void startDocument() throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
827 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
828 contentHandler.startDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
829 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
830 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
831 throw new JDOMException("Exception in startDocument", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
832 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
833 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
834
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
835 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
836 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
837 * Always the last method of all callbacks in all handlers
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
838 * to be invoked.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
839 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
840 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
841 private void endDocument() throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
842 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
843 contentHandler.endDocument();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
844
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
845 // reset locator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
846 locator = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
847 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
848 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
849 throw new JDOMException("Exception in endDocument", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
850 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
851 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
852
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
853 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
854 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
855 * This will invoke the <code>ContentHandler.processingInstruction</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
856 * callback when a processing instruction is encountered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
857 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
858 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
859 * @param pi <code>ProcessingInstruction</code> containing target and data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
860 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
861 private void processingInstruction(ProcessingInstruction pi)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
862 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
863 if (pi != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
864 String target = pi.getTarget();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
865 String data = pi.getData();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
866 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
867 contentHandler.processingInstruction(target, data);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
868 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
869 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
870 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
871 "Exception in processingInstruction", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
872 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
873 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
874 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
875
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
876 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
877 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
878 * This will recursively invoke all of the callbacks for a particular
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
879 * element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
880 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
881 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
882 * @param element <code>Element</code> used in callbacks.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
883 * @param namespaces <code>List</code> stack of Namespaces in scope.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
884 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
885 private void element(Element element, NamespaceStack namespaces)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
886 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
887 // used to check endPrefixMapping
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
888 int previouslyDeclaredNamespaces = namespaces.size();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
889
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
890 // contentHandler.startPrefixMapping()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
891 Attributes nsAtts = startPrefixMapping(element, namespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
892
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
893 // contentHandler.startElement()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
894 startElement(element, nsAtts);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
895
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
896 // handle content in the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
897 elementContent(element.getContent(), namespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
898
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
899 // update locator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
900 if (locator != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
901 locator.setNode(element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
902 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
903
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
904 // contentHandler.endElement()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
905 endElement(element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
906
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
907 // contentHandler.endPrefixMapping()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
908 endPrefixMapping(namespaces, previouslyDeclaredNamespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
909 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
910
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
911 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
912 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
913 * This will invoke the <code>ContentHandler.startPrefixMapping</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
914 * callback
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
915 * when a new namespace is encountered in the <code>Document</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
916 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
917 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
918 * @param element <code>Element</code> used in callbacks.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
919 * @param namespaces <code>List</code> stack of Namespaces in scope.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
920 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
921 * @return <code>Attributes</code> declaring the namespaces local to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
922 * <code>element</code> or <code>null</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
923 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
924 private Attributes startPrefixMapping(Element element,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
925 NamespaceStack namespaces)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
926 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
927 AttributesImpl nsAtts = null; // The namespaces as xmlns attributes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
928
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
929 Namespace ns = element.getNamespace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
930 if (ns != Namespace.XML_NAMESPACE) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
931 String prefix = ns.getPrefix();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
932 String uri = namespaces.getURI(prefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
933 if (!ns.getURI().equals(uri)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
934 namespaces.push(ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
935 nsAtts = this.addNsAttribute(nsAtts, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
936 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
937 contentHandler.startPrefixMapping(prefix, ns.getURI());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
938 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
939 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
940 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
941 "Exception in startPrefixMapping", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
942 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
943 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
944 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
945
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
946 // Fire additional namespace declarations
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
947 List additionalNamespaces = element.getAdditionalNamespaces();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
948 if (additionalNamespaces != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
949 Iterator itr = additionalNamespaces.iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
950 while (itr.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
951 ns = (Namespace)itr.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
952 String prefix = ns.getPrefix();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
953 String uri = namespaces.getURI(prefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
954 if (!ns.getURI().equals(uri)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
955 namespaces.push(ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
956 nsAtts = this.addNsAttribute(nsAtts, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
957 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
958 contentHandler.startPrefixMapping(prefix, ns.getURI());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
959 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
960 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
961 throw new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
962 "Exception in startPrefixMapping", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
963 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
964 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
965 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
966 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
967 return nsAtts;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
968 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
969
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
970 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
971 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
972 * This will invoke the <code>endPrefixMapping</code> callback in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
973 * <code>ContentHandler</code> when a namespace is goes out of scope
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
974 * in the <code>Document</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
975 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
976 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
977 * @param namespaces <code>List</code> stack of Namespaces in scope.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
978 * @param previouslyDeclaredNamespaces number of previously declared
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
979 * namespaces
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
980 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
981 private void endPrefixMapping(NamespaceStack namespaces,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
982 int previouslyDeclaredNamespaces)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
983 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
984 while (namespaces.size() > previouslyDeclaredNamespaces) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
985 String prefix = namespaces.pop();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
986 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
987 contentHandler.endPrefixMapping(prefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
988 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
989 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
990 throw new JDOMException("Exception in endPrefixMapping", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
991 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
992 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
993 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
994
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
995 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
996 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
997 * This will invoke the <code>startElement</code> callback
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
998 * in the <code>ContentHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
999 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1000 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1001 * @param element <code>Element</code> used in callbacks.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1002 * @param nsAtts <code>List</code> of namespaces to declare with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1003 * the element or <code>null</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1004 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1005 private void startElement(Element element, Attributes nsAtts)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1006 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1007 String namespaceURI = element.getNamespaceURI();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1008 String localName = element.getName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1009 String rawName = element.getQualifiedName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1010
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1011 // Allocate attribute list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1012 AttributesImpl atts = (nsAtts != null)?
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1013 new AttributesImpl(nsAtts): new AttributesImpl();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1014
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1015 List attributes = element.getAttributes();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1016 Iterator i = attributes.iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1017 while (i.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1018 Attribute a = (Attribute) i.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1019 atts.addAttribute(a.getNamespaceURI(),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1020 a.getName(),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1021 a.getQualifiedName(),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1022 getAttributeTypeName(a.getAttributeType()),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1023 a.getValue());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1024 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1025
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1026 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1027 contentHandler.startElement(namespaceURI, localName, rawName, atts);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1028 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1029 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1030 throw new JDOMException("Exception in startElement", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1031 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1032 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1033
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1034 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1035 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1036 * This will invoke the <code>endElement</code> callback
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1037 * in the <code>ContentHandler</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1038 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1039 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1040 * @param element <code>Element</code> used in callbacks.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1041 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1042 private void endElement(Element element) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1043 String namespaceURI = element.getNamespaceURI();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1044 String localName = element.getName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1045 String rawName = element.getQualifiedName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1046
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1047 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1048 contentHandler.endElement(namespaceURI, localName, rawName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1049 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1050 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1051 throw new JDOMException("Exception in endElement", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1052 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1053 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1054
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1055 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1056 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1057 * This will invoke the callbacks for the content of an element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1058 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1059 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1060 * @param content element content as a <code>List</code> of nodes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1061 * @param namespaces <code>List</code> stack of Namespaces in scope.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1062 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1063 private void elementContent(List content, NamespaceStack namespaces)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1064 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1065 for (Iterator i=content.iterator(); i.hasNext(); ) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1066 Object obj = i.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1067
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1068 if (obj instanceof Content) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1069 this.elementContent((Content)obj, namespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1070 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1071 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1072 // Not a valid element child. This could happen with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1073 // application-provided lists which may contain non
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1074 // JDOM objects.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1075 handleError(new JDOMException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1076 "Invalid element content: " + obj));
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
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1081 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1082 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1083 * This will invoke the callbacks for the content of an element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1084 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1085 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1086 * @param node a <code>Content</code> node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1087 * @param namespaces <code>List</code> stack of Namespaces in scope.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1088 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1089 private void elementContent(Content node, NamespaceStack namespaces)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1090 throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1091 // update locator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1092 if (locator != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1093 locator.setNode(node);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1094 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1095
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1096 if (node instanceof Element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1097 element((Element) node, namespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1098 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1099 else if (node instanceof CDATA) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1100 cdata(((CDATA) node).getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1101 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1102 else if (node instanceof Text) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1103 // contentHandler.characters()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1104 characters(((Text) node).getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1105 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1106 else if (node instanceof ProcessingInstruction) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1107 // contentHandler.processingInstruction()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1108 processingInstruction((ProcessingInstruction) node);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1109 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1110 else if (node instanceof Comment) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1111 // lexicalHandler.comment()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1112 comment(((Comment) node).getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1113 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1114 else if (node instanceof EntityRef) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1115 // contentHandler.skippedEntity()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1116 entityRef((EntityRef) node);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1117 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1118 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1119 // Not a valid element child. This could happen with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1120 // application-provided lists which may contain non
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1121 // JDOM objects.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1122 handleError(new JDOMException("Invalid element content: " + node));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1123 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1124 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1125
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1126 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1127 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1128 * This will be called for each chunk of CDATA section encountered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1129 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1130 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1131 * @param cdataText all text in the CDATA section, including whitespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1132 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1133 private void cdata(String cdataText) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1134 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1135 if (lexicalHandler != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1136 lexicalHandler.startCDATA();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1137 characters(cdataText);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1138 lexicalHandler.endCDATA();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1139 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1140 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1141 characters(cdataText);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1142 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1143 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1144 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1145 throw new JDOMException("Exception in CDATA", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1146 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1147 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1148
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1149 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1150 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1151 * This will be called for each chunk of character data encountered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1152 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1153 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1154 * @param elementText all text in an element, including whitespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1155 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1156 private void characters(String elementText) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1157 char[] c = elementText.toCharArray();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1158 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1159 contentHandler.characters(c, 0, c.length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1160 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1161 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1162 throw new JDOMException("Exception in characters", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1163 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1164 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1165
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1166 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1167 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1168 * This will be called for each chunk of comment data encontered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1169 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1170 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1171 * @param commentText all text in a comment, including whitespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1172 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1173 private void comment(String commentText) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1174 if (lexicalHandler != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1175 char[] c = commentText.toCharArray();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1176 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1177 lexicalHandler.comment(c, 0, c.length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1178 } catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1179 throw new JDOMException("Exception in comment", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1180 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1181 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1182 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1183
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1184 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1185 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1186 * This will invoke the <code>ContentHandler.skippedEntity</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1187 * callback when an entity reference is encountered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1188 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1189 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1190 * @param entity <code>EntityRef</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1191 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1192 private void entityRef(EntityRef entity) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1193 if (entity != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1194 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1195 // No need to worry about appending a '%' character as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1196 // we do not support parameter entities
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1197 contentHandler.skippedEntity(entity.getName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1198 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1199 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1200 throw new JDOMException("Exception in entityRef", se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1201 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1202 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1203 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1204
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1205
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1206 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1207 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1208 * Appends a namespace declaration in the form of a xmlns attribute to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1209 * an attribute list, crerating this latter if needed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1210 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1211 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1212 * @param atts <code>AttributeImpl</code> where to add the attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1213 * @param ns <code>Namespace</code> the namespace to declare.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1214 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1215 * @return <code>AttributeImpl</code> the updated attribute list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1216 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1217 private AttributesImpl addNsAttribute(AttributesImpl atts, Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1218 if (this.declareNamespaces) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1219 if (atts == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1220 atts = new AttributesImpl();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1221 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1222
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1223 String prefix = ns.getPrefix();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1224 if (prefix.equals("")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1225 atts.addAttribute("", // namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1226 "", // local name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1227 "xmlns", // qualified name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1228 "CDATA", // type
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1229 ns.getURI()); // value
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1230 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1231 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1232 atts.addAttribute("", // namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1233 "", // local name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1234 "xmlns:" + ns.getPrefix(), // qualified name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1235 "CDATA", // type
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1236 ns.getURI()); // value
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1237 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1238 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1239 return atts;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1240 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1241
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1242 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1243 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1244 * Returns the SAX 2.0 attribute type string from the type of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1245 * a JDOM Attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1246 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1247 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1248 * @param type <code>int</code> the type of the JDOM attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1249 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1250 * @return <code>String</code> the SAX 2.0 attribute type string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1251 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1252 * @see org.jdom.Attribute#getAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1253 * @see org.xml.sax.Attributes#getType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1254 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1255 private static String getAttributeTypeName(int type) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1256 if ((type < 0) || (type >= attrTypeToNameMap.length)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1257 type = Attribute.UNDECLARED_TYPE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1258 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1259 return attrTypeToNameMap[type];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1260 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1261
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1262 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1263 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1264 * Notifies the registered {@link ErrorHandler SAX error handler}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1265 * (if any) of an input processing error. The error handler can
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1266 * choose to absorb the error and let the processing continue.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1267 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1268 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1269 * @param exception <code>JDOMException</code> containing the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1270 * error information; will be wrapped in a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1271 * {@link SAXParseException} when reported to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1272 * the SAX error handler.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1273 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1274 * @throws JDOMException if no error handler has been registered
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1275 * or if the error handler fired a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1276 * {@link SAXException}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1277 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1278 private void handleError(JDOMException exception) throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1279 if (errorHandler != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1280 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1281 errorHandler.error(new SAXParseException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1282 exception.getMessage(), null, exception));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1283 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1284 catch (SAXException se) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1285 if (se.getException() instanceof JDOMException) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1286 throw (JDOMException)(se.getException());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1287 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1288 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1289 throw new JDOMException(se.getMessage(), se);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1290 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1291 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1292 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1293 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1294 throw exception;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1295 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1296 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1297
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1298 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1299 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1300 * Creates a SAX XMLReader.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1301 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1302 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1303 * @return <code>XMLReader</code> a SAX2 parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1304 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1305 * @throws Exception if no parser can be created.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1306 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1307 protected XMLReader createParser() throws Exception {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1308 XMLReader parser = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1309
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1310 // Try using JAXP...
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1311 // Note we need JAXP 1.1, and if JAXP 1.0 is all that's
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1312 // available then the getXMLReader call fails and we skip
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1313 // to the hard coded default parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1314 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1315 Class factoryClass =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1316 Class.forName("javax.xml.parsers.SAXParserFactory");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1317
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1318 // factory = SAXParserFactory.newInstance();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1319 Method newParserInstance =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1320 factoryClass.getMethod("newInstance", null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1321 Object factory = newParserInstance.invoke(null, null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1322
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1323 // jaxpParser = factory.newSAXParser();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1324 Method newSAXParser = factoryClass.getMethod("newSAXParser", null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1325 Object jaxpParser = newSAXParser.invoke(factory, null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1326
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1327 // parser = jaxpParser.getXMLReader();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1328 Class parserClass = jaxpParser.getClass();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1329 Method getXMLReader =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1330 parserClass.getMethod("getXMLReader", null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1331 parser = (XMLReader)getXMLReader.invoke(jaxpParser, null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1332 } catch (ClassNotFoundException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1333 //e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1334 } catch (InvocationTargetException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1335 //e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1336 } catch (NoSuchMethodException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1337 //e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1338 } catch (IllegalAccessException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1339 //e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1340 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1341
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1342 // Check to see if we got a parser yet, if not, try to use a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1343 // hard coded default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1344 if (parser == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1345 parser = XMLReaderFactory.createXMLReader(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1346 "org.apache.xerces.parsers.SAXParser");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1347 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1348 return parser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1349 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1350
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1351 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1352 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1353 * This will create a SAX XMLReader capable of parsing a DTD and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1354 * configure it so that the DTD parsing events are routed to the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1355 * handlers registered onto this SAXOutputter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1356 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1357 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1358 * @return <code>XMLReader</code> a SAX2 parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1359 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1360 * @throws JDOMException if no parser can be created.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1361 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1362 private XMLReader createDTDParser() throws JDOMException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1363 XMLReader parser = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1364
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1365 // Get a parser instance
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1366 try
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1367 {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1368 parser = createParser();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1369 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1370 catch (Exception ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1371 throw new JDOMException("Error in SAX parser allocation", ex1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1372 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1373
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1374 // Register handlers
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1375 if (this.getDTDHandler() != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1376 parser.setDTDHandler(this.getDTDHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1377 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1378 if (this.getEntityResolver() != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1379 parser.setEntityResolver(this.getEntityResolver());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1380 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1381 if (this.getLexicalHandler() != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1382 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1383 parser.setProperty(LEXICAL_HANDLER_SAX_PROPERTY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1384 this.getLexicalHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1385 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1386 catch (SAXException ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1387 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1388 parser.setProperty(LEXICAL_HANDLER_ALT_PROPERTY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1389 this.getLexicalHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1390 } catch (SAXException ex2) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1391 // Forget it!
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1392 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1393 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1394 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1395 if (this.getDeclHandler() != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1396 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1397 parser.setProperty(DECL_HANDLER_SAX_PROPERTY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1398 this.getDeclHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1399 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1400 catch (SAXException ex1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1401 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1402 parser.setProperty(DECL_HANDLER_ALT_PROPERTY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1403 this.getDeclHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1404 } catch (SAXException ex2) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1405 // Forget it!
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1406 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1407 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1408 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1409
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1410 // Absorb errors as much as possible, per Laurent
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1411 parser.setErrorHandler(new DefaultHandler());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1412
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1413 return parser;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1414 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1415
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1416 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1417 * Returns a JDOMLocator object referencing the node currently
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1418 * being processed by this outputter. The returned object is a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1419 * snapshot of the location information and can thus safely be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1420 * memorized for later use.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1421 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1422 * This method allows direct access to the location information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1423 * maintained by SAXOutputter without requiring to implement
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1424 * <code>XMLFilter</code>. (In SAX, locators are only available
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1425 * though the <code>ContentHandler</code> interface).</p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1426 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1427 * Note that location information is only available while
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1428 * SAXOutputter is outputting nodes. Hence this method should
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1429 * only be used by objects taking part in the output processing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1430 * such as <code>ErrorHandler</code>s.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1431 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1432 * @return a JDOMLocator object referencing the node currently
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1433 * being processed or <code>null</code> if no output
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1434 * operation is being performed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1435 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1436 public JDOMLocator getLocator() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1437 return (locator != null)? new JDOMLocator(locator): null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1438 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1439 }