| 1 |  |  | 
| 2 |  |  | 
| 3 |  |  | 
| 4 |  |  | 
| 5 |  |  | 
| 6 |  |  | 
| 7 |  |  | 
| 8 |  | package org.dom4j.io; | 
| 9 |  |  | 
| 10 |  | import java.lang.reflect.Method; | 
| 11 |  | import java.util.ArrayList; | 
| 12 |  | import java.util.HashMap; | 
| 13 |  | import java.util.List; | 
| 14 |  | import java.util.Map; | 
| 15 |  |  | 
| 16 |  | import org.dom4j.Branch; | 
| 17 |  | import org.dom4j.Document; | 
| 18 |  | import org.dom4j.DocumentFactory; | 
| 19 |  | import org.dom4j.DocumentType; | 
| 20 |  | import org.dom4j.Element; | 
| 21 |  | import org.dom4j.ElementHandler; | 
| 22 |  | import org.dom4j.Namespace; | 
| 23 |  | import org.dom4j.QName; | 
| 24 |  | import org.dom4j.dtd.AttributeDecl; | 
| 25 |  | import org.dom4j.dtd.ElementDecl; | 
| 26 |  | import org.dom4j.dtd.ExternalEntityDecl; | 
| 27 |  | import org.dom4j.dtd.InternalEntityDecl; | 
| 28 |  | import org.dom4j.tree.AbstractElement; | 
| 29 |  | import org.dom4j.tree.NamespaceStack; | 
| 30 |  |  | 
| 31 |  | import org.xml.sax.Attributes; | 
| 32 |  | import org.xml.sax.DTDHandler; | 
| 33 |  | import org.xml.sax.EntityResolver; | 
| 34 |  | import org.xml.sax.InputSource; | 
| 35 |  | import org.xml.sax.Locator; | 
| 36 |  | import org.xml.sax.SAXException; | 
| 37 |  | import org.xml.sax.SAXParseException; | 
| 38 |  | import org.xml.sax.ext.DeclHandler; | 
| 39 |  | import org.xml.sax.ext.LexicalHandler; | 
| 40 |  | import org.xml.sax.helpers.DefaultHandler; | 
| 41 |  |  | 
| 42 |  |  | 
| 43 |  |  | 
| 44 |  |  | 
| 45 |  |  | 
| 46 |  |  | 
| 47 |  |  | 
| 48 |  |  | 
| 49 |  |  | 
| 50 |  | public class SAXContentHandler extends DefaultHandler implements | 
| 51 |  | LexicalHandler, DeclHandler, DTDHandler { | 
| 52 |  |  | 
| 53 |  | private DocumentFactory documentFactory; | 
| 54 |  |  | 
| 55 |  |  | 
| 56 |  | private Document document; | 
| 57 |  |  | 
| 58 |  |  | 
| 59 |  | private ElementStack elementStack; | 
| 60 |  |  | 
| 61 |  |  | 
| 62 |  | private NamespaceStack namespaceStack; | 
| 63 |  |  | 
| 64 |  |  | 
| 65 |  | private ElementHandler elementHandler; | 
| 66 |  |  | 
| 67 |  |  | 
| 68 |  | private Locator locator; | 
| 69 |  |  | 
| 70 |  |  | 
| 71 |  | private String entity; | 
| 72 |  |  | 
| 73 |  |  | 
| 74 |  | private boolean insideDTDSection; | 
| 75 |  |  | 
| 76 |  |  | 
| 77 |  | private boolean insideCDATASection; | 
| 78 |  |  | 
| 79 |  |  | 
| 80 |  |  | 
| 81 |  |  | 
| 82 |  |  | 
| 83 |  | private StringBuffer cdataText; | 
| 84 |  |  | 
| 85 |  |  | 
| 86 |  | private Map availableNamespaceMap = new HashMap(); | 
| 87 |  |  | 
| 88 |  |  | 
| 89 |  | private List declaredNamespaceList = new ArrayList(); | 
| 90 |  |  | 
| 91 |  |  | 
| 92 |  | private List internalDTDDeclarations; | 
| 93 |  |  | 
| 94 |  |  | 
| 95 |  | private List externalDTDDeclarations; | 
| 96 |  |  | 
| 97 |  |  | 
| 98 |  | private int declaredNamespaceIndex; | 
| 99 |  |  | 
| 100 |  |  | 
| 101 |  | private EntityResolver entityResolver; | 
| 102 |  |  | 
| 103 |  | private InputSource inputSource; | 
| 104 |  |  | 
| 105 |  |  | 
| 106 |  | private Element currentElement; | 
| 107 |  |  | 
| 108 |  |  | 
| 109 |  | private boolean includeInternalDTDDeclarations = false; | 
| 110 |  |  | 
| 111 |  |  | 
| 112 |  | private boolean includeExternalDTDDeclarations = false; | 
| 113 |  |  | 
| 114 |  |  | 
| 115 |  | private int entityLevel; | 
| 116 |  |  | 
| 117 |  |  | 
| 118 |  | private boolean internalDTDsubset = false; | 
| 119 |  |  | 
| 120 |  |  | 
| 121 |  | private boolean mergeAdjacentText = false; | 
| 122 |  |  | 
| 123 |  |  | 
| 124 |  | private boolean textInTextBuffer = false; | 
| 125 |  |  | 
| 126 |  |  | 
| 127 |  | private boolean ignoreComments = false; | 
| 128 |  |  | 
| 129 |  |  | 
| 130 |  | private StringBuffer textBuffer; | 
| 131 |  |  | 
| 132 |  |  | 
| 133 |  | private boolean stripWhitespaceText = false; | 
| 134 |  |  | 
| 135 | 19 | public SAXContentHandler() { | 
| 136 | 19 | this(DocumentFactory.getInstance()); | 
| 137 |  | } | 
| 138 |  |  | 
| 139 | 19 | public SAXContentHandler(DocumentFactory documentFactory) { | 
| 140 | 19 | this(documentFactory, null); | 
| 141 |  | } | 
| 142 |  |  | 
| 143 | 5811 | public SAXContentHandler(DocumentFactory documentFactory, | 
| 144 |  | ElementHandler elementHandler) { | 
| 145 | 5811 | this(documentFactory, elementHandler, null); | 
| 146 | 5811 | this.elementStack = createElementStack(); | 
| 147 |  | } | 
| 148 |  |  | 
| 149 | 5811 | public SAXContentHandler(DocumentFactory documentFactory, | 
| 150 |  | ElementHandler elementHandler, ElementStack elementStack) { | 
| 151 | 5811 | this.documentFactory = documentFactory; | 
| 152 | 5811 | this.elementHandler = elementHandler; | 
| 153 | 5811 | this.elementStack = elementStack; | 
| 154 | 5811 | this.namespaceStack = new NamespaceStack(documentFactory); | 
| 155 |  | } | 
| 156 |  |  | 
| 157 |  |  | 
| 158 |  |  | 
| 159 |  |  | 
| 160 |  |  | 
| 161 |  |  | 
| 162 | 11692 | public Document getDocument() { | 
| 163 | 11692 | if (document == null) { | 
| 164 | 5814 | document = createDocument(); | 
| 165 |  | } | 
| 166 |  |  | 
| 167 | 11692 | return document; | 
| 168 |  | } | 
| 169 |  |  | 
| 170 |  |  | 
| 171 |  |  | 
| 172 | 5813 | public void setDocumentLocator(Locator documentLocator) { | 
| 173 | 5813 | this.locator = documentLocator; | 
| 174 |  | } | 
| 175 |  |  | 
| 176 | 23 | public void processingInstruction(String target, String data) | 
| 177 |  | throws SAXException { | 
| 178 | 23 | if (mergeAdjacentText && textInTextBuffer) { | 
| 179 | 0 | completeCurrentTextNode(); | 
| 180 |  | } | 
| 181 |  |  | 
| 182 | 23 | if (currentElement != null) { | 
| 183 | 1 | currentElement.addProcessingInstruction(target, data); | 
| 184 |  | } else { | 
| 185 | 22 | getDocument().addProcessingInstruction(target, data); | 
| 186 |  | } | 
| 187 |  | } | 
| 188 |  |  | 
| 189 | 5884 | public void startPrefixMapping(String prefix, String uri) | 
| 190 |  | throws SAXException { | 
| 191 | 5884 | namespaceStack.push(prefix, uri); | 
| 192 |  | } | 
| 193 |  |  | 
| 194 | 5884 | public void endPrefixMapping(String prefix) throws SAXException { | 
| 195 | 5884 | namespaceStack.pop(prefix); | 
| 196 | 5884 | declaredNamespaceIndex = namespaceStack.size(); | 
| 197 |  | } | 
| 198 |  |  | 
| 199 | 5814 | public void startDocument() throws SAXException { | 
| 200 |  |  | 
| 201 | 5814 | document = null; | 
| 202 | 5814 | currentElement = null; | 
| 203 |  |  | 
| 204 | 5814 | elementStack.clear(); | 
| 205 |  |  | 
| 206 | 5814 | if ((elementHandler != null) | 
| 207 |  | && (elementHandler instanceof DispatchHandler)) { | 
| 208 | 18 | elementStack.setDispatchHandler((DispatchHandler) elementHandler); | 
| 209 |  | } | 
| 210 |  |  | 
| 211 | 5814 | namespaceStack.clear(); | 
| 212 | 5814 | declaredNamespaceIndex = 0; | 
| 213 |  |  | 
| 214 | 5814 | if (mergeAdjacentText && (textBuffer == null)) { | 
| 215 | 4 | textBuffer = new StringBuffer(); | 
| 216 |  | } | 
| 217 |  |  | 
| 218 | 5814 | textInTextBuffer = false; | 
| 219 |  | } | 
| 220 |  |  | 
| 221 | 5814 | public void endDocument() throws SAXException { | 
| 222 | 5814 | namespaceStack.clear(); | 
| 223 | 5814 | elementStack.clear(); | 
| 224 | 5814 | currentElement = null; | 
| 225 | 5814 | textBuffer = null; | 
| 226 |  | } | 
| 227 |  |  | 
| 228 | 86721 | public void startElement(String namespaceURI, String localName, | 
| 229 |  | String qualifiedName, Attributes attributes) throws SAXException { | 
| 230 | 86721 | if (mergeAdjacentText && textInTextBuffer) { | 
| 231 | 1 | completeCurrentTextNode(); | 
| 232 |  | } | 
| 233 |  |  | 
| 234 | 86721 | QName qName = namespaceStack.getQName(namespaceURI, localName, | 
| 235 |  | qualifiedName); | 
| 236 |  |  | 
| 237 | 86721 | Branch branch = currentElement; | 
| 238 |  |  | 
| 239 | 86721 | if (branch == null) { | 
| 240 | 5814 | branch = getDocument(); | 
| 241 |  | } | 
| 242 |  |  | 
| 243 | 86721 | Element element = branch.addElement(qName); | 
| 244 |  |  | 
| 245 |  |  | 
| 246 | 86721 | addDeclaredNamespaces(element); | 
| 247 |  |  | 
| 248 |  |  | 
| 249 | 86721 | addAttributes(element, attributes); | 
| 250 |  |  | 
| 251 | 86721 | elementStack.pushElement(element); | 
| 252 | 86721 | currentElement = element; | 
| 253 |  |  | 
| 254 | 86721 | entity = null; | 
| 255 |  |  | 
| 256 | 86721 | if (elementHandler != null) { | 
| 257 | 78 | elementHandler.onStart(elementStack); | 
| 258 |  | } | 
| 259 |  | } | 
| 260 |  |  | 
| 261 | 86721 | public void endElement(String namespaceURI, String localName, String qName) | 
| 262 |  | throws SAXException { | 
| 263 | 86721 | if (mergeAdjacentText && textInTextBuffer) { | 
| 264 | 5 | completeCurrentTextNode(); | 
| 265 |  | } | 
| 266 |  |  | 
| 267 | 86721 | if ((elementHandler != null) && (currentElement != null)) { | 
| 268 | 78 | elementHandler.onEnd(elementStack); | 
| 269 |  | } | 
| 270 |  |  | 
| 271 | 86721 | elementStack.popElement(); | 
| 272 | 86721 | currentElement = elementStack.peekElement(); | 
| 273 |  | } | 
| 274 |  |  | 
| 275 | 109454 | public void characters(char[] ch, int start, int end) throws SAXException { | 
| 276 | 109454 | if (end == 0) { | 
| 277 | 0 | return; | 
| 278 |  | } | 
| 279 |  |  | 
| 280 | 109454 | if (currentElement != null) { | 
| 281 | 109454 | if (entity != null) { | 
| 282 | 4 | if (mergeAdjacentText && textInTextBuffer) { | 
| 283 | 0 | completeCurrentTextNode(); | 
| 284 |  | } | 
| 285 |  |  | 
| 286 | 4 | currentElement.addEntity(entity, new String(ch, start, end)); | 
| 287 | 4 | entity = null; | 
| 288 | 109450 | } else if (insideCDATASection) { | 
| 289 | 200 | if (mergeAdjacentText && textInTextBuffer) { | 
| 290 | 1 | completeCurrentTextNode(); | 
| 291 |  | } | 
| 292 |  |  | 
| 293 | 200 | cdataText.append(new String(ch, start, end)); | 
| 294 |  | } else { | 
| 295 | 109250 | if (mergeAdjacentText) { | 
| 296 | 32 | textBuffer.append(ch, start, end); | 
| 297 | 32 | textInTextBuffer = true; | 
| 298 |  | } else { | 
| 299 | 109218 | currentElement.addText(new String(ch, start, end)); | 
| 300 |  | } | 
| 301 |  | } | 
| 302 |  | } | 
| 303 |  | } | 
| 304 |  |  | 
| 305 |  |  | 
| 306 |  |  | 
| 307 |  |  | 
| 308 |  |  | 
| 309 |  |  | 
| 310 |  |  | 
| 311 |  |  | 
| 312 |  |  | 
| 313 |  |  | 
| 314 |  |  | 
| 315 |  |  | 
| 316 |  |  | 
| 317 |  |  | 
| 318 | 0 | public void warning(SAXParseException exception) throws SAXException { | 
| 319 |  |  | 
| 320 |  | } | 
| 321 |  |  | 
| 322 |  |  | 
| 323 |  |  | 
| 324 |  |  | 
| 325 |  |  | 
| 326 |  |  | 
| 327 |  |  | 
| 328 |  |  | 
| 329 |  |  | 
| 330 |  |  | 
| 331 |  |  | 
| 332 | 0 | public void error(SAXParseException exception) throws SAXException { | 
| 333 | 0 | throw exception; | 
| 334 |  | } | 
| 335 |  |  | 
| 336 |  |  | 
| 337 |  |  | 
| 338 |  |  | 
| 339 |  |  | 
| 340 |  |  | 
| 341 |  |  | 
| 342 |  |  | 
| 343 |  |  | 
| 344 |  |  | 
| 345 |  |  | 
| 346 | 0 | public void fatalError(SAXParseException exception) throws SAXException { | 
| 347 | 0 | throw exception; | 
| 348 |  | } | 
| 349 |  |  | 
| 350 |  |  | 
| 351 |  |  | 
| 352 | 11 | public void startDTD(String name, String publicId, String systemId) | 
| 353 |  | throws SAXException { | 
| 354 | 11 | getDocument().addDocType(name, publicId, systemId); | 
| 355 | 11 | insideDTDSection = true; | 
| 356 | 11 | internalDTDsubset = true; | 
| 357 |  | } | 
| 358 |  |  | 
| 359 | 11 | public void endDTD() throws SAXException { | 
| 360 | 11 | insideDTDSection = false; | 
| 361 |  |  | 
| 362 | 11 | DocumentType docType = getDocument().getDocType(); | 
| 363 |  |  | 
| 364 | 11 | if (docType != null) { | 
| 365 | 11 | if (internalDTDDeclarations != null) { | 
| 366 | 4 | docType.setInternalDeclarations(internalDTDDeclarations); | 
| 367 |  | } | 
| 368 |  |  | 
| 369 | 11 | if (externalDTDDeclarations != null) { | 
| 370 | 3 | docType.setExternalDeclarations(externalDTDDeclarations); | 
| 371 |  | } | 
| 372 |  | } | 
| 373 |  |  | 
| 374 | 11 | internalDTDDeclarations = null; | 
| 375 | 11 | externalDTDDeclarations = null; | 
| 376 |  | } | 
| 377 |  |  | 
| 378 | 433 | public void startEntity(String name) throws SAXException { | 
| 379 | 433 | ++entityLevel; | 
| 380 |  |  | 
| 381 |  |  | 
| 382 | 433 | entity = null; | 
| 383 |  |  | 
| 384 | 433 | if (!insideDTDSection) { | 
| 385 | 429 | if (!isIgnorableEntity(name)) { | 
| 386 | 5 | entity = name; | 
| 387 |  | } | 
| 388 |  | } | 
| 389 |  |  | 
| 390 |  |  | 
| 391 |  |  | 
| 392 |  |  | 
| 393 |  |  | 
| 394 | 433 | internalDTDsubset = false; | 
| 395 |  | } | 
| 396 |  |  | 
| 397 | 433 | public void endEntity(String name) throws SAXException { | 
| 398 | 433 | --entityLevel; | 
| 399 | 433 | entity = null; | 
| 400 |  |  | 
| 401 | 433 | if (entityLevel == 0) { | 
| 402 | 433 | internalDTDsubset = true; | 
| 403 |  | } | 
| 404 |  | } | 
| 405 |  |  | 
| 406 | 70 | public void startCDATA() throws SAXException { | 
| 407 | 70 | insideCDATASection = true; | 
| 408 | 70 | cdataText = new StringBuffer(); | 
| 409 |  | } | 
| 410 |  |  | 
| 411 | 70 | public void endCDATA() throws SAXException { | 
| 412 | 70 | insideCDATASection = false; | 
| 413 | 70 | currentElement.addCDATA(cdataText.toString()); | 
| 414 |  | } | 
| 415 |  |  | 
| 416 | 445 | public void comment(char[] ch, int start, int end) throws SAXException { | 
| 417 | 445 | if (!ignoreComments) { | 
| 418 | 445 | if (mergeAdjacentText && textInTextBuffer) { | 
| 419 | 1 | completeCurrentTextNode(); | 
| 420 |  | } | 
| 421 |  |  | 
| 422 | 445 | String text = new String(ch, start, end); | 
| 423 |  |  | 
| 424 | 445 | if (!insideDTDSection && (text.length() > 0)) { | 
| 425 | 442 | if (currentElement != null) { | 
| 426 | 422 | currentElement.addComment(text); | 
| 427 |  | } else { | 
| 428 | 20 | getDocument().addComment(text); | 
| 429 |  | } | 
| 430 |  | } | 
| 431 |  | } | 
| 432 |  | } | 
| 433 |  |  | 
| 434 |  |  | 
| 435 |  |  | 
| 436 |  |  | 
| 437 |  |  | 
| 438 |  |  | 
| 439 |  |  | 
| 440 |  |  | 
| 441 |  |  | 
| 442 |  |  | 
| 443 |  |  | 
| 444 |  |  | 
| 445 |  |  | 
| 446 |  |  | 
| 447 |  |  | 
| 448 |  |  | 
| 449 |  |  | 
| 450 |  |  | 
| 451 |  |  | 
| 452 |  |  | 
| 453 |  |  | 
| 454 |  |  | 
| 455 |  |  | 
| 456 |  |  | 
| 457 | 6 | public void elementDecl(String name, String model) throws SAXException { | 
| 458 | 6 | if (internalDTDsubset) { | 
| 459 | 3 | if (includeInternalDTDDeclarations) { | 
| 460 | 3 | addDTDDeclaration(new ElementDecl(name, model)); | 
| 461 |  | } | 
| 462 |  | } else { | 
| 463 | 3 | if (includeExternalDTDDeclarations) { | 
| 464 | 3 | addExternalDTDDeclaration(new ElementDecl(name, model)); | 
| 465 |  | } | 
| 466 |  | } | 
| 467 |  | } | 
| 468 |  |  | 
| 469 |  |  | 
| 470 |  |  | 
| 471 |  |  | 
| 472 |  |  | 
| 473 |  |  | 
| 474 |  |  | 
| 475 |  |  | 
| 476 |  |  | 
| 477 |  |  | 
| 478 |  |  | 
| 479 |  |  | 
| 480 |  |  | 
| 481 |  |  | 
| 482 |  |  | 
| 483 |  |  | 
| 484 |  |  | 
| 485 |  |  | 
| 486 |  |  | 
| 487 |  |  | 
| 488 |  |  | 
| 489 |  |  | 
| 490 |  |  | 
| 491 |  |  | 
| 492 |  |  | 
| 493 |  |  | 
| 494 |  |  | 
| 495 |  |  | 
| 496 |  |  | 
| 497 |  |  | 
| 498 |  |  | 
| 499 |  |  | 
| 500 |  |  | 
| 501 |  |  | 
| 502 | 3 | public void attributeDecl(String eName, String aName, String type, | 
| 503 |  | String valueDefault, String val) throws SAXException { | 
| 504 | 3 | if (internalDTDsubset) { | 
| 505 | 3 | if (includeInternalDTDDeclarations) { | 
| 506 | 3 | addDTDDeclaration(new AttributeDecl(eName, aName, type, | 
| 507 |  | valueDefault, val)); | 
| 508 |  | } | 
| 509 |  | } else { | 
| 510 | 0 | if (includeExternalDTDDeclarations) { | 
| 511 | 0 | addExternalDTDDeclaration(new AttributeDecl(eName, aName, type, | 
| 512 |  | valueDefault, val)); | 
| 513 |  | } | 
| 514 |  | } | 
| 515 |  | } | 
| 516 |  |  | 
| 517 |  |  | 
| 518 |  |  | 
| 519 |  |  | 
| 520 |  |  | 
| 521 |  |  | 
| 522 |  |  | 
| 523 |  |  | 
| 524 |  |  | 
| 525 |  |  | 
| 526 |  |  | 
| 527 |  |  | 
| 528 |  |  | 
| 529 |  |  | 
| 530 |  |  | 
| 531 |  |  | 
| 532 |  |  | 
| 533 |  |  | 
| 534 |  |  | 
| 535 |  |  | 
| 536 |  |  | 
| 537 |  |  | 
| 538 | 13 | public void internalEntityDecl(String name, String value) | 
| 539 |  | throws SAXException { | 
| 540 | 13 | if (internalDTDsubset) { | 
| 541 | 13 | if (includeInternalDTDDeclarations) { | 
| 542 | 13 | addDTDDeclaration(new InternalEntityDecl(name, value)); | 
| 543 |  | } | 
| 544 |  | } else { | 
| 545 | 0 | if (includeExternalDTDDeclarations) { | 
| 546 | 0 | addExternalDTDDeclaration(new InternalEntityDecl(name, value)); | 
| 547 |  | } | 
| 548 |  | } | 
| 549 |  | } | 
| 550 |  |  | 
| 551 |  |  | 
| 552 |  |  | 
| 553 |  |  | 
| 554 |  |  | 
| 555 |  |  | 
| 556 |  |  | 
| 557 |  |  | 
| 558 |  |  | 
| 559 |  |  | 
| 560 |  |  | 
| 561 |  |  | 
| 562 |  |  | 
| 563 |  |  | 
| 564 |  |  | 
| 565 |  |  | 
| 566 |  |  | 
| 567 |  |  | 
| 568 |  |  | 
| 569 |  |  | 
| 570 |  |  | 
| 571 |  |  | 
| 572 |  |  | 
| 573 | 0 | public void externalEntityDecl(String name, String publicId, String sysId) | 
| 574 |  | throws SAXException { | 
| 575 | 0 | ExternalEntityDecl declaration = new ExternalEntityDecl(name, publicId, | 
| 576 |  | sysId); | 
| 577 |  |  | 
| 578 | 0 | if (internalDTDsubset) { | 
| 579 | 0 | if (includeInternalDTDDeclarations) { | 
| 580 | 0 | addDTDDeclaration(declaration); | 
| 581 |  | } | 
| 582 |  | } else { | 
| 583 | 0 | if (includeExternalDTDDeclarations) { | 
| 584 | 0 | addExternalDTDDeclaration(declaration); | 
| 585 |  | } | 
| 586 |  | } | 
| 587 |  | } | 
| 588 |  |  | 
| 589 |  |  | 
| 590 |  |  | 
| 591 |  |  | 
| 592 |  |  | 
| 593 |  |  | 
| 594 |  |  | 
| 595 |  |  | 
| 596 |  |  | 
| 597 |  |  | 
| 598 |  |  | 
| 599 |  |  | 
| 600 |  |  | 
| 601 |  |  | 
| 602 |  |  | 
| 603 |  |  | 
| 604 |  |  | 
| 605 |  |  | 
| 606 |  |  | 
| 607 |  |  | 
| 608 |  |  | 
| 609 |  |  | 
| 610 |  |  | 
| 611 |  |  | 
| 612 |  |  | 
| 613 |  |  | 
| 614 |  |  | 
| 615 |  |  | 
| 616 |  |  | 
| 617 |  |  | 
| 618 |  |  | 
| 619 |  |  | 
| 620 |  |  | 
| 621 |  |  | 
| 622 |  |  | 
| 623 |  |  | 
| 624 | 0 | public void notationDecl(String name, String publicId, String systemId) | 
| 625 |  | throws SAXException { | 
| 626 |  |  | 
| 627 |  | } | 
| 628 |  |  | 
| 629 |  |  | 
| 630 |  |  | 
| 631 |  |  | 
| 632 |  |  | 
| 633 |  |  | 
| 634 |  |  | 
| 635 |  |  | 
| 636 |  |  | 
| 637 |  |  | 
| 638 |  |  | 
| 639 |  |  | 
| 640 |  |  | 
| 641 |  |  | 
| 642 |  |  | 
| 643 |  |  | 
| 644 |  |  | 
| 645 |  |  | 
| 646 |  |  | 
| 647 |  |  | 
| 648 |  |  | 
| 649 |  |  | 
| 650 |  |  | 
| 651 |  |  | 
| 652 |  |  | 
| 653 |  |  | 
| 654 |  |  | 
| 655 |  |  | 
| 656 |  |  | 
| 657 |  |  | 
| 658 | 0 | public void unparsedEntityDecl(String name, String publicId, | 
| 659 |  | String systemId, String notationName) throws SAXException { | 
| 660 |  |  | 
| 661 |  | } | 
| 662 |  |  | 
| 663 |  |  | 
| 664 |  |  | 
| 665 | 0 | public ElementStack getElementStack() { | 
| 666 | 0 | return elementStack; | 
| 667 |  | } | 
| 668 |  |  | 
| 669 | 0 | public void setElementStack(ElementStack elementStack) { | 
| 670 | 0 | this.elementStack = elementStack; | 
| 671 |  | } | 
| 672 |  |  | 
| 673 | 0 | public EntityResolver getEntityResolver() { | 
| 674 | 0 | return entityResolver; | 
| 675 |  | } | 
| 676 |  |  | 
| 677 | 5792 | public void setEntityResolver(EntityResolver entityResolver) { | 
| 678 | 5792 | this.entityResolver = entityResolver; | 
| 679 |  | } | 
| 680 |  |  | 
| 681 | 0 | public InputSource getInputSource() { | 
| 682 | 0 | return inputSource; | 
| 683 |  | } | 
| 684 |  |  | 
| 685 | 5792 | public void setInputSource(InputSource inputSource) { | 
| 686 | 5792 | this.inputSource = inputSource; | 
| 687 |  | } | 
| 688 |  |  | 
| 689 |  |  | 
| 690 |  |  | 
| 691 |  |  | 
| 692 |  |  | 
| 693 |  |  | 
| 694 |  |  | 
| 695 | 0 | public boolean isIncludeInternalDTDDeclarations() { | 
| 696 | 0 | return includeInternalDTDDeclarations; | 
| 697 |  | } | 
| 698 |  |  | 
| 699 |  |  | 
| 700 |  |  | 
| 701 |  |  | 
| 702 |  |  | 
| 703 |  |  | 
| 704 |  |  | 
| 705 |  |  | 
| 706 |  |  | 
| 707 | 5792 | public void setIncludeInternalDTDDeclarations(boolean include) { | 
| 708 | 5792 | this.includeInternalDTDDeclarations = include; | 
| 709 |  | } | 
| 710 |  |  | 
| 711 |  |  | 
| 712 |  |  | 
| 713 |  |  | 
| 714 |  |  | 
| 715 |  |  | 
| 716 |  |  | 
| 717 | 0 | public boolean isIncludeExternalDTDDeclarations() { | 
| 718 | 0 | return includeExternalDTDDeclarations; | 
| 719 |  | } | 
| 720 |  |  | 
| 721 |  |  | 
| 722 |  |  | 
| 723 |  |  | 
| 724 |  |  | 
| 725 |  |  | 
| 726 |  |  | 
| 727 |  |  | 
| 728 |  |  | 
| 729 | 5792 | public void setIncludeExternalDTDDeclarations(boolean include) { | 
| 730 | 5792 | this.includeExternalDTDDeclarations = include; | 
| 731 |  | } | 
| 732 |  |  | 
| 733 |  |  | 
| 734 |  |  | 
| 735 |  |  | 
| 736 |  |  | 
| 737 |  |  | 
| 738 | 0 | public boolean isMergeAdjacentText() { | 
| 739 | 0 | return mergeAdjacentText; | 
| 740 |  | } | 
| 741 |  |  | 
| 742 |  |  | 
| 743 |  |  | 
| 744 |  |  | 
| 745 |  |  | 
| 746 |  |  | 
| 747 |  |  | 
| 748 |  |  | 
| 749 | 5792 | public void setMergeAdjacentText(boolean mergeAdjacentText) { | 
| 750 | 5792 | this.mergeAdjacentText = mergeAdjacentText; | 
| 751 |  | } | 
| 752 |  |  | 
| 753 |  |  | 
| 754 |  |  | 
| 755 |  |  | 
| 756 |  |  | 
| 757 |  |  | 
| 758 |  |  | 
| 759 | 0 | public boolean isStripWhitespaceText() { | 
| 760 | 0 | return stripWhitespaceText; | 
| 761 |  | } | 
| 762 |  |  | 
| 763 |  |  | 
| 764 |  |  | 
| 765 |  |  | 
| 766 |  |  | 
| 767 |  |  | 
| 768 |  |  | 
| 769 |  |  | 
| 770 | 5792 | public void setStripWhitespaceText(boolean stripWhitespaceText) { | 
| 771 | 5792 | this.stripWhitespaceText = stripWhitespaceText; | 
| 772 |  | } | 
| 773 |  |  | 
| 774 |  |  | 
| 775 |  |  | 
| 776 |  |  | 
| 777 |  |  | 
| 778 |  |  | 
| 779 | 0 | public boolean isIgnoreComments() { | 
| 780 | 0 | return ignoreComments; | 
| 781 |  | } | 
| 782 |  |  | 
| 783 |  |  | 
| 784 |  |  | 
| 785 |  |  | 
| 786 |  |  | 
| 787 |  |  | 
| 788 |  |  | 
| 789 | 5792 | public void setIgnoreComments(boolean ignoreComments) { | 
| 790 | 5792 | this.ignoreComments = ignoreComments; | 
| 791 |  | } | 
| 792 |  |  | 
| 793 |  |  | 
| 794 |  |  | 
| 795 |  |  | 
| 796 |  |  | 
| 797 |  |  | 
| 798 |  |  | 
| 799 |  |  | 
| 800 | 8 | protected void completeCurrentTextNode() { | 
| 801 | 8 | if (stripWhitespaceText) { | 
| 802 | 0 | boolean whitespace = true; | 
| 803 |  |  | 
| 804 | 0 | for (int i = 0, size = textBuffer.length(); i < size; i++) { | 
| 805 | 0 | if (!Character.isWhitespace(textBuffer.charAt(i))) { | 
| 806 | 0 | whitespace = false; | 
| 807 |  |  | 
| 808 | 0 | break; | 
| 809 |  | } | 
| 810 |  | } | 
| 811 |  |  | 
| 812 | 0 | if (!whitespace) { | 
| 813 | 0 | currentElement.addText(textBuffer.toString()); | 
| 814 |  | } | 
| 815 |  | } else { | 
| 816 | 8 | currentElement.addText(textBuffer.toString()); | 
| 817 |  | } | 
| 818 |  |  | 
| 819 | 8 | textBuffer.setLength(0); | 
| 820 | 8 | textInTextBuffer = false; | 
| 821 |  | } | 
| 822 |  |  | 
| 823 |  |  | 
| 824 |  |  | 
| 825 |  |  | 
| 826 |  |  | 
| 827 |  |  | 
| 828 | 5814 | protected Document createDocument() { | 
| 829 | 5814 | String encoding = getEncoding(); | 
| 830 | 5814 | Document doc = documentFactory.createDocument(encoding); | 
| 831 |  |  | 
| 832 |  |  | 
| 833 | 5814 | doc.setEntityResolver(entityResolver); | 
| 834 |  |  | 
| 835 | 5814 | if (inputSource != null) { | 
| 836 | 5791 | doc.setName(inputSource.getSystemId()); | 
| 837 |  | } | 
| 838 |  |  | 
| 839 | 5814 | return doc; | 
| 840 |  | } | 
| 841 |  |  | 
| 842 | 5814 | private String getEncoding() { | 
| 843 | 5814 | if (locator == null) { | 
| 844 | 1 | return null; | 
| 845 |  | } | 
| 846 |  |  | 
| 847 |  |  | 
| 848 |  |  | 
| 849 | 5813 | try { | 
| 850 | 5813 | Method m = locator.getClass().getMethod("getEncoding", | 
| 851 |  | new Class[] {}); | 
| 852 |  |  | 
| 853 | 5801 | if (m != null) { | 
| 854 | 5801 | return (String) m.invoke(locator, null); | 
| 855 |  | } | 
| 856 |  | } catch (Exception e) { | 
| 857 |  |  | 
| 858 |  | } | 
| 859 |  |  | 
| 860 |  |  | 
| 861 | 12 | return null; | 
| 862 |  | } | 
| 863 |  |  | 
| 864 |  |  | 
| 865 |  |  | 
| 866 |  |  | 
| 867 |  |  | 
| 868 |  |  | 
| 869 |  |  | 
| 870 |  |  | 
| 871 |  |  | 
| 872 | 429 | protected boolean isIgnorableEntity(String name) { | 
| 873 | 429 | return "amp".equals(name) || "apos".equals(name) || "gt".equals(name) | 
| 874 |  | || "lt".equals(name) || "quot".equals(name); | 
| 875 |  | } | 
| 876 |  |  | 
| 877 |  |  | 
| 878 |  |  | 
| 879 |  |  | 
| 880 |  |  | 
| 881 |  |  | 
| 882 |  |  | 
| 883 |  |  | 
| 884 |  |  | 
| 885 | 86721 | protected void addDeclaredNamespaces(Element element) { | 
| 886 | 86701 | Namespace elementNamespace = element.getNamespace(); | 
| 887 |  |  | 
| 888 | 86721 | for (int size = namespaceStack.size(); declaredNamespaceIndex < size; | 
| 889 |  | declaredNamespaceIndex++) { | 
| 890 | 5884 | Namespace namespace = namespaceStack | 
| 891 |  | .getNamespace(declaredNamespaceIndex); | 
| 892 |  |  | 
| 893 |  |  | 
| 894 | 5884 | element.add(namespace); | 
| 895 |  |  | 
| 896 |  |  | 
| 897 |  | } | 
| 898 |  | } | 
| 899 |  |  | 
| 900 |  |  | 
| 901 |  |  | 
| 902 |  |  | 
| 903 |  |  | 
| 904 |  |  | 
| 905 |  |  | 
| 906 |  |  | 
| 907 |  |  | 
| 908 | 86721 | protected void addAttributes(Element element, Attributes attributes) { | 
| 909 |  |  | 
| 910 |  |  | 
| 911 | 86721 | boolean noNamespaceAttributes = false; | 
| 912 |  |  | 
| 913 | 86721 | if (element instanceof AbstractElement) { | 
| 914 |  |  | 
| 915 | 86700 | AbstractElement baseElement = (AbstractElement) element; | 
| 916 | 86721 | baseElement.setAttributes(attributes, namespaceStack, | 
| 917 |  | noNamespaceAttributes); | 
| 918 |  | } else { | 
| 919 | 0 | int size = attributes.getLength(); | 
| 920 |  |  | 
| 921 | 0 | for (int i = 0; i < size; i++) { | 
| 922 | 0 | String attributeQName = attributes.getQName(i); | 
| 923 |  |  | 
| 924 | 0 | if (noNamespaceAttributes | 
| 925 |  | || !attributeQName.startsWith("xmlns")) { | 
| 926 | 0 | String attributeURI = attributes.getURI(i); | 
| 927 | 0 | String attributeLocalName = attributes.getLocalName(i); | 
| 928 | 0 | String attributeValue = attributes.getValue(i); | 
| 929 |  |  | 
| 930 | 0 | QName qName = namespaceStack.getAttributeQName( | 
| 931 |  | attributeURI, attributeLocalName, attributeQName); | 
| 932 | 0 | element.addAttribute(qName, attributeValue); | 
| 933 |  | } | 
| 934 |  | } | 
| 935 |  | } | 
| 936 |  | } | 
| 937 |  |  | 
| 938 |  |  | 
| 939 |  |  | 
| 940 |  |  | 
| 941 |  |  | 
| 942 |  |  | 
| 943 |  |  | 
| 944 | 19 | protected void addDTDDeclaration(Object declaration) { | 
| 945 | 19 | if (internalDTDDeclarations == null) { | 
| 946 | 4 | internalDTDDeclarations = new ArrayList(); | 
| 947 |  | } | 
| 948 |  |  | 
| 949 | 19 | internalDTDDeclarations.add(declaration); | 
| 950 |  | } | 
| 951 |  |  | 
| 952 |  |  | 
| 953 |  |  | 
| 954 |  |  | 
| 955 |  |  | 
| 956 |  |  | 
| 957 |  |  | 
| 958 | 3 | protected void addExternalDTDDeclaration(Object declaration) { | 
| 959 | 3 | if (externalDTDDeclarations == null) { | 
| 960 | 3 | externalDTDDeclarations = new ArrayList(); | 
| 961 |  | } | 
| 962 |  |  | 
| 963 | 3 | externalDTDDeclarations.add(declaration); | 
| 964 |  | } | 
| 965 |  |  | 
| 966 | 5811 | protected ElementStack createElementStack() { | 
| 967 | 5811 | return new ElementStack(); | 
| 968 |  | } | 
| 969 |  | } | 
| 970 |  |  | 
| 971 |  |  | 
| 972 |  |  | 
| 973 |  |  | 
| 974 |  |  | 
| 975 |  |  | 
| 976 |  |  | 
| 977 |  |  | 
| 978 |  |  | 
| 979 |  |  | 
| 980 |  |  | 
| 981 |  |  | 
| 982 |  |  | 
| 983 |  |  | 
| 984 |  |  | 
| 985 |  |  | 
| 986 |  |  | 
| 987 |  |  | 
| 988 |  |  | 
| 989 |  |  | 
| 990 |  |  | 
| 991 |  |  | 
| 992 |  |  | 
| 993 |  |  | 
| 994 |  |  | 
| 995 |  |  | 
| 996 |  |  | 
| 997 |  |  | 
| 998 |  |  | 
| 999 |  |  | 
| 1000 |  |  | 
| 1001 |  |  | 
| 1002 |  |  | 
| 1003 |  |  | 
| 1004 |  |  | 
| 1005 |  |  | 
| 1006 |  |  |