| 1 |  |  | 
| 2 |  |  | 
| 3 |  |  | 
| 4 |  |  | 
| 5 |  |  | 
| 6 |  |  | 
| 7 |  |  | 
| 8 |  | package org.dom4j.io; | 
| 9 |  |  | 
| 10 |  | import java.io.File; | 
| 11 |  | import java.io.FileInputStream; | 
| 12 |  | import java.io.FileNotFoundException; | 
| 13 |  | import java.io.InputStream; | 
| 14 |  | import java.io.Reader; | 
| 15 |  | import java.io.Serializable; | 
| 16 |  | import java.net.URL; | 
| 17 |  |  | 
| 18 |  | import org.dom4j.Document; | 
| 19 |  | import org.dom4j.DocumentException; | 
| 20 |  | import org.dom4j.DocumentFactory; | 
| 21 |  | import org.dom4j.ElementHandler; | 
| 22 |  |  | 
| 23 |  | import org.xml.sax.EntityResolver; | 
| 24 |  | import org.xml.sax.ErrorHandler; | 
| 25 |  | import org.xml.sax.InputSource; | 
| 26 |  | import org.xml.sax.SAXException; | 
| 27 |  | import org.xml.sax.SAXParseException; | 
| 28 |  | import org.xml.sax.XMLFilter; | 
| 29 |  | import org.xml.sax.XMLReader; | 
| 30 |  | import org.xml.sax.helpers.DefaultHandler; | 
| 31 |  | import org.xml.sax.helpers.XMLReaderFactory; | 
| 32 |  |  | 
| 33 |  |  | 
| 34 |  |  | 
| 35 |  |  | 
| 36 |  |  | 
| 37 |  |  | 
| 38 |  |  | 
| 39 |  |  | 
| 40 |  |  | 
| 41 |  |  | 
| 42 |  |  | 
| 43 |  |  | 
| 44 |  |  | 
| 45 |  |  | 
| 46 |  |  | 
| 47 |  |  | 
| 48 |  |  | 
| 49 |  |  | 
| 50 |  |  | 
| 51 |  |  | 
| 52 |  |  | 
| 53 |  |  | 
| 54 |  |  | 
| 55 |  |  | 
| 56 |  |  | 
| 57 |  |  | 
| 58 |  |  | 
| 59 |  |  | 
| 60 |  |  | 
| 61 |  |  | 
| 62 |  |  | 
| 63 |  |  | 
| 64 |  |  | 
| 65 |  |  | 
| 66 |  |  | 
| 67 |  |  | 
| 68 |  |  | 
| 69 |  |  | 
| 70 |  |  | 
| 71 |  |  | 
| 72 |  |  | 
| 73 |  |  | 
| 74 |  |  | 
| 75 |  |  | 
| 76 |  |  | 
| 77 |  |  | 
| 78 |  |  | 
| 79 |  | public class SAXReader { | 
| 80 |  | private static final String SAX_STRING_INTERNING = | 
| 81 |  | "http://xml.org/sax/features/string-interning"; | 
| 82 |  | private static final String SAX_NAMESPACE_PREFIXES = | 
| 83 |  | "http://xml.org/sax/features/namespace-prefixes"; | 
| 84 |  | private static final String SAX_NAMESPACES = | 
| 85 |  | "http://xml.org/sax/features/namespaces"; | 
| 86 |  | private static final String SAX_DECL_HANDLER = | 
| 87 |  | "http://xml.org/sax/properties/declaration-handler"; | 
| 88 |  | private static final String SAX_LEXICAL_HANDLER = | 
| 89 |  | "http://xml.org/sax/properties/lexical-handler"; | 
| 90 |  | private static final String SAX_LEXICALHANDLER = | 
| 91 |  | "http://xml.org/sax/handlers/LexicalHandler"; | 
| 92 |  |  | 
| 93 |  |  | 
| 94 |  | private DocumentFactory factory; | 
| 95 |  |  | 
| 96 |  |  | 
| 97 |  | private XMLReader xmlReader; | 
| 98 |  |  | 
| 99 |  |  | 
| 100 |  | private boolean validating; | 
| 101 |  |  | 
| 102 |  |  | 
| 103 |  | private DispatchHandler dispatchHandler; | 
| 104 |  |  | 
| 105 |  |  | 
| 106 |  | private ErrorHandler errorHandler; | 
| 107 |  |  | 
| 108 |  |  | 
| 109 |  | private EntityResolver entityResolver; | 
| 110 |  |  | 
| 111 |  |  | 
| 112 |  | private boolean stringInternEnabled = true; | 
| 113 |  |  | 
| 114 |  |  | 
| 115 |  | private boolean includeInternalDTDDeclarations = false; | 
| 116 |  |  | 
| 117 |  |  | 
| 118 |  | private boolean includeExternalDTDDeclarations = false; | 
| 119 |  |  | 
| 120 |  |  | 
| 121 |  | private boolean mergeAdjacentText = false; | 
| 122 |  |  | 
| 123 |  |  | 
| 124 |  | private boolean stripWhitespaceText = false; | 
| 125 |  |  | 
| 126 |  |  | 
| 127 |  | private boolean ignoreComments = false; | 
| 128 |  |  | 
| 129 |  |  | 
| 130 |  | private String encoding = null; | 
| 131 |  |  | 
| 132 |  |  | 
| 133 |  |  | 
| 134 |  |  | 
| 135 |  |  | 
| 136 |  | private XMLFilter xmlFilter; | 
| 137 |  |  | 
| 138 | 5741 | public SAXReader() { | 
| 139 |  | } | 
| 140 |  |  | 
| 141 | 1 | public SAXReader(boolean validating) { | 
| 142 | 1 | this.validating = validating; | 
| 143 |  | } | 
| 144 |  |  | 
| 145 | 55 | public SAXReader(DocumentFactory factory) { | 
| 146 | 55 | this.factory = factory; | 
| 147 |  | } | 
| 148 |  |  | 
| 149 | 0 | public SAXReader(DocumentFactory factory, boolean validating) { | 
| 150 | 0 | this.factory = factory; | 
| 151 | 0 | this.validating = validating; | 
| 152 |  | } | 
| 153 |  |  | 
| 154 | 0 | public SAXReader(XMLReader xmlReader) { | 
| 155 | 0 | this.xmlReader = xmlReader; | 
| 156 |  | } | 
| 157 |  |  | 
| 158 | 0 | public SAXReader(XMLReader xmlReader, boolean validating) { | 
| 159 | 0 | this.xmlReader = xmlReader; | 
| 160 | 0 | this.validating = validating; | 
| 161 |  | } | 
| 162 |  |  | 
| 163 | 1 | public SAXReader(String xmlReaderClassName) throws SAXException { | 
| 164 | 1 | if (xmlReaderClassName != null) { | 
| 165 | 1 | this.xmlReader = XMLReaderFactory | 
| 166 |  | .createXMLReader(xmlReaderClassName); | 
| 167 |  | } | 
| 168 |  | } | 
| 169 |  |  | 
| 170 | 0 | public SAXReader(String xmlReaderClassName, boolean validating) | 
| 171 |  | throws SAXException { | 
| 172 | 0 | if (xmlReaderClassName != null) { | 
| 173 | 0 | this.xmlReader = XMLReaderFactory | 
| 174 |  | .createXMLReader(xmlReaderClassName); | 
| 175 |  | } | 
| 176 |  |  | 
| 177 | 0 | this.validating = validating; | 
| 178 |  | } | 
| 179 |  |  | 
| 180 |  |  | 
| 181 |  |  | 
| 182 |  |  | 
| 183 |  |  | 
| 184 |  |  | 
| 185 |  |  | 
| 186 |  |  | 
| 187 |  |  | 
| 188 |  |  | 
| 189 |  |  | 
| 190 |  |  | 
| 191 |  |  | 
| 192 |  |  | 
| 193 |  |  | 
| 194 |  |  | 
| 195 |  |  | 
| 196 |  |  | 
| 197 | 0 | public void setProperty(String name, Object value) throws SAXException { | 
| 198 | 0 | getXMLReader().setProperty(name, value); | 
| 199 |  | } | 
| 200 |  |  | 
| 201 |  |  | 
| 202 |  |  | 
| 203 |  |  | 
| 204 |  |  | 
| 205 |  |  | 
| 206 |  |  | 
| 207 |  |  | 
| 208 |  |  | 
| 209 |  |  | 
| 210 |  |  | 
| 211 |  |  | 
| 212 |  |  | 
| 213 |  |  | 
| 214 |  |  | 
| 215 |  |  | 
| 216 |  |  | 
| 217 | 0 | public void setFeature(String name, boolean value) throws SAXException { | 
| 218 | 0 | getXMLReader().setFeature(name, value); | 
| 219 |  | } | 
| 220 |  |  | 
| 221 |  |  | 
| 222 |  |  | 
| 223 |  |  | 
| 224 |  |  | 
| 225 |  |  | 
| 226 |  |  | 
| 227 |  |  | 
| 228 |  |  | 
| 229 |  |  | 
| 230 |  |  | 
| 231 |  |  | 
| 232 |  |  | 
| 233 |  |  | 
| 234 | 204 | public Document read(File file) throws DocumentException { | 
| 235 | 204 | try { | 
| 236 |  |  | 
| 237 |  |  | 
| 238 |  |  | 
| 239 |  |  | 
| 240 |  |  | 
| 241 |  |  | 
| 242 |  |  | 
| 243 | 204 | InputSource source = new InputSource(new FileInputStream(file)); | 
| 244 | 204 | if (this.encoding != null) { | 
| 245 | 0 | source.setEncoding(this.encoding); | 
| 246 |  | } | 
| 247 | 204 | String path = file.getAbsolutePath(); | 
| 248 |  |  | 
| 249 | 204 | if (path != null) { | 
| 250 |  |  | 
| 251 | 204 | StringBuffer sb = new StringBuffer("file://"); | 
| 252 |  |  | 
| 253 |  |  | 
| 254 | 204 | if (!path.startsWith(File.separator)) { | 
| 255 | 204 | sb.append("/"); | 
| 256 |  | } | 
| 257 |  |  | 
| 258 | 204 | path = path.replace('\\', '/'); | 
| 259 | 204 | sb.append(path); | 
| 260 |  |  | 
| 261 | 204 | source.setSystemId(sb.toString()); | 
| 262 |  | } | 
| 263 |  |  | 
| 264 | 204 | return read(source); | 
| 265 |  | } catch (FileNotFoundException e) { | 
| 266 | 0 | throw new DocumentException(e.getMessage(), e); | 
| 267 |  | } | 
| 268 |  | } | 
| 269 |  |  | 
| 270 |  |  | 
| 271 |  |  | 
| 272 |  |  | 
| 273 |  |  | 
| 274 |  |  | 
| 275 |  |  | 
| 276 |  |  | 
| 277 |  |  | 
| 278 |  |  | 
| 279 |  |  | 
| 280 |  |  | 
| 281 |  |  | 
| 282 |  |  | 
| 283 | 0 | public Document read(URL url) throws DocumentException { | 
| 284 | 0 | String systemID = url.toExternalForm(); | 
| 285 |  |  | 
| 286 | 0 | InputSource source = new InputSource(systemID); | 
| 287 | 0 | if (this.encoding != null) { | 
| 288 | 0 | source.setEncoding(this.encoding); | 
| 289 |  | } | 
| 290 |  |  | 
| 291 | 0 | return read(source); | 
| 292 |  | } | 
| 293 |  |  | 
| 294 |  |  | 
| 295 |  |  | 
| 296 |  |  | 
| 297 |  |  | 
| 298 |  |  | 
| 299 |  |  | 
| 300 |  |  | 
| 301 |  |  | 
| 302 |  |  | 
| 303 |  |  | 
| 304 |  |  | 
| 305 |  |  | 
| 306 |  |  | 
| 307 |  |  | 
| 308 |  |  | 
| 309 |  |  | 
| 310 |  |  | 
| 311 |  |  | 
| 312 |  |  | 
| 313 |  |  | 
| 314 |  |  | 
| 315 | 1 | public Document read(String systemId) throws DocumentException { | 
| 316 | 1 | InputSource source = new InputSource(systemId); | 
| 317 | 1 | if (this.encoding != null) { | 
| 318 | 0 | source.setEncoding(this.encoding); | 
| 319 |  | } | 
| 320 |  |  | 
| 321 | 1 | return read(source); | 
| 322 |  | } | 
| 323 |  |  | 
| 324 |  |  | 
| 325 |  |  | 
| 326 |  |  | 
| 327 |  |  | 
| 328 |  |  | 
| 329 |  |  | 
| 330 |  |  | 
| 331 |  |  | 
| 332 |  |  | 
| 333 |  |  | 
| 334 |  |  | 
| 335 |  |  | 
| 336 |  |  | 
| 337 | 1 | public Document read(InputStream in) throws DocumentException { | 
| 338 | 1 | InputSource source = new InputSource(in); | 
| 339 | 1 | if (this.encoding != null) { | 
| 340 | 0 | source.setEncoding(this.encoding); | 
| 341 |  | } | 
| 342 |  |  | 
| 343 | 1 | return read(source); | 
| 344 |  | } | 
| 345 |  |  | 
| 346 |  |  | 
| 347 |  |  | 
| 348 |  |  | 
| 349 |  |  | 
| 350 |  |  | 
| 351 |  |  | 
| 352 |  |  | 
| 353 |  |  | 
| 354 |  |  | 
| 355 |  |  | 
| 356 |  |  | 
| 357 |  |  | 
| 358 |  |  | 
| 359 | 31 | public Document read(Reader reader) throws DocumentException { | 
| 360 | 31 | InputSource source = new InputSource(reader); | 
| 361 | 31 | if (this.encoding != null) { | 
| 362 | 1 | source.setEncoding(this.encoding); | 
| 363 |  | } | 
| 364 |  |  | 
| 365 | 31 | return read(source); | 
| 366 |  | } | 
| 367 |  |  | 
| 368 |  |  | 
| 369 |  |  | 
| 370 |  |  | 
| 371 |  |  | 
| 372 |  |  | 
| 373 |  |  | 
| 374 |  |  | 
| 375 |  |  | 
| 376 |  |  | 
| 377 |  |  | 
| 378 |  |  | 
| 379 |  |  | 
| 380 |  |  | 
| 381 |  |  | 
| 382 |  |  | 
| 383 | 0 | public Document read(InputStream in, String systemId) | 
| 384 |  | throws DocumentException { | 
| 385 | 0 | InputSource source = new InputSource(in); | 
| 386 | 0 | source.setSystemId(systemId); | 
| 387 | 0 | if (this.encoding != null) { | 
| 388 | 0 | source.setEncoding(this.encoding); | 
| 389 |  | } | 
| 390 |  |  | 
| 391 | 0 | return read(source); | 
| 392 |  | } | 
| 393 |  |  | 
| 394 |  |  | 
| 395 |  |  | 
| 396 |  |  | 
| 397 |  |  | 
| 398 |  |  | 
| 399 |  |  | 
| 400 |  |  | 
| 401 |  |  | 
| 402 |  |  | 
| 403 |  |  | 
| 404 |  |  | 
| 405 |  |  | 
| 406 |  |  | 
| 407 |  |  | 
| 408 |  |  | 
| 409 | 0 | public Document read(Reader reader, String systemId) | 
| 410 |  | throws DocumentException { | 
| 411 | 0 | InputSource source = new InputSource(reader); | 
| 412 | 0 | source.setSystemId(systemId); | 
| 413 | 0 | if (this.encoding != null) { | 
| 414 | 0 | source.setEncoding(this.encoding); | 
| 415 |  | } | 
| 416 |  |  | 
| 417 | 0 | return read(source); | 
| 418 |  | } | 
| 419 |  |  | 
| 420 |  |  | 
| 421 |  |  | 
| 422 |  |  | 
| 423 |  |  | 
| 424 |  |  | 
| 425 |  |  | 
| 426 |  |  | 
| 427 |  |  | 
| 428 |  |  | 
| 429 |  |  | 
| 430 |  |  | 
| 431 |  |  | 
| 432 |  |  | 
| 433 | 5792 | public Document read(InputSource in) throws DocumentException { | 
| 434 | 5792 | try { | 
| 435 | 5792 | XMLReader reader = getXMLReader(); | 
| 436 |  |  | 
| 437 | 5792 | reader = installXMLFilter(reader); | 
| 438 |  |  | 
| 439 | 5792 | EntityResolver thatEntityResolver = this.entityResolver; | 
| 440 |  |  | 
| 441 | 5792 | if (thatEntityResolver == null) { | 
| 442 | 5762 | thatEntityResolver = createDefaultEntityResolver(in | 
| 443 |  | .getSystemId()); | 
| 444 | 5762 | this.entityResolver = thatEntityResolver; | 
| 445 |  | } | 
| 446 |  |  | 
| 447 | 5792 | reader.setEntityResolver(thatEntityResolver); | 
| 448 |  |  | 
| 449 | 5792 | SAXContentHandler contentHandler = createContentHandler(reader); | 
| 450 | 5792 | contentHandler.setEntityResolver(thatEntityResolver); | 
| 451 | 5792 | contentHandler.setInputSource(in); | 
| 452 |  |  | 
| 453 | 5792 | boolean internal = isIncludeInternalDTDDeclarations(); | 
| 454 | 5792 | boolean external = isIncludeExternalDTDDeclarations(); | 
| 455 |  |  | 
| 456 | 5792 | contentHandler.setIncludeInternalDTDDeclarations(internal); | 
| 457 | 5792 | contentHandler.setIncludeExternalDTDDeclarations(external); | 
| 458 | 5792 | contentHandler.setMergeAdjacentText(isMergeAdjacentText()); | 
| 459 | 5792 | contentHandler.setStripWhitespaceText(isStripWhitespaceText()); | 
| 460 | 5792 | contentHandler.setIgnoreComments(isIgnoreComments()); | 
| 461 | 5792 | reader.setContentHandler(contentHandler); | 
| 462 |  |  | 
| 463 | 5792 | configureReader(reader, contentHandler); | 
| 464 |  |  | 
| 465 | 5792 | reader.parse(in); | 
| 466 |  |  | 
| 467 | 5791 | return contentHandler.getDocument(); | 
| 468 |  | } catch (Exception e) { | 
| 469 | 1 | if (e instanceof SAXParseException) { | 
| 470 |  |  | 
| 471 | 0 | SAXParseException parseException = (SAXParseException) e; | 
| 472 | 0 | String systemId = parseException.getSystemId(); | 
| 473 |  |  | 
| 474 | 0 | if (systemId == null) { | 
| 475 | 0 | systemId = ""; | 
| 476 |  | } | 
| 477 |  |  | 
| 478 | 0 | String message = "Error on line " | 
| 479 |  | + parseException.getLineNumber() + " of document " | 
| 480 |  | + systemId + " : " + parseException.getMessage(); | 
| 481 |  |  | 
| 482 | 0 | throw new DocumentException(message, e); | 
| 483 |  | } else { | 
| 484 | 1 | throw new DocumentException(e.getMessage(), e); | 
| 485 |  | } | 
| 486 |  | } | 
| 487 |  | } | 
| 488 |  |  | 
| 489 |  |  | 
| 490 |  |  | 
| 491 |  |  | 
| 492 |  |  | 
| 493 |  |  | 
| 494 |  |  | 
| 495 |  |  | 
| 496 |  |  | 
| 497 |  |  | 
| 498 | 11556 | public boolean isValidating() { | 
| 499 | 11556 | return validating; | 
| 500 |  | } | 
| 501 |  |  | 
| 502 |  |  | 
| 503 |  |  | 
| 504 |  |  | 
| 505 |  |  | 
| 506 |  |  | 
| 507 |  |  | 
| 508 | 0 | public void setValidation(boolean validation) { | 
| 509 | 0 | this.validating = validation; | 
| 510 |  | } | 
| 511 |  |  | 
| 512 |  |  | 
| 513 |  |  | 
| 514 |  |  | 
| 515 |  |  | 
| 516 |  |  | 
| 517 |  |  | 
| 518 | 5792 | public boolean isIncludeInternalDTDDeclarations() { | 
| 519 | 5792 | return includeInternalDTDDeclarations; | 
| 520 |  | } | 
| 521 |  |  | 
| 522 |  |  | 
| 523 |  |  | 
| 524 |  |  | 
| 525 |  |  | 
| 526 |  |  | 
| 527 |  |  | 
| 528 |  |  | 
| 529 |  |  | 
| 530 | 5 | public void setIncludeInternalDTDDeclarations(boolean include) { | 
| 531 | 5 | this.includeInternalDTDDeclarations = include; | 
| 532 |  | } | 
| 533 |  |  | 
| 534 |  |  | 
| 535 |  |  | 
| 536 |  |  | 
| 537 |  |  | 
| 538 |  |  | 
| 539 |  |  | 
| 540 | 5792 | public boolean isIncludeExternalDTDDeclarations() { | 
| 541 | 5792 | return includeExternalDTDDeclarations; | 
| 542 |  | } | 
| 543 |  |  | 
| 544 |  |  | 
| 545 |  |  | 
| 546 |  |  | 
| 547 |  |  | 
| 548 |  |  | 
| 549 |  |  | 
| 550 |  |  | 
| 551 |  |  | 
| 552 | 4 | public void setIncludeExternalDTDDeclarations(boolean include) { | 
| 553 | 4 | this.includeExternalDTDDeclarations = include; | 
| 554 |  | } | 
| 555 |  |  | 
| 556 |  |  | 
| 557 |  |  | 
| 558 |  |  | 
| 559 |  |  | 
| 560 |  |  | 
| 561 |  |  | 
| 562 | 5792 | public boolean isStringInternEnabled() { | 
| 563 | 5792 | return stringInternEnabled; | 
| 564 |  | } | 
| 565 |  |  | 
| 566 |  |  | 
| 567 |  |  | 
| 568 |  |  | 
| 569 |  |  | 
| 570 |  |  | 
| 571 |  |  | 
| 572 |  |  | 
| 573 | 0 | public void setStringInternEnabled(boolean stringInternEnabled) { | 
| 574 | 0 | this.stringInternEnabled = stringInternEnabled; | 
| 575 |  | } | 
| 576 |  |  | 
| 577 |  |  | 
| 578 |  |  | 
| 579 |  |  | 
| 580 |  |  | 
| 581 |  |  | 
| 582 | 5792 | public boolean isMergeAdjacentText() { | 
| 583 | 5792 | return mergeAdjacentText; | 
| 584 |  | } | 
| 585 |  |  | 
| 586 |  |  | 
| 587 |  |  | 
| 588 |  |  | 
| 589 |  |  | 
| 590 |  |  | 
| 591 |  |  | 
| 592 |  |  | 
| 593 | 7 | public void setMergeAdjacentText(boolean mergeAdjacentText) { | 
| 594 | 7 | this.mergeAdjacentText = mergeAdjacentText; | 
| 595 |  | } | 
| 596 |  |  | 
| 597 |  |  | 
| 598 |  |  | 
| 599 |  |  | 
| 600 |  |  | 
| 601 |  |  | 
| 602 |  |  | 
| 603 | 5792 | public boolean isStripWhitespaceText() { | 
| 604 | 5792 | return stripWhitespaceText; | 
| 605 |  | } | 
| 606 |  |  | 
| 607 |  |  | 
| 608 |  |  | 
| 609 |  |  | 
| 610 |  |  | 
| 611 |  |  | 
| 612 |  |  | 
| 613 |  |  | 
| 614 | 0 | public void setStripWhitespaceText(boolean stripWhitespaceText) { | 
| 615 | 0 | this.stripWhitespaceText = stripWhitespaceText; | 
| 616 |  | } | 
| 617 |  |  | 
| 618 |  |  | 
| 619 |  |  | 
| 620 |  |  | 
| 621 |  |  | 
| 622 |  |  | 
| 623 | 5792 | public boolean isIgnoreComments() { | 
| 624 | 5792 | return ignoreComments; | 
| 625 |  | } | 
| 626 |  |  | 
| 627 |  |  | 
| 628 |  |  | 
| 629 |  |  | 
| 630 |  |  | 
| 631 |  |  | 
| 632 |  |  | 
| 633 | 0 | public void setIgnoreComments(boolean ignoreComments) { | 
| 634 | 0 | this.ignoreComments = ignoreComments; | 
| 635 |  | } | 
| 636 |  |  | 
| 637 |  |  | 
| 638 |  |  | 
| 639 |  |  | 
| 640 |  |  | 
| 641 |  |  | 
| 642 |  |  | 
| 643 | 5792 | public DocumentFactory getDocumentFactory() { | 
| 644 | 5792 | if (factory == null) { | 
| 645 | 5702 | factory = DocumentFactory.getInstance(); | 
| 646 |  | } | 
| 647 |  |  | 
| 648 | 5792 | return factory; | 
| 649 |  | } | 
| 650 |  |  | 
| 651 |  |  | 
| 652 |  |  | 
| 653 |  |  | 
| 654 |  |  | 
| 655 |  |  | 
| 656 |  |  | 
| 657 |  |  | 
| 658 |  |  | 
| 659 |  |  | 
| 660 |  |  | 
| 661 |  |  | 
| 662 | 8 | public void setDocumentFactory(DocumentFactory documentFactory) { | 
| 663 | 8 | this.factory = documentFactory; | 
| 664 |  | } | 
| 665 |  |  | 
| 666 |  |  | 
| 667 |  |  | 
| 668 |  |  | 
| 669 |  |  | 
| 670 |  |  | 
| 671 | 0 | public ErrorHandler getErrorHandler() { | 
| 672 | 0 | return errorHandler; | 
| 673 |  | } | 
| 674 |  |  | 
| 675 |  |  | 
| 676 |  |  | 
| 677 |  |  | 
| 678 |  |  | 
| 679 |  |  | 
| 680 |  |  | 
| 681 |  |  | 
| 682 | 0 | public void setErrorHandler(ErrorHandler errorHandler) { | 
| 683 | 0 | this.errorHandler = errorHandler; | 
| 684 |  | } | 
| 685 |  |  | 
| 686 |  |  | 
| 687 |  |  | 
| 688 |  |  | 
| 689 |  |  | 
| 690 |  |  | 
| 691 | 0 | public EntityResolver getEntityResolver() { | 
| 692 | 0 | return entityResolver; | 
| 693 |  | } | 
| 694 |  |  | 
| 695 |  |  | 
| 696 |  |  | 
| 697 |  |  | 
| 698 |  |  | 
| 699 |  |  | 
| 700 |  |  | 
| 701 | 3 | public void setEntityResolver(EntityResolver entityResolver) { | 
| 702 | 3 | this.entityResolver = entityResolver; | 
| 703 |  | } | 
| 704 |  |  | 
| 705 |  |  | 
| 706 |  |  | 
| 707 |  |  | 
| 708 |  |  | 
| 709 |  |  | 
| 710 |  |  | 
| 711 |  |  | 
| 712 |  |  | 
| 713 | 5792 | public XMLReader getXMLReader() throws SAXException { | 
| 714 | 5792 | if (xmlReader == null) { | 
| 715 | 5764 | xmlReader = createXMLReader(); | 
| 716 |  | } | 
| 717 |  |  | 
| 718 | 5792 | return xmlReader; | 
| 719 |  | } | 
| 720 |  |  | 
| 721 |  |  | 
| 722 |  |  | 
| 723 |  |  | 
| 724 |  |  | 
| 725 |  |  | 
| 726 |  |  | 
| 727 | 0 | public void setXMLReader(XMLReader reader) { | 
| 728 | 0 | this.xmlReader = reader; | 
| 729 |  | } | 
| 730 |  |  | 
| 731 |  |  | 
| 732 |  |  | 
| 733 |  |  | 
| 734 |  |  | 
| 735 |  |  | 
| 736 |  |  | 
| 737 |  |  | 
| 738 | 0 | public String getEncoding() { | 
| 739 | 0 | return encoding; | 
| 740 |  | } | 
| 741 |  |  | 
| 742 |  |  | 
| 743 |  |  | 
| 744 |  |  | 
| 745 |  |  | 
| 746 |  |  | 
| 747 |  |  | 
| 748 | 1 | public void setEncoding(String encoding) { | 
| 749 | 1 | this.encoding = encoding; | 
| 750 |  | } | 
| 751 |  |  | 
| 752 |  |  | 
| 753 |  |  | 
| 754 |  |  | 
| 755 |  |  | 
| 756 |  |  | 
| 757 |  |  | 
| 758 |  |  | 
| 759 |  |  | 
| 760 |  |  | 
| 761 |  |  | 
| 762 |  |  | 
| 763 | 0 | public void setXMLReaderClassName(String xmlReaderClassName) | 
| 764 |  | throws SAXException { | 
| 765 | 0 | setXMLReader(XMLReaderFactory.createXMLReader(xmlReaderClassName)); | 
| 766 |  | } | 
| 767 |  |  | 
| 768 |  |  | 
| 769 |  |  | 
| 770 |  |  | 
| 771 |  |  | 
| 772 |  |  | 
| 773 |  |  | 
| 774 |  |  | 
| 775 |  |  | 
| 776 |  |  | 
| 777 |  |  | 
| 778 | 21 | public void addHandler(String path, ElementHandler handler) { | 
| 779 | 21 | getDispatchHandler().addHandler(path, handler); | 
| 780 |  | } | 
| 781 |  |  | 
| 782 |  |  | 
| 783 |  |  | 
| 784 |  |  | 
| 785 |  |  | 
| 786 |  |  | 
| 787 |  |  | 
| 788 |  |  | 
| 789 | 0 | public void removeHandler(String path) { | 
| 790 | 0 | getDispatchHandler().removeHandler(path); | 
| 791 |  | } | 
| 792 |  |  | 
| 793 |  |  | 
| 794 |  |  | 
| 795 |  |  | 
| 796 |  |  | 
| 797 |  |  | 
| 798 |  |  | 
| 799 |  |  | 
| 800 |  |  | 
| 801 |  |  | 
| 802 | 0 | public void setDefaultHandler(ElementHandler handler) { | 
| 803 | 0 | getDispatchHandler().setDefaultHandler(handler); | 
| 804 |  | } | 
| 805 |  |  | 
| 806 |  |  | 
| 807 |  |  | 
| 808 |  |  | 
| 809 |  |  | 
| 810 |  |  | 
| 811 | 0 | public void resetHandlers() { | 
| 812 | 0 | getDispatchHandler().resetHandlers(); | 
| 813 |  | } | 
| 814 |  |  | 
| 815 |  |  | 
| 816 |  |  | 
| 817 |  |  | 
| 818 |  |  | 
| 819 |  |  | 
| 820 | 5792 | public XMLFilter getXMLFilter() { | 
| 821 | 5792 | return xmlFilter; | 
| 822 |  | } | 
| 823 |  |  | 
| 824 |  |  | 
| 825 |  |  | 
| 826 |  |  | 
| 827 |  |  | 
| 828 |  |  | 
| 829 |  |  | 
| 830 | 0 | public void setXMLFilter(XMLFilter filter) { | 
| 831 | 0 | this.xmlFilter = filter; | 
| 832 |  | } | 
| 833 |  |  | 
| 834 |  |  | 
| 835 |  |  | 
| 836 |  |  | 
| 837 |  |  | 
| 838 |  |  | 
| 839 |  |  | 
| 840 |  |  | 
| 841 |  |  | 
| 842 |  |  | 
| 843 |  |  | 
| 844 |  |  | 
| 845 |  |  | 
| 846 |  |  | 
| 847 | 5792 | protected XMLReader installXMLFilter(XMLReader reader) { | 
| 848 | 5792 | XMLFilter filter = getXMLFilter(); | 
| 849 |  |  | 
| 850 | 5792 | if (filter != null) { | 
| 851 |  |  | 
| 852 | 0 | XMLFilter root = filter; | 
| 853 |  |  | 
| 854 | 0 | while (true) { | 
| 855 | 0 | XMLReader parent = root.getParent(); | 
| 856 |  |  | 
| 857 | 0 | if (parent instanceof XMLFilter) { | 
| 858 | 0 | root = (XMLFilter) parent; | 
| 859 |  | } else { | 
| 860 | 0 | break; | 
| 861 |  | } | 
| 862 |  | } | 
| 863 |  |  | 
| 864 | 0 | root.setParent(reader); | 
| 865 |  |  | 
| 866 | 0 | return filter; | 
| 867 |  | } | 
| 868 |  |  | 
| 869 | 5792 | return reader; | 
| 870 |  | } | 
| 871 |  |  | 
| 872 | 21 | protected DispatchHandler getDispatchHandler() { | 
| 873 | 21 | if (dispatchHandler == null) { | 
| 874 | 21 | dispatchHandler = new DispatchHandler(); | 
| 875 |  | } | 
| 876 |  |  | 
| 877 | 21 | return dispatchHandler; | 
| 878 |  | } | 
| 879 |  |  | 
| 880 | 0 | protected void setDispatchHandler(DispatchHandler dispatchHandler) { | 
| 881 | 0 | this.dispatchHandler = dispatchHandler; | 
| 882 |  | } | 
| 883 |  |  | 
| 884 |  |  | 
| 885 |  |  | 
| 886 |  |  | 
| 887 |  |  | 
| 888 |  |  | 
| 889 |  |  | 
| 890 |  |  | 
| 891 |  |  | 
| 892 |  |  | 
| 893 | 5764 | protected XMLReader createXMLReader() throws SAXException { | 
| 894 | 5764 | return SAXHelper.createXMLReader(isValidating()); | 
| 895 |  | } | 
| 896 |  |  | 
| 897 |  |  | 
| 898 |  |  | 
| 899 |  |  | 
| 900 |  |  | 
| 901 |  |  | 
| 902 |  |  | 
| 903 |  |  | 
| 904 |  |  | 
| 905 |  |  | 
| 906 |  |  | 
| 907 |  |  | 
| 908 | 5792 | protected void configureReader(XMLReader reader, DefaultHandler handler) | 
| 909 |  | throws DocumentException { | 
| 910 |  |  | 
| 911 | 5792 | SAXHelper.setParserProperty(reader, SAX_LEXICALHANDLER, handler); | 
| 912 |  |  | 
| 913 |  |  | 
| 914 | 5792 | SAXHelper.setParserProperty(reader, SAX_LEXICAL_HANDLER, handler); | 
| 915 |  |  | 
| 916 |  |  | 
| 917 | 5792 | if (includeInternalDTDDeclarations || includeExternalDTDDeclarations) { | 
| 918 | 6 | SAXHelper.setParserProperty(reader, SAX_DECL_HANDLER, handler); | 
| 919 |  | } | 
| 920 |  |  | 
| 921 |  |  | 
| 922 | 5792 | SAXHelper.setParserFeature(reader, SAX_NAMESPACES, true); | 
| 923 |  |  | 
| 924 | 5792 | SAXHelper.setParserFeature(reader, SAX_NAMESPACE_PREFIXES, false); | 
| 925 |  |  | 
| 926 |  |  | 
| 927 | 5792 | SAXHelper.setParserFeature(reader, SAX_STRING_INTERNING, | 
| 928 |  | isStringInternEnabled()); | 
| 929 |  |  | 
| 930 |  |  | 
| 931 |  |  | 
| 932 |  |  | 
| 933 |  |  | 
| 934 |  |  | 
| 935 |  |  | 
| 936 |  |  | 
| 937 |  |  | 
| 938 |  |  | 
| 939 | 5792 | SAXHelper.setParserFeature(reader, | 
| 940 |  | "http://xml.org/sax/features/use-locator2", true); | 
| 941 |  |  | 
| 942 | 5792 | try { | 
| 943 |  |  | 
| 944 | 5792 | reader.setFeature("http://xml.org/sax/features/validation", | 
| 945 |  | isValidating()); | 
| 946 |  |  | 
| 947 | 5792 | if (errorHandler != null) { | 
| 948 | 0 | reader.setErrorHandler(errorHandler); | 
| 949 |  | } else { | 
| 950 | 5792 | reader.setErrorHandler(handler); | 
| 951 |  | } | 
| 952 |  | } catch (Exception e) { | 
| 953 | 0 | if (isValidating()) { | 
| 954 | 0 | throw new DocumentException("Validation not supported for" | 
| 955 |  | + " XMLReader: " + reader, e); | 
| 956 |  | } | 
| 957 |  | } | 
| 958 |  | } | 
| 959 |  |  | 
| 960 |  |  | 
| 961 |  |  | 
| 962 |  |  | 
| 963 |  |  | 
| 964 |  |  | 
| 965 |  |  | 
| 966 |  |  | 
| 967 |  |  | 
| 968 | 5792 | protected SAXContentHandler createContentHandler(XMLReader reader) { | 
| 969 | 5792 | return new SAXContentHandler(getDocumentFactory(), dispatchHandler); | 
| 970 |  | } | 
| 971 |  |  | 
| 972 | 5762 | protected EntityResolver createDefaultEntityResolver(String systemId) { | 
| 973 | 5762 | String prefix = null; | 
| 974 |  |  | 
| 975 | 5762 | if ((systemId != null) && (systemId.length() > 0)) { | 
| 976 | 179 | int idx = systemId.lastIndexOf('/'); | 
| 977 |  |  | 
| 978 | 179 | if (idx > 0) { | 
| 979 | 178 | prefix = systemId.substring(0, idx + 1); | 
| 980 |  | } | 
| 981 |  | } | 
| 982 |  |  | 
| 983 | 5762 | return new SAXEntityResolver(prefix); | 
| 984 |  | } | 
| 985 |  |  | 
| 986 |  | protected static class SAXEntityResolver implements EntityResolver, | 
| 987 |  | Serializable { | 
| 988 |  | protected String uriPrefix; | 
| 989 |  |  | 
| 990 | 5762 | public SAXEntityResolver(String uriPrefix) { | 
| 991 | 5762 | this.uriPrefix = uriPrefix; | 
| 992 |  | } | 
| 993 |  |  | 
| 994 | 5 | public InputSource resolveEntity(String publicId, String systemId) { | 
| 995 |  |  | 
| 996 | 5 | if ((systemId != null) && (systemId.length() > 0)) { | 
| 997 | 5 | if ((uriPrefix != null) && (systemId.indexOf(':') <= 0)) { | 
| 998 | 2 | systemId = uriPrefix + systemId; | 
| 999 |  | } | 
| 1000 |  | } | 
| 1001 |  |  | 
| 1002 | 5 | return new InputSource(systemId); | 
| 1003 |  | } | 
| 1004 |  | } | 
| 1005 |  | } | 
| 1006 |  |  | 
| 1007 |  |  | 
| 1008 |  |  | 
| 1009 |  |  | 
| 1010 |  |  | 
| 1011 |  |  | 
| 1012 |  |  | 
| 1013 |  |  | 
| 1014 |  |  | 
| 1015 |  |  | 
| 1016 |  |  | 
| 1017 |  |  | 
| 1018 |  |  | 
| 1019 |  |  | 
| 1020 |  |  | 
| 1021 |  |  | 
| 1022 |  |  | 
| 1023 |  |  | 
| 1024 |  |  | 
| 1025 |  |  | 
| 1026 |  |  | 
| 1027 |  |  | 
| 1028 |  |  | 
| 1029 |  |  | 
| 1030 |  |  | 
| 1031 |  |  | 
| 1032 |  |  | 
| 1033 |  |  | 
| 1034 |  |  | 
| 1035 |  |  | 
| 1036 |  |  | 
| 1037 |  |  | 
| 1038 |  |  | 
| 1039 |  |  | 
| 1040 |  |  | 
| 1041 |  |  | 
| 1042 |  |  |