| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.event; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.expr.parser.ExplicitLocation; |
| 12 |
import net.sf.saxon.expr.parser.Location; |
| 13 |
import net.sf.saxon.lib.Feature; |
| 14 |
import net.sf.saxon.om.*; |
| 15 |
import net.sf.saxon.trans.QuitParsingException; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
import net.sf.saxon.tree.tiny.CharSlice; |
| 18 |
import net.sf.saxon.tree.tiny.CompressedWhitespace; |
| 19 |
import net.sf.saxon.type.*; |
| 20 |
import net.sf.saxon.value.Whitespace; |
| 21 |
import org.xml.sax.*; |
| 22 |
import org.xml.sax.ext.Attributes2; |
| 23 |
import org.xml.sax.ext.LexicalHandler; |
| 24 |
|
| 25 |
import javax.xml.transform.Result; |
| 26 |
import java.net.URI; |
| 27 |
import java.net.URISyntaxException; |
| 28 |
import java.util.Arrays; |
| 29 |
import java.util.HashMap; |
| 30 |
import java.util.Stack; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public class ReceivingContentHandler |
| 50 |
implements ContentHandler, LexicalHandler, DTDHandler |
| 51 |
{ |
| 52 |
private PipelineConfiguration pipe; |
| 53 |
private Receiver receiver; |
| 54 |
private boolean inDTD = false; |
| 55 |
private LocalLocator localLocator = new LocalLocator(ExplicitLocation.UNKNOWN_LOCATION); |
| 56 |
private boolean lineNumbering; |
| 57 |
private Location lastTextNodeLocator; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
private char[] buffer = new char[512]; |
| 62 |
private int charsUsed = 0; |
| 63 |
private CharSlice slice = new CharSlice(buffer, 0, 0); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
private NamespaceBinding[] namespaces = new NamespaceBinding[20]; |
| 68 |
private int namespacesUsed = 0; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
private boolean ignoreIgnorable = false; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
private boolean retainDTDAttributeTypes = false; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
private boolean allowDisableOutputEscaping = false; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
private boolean escapingDisabled = false; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
private boolean afterStartTag = true; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
private HashMap<String, HashMap<String, NodeName>> nameCache = new HashMap<>(10); |
| 102 |
private HashMap<String, NodeName> noNamespaceNameCache = new HashMap<>(10); |
| 103 |
|
| 104 |
|
| 105 |
private int defaultedAttributesAction = 0; |
| 106 |
|
| 107 |
|
| 108 |
private Stack<Integer> elementDepthWithinEntity; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public ReceivingContentHandler() { |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public void reset() { |
| 124 |
pipe = null; |
| 125 |
receiver = null; |
| 126 |
ignoreIgnorable = false; |
| 127 |
retainDTDAttributeTypes = false; |
| 128 |
charsUsed = 0; |
| 129 |
slice.setLength(0); |
| 130 |
namespacesUsed = 0; |
| 131 |
localLocator = new LocalLocator(ExplicitLocation.UNKNOWN_LOCATION); |
| 132 |
allowDisableOutputEscaping = false; |
| 133 |
escapingDisabled = false; |
| 134 |
lineNumbering = false; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public void setReceiver(Receiver receiver) { |
| 146 |
this.receiver = receiver; |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public Receiver getReceiver() { |
| 157 |
return receiver; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public void setPipelineConfiguration(PipelineConfiguration pipe) { |
| 168 |
this.pipe = pipe; |
| 169 |
Configuration config = pipe.getConfiguration(); |
| 170 |
ignoreIgnorable = pipe.getParseOptions().getSpaceStrippingRule() != NoElementsSpaceStrippingRule.getInstance(); |
| 171 |
retainDTDAttributeTypes = config.getBooleanProperty(Feature.RETAIN_DTD_ATTRIBUTE_TYPES); |
| 172 |
if (!pipe.getParseOptions().isExpandAttributeDefaults()) { |
| 173 |
defaultedAttributesAction = -1; |
| 174 |
} else if (config.getBooleanProperty(Feature.MARK_DEFAULTED_ATTRIBUTES)) { |
| 175 |
defaultedAttributesAction = +1; |
| 176 |
} |
| 177 |
allowDisableOutputEscaping = config.getConfigurationProperty(Feature.USE_PI_DISABLE_OUTPUT_ESCAPING); |
| 178 |
lineNumbering = pipe.getParseOptions().isLineNumbering(); |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public PipelineConfiguration getPipelineConfiguration() { |
| 189 |
return pipe; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
public Configuration getConfiguration() { |
| 199 |
return pipe.getConfiguration(); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
public void setIgnoreIgnorableWhitespace(boolean ignore) { |
| 213 |
ignoreIgnorable = ignore; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public boolean isIgnoringIgnorableWhitespace() { |
| 225 |
return ignoreIgnorable; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public void startDocument() throws SAXException { |
| 233 |
|
| 234 |
try { |
| 235 |
charsUsed = 0; |
| 236 |
namespacesUsed = 0; |
| 237 |
receiver.setPipelineConfiguration(pipe); |
| 238 |
String systemId = localLocator.getSystemId(); |
| 239 |
if (systemId != null) { |
| 240 |
receiver.setSystemId(localLocator.getSystemId()); |
| 241 |
} |
| 242 |
receiver.open(); |
| 243 |
receiver.startDocument(0); |
| 244 |
} catch (QuitParsingException quit) { |
| 245 |
getPipelineConfiguration().getErrorListener().warning(quit); |
| 246 |
throw new SAXException(quit); |
| 247 |
} catch (XPathException err) { |
| 248 |
throw new SAXException(err); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
public void endDocument() throws SAXException { |
| 257 |
|
| 258 |
try { |
| 259 |
flush(true); |
| 260 |
receiver.endDocument(); |
| 261 |
receiver.close(); |
| 262 |
} catch (ValidationException err) { |
| 263 |
err.setLocator(localLocator); |
| 264 |
throw new SAXException(err); |
| 265 |
} catch (QuitParsingException err) { |
| 266 |
|
| 267 |
} catch (XPathException err) { |
| 268 |
err.maybeSetLocation(localLocator); |
| 269 |
throw new SAXException(err); |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public void setDocumentLocator(Locator locator) { |
| 279 |
localLocator = new LocalLocator(locator); |
| 280 |
if (!lineNumbering) { |
| 281 |
lastTextNodeLocator = localLocator; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
public void startPrefixMapping(String prefix, String uri) { |
| 290 |
|
| 291 |
if (prefix.equals("xmlns")) { |
| 292 |
|
| 293 |
|
| 294 |
return; |
| 295 |
} |
| 296 |
if (namespacesUsed >= namespaces.length) { |
| 297 |
namespaces = Arrays.copyOf(namespaces, namespacesUsed * 2); |
| 298 |
} |
| 299 |
namespaces[namespacesUsed++] = new NamespaceBinding(prefix, uri); |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
public void endPrefixMapping(String prefix) { |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
public void startElement(String uri, String localname, String rawname, Attributes atts) |
| 356 |
throws SAXException { |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
try { |
| 364 |
flush(true); |
| 365 |
|
| 366 |
NodeName elementName = getNodeName(uri, localname, rawname); |
| 367 |
receiver.startElement(elementName, Untyped.getInstance(), localLocator, ReceiverOptions.NAMESPACE_OK); |
| 368 |
|
| 369 |
localLocator.levelInEntity++; |
| 370 |
for (int n = 0; n < namespacesUsed; n++) { |
| 371 |
receiver.namespace(namespaces[n], 0); |
| 372 |
} |
| 373 |
|
| 374 |
for (int a = 0; a < atts.getLength(); a++) { |
| 375 |
int properties = ReceiverOptions.NAMESPACE_OK; |
| 376 |
String qname = atts.getQName(a); |
| 377 |
if (qname.startsWith("xmlns") && (qname.length()==5 || qname.charAt(5)==':')) { |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
continue; |
| 384 |
} |
| 385 |
|
| 386 |
if (defaultedAttributesAction != 0 |
| 387 |
&& atts instanceof Attributes2 |
| 388 |
&& !((Attributes2) atts).isSpecified(qname)) { |
| 389 |
if (defaultedAttributesAction == -1) { |
| 390 |
|
| 391 |
continue; |
| 392 |
} else { |
| 393 |
|
| 394 |
properties |= ReceiverOptions.DEFAULTED_ATTRIBUTE; |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
NodeName attCode = getNodeName(atts.getURI(a), atts.getLocalName(a), atts.getQName(a)); |
| 399 |
String type = atts.getType(a); |
| 400 |
SimpleType typeCode = BuiltInAtomicType.UNTYPED_ATOMIC; |
| 401 |
if (retainDTDAttributeTypes) { |
| 402 |
switch (type) { |
| 403 |
case "CDATA": |
| 404 |
|
| 405 |
break; |
| 406 |
case "ID": |
| 407 |
typeCode = BuiltInAtomicType.ID; |
| 408 |
break; |
| 409 |
case "IDREF": |
| 410 |
typeCode = BuiltInAtomicType.IDREF; |
| 411 |
break; |
| 412 |
case "IDREFS": |
| 413 |
typeCode = BuiltInListType.IDREFS; |
| 414 |
break; |
| 415 |
case "NMTOKEN": |
| 416 |
typeCode = BuiltInAtomicType.NMTOKEN; |
| 417 |
break; |
| 418 |
case "NMTOKENS": |
| 419 |
typeCode = BuiltInListType.NMTOKENS; |
| 420 |
break; |
| 421 |
case "ENTITY": |
| 422 |
typeCode = BuiltInAtomicType.ENTITY; |
| 423 |
break; |
| 424 |
case "ENTITIES": |
| 425 |
typeCode = BuiltInListType.ENTITIES; |
| 426 |
break; |
| 427 |
} |
| 428 |
} else { |
| 429 |
switch (type) { |
| 430 |
case "ID": |
| 431 |
properties |= ReceiverOptions.IS_ID; |
| 432 |
break; |
| 433 |
case "IDREF": |
| 434 |
properties |= ReceiverOptions.IS_IDREF; |
| 435 |
break; |
| 436 |
case "IDREFS": |
| 437 |
properties |= ReceiverOptions.IS_IDREF; |
| 438 |
break; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
receiver.attribute(attCode, typeCode, atts.getValue(a), localLocator, properties); |
| 443 |
} |
| 444 |
|
| 445 |
afterStartTag = true; |
| 446 |
receiver.startContent(); |
| 447 |
|
| 448 |
namespacesUsed = 0; |
| 449 |
} catch (XPathException err) { |
| 450 |
err.maybeSetLocation(localLocator); |
| 451 |
throw new SAXException(err); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
private NodeName getNodeName(String uri, String localname, String rawname) throws SAXException { |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
if (rawname.isEmpty()) { |
| 472 |
throw new SAXException("Saxon requires an XML parser that reports the QName of each element"); |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
if (localname.isEmpty()) { |
| 477 |
throw new SAXException("Parser configuration problem: namespace reporting is not enabled"); |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
HashMap<String, NodeName> map2 = uri.isEmpty() ? noNamespaceNameCache : nameCache.get(uri); |
| 486 |
if (map2 == null) { |
| 487 |
map2 = new HashMap<>(50); |
| 488 |
nameCache.put(uri, map2); |
| 489 |
if (uri.isEmpty()) { |
| 490 |
noNamespaceNameCache = map2; |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
NodeName n = map2.get(rawname); |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
if (n == null) { |
| 501 |
if (uri.isEmpty()) { |
| 502 |
NoNamespaceName qn = new NoNamespaceName(localname); |
| 503 |
map2.put(rawname, qn); |
| 504 |
return qn; |
| 505 |
} else { |
| 506 |
String prefix = NameChecker.getPrefix(rawname); |
| 507 |
FingerprintedQName qn = new FingerprintedQName(prefix, uri, localname); |
| 508 |
map2.put(rawname, qn); |
| 509 |
return qn; |
| 510 |
} |
| 511 |
} else { |
| 512 |
return n; |
| 513 |
} |
| 514 |
|
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
public void endElement(String uri, String localname, String rawname) throws SAXException { |
| 523 |
|
| 524 |
try { |
| 525 |
|
| 526 |
flush(!afterStartTag); |
| 527 |
localLocator.levelInEntity--; |
| 528 |
receiver.endElement(); |
| 529 |
} catch (ValidationException err) { |
| 530 |
err.maybeSetLocation(localLocator); |
| 531 |
if (!err.hasBeenReported()) { |
| 532 |
pipe.getErrorListener().fatalError(err); |
| 533 |
} |
| 534 |
err.setHasBeenReported(true); |
| 535 |
throw new SAXException(err); |
| 536 |
} catch (XPathException err) { |
| 537 |
err.maybeSetLocation(localLocator); |
| 538 |
throw new SAXException(err); |
| 539 |
} |
| 540 |
afterStartTag = false; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
public void characters(char ch[], int start, int length) { |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
while (charsUsed + length > buffer.length) { |
| 553 |
buffer = Arrays.copyOf(buffer, buffer.length*2); |
| 554 |
slice = new CharSlice(buffer, 0, 0); |
| 555 |
} |
| 556 |
System.arraycopy(ch, start, buffer, charsUsed, length); |
| 557 |
charsUsed += length; |
| 558 |
if (lineNumbering) { |
| 559 |
lastTextNodeLocator = localLocator.saveLocation(); |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
public void ignorableWhitespace(char ch[], int start, int length) { |
| 569 |
if (!ignoreIgnorable) { |
| 570 |
characters(ch, start, length); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
public void processingInstruction(String name, String remainder) throws SAXException { |
| 579 |
try { |
| 580 |
flush(true); |
| 581 |
if (!inDTD) { |
| 582 |
if (name == null) { |
| 583 |
|
| 584 |
comment(remainder.toCharArray(), 0, remainder.length()); |
| 585 |
} else { |
| 586 |
|
| 587 |
if (!NameChecker.isValidNCName(name)) { |
| 588 |
throw new SAXException("Invalid processing instruction name (" + name + ')'); |
| 589 |
} |
| 590 |
if (allowDisableOutputEscaping) { |
| 591 |
if (name.equals(Result.PI_DISABLE_OUTPUT_ESCAPING)) { |
| 592 |
|
| 593 |
escapingDisabled = true; |
| 594 |
return; |
| 595 |
} else if (name.equals(Result.PI_ENABLE_OUTPUT_ESCAPING)) { |
| 596 |
|
| 597 |
escapingDisabled = false; |
| 598 |
return; |
| 599 |
} |
| 600 |
} |
| 601 |
CharSequence data; |
| 602 |
if (remainder == null) { |
| 603 |
|
| 604 |
data = ""; |
| 605 |
} else { |
| 606 |
|
| 607 |
data = Whitespace.removeLeadingWhitespace(remainder); |
| 608 |
} |
| 609 |
receiver.processingInstruction(name, data, localLocator, 0); |
| 610 |
} |
| 611 |
} |
| 612 |
} catch (XPathException err) { |
| 613 |
throw new SAXException(err); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
public void comment(char ch[], int start, int length) throws SAXException { |
| 623 |
try { |
| 624 |
flush(true); |
| 625 |
if (!inDTD) { |
| 626 |
receiver.comment(new CharSlice(ch, start, length), localLocator, 0); |
| 627 |
} |
| 628 |
} catch (XPathException err) { |
| 629 |
throw new SAXException(err); |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
private void flush(boolean compress) throws XPathException { |
| 643 |
if (charsUsed > 0) { |
| 644 |
slice.setLength(charsUsed); |
| 645 |
CharSequence cs = compress ? CompressedWhitespace.compress(slice) : slice; |
| 646 |
receiver.characters(cs, lastTextNodeLocator, |
| 647 |
escapingDisabled ? ReceiverOptions.DISABLE_ESCAPING : ReceiverOptions.WHOLE_TEXT_NODE); |
| 648 |
charsUsed = 0; |
| 649 |
escapingDisabled = false; |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
public void skippedEntity(String name) { |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
public void startDTD(String name, String publicId, String systemId) { |
| 669 |
inDTD = true; |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
public void endDTD() { |
| 678 |
inDTD = false; |
| 679 |
} |
| 680 |
|
| 681 |
public void startEntity(String name) { |
| 682 |
if (elementDepthWithinEntity == null) { |
| 683 |
elementDepthWithinEntity = new Stack<>(); |
| 684 |
} |
| 685 |
elementDepthWithinEntity.push(localLocator.levelInEntity); |
| 686 |
localLocator.levelInEntity = 0; |
| 687 |
} |
| 688 |
|
| 689 |
public void endEntity(String name) { |
| 690 |
localLocator.levelInEntity = elementDepthWithinEntity.pop(); |
| 691 |
} |
| 692 |
|
| 693 |
public void startCDATA() { |
| 694 |
} |
| 695 |
|
| 696 |
public void endCDATA() { |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
public void notationDecl(String name, |
| 705 |
String publicId, |
| 706 |
String systemId) { |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
public void unparsedEntityDecl(String name, |
| 711 |
String publicId, |
| 712 |
String systemId, |
| 713 |
String notationName) throws SAXException { |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
String uri = systemId; |
| 718 |
if (localLocator != null) { |
| 719 |
try { |
| 720 |
URI suppliedURI = new URI(systemId); |
| 721 |
if (!suppliedURI.isAbsolute()) { |
| 722 |
String baseURI = localLocator.getSystemId(); |
| 723 |
if (baseURI != null) { |
| 724 |
URI absoluteURI = new URI(baseURI).resolve(systemId); |
| 725 |
uri = absoluteURI.toString(); |
| 726 |
} |
| 727 |
} |
| 728 |
} catch (URISyntaxException err) { |
| 729 |
|
| 730 |
} |
| 731 |
} |
| 732 |
try { |
| 733 |
receiver.setUnparsedEntity(name, uri, publicId); |
| 734 |
} catch (XPathException err) { |
| 735 |
throw new SAXException(err); |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
public static class LocalLocator implements Location { |
| 747 |
|
| 748 |
private Locator saxLocator; |
| 749 |
public int levelInEntity; |
| 750 |
|
| 751 |
public LocalLocator(Locator saxLocator) { |
| 752 |
this.saxLocator = saxLocator; |
| 753 |
this.levelInEntity = 0; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
public String getSystemId() { |
| 764 |
return saxLocator.getSystemId(); |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
public String getPublicId() { |
| 775 |
return saxLocator.getPublicId(); |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
public int getLineNumber() { |
| 785 |
return saxLocator.getLineNumber(); |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
public int getColumnNumber() { |
| 795 |
return saxLocator.getColumnNumber(); |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
public Location saveLocation() { |
| 805 |
return new ExplicitLocation(getSystemId(), getLineNumber(), getColumnNumber()); |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
} |
| 810 |
|