annotate NGSrich_0.5.5/src/org/jdom/input/SAXHandler.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: SAXHandler.java,v 1.73 2007/11/10 05:29:00 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 All rights reserved.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 modification, are permitted provided that the following conditions
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 are met:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 1. Redistributions of source code must retain the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 notice, this list of conditions, and the following disclaimer.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 2. Redistributions in binary form must reproduce the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 notice, this list of conditions, and the disclaimer that follows
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 these conditions in the documentation and/or other materials
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 provided with the distribution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 3. The name "JDOM" must not be used to endorse or promote products
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 derived from this software without prior written permission. For
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 written permission, please contact <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 4. Products derived from this software may not be called "JDOM", nor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 may "JDOM" appear in their name, without prior written permission
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 from the JDOM Project Management <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 In addition, we request (but do not require) that you include in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 end-user documentation provided with the redistribution and/or in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 software itself an acknowledgement equivalent to the following:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 "This product includes software developed by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 JDOM Project (http://www.jdom.org/)."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 Alternatively, the acknowledgment may be graphical using the logos
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 available at http://www.jdom.org/images/logos.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 SUCH DAMAGE.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 This software consists of voluntary contributions made by many
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 individuals on behalf of the JDOM Project and was originally
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 on the JDOM Project, please see <http://www.jdom.org/>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 package org.jdom.input;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 import java.util.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 import org.jdom.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 import org.xml.sax.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 import org.xml.sax.ext.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 import org.xml.sax.helpers.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 * A support class for {@link SAXBuilder}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * @version $Revision: 1.73 $, $Date: 2007/11/10 05:29:00 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 * @author Philip Nelson
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 * @author Bradley S. Huffman
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 * @author phil@triloggroup.com
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 public class SAXHandler extends DefaultHandler implements LexicalHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 DeclHandler,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 DTDHandler {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 "@(#) $RCSfile: SAXHandler.java,v $ $Revision: 1.73 $ $Date: 2007/11/10 05:29:00 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 /** Hash table to map SAX attribute type names to JDOM attribute types. */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 private static final Map attrNameToTypeMap = new HashMap(13);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 /** <code>Document</code> object being built */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 private Document document;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 /** <code>Element</code> object being built */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 private Element currentElement;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 /** Indicator of where in the document we are */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 private boolean atRoot;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 /** Indicator of whether we are in the DocType. Note that the DTD consists
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 * of both the internal subset (inside the <!DOCTYPE> tag) and the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 * external subset (in a separate .dtd file). */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 private boolean inDTD = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 /** Indicator of whether we are in the internal subset */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 private boolean inInternalSubset = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 /** Indicator of whether we previously were in a CDATA */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 private boolean previousCDATA = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 /** Indicator of whether we are in a CDATA */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 private boolean inCDATA = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 /** Indicator of whether we should expand entities */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 private boolean expand = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 /** Indicator of whether we are actively suppressing (non-expanding) a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 current entity */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 private boolean suppress = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 /** How many nested entities we're currently within */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 private int entityDepth = 0; // XXX may not be necessary anymore?
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 /** Temporary holder for namespaces that have been declared with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 * startPrefixMapping, but are not yet available on the element */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 private List declaredNamespaces;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 /** Temporary holder for the internal subset */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 private StringBuffer internalSubset = new StringBuffer();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 /** Temporary holder for Text and CDATA */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 private TextBuffer textBuffer = new TextBuffer();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 /** The external entities defined in this document */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 private Map externalEntities;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 /** The JDOMFactory used for JDOM object creation */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 private JDOMFactory factory;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 /** Whether to ignore ignorable whitespace */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 private boolean ignoringWhite = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 /** Whether to ignore text containing all whitespace */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 private boolean ignoringBoundaryWhite = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 /** The SAX Locator object provided by the parser */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 private Locator locator;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 * Class initializer: Populate a table to translate SAX attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 * type names into JDOM attribute type value (integer).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 * <b>Note that all the mappings defined below are compliant with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 * the SAX 2.0 specification exception for "ENUMERATION" with is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 * specific to Crimson 1.1.X and Xerces 2.0.0-betaX which report
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 * attributes of enumerated types with a type "ENUMERATION"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 * instead of the expected "NMTOKEN".
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 * Note also that Xerces 1.4.X is not SAX 2.0 compliant either
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 * but handling its case requires
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 * {@link #getAttributeType specific code}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 static {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 attrNameToTypeMap.put("CDATA",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 new Integer(Attribute.CDATA_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 attrNameToTypeMap.put("ID",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 new Integer(Attribute.ID_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 attrNameToTypeMap.put("IDREF",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 new Integer(Attribute.IDREF_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 attrNameToTypeMap.put("IDREFS",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 new Integer(Attribute.IDREFS_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 attrNameToTypeMap.put("ENTITY",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 new Integer(Attribute.ENTITY_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 attrNameToTypeMap.put("ENTITIES",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 new Integer(Attribute.ENTITIES_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 attrNameToTypeMap.put("NMTOKEN",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 new Integer(Attribute.NMTOKEN_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 attrNameToTypeMap.put("NMTOKENS",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 new Integer(Attribute.NMTOKENS_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 attrNameToTypeMap.put("NOTATION",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 new Integer(Attribute.NOTATION_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 attrNameToTypeMap.put("ENUMERATION",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 new Integer(Attribute.ENUMERATED_TYPE));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 * This will create a new <code>SAXHandler</code> that listens to SAX
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 * events and creates a JDOM Document. The objects will be constructed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 * using the default factory.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 public SAXHandler() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 this(null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 * This will create a new <code>SAXHandler</code> that listens to SAX
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 * events and creates a JDOM Document. The objects will be constructed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 * using the provided factory.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 * @param factory <code>JDOMFactory</code> to be used for constructing
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 * objects
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 public SAXHandler(JDOMFactory factory) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 if (factory != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 this.factory = factory;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 this.factory = new DefaultJDOMFactory();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 atRoot = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 declaredNamespaces = new ArrayList();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 externalEntities = new HashMap();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 document = this.factory.document(null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 * Pushes an element onto the tree under construction. Allows subclasses
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 * to put content under a dummy root element which is useful for building
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 * content that would otherwise be a non-well formed document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 * @param element root element under which content will be built
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 protected void pushElement(Element element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 if (atRoot) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 document.setRootElement(element); // XXX should we use a factory call?
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 atRoot = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 factory.addContent(currentElement, element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 currentElement = element;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 * Returns the document. Should be called after parsing is complete.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 * @return <code>Document</code> - Document that was built
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 public Document getDocument() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 return document;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 * Returns the factory used for constructing objects.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 * @return <code>JDOMFactory</code> - the factory used for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 * constructing objects.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 * @see #SAXHandler(org.jdom.JDOMFactory)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 public JDOMFactory getFactory() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 return factory;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 * This sets whether or not to expand entities during the build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 * A true means to expand entities as normal content. A false means to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 * leave entities unexpanded as <code>EntityRef</code> objects. The
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 * default is true.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 * @param expand <code>boolean</code> indicating whether entity expansion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 * should occur.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 public void setExpandEntities(boolean expand) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 this.expand = expand;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 * Returns whether or not entities will be expanded during the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 * build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 * @return <code>boolean</code> - whether entity expansion
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 * will occur during build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 * @see #setExpandEntities
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 public boolean getExpandEntities() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 return expand;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 * Specifies whether or not the parser should elminate whitespace in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 * element content (sometimes known as "ignorable whitespace") when
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 * building the document. Only whitespace which is contained within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 * element content that has an element only content model will be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 * eliminated (see XML Rec 3.2.1). For this setting to take effect
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 * requires that validation be turned on. The default value of this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 * setting is <code>false</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 * @param ignoringWhite Whether to ignore ignorable whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 public void setIgnoringElementContentWhitespace(boolean ignoringWhite) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 this.ignoringWhite = ignoringWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 * Specifies whether or not the parser should elminate text() nodes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 * containing only whitespace when building the document. See
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 * {@link SAXBuilder#setIgnoringBoundaryWhitespace(boolean)}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 * @param ignoringBoundaryWhite Whether to ignore only whitespace content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 public void setIgnoringBoundaryWhitespace(boolean ignoringBoundaryWhite) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 this.ignoringBoundaryWhite = ignoringBoundaryWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 * Returns whether or not the parser will elminate element content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 * containing only whitespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 * @return <code>boolean</code> - whether only whitespace content will
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 * be ignored during build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 * @see #setIgnoringBoundaryWhitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314 public boolean getIgnoringBoundaryWhitespace() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 return ignoringBoundaryWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319 * Returns whether or not the parser will elminate whitespace in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 * element content (sometimes known as "ignorable whitespace") when
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 * building the document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 * @return <code>boolean</code> - whether ignorable whitespace will
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324 * be ignored during build.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326 * @see #setIgnoringElementContentWhitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 public boolean getIgnoringElementContentWhitespace() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329 return ignoringWhite;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 public void startDocument() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333 if (locator != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 document.setBaseURI(locator.getSystemId());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 * This is called when the parser encounters an external entity
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 * declaration.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 * @param name entity name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 * @param publicID public id
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 * @param systemID system id
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 public void externalEntityDecl(String name,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 String publicID, String systemID)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 // Store the public and system ids for the name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351 externalEntities.put(name, new String[]{publicID, systemID});
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 if (!inInternalSubset) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 internalSubset.append(" <!ENTITY ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 .append(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 appendExternalId(publicID, systemID);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358 internalSubset.append(">\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362 * This handles an attribute declaration in the internal subset.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364 * @param eName <code>String</code> element name of attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 * @param aName <code>String</code> attribute name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 * @param type <code>String</code> attribute type
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367 * @param valueDefault <code>String</code> default value of attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368 * @param value <code>String</code> value of attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 public void attributeDecl(String eName, String aName, String type,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 String valueDefault, String value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 if (!inInternalSubset) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 internalSubset.append(" <!ATTLIST ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378 .append(eName)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 .append(' ')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380 .append(aName)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 .append(' ')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 .append(type)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383 .append(' ');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 if (valueDefault != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385 internalSubset.append(valueDefault);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 internalSubset.append('\"')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388 .append(value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389 .append('\"');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 if ((valueDefault != null) && (valueDefault.equals("#FIXED"))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392 internalSubset.append(" \"")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393 .append(value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394 .append('\"');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 internalSubset.append(">\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400 * Handle an element declaration in a DTD.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 * @param name <code>String</code> name of element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403 * @param model <code>String</code> model of the element in DTD syntax
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406 public void elementDecl(String name, String model) throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 // Skip elements that come from the external subset
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408 if (!inInternalSubset) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 internalSubset.append(" <!ELEMENT ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 .append(name)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412 .append(' ')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 .append(model)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 .append(">\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 * Handle an internal entity declaration in a DTD.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420 * @param name <code>String</code> name of entity
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 * @param value <code>String</code> value of the entity
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424 public void internalEntityDecl(String name, String value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 // Skip entities that come from the external subset
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428 if (!inInternalSubset) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430 internalSubset.append(" <!ENTITY ");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431 if (name.startsWith("%")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 internalSubset.append("% ").append(name.substring(1));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 internalSubset.append(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436 internalSubset.append(" \"")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 .append(value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438 .append("\">\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 * This will indicate that a processing instruction has been encountered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 * (The XML declaration is not a processing instruction and will not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 * be reported.)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446 * @param target <code>String</code> target of PI
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 * @param data <code>String</code> containing all data sent to the PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 * This typically looks like one or more attribute value
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 * pairs.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 public void processingInstruction(String target, String data)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 if (atRoot) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 factory.addContent(document, factory.processingInstruction(target, data));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 factory.addContent(getCurrentElement(),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463 factory.processingInstruction(target, data));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 * This indicates that an unresolvable entity reference has been
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 * encountered, normally because the external DTD subset has not been
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470 * read.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 * @param name <code>String</code> name of entity
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
474 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
475 public void skippedEntity(String name)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
476 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
477
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
478 // We don't handle parameter entity references.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
479 if (name.startsWith("%")) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
480
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
481 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
482
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
483 factory.addContent(getCurrentElement(), factory.entityRef(name));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
484 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
485
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
486 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
487 * This will add the prefix mapping to the JDOM
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
488 * <code>Document</code> object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
489 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
490 * @param prefix <code>String</code> namespace prefix.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
491 * @param uri <code>String</code> namespace URI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
492 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
493 public void startPrefixMapping(String prefix, String uri)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
494 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
495
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
496 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
497
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
498 Namespace ns = Namespace.getNamespace(prefix, uri);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
499 declaredNamespaces.add(ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
500 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
501
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
502 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
503 * This reports the occurrence of an actual element. It will include
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
504 * the element's attributes, with the exception of XML vocabulary
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
505 * specific attributes, such as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
506 * <code>xmlns:[namespace prefix]</code> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
507 * <code>xsi:schemaLocation</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
508 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
509 * @param namespaceURI <code>String</code> namespace URI this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
510 * is associated with, or an empty
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
511 * <code>String</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
512 * @param localName <code>String</code> name of element (with no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
513 * namespace prefix, if one is present)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
514 * @param qName <code>String</code> XML 1.0 version of element name:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
515 * [namespace prefix]:[localName]
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
516 * @param atts <code>Attributes</code> list for this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
517 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
518 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
519 public void startElement(String namespaceURI, String localName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
520 String qName, Attributes atts)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
521 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
522 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
523
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
524 Element element = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
525
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
526 if ((namespaceURI != null) && (!namespaceURI.equals(""))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
527 String prefix = "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
528
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
529 // Determine any prefix on the Element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
530 if (!qName.equals(localName)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
531 int split = qName.indexOf(":");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
532 prefix = qName.substring(0, split);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
533 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
534 Namespace elementNamespace =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
535 Namespace.getNamespace(prefix, namespaceURI);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
536 element = factory.element(localName, elementNamespace);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
537 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
538 element = factory.element(localName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
539 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
540
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
541 // Take leftover declared namespaces and add them to this element's
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
542 // map of namespaces
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
543 if (declaredNamespaces.size() > 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
544 transferNamespaces(element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
545 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
546
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
547 // Handle attributes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
548 for (int i=0, len=atts.getLength(); i<len; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
549 Attribute attribute = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
550
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
551 String attLocalName = atts.getLocalName(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
552 String attQName = atts.getQName(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
553 int attType = getAttributeType(atts.getType(i));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
554
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
555 // Bypass any xmlns attributes which might appear, as we got
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
556 // them already in startPrefixMapping().
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
557 // This is sometimes necessary when SAXHandler is used with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
558 // another source than SAXBuilder, as with JDOMResult.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
559 if (attQName.startsWith("xmlns:") || attQName.equals("xmlns")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
560 continue;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
561 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
562
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
563 // First clause per http://markmail.org/message/2p245ggcjst27xe6
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
564 // patch from Mattias Jiderhamn
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
565 if ("".equals(attLocalName) && attQName.indexOf(":") == -1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
566 attribute = factory.attribute(attQName, atts.getValue(i), attType);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
567 } else if (!attQName.equals(attLocalName)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
568 String attPrefix = attQName.substring(0, attQName.indexOf(":"));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
569 Namespace attNs = Namespace.getNamespace(attPrefix,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
570 atts.getURI(i));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
571
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
572 attribute = factory.attribute(attLocalName, atts.getValue(i),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
573 attType, attNs);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
574 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
575 attribute = factory.attribute(attLocalName, atts.getValue(i),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
576 attType);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
577 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
578 factory.setAttribute(element, attribute);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
579 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
580
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
581 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
582
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
583 if (atRoot) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
584 document.setRootElement(element); // XXX should we use a factory call?
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
585 atRoot = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
586 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
587 factory.addContent(getCurrentElement(), element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
588 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
589 currentElement = element;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
590 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
591
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
592 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
593 * This will take the supplied <code>{@link Element}</code> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
594 * transfer its namespaces to the global namespace storage.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
595 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
596 * @param element <code>Element</code> to read namespaces from.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
597 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
598 private void transferNamespaces(Element element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
599 Iterator i = declaredNamespaces.iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
600 while (i.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
601 Namespace ns = (Namespace)i.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
602 if (ns != element.getNamespace()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
603 element.addNamespaceDeclaration(ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
604 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
605 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
606 declaredNamespaces.clear();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
607 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
608
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
609 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
610 * This will report character data (within an element).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
611 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
612 * @param ch <code>char[]</code> character array with character data
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
613 * @param start <code>int</code> index in array where data starts.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
614 * @param length <code>int</code> length of data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
615 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
616 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
617 public void characters(char[] ch, int start, int length)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
618 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
619
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
620 if (suppress || (length == 0))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
621 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
622
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
623 if (previousCDATA != inCDATA) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
624 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
625 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
626
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
627 textBuffer.append(ch, start, length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
628 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
629
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
630 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
631 * Capture ignorable whitespace as text. If
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
632 * setIgnoringElementContentWhitespace(true) has been called then this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
633 * method does nothing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
634 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
635 * @param ch <code>[]</code> - char array of ignorable whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
636 * @param start <code>int</code> - starting position within array
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
637 * @param length <code>int</code> - length of whitespace after start
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
638 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
639 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
640 public void ignorableWhitespace(char[] ch, int start, int length)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
641 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
642 if (!ignoringWhite) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
643 characters(ch, start, length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
644 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
645 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
646
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
647 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
648 * This will flush any characters from SAX character calls we've
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
649 * been buffering.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
650 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
651 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
652 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
653 protected void flushCharacters() throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
654 if (ignoringBoundaryWhite) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
655 if (!textBuffer.isAllWhitespace()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
656 flushCharacters(textBuffer.toString());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
657 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
658 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
659 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
660 flushCharacters(textBuffer.toString());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
661 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
662 textBuffer.clear();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
663 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
664
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
665 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
666 * Flush the given string into the document. This is a protected method
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
667 * so subclassers can control text handling without knowledge of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
668 * internals of this class.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
669 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
670 * @param data string to flush
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
671 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
672 protected void flushCharacters(String data) throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
673 if (data.length() == 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
674 previousCDATA = inCDATA;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
675 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
676 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
677
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
678 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
679 * This is commented out because of some problems with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
680 * the inline DTDs that Xerces seems to have.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
681 if (!inDTD) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
682 if (inEntity) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
683 getCurrentElement().setContent(factory.text(data));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
684 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
685 getCurrentElement().addContent(factory.text(data));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
686 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
687 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
688
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
689 if (previousCDATA) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
690 factory.addContent(getCurrentElement(), factory.cdata(data));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
691 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
692 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
693 factory.addContent(getCurrentElement(), factory.text(data));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
694 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
695
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
696 previousCDATA = inCDATA;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
697 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
698
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
699 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
700 * Indicates the end of an element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
701 * (<code>&lt;/[element name]&gt;</code>) is reached. Note that
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
702 * the parser does not distinguish between empty
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
703 * elements and non-empty elements, so this will occur uniformly.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
704 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
705 * @param namespaceURI <code>String</code> URI of namespace this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
706 * element is associated with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
707 * @param localName <code>String</code> name of element without prefix
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
708 * @param qName <code>String</code> name of element in XML 1.0 form
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
709 * @throws SAXException when things go wrong
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
710 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
711 public void endElement(String namespaceURI, String localName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
712 String qName) throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
713
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
714 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
715
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
716 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
717
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
718 if (!atRoot) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
719 Parent p = currentElement.getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
720 if (p instanceof Document) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
721 atRoot = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
722 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
723 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
724 currentElement = (Element) p;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
725 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
726 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
727 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
728 throw new SAXException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
729 "Ill-formed XML document (missing opening tag for " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
730 localName + ")");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
731 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
732 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
733
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
734 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
735 * This will signify that a DTD is being parsed, and can be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
736 * used to ensure that comments and other lexical structures
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
737 * in the DTD are not added to the JDOM <code>Document</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
738 * object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
739 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
740 * @param name <code>String</code> name of element listed in DTD
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
741 * @param publicID <code>String</code> public ID of DTD
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
742 * @param systemID <code>String</code> system ID of DTD
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
743 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
744 public void startDTD(String name, String publicID, String systemID)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
745 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
746
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
747 flushCharacters(); // Is this needed here?
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
748
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
749 factory.addContent(document, factory.docType(name, publicID, systemID));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
750 inDTD = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
751 inInternalSubset = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
752 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
753
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
754 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
755 * This signifies that the reading of the DTD is complete.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
756 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
757 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
758 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
759 public void endDTD() throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
760
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
761 document.getDocType().setInternalSubset(internalSubset.toString());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
762 inDTD = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
763 inInternalSubset = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
764 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
765
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
766 public void startEntity(String name) throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
767 entityDepth++;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
768
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
769 if (expand || entityDepth > 1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
770 // Short cut out if we're expanding or if we're nested
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
771 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
772 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
773
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
774 // A "[dtd]" entity indicates the beginning of the external subset
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
775 if (name.equals("[dtd]")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
776 inInternalSubset = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
777 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
778 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
779
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
780 // Ignore DTD references, and translate the standard 5
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
781 if ((!inDTD) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
782 (!name.equals("amp")) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
783 (!name.equals("lt")) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
784 (!name.equals("gt")) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
785 (!name.equals("apos")) &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
786 (!name.equals("quot"))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
787
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
788 if (!expand) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
789 String pub = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
790 String sys = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
791 String[] ids = (String[]) externalEntities.get(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
792 if (ids != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
793 pub = ids[0]; // may be null, that's OK
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
794 sys = ids[1]; // may be null, that's OK
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
795 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
796 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
797 * if no current element, this entity belongs to an attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
798 * in these cases, it is an error on the part of the parser
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
799 * to call startEntity but this will help in some cases.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
800 * See org/xml/sax/ext/LexicalHandler.html#startEntity(java.lang.String)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
801 * for more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
802 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
803 if (!atRoot) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
804 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
805 EntityRef entity = factory.entityRef(name, pub, sys);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
806
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
807 // no way to tell if the entity was from an attribute or element so just assume element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
808 factory.addContent(getCurrentElement(), entity);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
809 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
810 suppress = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
811 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
812 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
813 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
814
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
815 public void endEntity(String name) throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
816 entityDepth--;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
817 if (entityDepth == 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
818 // No way are we suppressing if not in an entity,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
819 // regardless of the "expand" value
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
820 suppress = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
821 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
822 if (name.equals("[dtd]")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
823 inInternalSubset = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
824 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
825 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
826
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
827 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
828 * Report a CDATA section
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
829 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
830 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
831 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
832 public void startCDATA() throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
833 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
834
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
835 inCDATA = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
836 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
837
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
838 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
839 * Report a CDATA section
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
840 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
841 public void endCDATA() throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
842 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
843
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
844 previousCDATA = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
845 inCDATA = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
846 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
847
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
848 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
849 * This reports that a comments is parsed. If not in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
850 * DTD, this comment is added to the current JDOM
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
851 * <code>Element</code>, or the <code>Document</code> itself
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
852 * if at that level.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
853 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
854 * @param ch <code>ch[]</code> array of comment characters.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
855 * @param start <code>int</code> index to start reading from.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
856 * @param length <code>int</code> length of data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
857 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
858 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
859 public void comment(char[] ch, int start, int length)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
860 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
861
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
862 if (suppress) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
863
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
864 flushCharacters();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
865
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
866 String commentText = new String(ch, start, length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
867 if (inDTD && inInternalSubset && (expand == false)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
868 internalSubset.append(" <!--")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
869 .append(commentText)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
870 .append("-->\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
871 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
872 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
873 if ((!inDTD) && (!commentText.equals(""))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
874 if (atRoot) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
875 factory.addContent(document, factory.comment(commentText));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
876 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
877 factory.addContent(getCurrentElement(), factory.comment(commentText));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
878 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
879 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
880 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
881
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
882 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
883 * Handle the declaration of a Notation in a DTD
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
884 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
885 * @param name name of the notation
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
886 * @param publicID the public ID of the notation
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
887 * @param systemID the system ID of the notation
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
888 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
889 public void notationDecl(String name, String publicID, String systemID)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
890 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
891
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
892 if (!inInternalSubset) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
893
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
894 internalSubset.append(" <!NOTATION ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
895 .append(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
896 appendExternalId(publicID, systemID);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
897 internalSubset.append(">\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
898 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
899
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
900 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
901 * Handler for unparsed entity declarations in the DTD
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
902 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
903 * @param name <code>String</code> of the unparsed entity decl
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
904 * @param publicID <code>String</code> of the unparsed entity decl
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
905 * @param systemID <code>String</code> of the unparsed entity decl
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
906 * @param notationName <code>String</code> of the unparsed entity decl
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
907 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
908 public void unparsedEntityDecl(String name, String publicID,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
909 String systemID, String notationName)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
910 throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
911
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
912 if (!inInternalSubset) return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
913
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
914 internalSubset.append(" <!ENTITY ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
915 .append(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
916 appendExternalId(publicID, systemID);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
917 internalSubset.append(" NDATA ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
918 .append(notationName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
919 internalSubset.append(">\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
920 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
921
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
922 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
923 * Appends an external ID to the internal subset buffer. Either publicID
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
924 * or systemID may be null, but not both.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
925 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
926 * @param publicID the public ID
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
927 * @param systemID the system ID
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
928 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
929 private void appendExternalId(String publicID, String systemID) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
930 if (publicID != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
931 internalSubset.append(" PUBLIC \"")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
932 .append(publicID)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
933 .append('\"');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
934 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
935 if (systemID != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
936 if (publicID == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
937 internalSubset.append(" SYSTEM ");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
938 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
939 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
940 internalSubset.append(' ');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
941 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
942 internalSubset.append('\"')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
943 .append(systemID)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
944 .append('\"');
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
945 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
946 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
947
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
948 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
949 * Returns the being-parsed element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
950 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
951 * @return <code>Element</code> - element being built.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
952 * @throws SAXException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
953 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
954 public Element getCurrentElement() throws SAXException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
955 if (currentElement == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
956 throw new SAXException(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
957 "Ill-formed XML document (multiple root elements detected)");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
958 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
959 return currentElement;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
960 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
961
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
962 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
963 * Returns the the JDOM Attribute type value from the SAX 2.0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
964 * attribute type string provided by the parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
965 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
966 * @param typeName <code>String</code> the SAX 2.0 attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
967 * type string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
968 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
969 * @return <code>int</code> the JDOM attribute type.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
970 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
971 * @see Attribute#setAttributeType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
972 * @see Attributes#getType
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
973 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
974 private static int getAttributeType(String typeName) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
975 Integer type = (Integer)(attrNameToTypeMap.get(typeName));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
976 if (type == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
977 if (typeName != null && typeName.length() > 0 &&
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
978 typeName.charAt(0) == '(') {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
979 // Xerces 1.4.X reports attributes of enumerated type with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
980 // a type string equals to the enumeration definition, i.e.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
981 // starting with a parenthesis.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
982 return Attribute.ENUMERATED_TYPE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
983 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
984 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
985 return Attribute.UNDECLARED_TYPE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
986 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
987 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
988 return type.intValue();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
989 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
990 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
991
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
992 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
993 * Receives an object for locating the origin of SAX document
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
994 * events. This method is invoked by the SAX parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
995 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
996 * {@link org.jdom.JDOMFactory} implementations can use the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
997 * {@link #getDocumentLocator} method to get access to the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
998 * {@link Locator} during parse.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
999 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1000 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1001 * @param locator <code>Locator</code> an object that can return
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1002 * the location of any SAX document event.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1003 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1004 public void setDocumentLocator(Locator locator) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1005 this.locator = locator;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1006 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1007
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1008 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1009 * Provides access to the {@link Locator} object provided by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1010 * SAX parser.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1011 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1012 * @return <code>Locator</code> an object that can return
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1013 * the location of any SAX document event.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1014 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1015 public Locator getDocumentLocator() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1016 return locator;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1017 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1018 }