| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.tree.linked; |
| 9 |
|
| 10 |
import net.sf.saxon.event.CopyInformee; |
| 11 |
import net.sf.saxon.event.Receiver; |
| 12 |
import net.sf.saxon.event.ReceiverOptions; |
| 13 |
import net.sf.saxon.expr.parser.ExplicitLocation; |
| 14 |
import net.sf.saxon.expr.parser.Location; |
| 15 |
import net.sf.saxon.lib.NamespaceConstant; |
| 16 |
import net.sf.saxon.om.*; |
| 17 |
import net.sf.saxon.pattern.NodeKindTest; |
| 18 |
import net.sf.saxon.trans.XPathException; |
| 19 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 20 |
import net.sf.saxon.tree.util.AttributeCollectionImpl; |
| 21 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 22 |
import net.sf.saxon.tree.util.NamespaceIterator; |
| 23 |
import net.sf.saxon.tree.util.Navigator; |
| 24 |
import net.sf.saxon.type.*; |
| 25 |
import net.sf.saxon.value.AtomicValue; |
| 26 |
import net.sf.saxon.value.Whitespace; |
| 27 |
|
| 28 |
import java.util.Arrays; |
| 29 |
import java.util.HashSet; |
| 30 |
import java.util.Iterator; |
| 31 |
import java.util.Set; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class ElementImpl extends ParentNodeImpl implements NamespaceResolver { |
| 41 |
|
| 42 |
private NodeName nodeName; |
| 43 |
private SchemaType type = Untyped.getInstance(); |
| 44 |
private AttributeCollection attributeList; |
| 45 |
private NamespaceBinding[] namespaceList = null; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public ElementImpl() { |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public void setAttributeList(AttributeCollection atts) { |
| 61 |
this.attributeList = atts; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public void setNamespaceList(NamespaceBinding[] namespaces) { |
| 71 |
this.namespaceList = namespaces; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public void setNodeName(NodeName name) { |
| 80 |
this.nodeName = name; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public void initialise( NodeName elemName, SchemaType elementType, AttributeCollectionImpl atts, NodeInfo parent, |
| 94 |
int sequenceNumber) { |
| 95 |
this.nodeName = elemName; |
| 96 |
this.type = elementType; |
| 97 |
setRawParent((ParentNodeImpl) parent); |
| 98 |
setRawSequenceNumber(sequenceNumber); |
| 99 |
attributeList = atts; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
@Override |
| 108 |
public NodeName getNodeName() { |
| 109 |
return nodeName; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public void setLocation(String systemId, int line, int column) { |
| 121 |
DocumentImpl root = getRawParent().getPhysicalRoot(); |
| 122 |
root.setLineAndColumn(getRawSequenceNumber(), line, column); |
| 123 |
root.setSystemId(getRawSequenceNumber(), systemId); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public void setSystemId(String uri) { |
| 133 |
getPhysicalRoot().setSystemId(getRawSequenceNumber(), uri); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public NodeInfo getRoot() { |
| 141 |
ParentNodeImpl up = getRawParent(); |
| 142 |
if (up == null || (up instanceof DocumentImpl && ((DocumentImpl) up).isImaginary())) { |
| 143 |
return this; |
| 144 |
} else { |
| 145 |
return up.getRoot(); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public final String getSystemId() { |
| 155 |
DocumentImpl root = getPhysicalRoot(); |
| 156 |
return root == null ? null : root.getSystemId(getRawSequenceNumber()); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public String getBaseURI() { |
| 165 |
return Navigator.getBaseURI(this, n -> getPhysicalRoot().isTopWithinEntity((ElementImpl)n)); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public AttributeCollection gsetAttributeCollection() { |
| 176 |
return this.attributeList; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public boolean isNilled() { |
| 187 |
return getPhysicalRoot().isNilledElement(this); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
public void setTypeAnnotation(SchemaType type) { |
| 199 |
this.type = type; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
public void setNilled() { |
| 207 |
getPhysicalRoot().addNilledElement(this); |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
@Override |
| 217 |
public SchemaType getSchemaType() { |
| 218 |
return type; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
public int getLineNumber() { |
| 226 |
DocumentImpl root = getPhysicalRoot(); |
| 227 |
if (root == null) { |
| 228 |
return -1; |
| 229 |
} else { |
| 230 |
return root.getLineNumber(getRawSequenceNumber()); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
public int getColumnNumber() { |
| 239 |
DocumentImpl root = getPhysicalRoot(); |
| 240 |
if (root == null) { |
| 241 |
return -1; |
| 242 |
} else { |
| 243 |
return root.getColumnNumber(getRawSequenceNumber()); |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
public void generateId( FastStringBuffer buffer) { |
| 254 |
int sequence = getRawSequenceNumber(); |
| 255 |
if (sequence >= 0) { |
| 256 |
getPhysicalRoot().generateId(buffer); |
| 257 |
buffer.append("e"); |
| 258 |
buffer.append(Integer.toString(sequence)); |
| 259 |
} else { |
| 260 |
getRawParent().generateId(buffer); |
| 261 |
buffer.append("f"); |
| 262 |
buffer.append(Integer.toString(getSiblingPosition())); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public final int getNodeKind() { |
| 273 |
return Type.ELEMENT; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public void copy(Receiver out, int copyOptions, Location location) throws XPathException { |
| 292 |
|
| 293 |
SchemaType typeCode = CopyOptions.includes(copyOptions, CopyOptions.TYPE_ANNOTATIONS) ? |
| 294 |
getSchemaType() : Untyped.getInstance(); |
| 295 |
CopyInformee informee = (CopyInformee) out.getPipelineConfiguration().getComponent(CopyInformee.class.getName()); |
| 296 |
if (informee != null) { |
| 297 |
Object o = informee.notifyElementNode(this); |
| 298 |
if (o instanceof Location) { |
| 299 |
location = (Location)o; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
out.startElement(NameOfNode.makeName(this), typeCode, location, 0); |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
int childCopyOptions = copyOptions & ~CopyOptions.ALL_NAMESPACES; |
| 308 |
if ((copyOptions & CopyOptions.LOCAL_NAMESPACES) != 0) { |
| 309 |
NamespaceBinding[] localNamespaces = getDeclaredNamespaces(null); |
| 310 |
for (NamespaceBinding ns : localNamespaces) { |
| 311 |
if (ns == null) { |
| 312 |
break; |
| 313 |
} |
| 314 |
out.namespace(ns, 0); |
| 315 |
} |
| 316 |
} else if ((copyOptions & CopyOptions.ALL_NAMESPACES) != 0) { |
| 317 |
NamespaceIterator.sendNamespaces(this, out); |
| 318 |
childCopyOptions |= CopyOptions.LOCAL_NAMESPACES; |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
if (attributeList != null) { |
| 324 |
for (int i = 0; i < attributeList.getLength(); i++) { |
| 325 |
NodeName nc = attributeList.getNodeName(i); |
| 326 |
if (nc != null) { |
| 327 |
|
| 328 |
out.attribute(nc, BuiltInAtomicType.UNTYPED_ATOMIC, attributeList.getValue(i), ExplicitLocation.UNKNOWN_LOCATION, 0); |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
out.startContent(); |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
NodeImpl next = getFirstChild(); |
| 338 |
while (next != null) { |
| 339 |
next.copy(out, childCopyOptions, location); |
| 340 |
next = next.getNextSibling(); |
| 341 |
} |
| 342 |
|
| 343 |
out.endElement(); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public void delete() { |
| 351 |
DocumentImpl root = getPhysicalRoot(); |
| 352 |
super.delete(); |
| 353 |
if (root != null) { |
| 354 |
AxisIterator iter = iterateAxis(AxisInfo.DESCENDANT_OR_SELF, NodeKindTest.ELEMENT); |
| 355 |
while (true) { |
| 356 |
ElementImpl n = (ElementImpl) iter.next(); |
| 357 |
int atts = attributeList.getLength(); |
| 358 |
for (int index = 0; index < atts; index++) { |
| 359 |
if (attributeList.isId(index)) { |
| 360 |
root.deregisterID(attributeList.getValue(index)); |
| 361 |
} |
| 362 |
} |
| 363 |
if (n == null) { |
| 364 |
break; |
| 365 |
} |
| 366 |
root.deIndex(n); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
public void rename(NodeName newName) { |
| 378 |
String prefix = newName.getPrefix(); |
| 379 |
String uri = newName.getURI(); |
| 380 |
NamespaceBinding ns = new NamespaceBinding(prefix, uri); |
| 381 |
String uc = getURIForPrefix(prefix, true); |
| 382 |
if (uc == null) { |
| 383 |
uc = ""; |
| 384 |
} |
| 385 |
if (!uc.equals(uri)) { |
| 386 |
if (uc.isEmpty()) { |
| 387 |
addNamespace(ns, false); |
| 388 |
} else { |
| 389 |
throw new IllegalArgumentException( |
| 390 |
"Namespace binding of new name conflicts with existing namespace binding"); |
| 391 |
} |
| 392 |
} |
| 393 |
nodeName = newName; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
public void addNamespace( NamespaceBinding nscode, boolean unused) { |
| 410 |
if (nscode.getURI().isEmpty()) { |
| 411 |
throw new IllegalArgumentException("Cannot add a namespace undeclaration"); |
| 412 |
} |
| 413 |
addNamespaceInternal(nscode, true); |
| 414 |
} |
| 415 |
|
| 416 |
private void addNamespaceInternal( NamespaceBinding nscode, boolean externalCall) { |
| 417 |
if (namespaceList == null) { |
| 418 |
namespaceList = new NamespaceBinding[]{nscode}; |
| 419 |
} else { |
| 420 |
NamespaceBinding[] nsList = namespaceList; |
| 421 |
for (int i = 0; i < nsList.length; i++) { |
| 422 |
if (nsList[i].equals(nscode)) { |
| 423 |
return; |
| 424 |
} |
| 425 |
if (nsList[i].getPrefix().equals(nscode.getPrefix())) { |
| 426 |
if (nsList[i].getURI().isEmpty()) { |
| 427 |
|
| 428 |
nsList[i] = nscode; |
| 429 |
return; |
| 430 |
} else if (externalCall) { |
| 431 |
throw new IllegalArgumentException("New namespace conflicts with existing namespace binding"); |
| 432 |
} else { |
| 433 |
return; |
| 434 |
} |
| 435 |
} |
| 436 |
} |
| 437 |
int len = nsList.length; |
| 438 |
NamespaceBinding[] ns2 = new NamespaceBinding[len + 1]; |
| 439 |
System.arraycopy(nsList, 0, ns2, 0, len); |
| 440 |
ns2[len] = nscode; |
| 441 |
namespaceList = ns2; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
public void replaceStringValue( CharSequence stringValue) { |
| 453 |
if (stringValue.length() == 0) { |
| 454 |
setChildren(null); |
| 455 |
} else { |
| 456 |
TextImpl text = new TextImpl(stringValue.toString()); |
| 457 |
text.setRawParent(this); |
| 458 |
setChildren(text); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
public void addAttribute( NodeName nameCode, SimpleType attType, CharSequence value, int properties) { |
| 479 |
if (attributeList == null || attributeList.getLength() == 0) { |
| 480 |
attributeList = new AttributeCollectionImpl(getConfiguration()); |
| 481 |
} |
| 482 |
AttributeCollectionImpl atts = (AttributeCollectionImpl) attributeList; |
| 483 |
int index = atts.findByNodeName(nameCode); |
| 484 |
if (index == -1) { |
| 485 |
atts.addAttribute(nameCode, attType, value.toString(), ExplicitLocation.UNKNOWN_LOCATION, 0); |
| 486 |
} else { |
| 487 |
throw new IllegalStateException( |
| 488 |
"Cannot add an attribute to an element as it already has an attribute with the specified name"); |
| 489 |
} |
| 490 |
if (!nameCode.hasURI("")) { |
| 491 |
|
| 492 |
NamespaceBinding binding = nameCode.getNamespaceBinding(); |
| 493 |
String prefix = binding.getPrefix(); |
| 494 |
String uc = getURIForPrefix(prefix, false); |
| 495 |
if (uc == null) { |
| 496 |
|
| 497 |
addNamespace(binding, false); |
| 498 |
} else if (!uc.equals(binding.getURI())) { |
| 499 |
throw new IllegalStateException( |
| 500 |
"Namespace binding of new name conflicts with existing namespace binding"); |
| 501 |
} |
| 502 |
} |
| 503 |
if ((properties & ReceiverOptions.IS_ID) != 0) { |
| 504 |
DocumentImpl root = getPhysicalRoot(); |
| 505 |
if (root != null) { |
| 506 |
root.registerID(this, Whitespace.trim(value)); |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
public void removeAttribute( NodeInfo attribute) { |
| 522 |
if (!(attribute instanceof AttributeImpl)) { |
| 523 |
return; |
| 524 |
} |
| 525 |
AttributeCollectionImpl atts = (AttributeCollectionImpl) getAttributeList(); |
| 526 |
int index = ((AttributeImpl) attribute).getSiblingPosition(); |
| 527 |
if (index >= 0 && atts.isId(index)) { |
| 528 |
DocumentImpl root = getPhysicalRoot(); |
| 529 |
root.deregisterID(atts.getValue(index)); |
| 530 |
} |
| 531 |
atts.removeAttribute(index); |
| 532 |
((AttributeImpl) attribute).setRawParent(null); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
public void removeTypeAnnotation() { |
| 542 |
if (getSchemaType() != Untyped.getInstance()) { |
| 543 |
type = AnyType.getInstance(); |
| 544 |
getRawParent().removeTypeAnnotation(); |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public void setNamespaceDeclarations(NamespaceBinding[] namespaces, int namespacesUsed) { |
| 556 |
namespaceList = new NamespaceBinding[namespacesUsed]; |
| 557 |
System.arraycopy(namespaces, 0, namespaceList, 0, namespacesUsed); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
public String getURIForPrefix( String prefix, boolean useDefault) { |
| 575 |
if (prefix.equals("xml")) { |
| 576 |
return NamespaceConstant.XML; |
| 577 |
} |
| 578 |
if (prefix.isEmpty() && !useDefault) { |
| 579 |
return NamespaceConstant.NULL; |
| 580 |
} |
| 581 |
|
| 582 |
if (namespaceList != null) { |
| 583 |
for (NamespaceBinding aNamespaceList : namespaceList) { |
| 584 |
if (aNamespaceList.getPrefix().equals(prefix)) { |
| 585 |
String uri = aNamespaceList.getURI(); |
| 586 |
return uri.isEmpty() && !prefix.isEmpty() ? null : uri; |
| 587 |
} |
| 588 |
} |
| 589 |
} |
| 590 |
NodeInfo next = getRawParent(); |
| 591 |
if (next.getNodeKind() == Type.DOCUMENT) { |
| 592 |
return prefix.isEmpty() ? NamespaceConstant.NULL : null; |
| 593 |
} else { |
| 594 |
return ((ElementImpl) next).getURIForPrefix(prefix, useDefault); |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
public Iterator<String> iteratePrefixes() { |
| 605 |
return new Iterator<String>() { |
| 606 |
private NamePool pool = null; |
| 607 |
private Iterator<NamespaceBinding> iter = NamespaceIterator.iterateNamespaces(ElementImpl.this); |
| 608 |
|
| 609 |
public boolean hasNext() { |
| 610 |
return pool == null || iter.hasNext(); |
| 611 |
} |
| 612 |
|
| 613 |
public String next() { |
| 614 |
if (pool == null) { |
| 615 |
pool = getNamePool(); |
| 616 |
return "xml"; |
| 617 |
} else { |
| 618 |
return iter.next().getPrefix(); |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
public void remove() { |
| 623 |
throw new UnsupportedOperationException("remove"); |
| 624 |
} |
| 625 |
}; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
public boolean isInScopeNamespace( String uri) { |
| 637 |
if (uri.equals(NamespaceConstant.XML)) { |
| 638 |
return true; |
| 639 |
} |
| 640 |
for (NamespaceBinding b : namespaceList) { |
| 641 |
if (b.getURI().equals(uri)) { |
| 642 |
return true; |
| 643 |
} |
| 644 |
} |
| 645 |
return false; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] buffer) { |
| 661 |
return namespaceList == null ? NamespaceBinding.EMPTY_ARRAY : namespaceList; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
protected void fixupInsertedNamespaces(boolean inherit) { |
| 674 |
if (getRawParent().getNodeKind() == Type.DOCUMENT) { |
| 675 |
return; |
| 676 |
} |
| 677 |
|
| 678 |
Set<NamespaceBinding> childNamespaces = new HashSet<>(); |
| 679 |
if (namespaceList != null) { |
| 680 |
childNamespaces.addAll(Arrays.asList(namespaceList)); |
| 681 |
} |
| 682 |
|
| 683 |
NamespaceResolver inscope = new InscopeNamespaceResolver(getRawParent()); |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
if (getURI().isEmpty() && !inscope.getURIForPrefix("", true).isEmpty()) { |
| 688 |
childNamespaces.add(NamespaceBinding.DEFAULT_UNDECLARATION); |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
if (!inherit) { |
| 694 |
Iterator it = inscope.iteratePrefixes(); |
| 695 |
while (it.hasNext()) { |
| 696 |
String prefix = (String) it.next(); |
| 697 |
if (!prefix.equals("xml")) { |
| 698 |
boolean found = false; |
| 699 |
if (namespaceList != null) { |
| 700 |
for (NamespaceBinding aNamespaceList : namespaceList) { |
| 701 |
if (aNamespaceList.getPrefix().equals(prefix)) { |
| 702 |
found = true; |
| 703 |
break; |
| 704 |
} |
| 705 |
} |
| 706 |
} |
| 707 |
if (!found) { |
| 708 |
childNamespaces.add(new NamespaceBinding(prefix, "")); |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
if (namespaceList != null) { |
| 717 |
for (NamespaceBinding nscode : namespaceList) { |
| 718 |
String prefix = nscode.getPrefix(); |
| 719 |
String uri = nscode.getURI(); |
| 720 |
String parentUri = inscope.getURIForPrefix(prefix, true); |
| 721 |
if (parentUri != null && parentUri.equals(uri)) { |
| 722 |
|
| 723 |
childNamespaces.remove(nscode); |
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
NamespaceBinding[] n2 = new NamespaceBinding[childNamespaces.size()]; |
| 728 |
int j = 0; |
| 729 |
for (NamespaceBinding childNamespace : childNamespaces) { |
| 730 |
n2[j++] = childNamespace; |
| 731 |
} |
| 732 |
namespaceList = n2; |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
public AttributeCollection getAttributeList() { |
| 744 |
return attributeList == null ? AttributeCollectionImpl.EMPTY_ATTRIBUTE_COLLECTION : attributeList; |
| 745 |
} |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
public NamespaceBinding[] getNamespaceList() { |
| 755 |
return namespaceList; |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
public String getAttributeValue( String uri, String localName) { |
| 768 |
return attributeList == null ? null : attributeList.getValue(uri, localName); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
public boolean isId() { |
| 778 |
|
| 779 |
|
| 780 |
try { |
| 781 |
SchemaType type = getSchemaType(); |
| 782 |
return type.getFingerprint() == StandardNames.XS_ID || |
| 783 |
type.isIdType() && NameChecker.isValidNCName(getStringValueCS()); |
| 784 |
} catch (MissingComponentException e) { |
| 785 |
return false; |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
public boolean isIdref() { |
| 790 |
return isIdRefNode(this); |
| 791 |
} |
| 792 |
|
| 793 |
static boolean isIdRefNode(NodeImpl node) { |
| 794 |
SchemaType type = node.getSchemaType(); |
| 795 |
try { |
| 796 |
if (type.isIdRefType()) { |
| 797 |
if (type == BuiltInAtomicType.IDREF || type == BuiltInListType.IDREFS) { |
| 798 |
return true; |
| 799 |
} |
| 800 |
try { |
| 801 |
for (AtomicValue av : node.atomize()) { |
| 802 |
if (av.getItemType().isIdRefType()) { |
| 803 |
return true; |
| 804 |
} |
| 805 |
} |
| 806 |
} catch (XPathException err) { |
| 807 |
|
| 808 |
} |
| 809 |
} |
| 810 |
} catch (MissingComponentException e) { |
| 811 |
return false; |
| 812 |
} |
| 813 |
return false; |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
} |
| 818 |
|