| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.expr.*; |
| 12 |
import net.sf.saxon.expr.instruct.*; |
| 13 |
import net.sf.saxon.expr.parser.*; |
| 14 |
import net.sf.saxon.expr.sort.SortKeyDefinition; |
| 15 |
import net.sf.saxon.expr.sort.SortKeyDefinitionList; |
| 16 |
import net.sf.saxon.functions.Current; |
| 17 |
import net.sf.saxon.lib.Feature; |
| 18 |
import net.sf.saxon.lib.NamespaceConstant; |
| 19 |
import net.sf.saxon.lib.StringCollator; |
| 20 |
import net.sf.saxon.lib.Validation; |
| 21 |
import net.sf.saxon.om.*; |
| 22 |
import net.sf.saxon.pattern.*; |
| 23 |
import net.sf.saxon.trace.InstructionInfo; |
| 24 |
import net.sf.saxon.trace.LocationKind; |
| 25 |
import net.sf.saxon.trans.*; |
| 26 |
import net.sf.saxon.tree.AttributeLocation; |
| 27 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 28 |
import net.sf.saxon.tree.iter.ListIterator; |
| 29 |
import net.sf.saxon.tree.linked.ElementImpl; |
| 30 |
import net.sf.saxon.tree.linked.NodeImpl; |
| 31 |
import net.sf.saxon.tree.linked.TextImpl; |
| 32 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 33 |
import net.sf.saxon.tree.util.NamespaceIterator; |
| 34 |
import net.sf.saxon.tree.util.Navigator; |
| 35 |
import net.sf.saxon.type.*; |
| 36 |
import net.sf.saxon.value.BigDecimalValue; |
| 37 |
import net.sf.saxon.value.SequenceType; |
| 38 |
import net.sf.saxon.value.Whitespace; |
| 39 |
|
| 40 |
import javax.xml.transform.SourceLocator; |
| 41 |
import javax.xml.transform.TransformerException; |
| 42 |
import java.math.BigDecimal; |
| 43 |
import java.net.URI; |
| 44 |
import java.net.URISyntaxException; |
| 45 |
import java.util.*; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public abstract class StyleElement extends ElementImpl { |
| 55 |
|
| 56 |
protected String[] extensionNamespaces = null; |
| 57 |
private String[] excludedNamespaces = null; |
| 58 |
protected int version = -1; |
| 59 |
protected ExpressionContext staticContext = null; |
| 60 |
protected XPathException validationError = null; |
| 61 |
protected int reportingCircumstances = REPORT_ALWAYS; |
| 62 |
protected String defaultXPathNamespace = null; |
| 63 |
protected String defaultCollationName = null; |
| 64 |
protected StructuredQName defaultMode; |
| 65 |
protected boolean expandText = false; |
| 66 |
private boolean explaining = false; |
| 67 |
private StructuredQName objectName; |
| 68 |
private String baseURI; |
| 69 |
private Compilation compilation; |
| 70 |
private ExplicitLocation savedLocation = null; |
| 71 |
private int defaultValidation = Validation.DEFAULT; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static final int REPORT_ALWAYS = 1; |
| 76 |
public static final int REPORT_UNLESS_FORWARDS_COMPATIBLE = 2; |
| 77 |
public static final int REPORT_IF_INSTANTIATED = 3; |
| 78 |
public static final int REPORT_STATICALLY_UNLESS_FALLBACK_AVAILABLE = 4; |
| 79 |
public static final int REPORT_DYNAMICALLY_UNLESS_FALLBACK_AVAILABLE = 5; |
| 80 |
public static final int IGNORED_INSTRUCTION = 6; |
| 81 |
|
| 82 |
protected int actionsCompleted = 0; |
| 83 |
public static final int ACTION_VALIDATE = 1; |
| 84 |
public static final int ACTION_COMPILE = 2; |
| 85 |
public static final int ACTION_TYPECHECK = 4; |
| 86 |
public static final int ACTION_OPTIMIZE = 8; |
| 87 |
public static final int ACTION_FIXUP = 16; |
| 88 |
public static final int ACTION_PROCESS_ATTRIBUTES = 32; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public StyleElement() { |
| 96 |
} |
| 97 |
|
| 98 |
public Compilation getCompilation() { |
| 99 |
return compilation; |
| 100 |
} |
| 101 |
|
| 102 |
public void setCompilation(Compilation compilation) { |
| 103 |
this.compilation = compilation; |
| 104 |
} |
| 105 |
|
| 106 |
public StylesheetPackage getPackageData() { |
| 107 |
return getPrincipalStylesheetModule().getStylesheetPackage(); |
| 108 |
} |
| 109 |
|
| 110 |
public Configuration getConfiguration() { |
| 111 |
return compilation.getConfiguration(); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public ExpressionContext getStaticContext() { |
| 121 |
if (staticContext == null) { |
| 122 |
staticContext = new ExpressionContext(this, null); |
| 123 |
} |
| 124 |
return staticContext; |
| 125 |
} |
| 126 |
|
| 127 |
public ExpressionContext getStaticContext(StructuredQName attributeName) { |
| 128 |
return new ExpressionContext(this, attributeName); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public String getBaseURI() { |
| 139 |
if (baseURI == null) { |
| 140 |
baseURI = super.getBaseURI(); |
| 141 |
} |
| 142 |
return baseURI; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public ExpressionVisitor makeExpressionVisitor() { |
| 152 |
return ExpressionVisitor.make(getStaticContext()); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
public boolean isSchemaAware() { |
| 162 |
return getCompilation().isSchemaAware(); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
protected boolean isExplaining() { |
| 172 |
return explaining; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public void substituteFor(StyleElement temp) { |
| 185 |
setRawParent(temp.getRawParent()); |
| 186 |
setAttributeList(temp.getAttributeList()); |
| 187 |
setNamespaceList(temp.getNamespaceList()); |
| 188 |
setNodeName(temp.getNodeName()); |
| 189 |
setRawSequenceNumber(temp.getRawSequenceNumber()); |
| 190 |
extensionNamespaces = temp.extensionNamespaces; |
| 191 |
excludedNamespaces = temp.excludedNamespaces; |
| 192 |
version = temp.version; |
| 193 |
staticContext = temp.staticContext; |
| 194 |
validationError = temp.validationError; |
| 195 |
reportingCircumstances = temp.reportingCircumstances; |
| 196 |
compilation = temp.compilation; |
| 197 |
|
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public void setValidationError(TransformerException reason, |
| 209 |
int circumstances) { |
| 210 |
validationError = XPathException.makeXPathException(reason); |
| 211 |
reportingCircumstances = circumstances; |
| 212 |
} |
| 213 |
|
| 214 |
public void setIgnoreInstruction() { |
| 215 |
reportingCircumstances = IGNORED_INSTRUCTION; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public boolean isInstruction() { |
| 225 |
return false; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public boolean isDeclaration() { |
| 236 |
return false; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public Visibility getVisibility() { |
| 249 |
String vis = getAttributeValue("", "visibility"); |
| 250 |
if (vis == null) { |
| 251 |
return Visibility.PRIVATE; |
| 252 |
} else { |
| 253 |
return interpretVisibilityValue(vis, ""); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public Visibility getDeclaredVisibility() { |
| 265 |
String vis = getAttributeValue("", "visibility"); |
| 266 |
if (vis == null) { |
| 267 |
return null; |
| 268 |
} else { |
| 269 |
return interpretVisibilityValue(vis, ""); |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
protected boolean markTailCalls() { |
| 281 |
return false; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
protected boolean mayContainSequenceConstructor() { |
| 291 |
return false; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
protected boolean mayContainFallback() { |
| 302 |
return mayContainSequenceConstructor(); |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
protected boolean mayContainParam() { |
| 312 |
return false; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
public XSLModuleRoot getContainingStylesheet() { |
| 323 |
NodeInfo parent = getParent(); |
| 324 |
if (parent instanceof XSLModuleRoot) { |
| 325 |
return (XSLModuleRoot) parent; |
| 326 |
} else if (parent instanceof StyleElement) { |
| 327 |
return ((StyleElement) parent).getContainingStylesheet(); |
| 328 |
} else { |
| 329 |
|
| 330 |
|
| 331 |
return null; |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
public int getDefaultValidation() { |
| 344 |
int v = defaultValidation; |
| 345 |
NodeInfo p = this; |
| 346 |
while (v == Validation.DEFAULT) { |
| 347 |
p = p.getParent(); |
| 348 |
if (!(p instanceof StyleElement)) { |
| 349 |
return Validation.STRIP; |
| 350 |
} |
| 351 |
v = ((StyleElement) p).defaultValidation; |
| 352 |
} |
| 353 |
return v; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public final StructuredQName makeQName(String lexicalQName) |
| 370 |
throws XPathException { |
| 371 |
|
| 372 |
StructuredQName qName; |
| 373 |
try { |
| 374 |
qName = StructuredQName.fromLexicalQName(lexicalQName, false, |
| 375 |
true, this); |
| 376 |
} catch (XPathException e) { |
| 377 |
e.setIsStaticError(true); |
| 378 |
String code = e.getErrorCodeLocalPart(); |
| 379 |
if ("FONS0004".equals(code)) { |
| 380 |
e.setErrorCode("XTSE0280"); |
| 381 |
} else if ("FOCA0002".equals(code)) { |
| 382 |
e.setErrorCode("XTSE0020"); |
| 383 |
} else if (code == null) { |
| 384 |
e.setErrorCode("XTSE0020"); |
| 385 |
} |
| 386 |
e.setLocator(this); |
| 387 |
throw e; |
| 388 |
} |
| 389 |
if (NamespaceConstant.isReserved(qName.getURI())) { |
| 390 |
if (qName.hasURI(NamespaceConstant.XSLT)) { |
| 391 |
if (qName.getLocalPart().equals("initial-template") |
| 392 |
&& (this instanceof XSLTemplate || this instanceof XSLCallTemplate)) { |
| 393 |
return qName; |
| 394 |
} |
| 395 |
if (qName.getLocalPart().equals("original")) { |
| 396 |
|
| 397 |
if (findAncestorElement(StandardNames.XSL_OVERRIDE) != null) { |
| 398 |
return qName; |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
XPathException err = new XPathException("Namespace prefix " + |
| 403 |
qName.getPrefix() + " refers to a reserved namespace"); |
| 404 |
err.setIsStaticError(true); |
| 405 |
err.setErrorCode("XTSE0080"); |
| 406 |
throw err; |
| 407 |
} |
| 408 |
return qName; |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public StyleElement findAncestorElement(int fingerprint) { |
| 420 |
Optional<NodeInfo> ancestor = iterateAxis(AxisInfo.ANCESTOR).firstWith( |
| 421 |
node -> node instanceof StyleElement && node.getFingerprint() == fingerprint); |
| 422 |
return (StyleElement) ancestor.orElse(null); |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
public StylesheetPackage getUsedPackage() { |
| 433 |
return null; |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public Actor getXslOriginal(int componentKind) throws XPathException { |
| 447 |
StyleElement container = componentKind == getFingerprint() ? this : findAncestorElement(componentKind); |
| 448 |
if (!(container instanceof StylesheetComponent)) { |
| 449 |
throw new XPathException( |
| 450 |
"A reference to xsl:original appears within the wrong kind of component: in this case" + |
| 451 |
", it must be within xsl:" + getNamePool().getLocalName(componentKind), "XTSE0650", this); |
| 452 |
} |
| 453 |
SymbolicName originalName = ((StylesheetComponent) container).getSymbolicName(); |
| 454 |
StyleElement xslOverride = container.findAncestorElement(StandardNames.XSL_OVERRIDE); |
| 455 |
if (xslOverride == null) { |
| 456 |
throw new XPathException("A reference to xsl:original can be used only within an xsl:override element"); |
| 457 |
} |
| 458 |
StyleElement usePackage = xslOverride.findAncestorElement(StandardNames.XSL_USE_PACKAGE); |
| 459 |
if (usePackage == null) { |
| 460 |
throw new XPathException("The parent of xsl:override must be an xsl:use-package element", "XTSE0010", xslOverride); |
| 461 |
} |
| 462 |
|
| 463 |
Component overridden = usePackage.getUsedPackage().getComponent(originalName); |
| 464 |
if (overridden == null) { |
| 465 |
|
| 466 |
return null; |
| 467 |
} |
| 468 |
return overridden.getActor(); |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
public Component getOverriddenComponent() { |
| 478 |
if (!(this instanceof StylesheetComponent)) { |
| 479 |
return null; |
| 480 |
} |
| 481 |
SymbolicName originalName = ((StylesheetComponent) this).getSymbolicName(); |
| 482 |
StyleElement xslOverride = findAncestorElement(StandardNames.XSL_OVERRIDE); |
| 483 |
if (xslOverride == null) { |
| 484 |
return null; |
| 485 |
} |
| 486 |
StyleElement usePackage = xslOverride.findAncestorElement(StandardNames.XSL_USE_PACKAGE); |
| 487 |
if (usePackage == null) { |
| 488 |
return null; |
| 489 |
} |
| 490 |
|
| 491 |
return usePackage.getUsedPackage().getComponent(originalName); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
public SavedNamespaceContext makeNamespaceContext() { |
| 503 |
StylesheetPackage pack = getPackageData(); |
| 504 |
return new SavedNamespaceContext(NamespaceIterator.iterateNamespaces(this)); |
| 505 |
} |
| 506 |
|
| 507 |
public RetainedStaticContext makeRetainedStaticContext() { |
| 508 |
return getStaticContext().makeRetainedStaticContext(); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public boolean changesRetainedStaticContext() { |
| 520 |
NodeImpl parent = getParent(); |
| 521 |
return parent == null |
| 522 |
|| !ExpressionTool.equalOrNull(getBaseURI(), parent.getBaseURI()) |
| 523 |
|| defaultCollationName != null |
| 524 |
|| defaultXPathNamespace != null |
| 525 |
|| getDeclaredNamespaces(NamespaceBinding.EMPTY_ARRAY).length != 0 |
| 526 |
|| !(parent instanceof StyleElement) |
| 527 |
|| getEffectiveVersion() != ((StyleElement) getParent()).getEffectiveVersion(); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
public NamespaceResolver getNamespaceResolver() { |
| 538 |
return this; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
public void processAllAttributes() throws XPathException { |
| 548 |
processDefaultCollationAttribute(); |
| 549 |
processDefaultMode(); |
| 550 |
staticContext = new ExpressionContext(this, null); |
| 551 |
processAttributes(); |
| 552 |
iterateAxis(AxisInfo.CHILD).forEachOrFail(child -> { |
| 553 |
if (child instanceof StyleElement) { |
| 554 |
((StyleElement) child).processAllAttributes(); |
| 555 |
if (((StyleElement) child).explaining) { |
| 556 |
|
| 557 |
|
| 558 |
explaining = true; |
| 559 |
} |
| 560 |
} |
| 561 |
}); |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
public void processStandardAttributes(String namespace) { |
| 590 |
processExtensionElementAttribute(namespace); |
| 591 |
processExcludedNamespaces(namespace); |
| 592 |
processVersionAttribute(namespace); |
| 593 |
processDefaultXPathNamespaceAttribute(namespace); |
| 594 |
processDefaultValidationAttribute(namespace); |
| 595 |
processExpandTextAttribute(namespace); |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
public String getAttributeValue(String clarkName) { |
| 607 |
NodeName nn = FingerprintedQName.fromClarkName(clarkName); |
| 608 |
return getAttributeValue(nn.getURI(), nn.getLocalPart()); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
protected final void processAttributes() { |
| 617 |
try { |
| 618 |
prepareAttributes(); |
| 619 |
} catch (XPathException err) { |
| 620 |
compileError(err); |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
protected void checkUnknownAttribute(NodeName nc) { |
| 631 |
|
| 632 |
String attributeURI = nc.getURI(); |
| 633 |
String elementURI = getURI(); |
| 634 |
String clarkName = nc.getStructuredQName().getClarkName(); |
| 635 |
|
| 636 |
if (clarkName.equals(StandardNames.SAXON_EXPLAIN)) { |
| 637 |
String value = getAttributeValue(clarkName); |
| 638 |
explaining = processBooleanAttribute("saxon:explain", value); |
| 639 |
} |
| 640 |
|
| 641 |
if (forwardsCompatibleModeIsEnabled()) { |
| 642 |
|
| 643 |
return; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
if (isInstruction() && |
| 649 |
attributeURI.equals(NamespaceConstant.XSLT) && |
| 650 |
!elementURI.equals(NamespaceConstant.XSLT) && |
| 651 |
(clarkName.endsWith("}default-collation") || |
| 652 |
clarkName.endsWith("}default-mode") || |
| 653 |
clarkName.endsWith("}xpath-default-namespace") || |
| 654 |
clarkName.endsWith("}expand-text") || |
| 655 |
clarkName.endsWith("}extension-element-prefixes") || |
| 656 |
clarkName.endsWith("}exclude-result-prefixes") || |
| 657 |
clarkName.endsWith("}version") || |
| 658 |
clarkName.endsWith("}default-validation") || |
| 659 |
clarkName.endsWith("}use-when"))) { |
| 660 |
return; |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
if (elementURI.equals(NamespaceConstant.XSLT) && |
| 666 |
(clarkName.equals("default-collation") || |
| 667 |
clarkName.equals("default-mode") || |
| 668 |
clarkName.equals("expand-text") || |
| 669 |
clarkName.equals("xpath-default-namespace") || |
| 670 |
clarkName.equals("extension-element-prefixes") || |
| 671 |
clarkName.equals("exclude-result-prefixes") || |
| 672 |
clarkName.equals("version") || |
| 673 |
clarkName.equals("default-validation") || |
| 674 |
clarkName.equals("use-when"))) { |
| 675 |
return; |
| 676 |
} |
| 677 |
|
| 678 |
if ("".equals(attributeURI) || NamespaceConstant.XSLT.equals(attributeURI)) { |
| 679 |
compileErrorInAttribute("Attribute " + Err.wrap(nc.getDisplayName(), Err.ATTRIBUTE) + |
| 680 |
" is not allowed on element " + Err.wrap(getDisplayName(), Err.ELEMENT), |
| 681 |
"XTSE0090", clarkName); |
| 682 |
} else if (NamespaceConstant.SAXON.equals(attributeURI)) { |
| 683 |
compileWarning("Unrecognized attribute in Saxon namespace: " + nc.getDisplayName(), "XTSE0090"); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
protected abstract void prepareAttributes() throws XPathException; |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
protected StyleElement getLastChildInstruction() { |
| 705 |
StyleElement last = null; |
| 706 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 707 |
NodeInfo child; |
| 708 |
while ((child = kids.next()) != null) { |
| 709 |
if (child instanceof StyleElement) { |
| 710 |
last = (StyleElement) child; |
| 711 |
} else { |
| 712 |
last = null; |
| 713 |
} |
| 714 |
} |
| 715 |
return last; |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
public Expression makeExpression(String expression, int attIndex) { |
| 729 |
try { |
| 730 |
StaticContext env = staticContext; |
| 731 |
if (attIndex >= 0) { |
| 732 |
StructuredQName attName = getAttributeList().getNodeName(attIndex).getStructuredQName(); |
| 733 |
env = getStaticContext(attName); |
| 734 |
} |
| 735 |
return ExpressionTool.make(expression, env, 0, Token.EOF, |
| 736 |
getCompilation().getCompilerInfo().getCodeInjector()); |
| 737 |
} catch (XPathException err) { |
| 738 |
err.maybeSetLocation(allocateLocation()); |
| 739 |
if (err.isReportableStatically()) { |
| 740 |
compileError(err); |
| 741 |
} |
| 742 |
ErrorExpression erexp = new ErrorExpression(err); |
| 743 |
erexp.setRetainedStaticContext(makeRetainedStaticContext()); |
| 744 |
erexp.setLocation(allocateLocation()); |
| 745 |
return erexp; |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
public Pattern makePattern(String pattern, String attributeName) { |
| 757 |
try { |
| 758 |
StaticContext env = getStaticContext(new StructuredQName("", "", attributeName)); |
| 759 |
Pattern p = Pattern.make(pattern, env, getCompilation().getPackageData()); |
| 760 |
p.setLocation(allocateLocation()); |
| 761 |
return p; |
| 762 |
} catch (XPathException err) { |
| 763 |
if ("XPST0003".equals(err.getErrorCodeLocalPart())) { |
| 764 |
err.setErrorCode("XTSE0340"); |
| 765 |
} |
| 766 |
compileError(err); |
| 767 |
NodeTestPattern nsp = new NodeTestPattern(AnyNodeTest.getInstance()); |
| 768 |
nsp.setLocation(allocateLocation()); |
| 769 |
return nsp; |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
protected Expression makeAttributeValueTemplate(String expression, int attIndex) { |
| 782 |
StaticContext env = attIndex == -1 ? |
| 783 |
staticContext : |
| 784 |
getStaticContext(getAttributeList().getNodeName(attIndex).getStructuredQName()); |
| 785 |
if (attIndex >= 0) { |
| 786 |
StructuredQName attName = getAttributeList().getNodeName(attIndex).getStructuredQName(); |
| 787 |
env = getStaticContext(attName); |
| 788 |
} |
| 789 |
try { |
| 790 |
return AttributeValueTemplate.make(expression, env); |
| 791 |
} catch (XPathException err) { |
| 792 |
compileError(err); |
| 793 |
return new StringLiteral(expression); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
protected void checkAttributeValue(String name, String value, boolean avt, String[] allowed) { |
| 808 |
if (avt && value.contains("{")) { |
| 809 |
return; |
| 810 |
} |
| 811 |
if (Arrays.binarySearch(allowed, value) < 0) { |
| 812 |
FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.C64); |
| 813 |
sb.append("Invalid value for "); |
| 814 |
sb.append("@"); |
| 815 |
sb.append(name); |
| 816 |
sb.append(". Value must be one of ("); |
| 817 |
for (int i = 0; i < allowed.length; i++) { |
| 818 |
sb.append(i == 0 ? "" : "|"); |
| 819 |
sb.append(allowed[i]); |
| 820 |
} |
| 821 |
sb.append(")"); |
| 822 |
compileError(sb.toString(), "XTSE0020"); |
| 823 |
} |
| 824 |
} |
| 825 |
|
| 826 |
protected final static String[] YES_NO = new String[]{"0", "1", "false", "no", "true", "yes"}; |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
public boolean processBooleanAttribute(String name, String value) { |
| 837 |
String s = Whitespace.trim(value); |
| 838 |
if (isYes(s)) { |
| 839 |
return true; |
| 840 |
} else if (isNo(s)) { |
| 841 |
return false; |
| 842 |
} else { |
| 843 |
invalidAttribute(name, "yes|no | true|false | 1|0"); |
| 844 |
return false; |
| 845 |
} |
| 846 |
|
| 847 |
} |
| 848 |
|
| 849 |
static boolean isYes(String s) { |
| 850 |
return "yes".equals(s) || "true".equals(s) || "1".equals(s); |
| 851 |
} |
| 852 |
|
| 853 |
static boolean isNo(String s) { |
| 854 |
return "no".equals(s) || "false".equals(s) || "0".equals(s); |
| 855 |
} |
| 856 |
|
| 857 |
boolean processStreamableAtt(String streamableAtt) { |
| 858 |
boolean streamable = processBooleanAttribute("streamable", streamableAtt); |
| 859 |
if (streamable) { |
| 860 |
if (!getConfiguration().isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XSLT)) { |
| 861 |
compileWarning("Request for streaming ignored: this Saxon configuration does not support streaming", SaxonErrorCode.SXST0068); |
| 862 |
return false; |
| 863 |
} |
| 864 |
if ("off".equals(getConfiguration().getConfigurationProperty(Feature.STREAMABILITY))) { |
| 865 |
compileWarning("Request for streaming ignored: streaming is disabled in this Saxon configuration", SaxonErrorCode.SXST0068); |
| 866 |
return false; |
| 867 |
} |
| 868 |
} |
| 869 |
return streamable; |
| 870 |
} |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
public SequenceType makeSequenceType(String sequenceType) |
| 882 |
throws XPathException { |
| 883 |
ExpressionContext env = getStaticContext(); |
| 884 |
int languageLevel = env.getXPathVersion(); |
| 885 |
if (languageLevel == 30) { |
| 886 |
languageLevel = 305; |
| 887 |
} |
| 888 |
XPathParser parser = |
| 889 |
getConfiguration().newExpressionParser("XP", false, languageLevel); |
| 890 |
QNameParser qp = new QNameParser(staticContext.getNamespaceResolver()); |
| 891 |
qp.setAcceptEQName(staticContext.getXPathVersion() >= 30); |
| 892 |
qp.setDefaultNamespace(""); |
| 893 |
qp.setErrorOnBadSyntax("XPST0003"); |
| 894 |
qp.setErrorOnUnresolvedPrefix("XPST0081"); |
| 895 |
parser.setQNameParser(qp); |
| 896 |
return parser.parseSequenceType(sequenceType, staticContext); |
| 897 |
} |
| 898 |
|
| 899 |
public SequenceType makeExtendedSequenceType(String sequenceType) |
| 900 |
throws XPathException { |
| 901 |
getStaticContext(); |
| 902 |
XPathParser parser = |
| 903 |
getConfiguration().newExpressionParser("XP", false, 31); |
| 904 |
QNameParser qp = new QNameParser(staticContext.getNamespaceResolver()); |
| 905 |
qp.setAcceptEQName(staticContext.getXPathVersion() >= 30); |
| 906 |
qp.setDefaultNamespace(""); |
| 907 |
qp.setErrorOnBadSyntax("XPST0003"); |
| 908 |
qp.setErrorOnUnresolvedPrefix("XPST0081"); |
| 909 |
parser.setQNameParser(qp); |
| 910 |
return parser.parseExtendedSequenceType(sequenceType, staticContext); |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
protected void processExtensionElementAttribute(String ns) { |
| 920 |
String ext = getAttributeValue(ns, "extension-element-prefixes"); |
| 921 |
if (ext != null) { |
| 922 |
|
| 923 |
int count = 0; |
| 924 |
StringTokenizer st1 = new StringTokenizer(ext, " \t\n\r", false); |
| 925 |
while (st1.hasMoreTokens()) { |
| 926 |
st1.nextToken(); |
| 927 |
count++; |
| 928 |
} |
| 929 |
extensionNamespaces = new String[count]; |
| 930 |
count = 0; |
| 931 |
StringTokenizer st2 = new StringTokenizer(ext, " \t\n\r", false); |
| 932 |
while (st2.hasMoreTokens()) { |
| 933 |
String s = st2.nextToken(); |
| 934 |
if ("#default".equals(s)) { |
| 935 |
s = ""; |
| 936 |
} |
| 937 |
String uri = getURIForPrefix(s, false); |
| 938 |
if (uri == null) { |
| 939 |
compileError("Namespace prefix " + s + " is undeclared", "XTSE1430"); |
| 940 |
extensionNamespaces[count++] = NamespaceConstant.SAXON; |
| 941 |
} else if (NamespaceConstant.isReserved(uri)) { |
| 942 |
compileError("Namespace " + uri + " is reserved: it cannot be used for extension instructions " + |
| 943 |
"(perhaps exclude-result-prefixes was intended).", |
| 944 |
"XTSE0085"); |
| 945 |
extensionNamespaces[count++] = NamespaceConstant.SAXON; |
| 946 |
} else { |
| 947 |
extensionNamespaces[count++] = uri; |
| 948 |
} |
| 949 |
} |
| 950 |
} |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
protected void processExcludedNamespaces(String ns) { |
| 960 |
String ext = getAttributeValue(ns, "exclude-result-prefixes"); |
| 961 |
if (ext != null) { |
| 962 |
if ("#all".equals(Whitespace.trim(ext))) { |
| 963 |
Iterator<NamespaceBinding> codes = NamespaceIterator.iterateNamespaces(this); |
| 964 |
List<String> excluded = new ArrayList<>(); |
| 965 |
while (codes.hasNext()) { |
| 966 |
excluded.add(codes.next().getURI()); |
| 967 |
} |
| 968 |
excludedNamespaces = excluded.toArray(new String[0]); |
| 969 |
} else { |
| 970 |
|
| 971 |
int count = 0; |
| 972 |
StringTokenizer st1 = new StringTokenizer(ext, " \t\n\r", false); |
| 973 |
while (st1.hasMoreTokens()) { |
| 974 |
st1.nextToken(); |
| 975 |
count++; |
| 976 |
} |
| 977 |
excludedNamespaces = new String[count]; |
| 978 |
count = 0; |
| 979 |
StringTokenizer st2 = new StringTokenizer(ext, " \t\n\r", false); |
| 980 |
while (st2.hasMoreTokens()) { |
| 981 |
String s = st2.nextToken(); |
| 982 |
if ("#default".equals(s)) { |
| 983 |
s = ""; |
| 984 |
} else if ("#all".equals(s)) { |
| 985 |
compileError("In exclude-result-prefixes, cannot mix #all with other values", "XTSE0020"); |
| 986 |
} |
| 987 |
String uri = getURIForPrefix(s, true); |
| 988 |
if (uri == null) { |
| 989 |
excludedNamespaces = null; |
| 990 |
compileError("Namespace prefix " + s + " is not declared", "XTSE0808"); |
| 991 |
break; |
| 992 |
} |
| 993 |
excludedNamespaces[count++] = uri; |
| 994 |
if (s.isEmpty() && uri.isEmpty()) { |
| 995 |
compileError("Cannot exclude the #default namespace when no default namespace is declared", |
| 996 |
"XTSE0809"); |
| 997 |
} |
| 998 |
} |
| 999 |
} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
protected void processVersionAttribute(String ns) { |
| 1010 |
String v = Whitespace.trim(getAttributeValue(ns, "version")); |
| 1011 |
if (v != null) { |
| 1012 |
ConversionResult val = BigDecimalValue.makeDecimalValue(v, true); |
| 1013 |
if (val instanceof ValidationFailure) { |
| 1014 |
version = 30; |
| 1015 |
compileError("The version attribute must be a decimal literal", "XTSE0110"); |
| 1016 |
} else { |
| 1017 |
|
| 1018 |
version = ((BigDecimalValue) val).getDecimalValue().multiply(BigDecimal.TEN).intValue(); |
| 1019 |
if (version < 20 && version != 10) { |
| 1020 |
|
| 1021 |
|
| 1022 |
issueWarning("Unrecognized version " + val + ": treated as 1.0", this); |
| 1023 |
version = 10; |
| 1024 |
} else if (version > 20 && version < 30) { |
| 1025 |
issueWarning("Unrecognized version " + val + ": treated as 2.0", this); |
| 1026 |
version = 20; |
| 1027 |
} |
| 1028 |
} |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
public int getEffectiveVersion() { |
| 1040 |
if (version == -1) { |
| 1041 |
NodeInfo node = getParent(); |
| 1042 |
if (node instanceof StyleElement) { |
| 1043 |
version = ((StyleElement) node).getEffectiveVersion(); |
| 1044 |
} else { |
| 1045 |
return 20; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
return version; |
| 1049 |
} |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
public String getEffectiveVersionAsString() { |
| 1058 |
return Double.toString(getEffectiveVersion() / 10); |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
protected int validateValidationAttribute(String value) { |
| 1069 |
int code = Validation.getCode(value); |
| 1070 |
if (code == Validation.INVALID) { |
| 1071 |
String prefix = this instanceof LiteralResultElement ? "xsl:" : ""; |
| 1072 |
compileError("Invalid value of " + prefix + "validation attribute: '" + value + "'", "XTSE0020"); |
| 1073 |
code = getDefaultValidation(); |
| 1074 |
} |
| 1075 |
if (!isSchemaAware()) { |
| 1076 |
if (code == Validation.STRICT) { |
| 1077 |
compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660"); |
| 1078 |
} |
| 1079 |
code = Validation.STRIP; |
| 1080 |
} |
| 1081 |
return code; |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
public boolean forwardsCompatibleModeIsEnabled() { |
| 1091 |
return getEffectiveVersion() > 30; |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
public boolean xPath10ModeIsEnabled() { |
| 1102 |
return getEffectiveVersion() < 20; |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
protected void processDefaultCollationAttribute() throws XPathException { |
| 1112 |
String ns = getURI().equals(NamespaceConstant.XSLT) ? "" : NamespaceConstant.XSLT; |
| 1113 |
String v = getAttributeValue(ns, "default-collation"); |
| 1114 |
StringBuilder reasons = new StringBuilder(); |
| 1115 |
if (v != null) { |
| 1116 |
StringTokenizer st = new StringTokenizer(v, " \t\n\r", false); |
| 1117 |
while (st.hasMoreTokens()) { |
| 1118 |
String uri = st.nextToken(); |
| 1119 |
if (uri.equals(NamespaceConstant.CODEPOINT_COLLATION_URI)) { |
| 1120 |
defaultCollationName = uri; |
| 1121 |
return; |
| 1122 |
} else { |
| 1123 |
URI collationURI; |
| 1124 |
try { |
| 1125 |
collationURI = new URI(uri); |
| 1126 |
if (!collationURI.isAbsolute()) { |
| 1127 |
URI base = new URI(getBaseURI()); |
| 1128 |
collationURI = base.resolve(collationURI); |
| 1129 |
uri = collationURI.toString(); |
| 1130 |
} |
| 1131 |
} catch (URISyntaxException err) { |
| 1132 |
compileError("default collation '" + uri + "' is not a valid URI"); |
| 1133 |
uri = NamespaceConstant.CODEPOINT_COLLATION_URI; |
| 1134 |
} |
| 1135 |
|
| 1136 |
try { |
| 1137 |
if (getConfiguration().getCollation(uri) != null) { |
| 1138 |
defaultCollationName = uri; |
| 1139 |
return; |
| 1140 |
} else { |
| 1141 |
if (reasons.length() != 0) { |
| 1142 |
reasons.append("; "); |
| 1143 |
} |
| 1144 |
reasons.append("Collation ").append(uri).append(" is not recognized"); |
| 1145 |
|
| 1146 |
} |
| 1147 |
} catch (XPathException e) { |
| 1148 |
if (reasons.length() != 0) { |
| 1149 |
reasons.append("; "); |
| 1150 |
} |
| 1151 |
reasons.append("Collation ").append(uri).append(" is not recognized (").append(e.getMessage()).append(")"); |
| 1152 |
|
| 1153 |
} |
| 1154 |
|
| 1155 |
} |
| 1156 |
|
| 1157 |
} |
| 1158 |
String msg = "No recognized collation URI found in default-collation attribute"; |
| 1159 |
if (reasons.length() != 0) { |
| 1160 |
msg += ". "; |
| 1161 |
msg += reasons.toString(); |
| 1162 |
} |
| 1163 |
compileErrorInAttribute(msg, "XTSE0125", |
| 1164 |
new StructuredQName("", ns, "default-collation").getClarkName()); |
| 1165 |
} |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
protected String getDefaultCollationName() { |
| 1176 |
StyleElement e = this; |
| 1177 |
while (true) { |
| 1178 |
if (e.defaultCollationName != null) { |
| 1179 |
return e.defaultCollationName; |
| 1180 |
} |
| 1181 |
NodeInfo p = e.getParent(); |
| 1182 |
if (!(p instanceof StyleElement)) { |
| 1183 |
break; |
| 1184 |
} |
| 1185 |
e = (StyleElement) p; |
| 1186 |
} |
| 1187 |
return getConfiguration().getDefaultCollationName(); |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
public StringCollator findCollation(String name, String baseURI) throws XPathException { |
| 1201 |
return getConfiguration().getCollation(name, baseURI); |
| 1202 |
} |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
protected void processDefaultMode() throws XPathException { |
| 1211 |
String ns = getURI().equals(NamespaceConstant.XSLT) ? "" : NamespaceConstant.XSLT; |
| 1212 |
String v = getAttributeValue(ns, "default-mode"); |
| 1213 |
if (v != null) { |
| 1214 |
if (v.equals("#unnamed")) { |
| 1215 |
defaultMode = Mode.UNNAMED_MODE_NAME; |
| 1216 |
} else { |
| 1217 |
defaultMode = makeQName(v); |
| 1218 |
} |
| 1219 |
} |
| 1220 |
PrincipalStylesheetModule psm = compilation.getPrincipalStylesheetModule(); |
| 1221 |
final StructuredQName checkedName = defaultMode; |
| 1222 |
if (psm != null && psm.isDeclaredModes()) { |
| 1223 |
|
| 1224 |
psm.addFixupAction(() -> { |
| 1225 |
if (psm.getRuleManager().obtainMode(checkedName, false) == null) { |
| 1226 |
XPathException err = new XPathException("Mode " + checkedName.getDisplayName() + " is not declared in an xsl:mode declaration", "XTSE3085"); |
| 1227 |
err.setLocation(this); |
| 1228 |
throw err; |
| 1229 |
} |
| 1230 |
}); |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
public StructuredQName getDefaultMode() throws XPathException { |
| 1243 |
if (defaultMode == null) { |
| 1244 |
processDefaultMode(); |
| 1245 |
if (defaultMode == null) { |
| 1246 |
NodeInfo p = getParent(); |
| 1247 |
if (p instanceof StyleElement) { |
| 1248 |
return defaultMode = ((StyleElement) p).getDefaultMode(); |
| 1249 |
} else { |
| 1250 |
return defaultMode = Mode.UNNAMED_MODE_NAME; |
| 1251 |
} |
| 1252 |
} |
| 1253 |
} |
| 1254 |
return defaultMode; |
| 1255 |
} |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
protected boolean definesExtensionElement(String uri) { |
| 1269 |
if (extensionNamespaces == null) { |
| 1270 |
return false; |
| 1271 |
} |
| 1272 |
for (String extensionNamespace : extensionNamespaces) { |
| 1273 |
if (extensionNamespace.equals(uri)) { |
| 1274 |
return true; |
| 1275 |
} |
| 1276 |
} |
| 1277 |
return false; |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
public boolean isExtensionNamespace(String uri) { |
| 1289 |
NodeInfo anc = this; |
| 1290 |
while (anc instanceof StyleElement) { |
| 1291 |
if (((StyleElement) anc).definesExtensionElement(uri)) { |
| 1292 |
return true; |
| 1293 |
} |
| 1294 |
anc = anc.getParent(); |
| 1295 |
} |
| 1296 |
return false; |
| 1297 |
} |
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
protected boolean definesExcludedNamespace(String uri) { |
| 1308 |
if (excludedNamespaces == null) { |
| 1309 |
return false; |
| 1310 |
} |
| 1311 |
for (String excludedNamespace : excludedNamespaces) { |
| 1312 |
if (excludedNamespace.equals(uri)) { |
| 1313 |
return true; |
| 1314 |
} |
| 1315 |
} |
| 1316 |
return false; |
| 1317 |
} |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
public boolean isExcludedNamespace(String uri) { |
| 1330 |
if (uri.equals(NamespaceConstant.XSLT) || uri.equals(NamespaceConstant.XML)) { |
| 1331 |
return true; |
| 1332 |
} |
| 1333 |
if (isExtensionNamespace(uri)) { |
| 1334 |
return true; |
| 1335 |
} |
| 1336 |
NodeInfo anc = this; |
| 1337 |
while (anc instanceof StyleElement) { |
| 1338 |
if (((StyleElement) anc).definesExcludedNamespace(uri)) { |
| 1339 |
return true; |
| 1340 |
} |
| 1341 |
anc = anc.getParent(); |
| 1342 |
} |
| 1343 |
return false; |
| 1344 |
} |
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
protected void processDefaultXPathNamespaceAttribute(String ns) { |
| 1353 |
String v = getAttributeValue(ns, "xpath-default-namespace"); |
| 1354 |
if (v != null) { |
| 1355 |
defaultXPathNamespace = v; |
| 1356 |
} |
| 1357 |
} |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
public String getDefaultXPathNamespace() { |
| 1367 |
NodeInfo anc = this; |
| 1368 |
while (anc instanceof StyleElement) { |
| 1369 |
String x = ((StyleElement) anc).defaultXPathNamespace; |
| 1370 |
if (x != null) { |
| 1371 |
return x; |
| 1372 |
} |
| 1373 |
anc = anc.getParent(); |
| 1374 |
} |
| 1375 |
return NamespaceConstant.NULL; |
| 1376 |
|
| 1377 |
} |
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
protected void processExpandTextAttribute(String ns) { |
| 1386 |
String v = getAttributeValue(ns, "expand-text"); |
| 1387 |
if (v != null) { |
| 1388 |
expandText = processBooleanAttribute("expand-text", v); |
| 1389 |
} else { |
| 1390 |
NodeInfo parent = getParent(); |
| 1391 |
expandText = parent instanceof StyleElement && ((StyleElement) parent).expandText; |
| 1392 |
} |
| 1393 |
} |
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
protected void processDefaultValidationAttribute(String ns) { |
| 1402 |
String v = getAttributeValue(ns, "default-validation"); |
| 1403 |
if (v != null) { |
| 1404 |
int val = Validation.getCode(v); |
| 1405 |
if (val == Validation.STRIP || val == Validation.PRESERVE) { |
| 1406 |
defaultValidation = val; |
| 1407 |
} else { |
| 1408 |
compileErrorInAttribute("@default-validation must be preserve|strip", "XTSE0020", "default-validation"); |
| 1409 |
} |
| 1410 |
} |
| 1411 |
} |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
public boolean isExpandingText() { |
| 1420 |
return expandText; |
| 1421 |
} |
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
public SchemaType getSchemaType(String typeAtt) throws XPathException { |
| 1435 |
try { |
| 1436 |
String uri; |
| 1437 |
String lname; |
| 1438 |
if (typeAtt.startsWith("Q{")) { |
| 1439 |
StructuredQName q = makeQName(typeAtt); |
| 1440 |
uri = q.getURI(); |
| 1441 |
lname = q.getLocalPart(); |
| 1442 |
} else { |
| 1443 |
String[] parts = NameChecker.getQNameParts(typeAtt); |
| 1444 |
lname = parts[1]; |
| 1445 |
if ("".equals(parts[0])) { |
| 1446 |
|
| 1447 |
uri = getDefaultXPathNamespace(); |
| 1448 |
} else { |
| 1449 |
uri = getURIForPrefix(parts[0], false); |
| 1450 |
if (uri == null) { |
| 1451 |
compileError("Namespace prefix for type annotation is undeclared", "XTSE1520"); |
| 1452 |
return null; |
| 1453 |
} |
| 1454 |
} |
| 1455 |
} |
| 1456 |
if (uri.equals(NamespaceConstant.SCHEMA)) { |
| 1457 |
SchemaType t = BuiltInType.getSchemaTypeByLocalName(lname); |
| 1458 |
if (t == null) { |
| 1459 |
compileError("Unknown built-in type " + typeAtt, "XTSE1520"); |
| 1460 |
return null; |
| 1461 |
} |
| 1462 |
return t; |
| 1463 |
} |
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
if (!getPrincipalStylesheetModule().isImportedSchema(uri)) { |
| 1468 |
compileError("There is no imported schema for the namespace of type " + typeAtt, "XTSE1520"); |
| 1469 |
return null; |
| 1470 |
} |
| 1471 |
StructuredQName qName = new StructuredQName("", uri, lname); |
| 1472 |
SchemaType stype = getConfiguration().getSchemaType(qName); |
| 1473 |
if (stype == null) { |
| 1474 |
compileError("There is no type named " + typeAtt + " in an imported schema", "XTSE1520"); |
| 1475 |
} |
| 1476 |
return stype; |
| 1477 |
|
| 1478 |
} catch (QNameException err) { |
| 1479 |
compileError("Invalid type name. " + err.getMessage(), "XTSE1520"); |
| 1480 |
} |
| 1481 |
return null; |
| 1482 |
} |
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
public SimpleType getTypeAnnotation(SchemaType schemaType) { |
| 1492 |
return (SimpleType) schemaType; |
| 1493 |
} |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 1506 |
} |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
public void postValidate() throws XPathException { |
| 1516 |
} |
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
public void index(ComponentDeclaration decl, PrincipalStylesheetModule top) throws XPathException { |
| 1528 |
} |
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
public Expression typeCheck(String name, Expression exp) throws XPathException { |
| 1546 |
|
| 1547 |
if (exp == null) { |
| 1548 |
return null; |
| 1549 |
} |
| 1550 |
Configuration config = getConfiguration(); |
| 1551 |
if (config.getBooleanProperty(Feature.STRICT_STREAMABILITY)) { |
| 1552 |
return exp; |
| 1553 |
} |
| 1554 |
try { |
| 1555 |
exp = exp.typeCheck(makeExpressionVisitor(), config.makeContextItemStaticInfo(Type.ITEM_TYPE, true)); |
| 1556 |
exp = ExpressionTool.resolveCallsToCurrentFunction(exp); |
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
CodeInjector injector = getCompilation().getCompilerInfo().getCodeInjector(); |
| 1565 |
if (injector != null) { |
| 1566 |
return injector.inject(exp, getStaticContext(), LocationKind.XPATH_IN_XSLT, new StructuredQName("", "", name)); |
| 1567 |
} |
| 1568 |
return exp; |
| 1569 |
} catch (XPathException err) { |
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
if (err.isReportableStatically()) { |
| 1574 |
err.setLocation(new AttributeLocation(this, StructuredQName.fromClarkName(name))); |
| 1575 |
compileError(err); |
| 1576 |
return exp; |
| 1577 |
} else { |
| 1578 |
ErrorExpression erexp = new ErrorExpression(err); |
| 1579 |
erexp.setLocation(allocateLocation()); |
| 1580 |
return erexp; |
| 1581 |
} |
| 1582 |
} |
| 1583 |
} |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
public void allocateLocalSlots(Expression exp) { |
| 1592 |
SlotManager slotManager = getContainingSlotManager(); |
| 1593 |
if (slotManager == null) { |
| 1594 |
throw new AssertionError("Slot manager has not been allocated"); |
| 1595 |
} else { |
| 1596 |
int firstSlot = slotManager.getNumberOfVariables(); |
| 1597 |
int highWater = ExpressionTool.allocateSlots(exp, firstSlot, slotManager); |
| 1598 |
if (highWater > firstSlot) { |
| 1599 |
slotManager.setNumberOfVariables(highWater); |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
} |
| 1606 |
} |
| 1607 |
} |
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
public Pattern typeCheck(String name, Pattern pattern) throws XPathException { |
| 1623 |
if (pattern == null) { |
| 1624 |
return null; |
| 1625 |
} |
| 1626 |
try { |
| 1627 |
ItemType cit = Type.ITEM_TYPE; |
| 1628 |
pattern = pattern.typeCheck(makeExpressionVisitor(), getConfiguration().makeContextItemStaticInfo(cit, true)); |
| 1629 |
boolean usesCurrent = false; |
| 1630 |
|
| 1631 |
for (Operand o : pattern.operands()) { |
| 1632 |
Expression filter = o.getChildExpression(); |
| 1633 |
if (ExpressionTool.callsFunction(filter, Current.FN_CURRENT, false)) { |
| 1634 |
usesCurrent = true; |
| 1635 |
break; |
| 1636 |
} |
| 1637 |
} |
| 1638 |
if (usesCurrent) { |
| 1639 |
PatternThatSetsCurrent p2 = new PatternThatSetsCurrent(pattern); |
| 1640 |
pattern.bindCurrent(p2.getCurrentBinding()); |
| 1641 |
pattern = p2; |
| 1642 |
} |
| 1643 |
|
| 1644 |
return pattern; |
| 1645 |
} catch (XPathException err) { |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
if (err.isReportableStatically()) { |
| 1650 |
XPathException e2 = new XPathException("Error in " + name + " pattern", err); |
| 1651 |
e2.setLocator(this); |
| 1652 |
e2.setErrorCodeQName(err.getErrorCodeQName()); |
| 1653 |
throw e2; |
| 1654 |
} else { |
| 1655 |
Pattern p = new BasePatternWithPredicate( |
| 1656 |
new NodeTestPattern(ErrorType.getInstance()), new ErrorExpression(err)); |
| 1657 |
p.setLocation(allocateLocation()); |
| 1658 |
return p; |
| 1659 |
} |
| 1660 |
} |
| 1661 |
} |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
public void fixupReferences() throws XPathException { |
| 1671 |
iterateAxis(AxisInfo.CHILD).forEachOrFail(child -> { |
| 1672 |
if (child instanceof StyleElement) { |
| 1673 |
((StyleElement) child).fixupReferences(); |
| 1674 |
} |
| 1675 |
}); |
| 1676 |
} |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
public SlotManager getContainingSlotManager() { |
| 1686 |
NodeImpl node = this; |
| 1687 |
while (true) { |
| 1688 |
NodeImpl next = node.getParent(); |
| 1689 |
assert next != null; |
| 1690 |
if (next instanceof XSLModuleRoot || next.getFingerprint() == StandardNames.XSL_OVERRIDE) { |
| 1691 |
if (node instanceof StylesheetComponent) { |
| 1692 |
return ((StylesheetComponent) node).getSlotManager(); |
| 1693 |
} else { |
| 1694 |
return null; |
| 1695 |
} |
| 1696 |
} |
| 1697 |
node = next; |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
public void validateSubtree(ComponentDeclaration decl, boolean excludeStylesheet) throws XPathException { |
| 1711 |
if (isActionCompleted(StyleElement.ACTION_VALIDATE)) { |
| 1712 |
return; |
| 1713 |
} |
| 1714 |
setActionCompleted(StyleElement.ACTION_VALIDATE); |
| 1715 |
if (validationError != null) { |
| 1716 |
if (reportingCircumstances == REPORT_ALWAYS) { |
| 1717 |
compileError(validationError); |
| 1718 |
} else if (reportingCircumstances == REPORT_UNLESS_FORWARDS_COMPATIBLE |
| 1719 |
&& !forwardsCompatibleModeIsEnabled()) { |
| 1720 |
compileError(validationError); |
| 1721 |
} else if (reportingCircumstances == REPORT_STATICALLY_UNLESS_FALLBACK_AVAILABLE) { |
| 1722 |
boolean hasFallback = false; |
| 1723 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 1724 |
NodeInfo child; |
| 1725 |
while ((child = kids.next()) != null) { |
| 1726 |
if (child instanceof XSLFallback) { |
| 1727 |
hasFallback = true; |
| 1728 |
((XSLFallback) child).validateSubtree(decl, false); |
| 1729 |
} |
| 1730 |
} |
| 1731 |
if (!hasFallback) { |
| 1732 |
compileError(validationError); |
| 1733 |
} |
| 1734 |
|
| 1735 |
} else if (reportingCircumstances == REPORT_DYNAMICALLY_UNLESS_FALLBACK_AVAILABLE) { |
| 1736 |
iterateAxis(AxisInfo.CHILD).forEachOrFail(child -> { |
| 1737 |
if (child instanceof XSLFallback) { |
| 1738 |
((XSLFallback) child).validateSubtree(decl, false); |
| 1739 |
} |
| 1740 |
}); |
| 1741 |
} |
| 1742 |
} else { |
| 1743 |
try { |
| 1744 |
validate(decl); |
| 1745 |
} catch (XPathException err) { |
| 1746 |
compileError(err); |
| 1747 |
} |
| 1748 |
validateChildren(decl, excludeStylesheet); |
| 1749 |
if (getCompilation().getErrorCount() == 0) { |
| 1750 |
postValidate(); |
| 1751 |
} |
| 1752 |
} |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
protected void validateChildren(ComponentDeclaration decl, boolean excludeStylesheet) throws XPathException { |
| 1765 |
boolean containsInstructions = mayContainSequenceConstructor(); |
| 1766 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 1767 |
StyleElement lastChild = null; |
| 1768 |
boolean endsWithTextTemplate = false; |
| 1769 |
NodeInfo child; |
| 1770 |
while ((child = kids.next()) != null) { |
| 1771 |
if (child instanceof StyleElement) { |
| 1772 |
if (!(excludeStylesheet && child instanceof XSLStylesheet)) { |
| 1773 |
endsWithTextTemplate = false; |
| 1774 |
if (containsInstructions && !((StyleElement) child).isInstruction() |
| 1775 |
&& !isPermittedChild((StyleElement) child)) { |
| 1776 |
((StyleElement) child).compileError("An " + getDisplayName() + " element must not contain an " + |
| 1777 |
child.getDisplayName() + " element", "XTSE0010"); |
| 1778 |
} |
| 1779 |
((StyleElement) child).validateSubtree(decl, excludeStylesheet); |
| 1780 |
lastChild = (StyleElement) child; |
| 1781 |
} |
| 1782 |
} else { |
| 1783 |
endsWithTextTemplate = examineTextNode(child); |
| 1784 |
} |
| 1785 |
} |
| 1786 |
if (lastChild instanceof XSLLocalVariable && |
| 1787 |
!(this instanceof XSLStylesheet) && !endsWithTextTemplate) { |
| 1788 |
lastChild.compileWarning("A variable with no following sibling instructions has no effect", |
| 1789 |
SaxonErrorCode.SXWN9001); |
| 1790 |
} |
| 1791 |
} |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
private boolean examineTextNode(NodeInfo node) throws XPathException { |
| 1801 |
if (node instanceof TextValueTemplateNode) { |
| 1802 |
((TextValueTemplateNode) node).validate(); |
| 1803 |
return !(((TextValueTemplateNode) node).getContentExpression() instanceof Literal); |
| 1804 |
} else { |
| 1805 |
return false; |
| 1806 |
} |
| 1807 |
} |
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
protected boolean isPermittedChild(StyleElement child) { |
| 1818 |
return false; |
| 1819 |
} |
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
public PrincipalStylesheetModule getPrincipalStylesheetModule() { |
| 1829 |
return getCompilation().getPrincipalStylesheetModule(); |
| 1830 |
} |
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
public StylesheetPackage getContainingPackage() { |
| 1840 |
PrincipalStylesheetModule psm = getPrincipalStylesheetModule(); |
| 1841 |
return psm==null ? null : psm.getStylesheetPackage(); |
| 1842 |
} |
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
protected void checkSortComesFirst(boolean sortRequired) { |
| 1851 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 1852 |
boolean sortFound = false; |
| 1853 |
boolean nonSortFound = false; |
| 1854 |
NodeInfo child; |
| 1855 |
while ((child = kids.next()) != null) { |
| 1856 |
if (child instanceof XSLSort) { |
| 1857 |
if (nonSortFound) { |
| 1858 |
((XSLSort) child).compileError("Within " + getDisplayName() + |
| 1859 |
", xsl:sort elements must come before other instructions", "XTSE0010"); |
| 1860 |
} |
| 1861 |
sortFound = true; |
| 1862 |
} else if (child.getNodeKind() == Type.TEXT) { |
| 1863 |
|
| 1864 |
if (!Whitespace.isWhite(child.getStringValueCS())) { |
| 1865 |
nonSortFound = true; |
| 1866 |
} |
| 1867 |
} else { |
| 1868 |
nonSortFound = true; |
| 1869 |
} |
| 1870 |
} |
| 1871 |
if (sortRequired && !sortFound) { |
| 1872 |
compileError(getDisplayName() + " must have at least one xsl:sort child", "XTSE0010"); |
| 1873 |
} |
| 1874 |
} |
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
public void checkTopLevel( String errorCode, boolean allowOverride) { |
| 1886 |
NodeImpl parent = getParent(); |
| 1887 |
assert parent != null; |
| 1888 |
if (parent.getFingerprint() == StandardNames.XSL_OVERRIDE) { |
| 1889 |
if (!allowOverride) { |
| 1890 |
compileError("Element " + getDisplayName() + " is not allowed as a child of xsl:override"); |
| 1891 |
} |
| 1892 |
} else if (!isTopLevel()) { |
| 1893 |
compileError("Element " + getDisplayName() + " must be top-level (a child of xsl:stylesheet, xsl:transform, or xsl:package)", errorCode); |
| 1894 |
} |
| 1895 |
} |
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
public void checkEmpty() { |
| 1902 |
if (hasChildNodes()) { |
| 1903 |
compileError("Element must be empty", "XTSE0260"); |
| 1904 |
} |
| 1905 |
} |
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
public void reportAbsence(String attribute) { |
| 1914 |
compileError("Element must have an " + Err.wrap(attribute, Err.ATTRIBUTE) + " attribute", "XTSE0010"); |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
public Expression compile(Compilation compilation, ComponentDeclaration decl) throws XPathException { |
| 1931 |
|
| 1932 |
return null; |
| 1933 |
} |
| 1934 |
|
| 1935 |
protected boolean isWithinDeclaredStreamableConstruct() { |
| 1936 |
String streamableAtt = getAttributeValue("streamable"); |
| 1937 |
if (streamableAtt != null) { |
| 1938 |
return processStreamableAtt(streamableAtt); |
| 1939 |
} |
| 1940 |
NodeInfo parent = getParent(); |
| 1941 |
return parent instanceof StyleElement && ((StyleElement) parent).isWithinDeclaredStreamableConstruct(); |
| 1942 |
} |
| 1943 |
|
| 1944 |
protected String generateId() { |
| 1945 |
FastStringBuffer buff = new FastStringBuffer(FastStringBuffer.C16); |
| 1946 |
generateId(buff); |
| 1947 |
return buff.toString(); |
| 1948 |
} |
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
public void compileDeclaration(Compilation compilation, ComponentDeclaration decl) throws XPathException { |
| 1960 |
|
| 1961 |
} |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
public Expression compileSequenceConstructor(Compilation compilation, ComponentDeclaration decl, |
| 1976 |
boolean includeParams) |
| 1977 |
throws XPathException { |
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
boolean containsEmptyTest = false; |
| 1988 |
boolean containsLocalVariable = false; |
| 1989 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 1990 |
NodeInfo child; |
| 1991 |
while ((child = kids.next()) != null) { |
| 1992 |
int fp = child.getFingerprint(); |
| 1993 |
if (fp == StandardNames.XSL_VARIABLE) { |
| 1994 |
containsLocalVariable = true; |
| 1995 |
} |
| 1996 |
if (fp == StandardNames.XSL_ON_EMPTY || fp == StandardNames.XSL_ON_NON_EMPTY) { |
| 1997 |
containsEmptyTest = true; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
if (containsEmptyTest) { |
| 2001 |
List<NodeInfo> vars = new ArrayList<>(); |
| 2002 |
List<NodeInfo> onEmpties = new ArrayList<>(); |
| 2003 |
List<NodeInfo> others = new ArrayList<>(); |
| 2004 |
iterateAxis(AxisInfo.CHILD).forEach(kid -> { |
| 2005 |
int fp = kid.getFingerprint(); |
| 2006 |
if (fp == StandardNames.XSL_VARIABLE || fp == StandardNames.XSL_PARAM) { |
| 2007 |
vars.add(kid); |
| 2008 |
} else if (fp == StandardNames.XSL_ON_EMPTY) { |
| 2009 |
onEmpties.add(kid); |
| 2010 |
} else { |
| 2011 |
others.add(kid); |
| 2012 |
} |
| 2013 |
}); |
| 2014 |
vars.addAll(others); |
| 2015 |
vars.addAll(onEmpties); |
| 2016 |
return compileSequenceConstructor(compilation, decl, new ListIterator<>(vars), includeParams); |
| 2017 |
} else { |
| 2018 |
return compileSequenceConstructor(compilation, decl, iterateAxis(AxisInfo.CHILD), includeParams); |
| 2019 |
} |
| 2020 |
} |
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
public Expression compileSequenceConstructor(Compilation compilation, ComponentDeclaration decl, |
| 2039 |
SequenceIterator iter, boolean includeParams) |
| 2040 |
throws XPathException { |
| 2041 |
|
| 2042 |
Location locationId = allocateLocation(); |
| 2043 |
List<Expression> contents = new ArrayList<>(10); |
| 2044 |
boolean containsSpecials = false; |
| 2045 |
NodeInfo node; |
| 2046 |
while ((node = (NodeInfo) iter.next()) != null) { |
| 2047 |
if (node.getNodeKind() == Type.TEXT) { |
| 2048 |
if (isExpandingText()) { |
| 2049 |
compileContentValueTemplate((TextImpl) node, contents); |
| 2050 |
} else { |
| 2051 |
|
| 2052 |
AxisIterator lookahead = node.iterateAxis(AxisInfo.FOLLOWING_SIBLING); |
| 2053 |
NodeInfo sibling = lookahead.next(); |
| 2054 |
if (!(sibling instanceof XSLLocalParam || sibling instanceof XSLSort |
| 2055 |
|| sibling instanceof XSLContextItem || sibling instanceof XSLOnCompletion)) { |
| 2056 |
|
| 2057 |
|
| 2058 |
Expression text = new ValueOf(new StringLiteral(node.getStringValue()), false, false); |
| 2059 |
text.setLocation(allocateLocation()); |
| 2060 |
|
| 2061 |
CodeInjector injector = getCompilation().getCompilerInfo().getCodeInjector(); |
| 2062 |
if (injector != null) { |
| 2063 |
Expression tracer = injector.inject(text, getStaticContext(), StandardNames.XSL_TEXT, null); |
| 2064 |
tracer.setLocation(text.getLocation()); |
| 2065 |
text = tracer; |
| 2066 |
} |
| 2067 |
|
| 2068 |
contents.add(text); |
| 2069 |
} |
| 2070 |
} |
| 2071 |
|
| 2072 |
} else if (node instanceof XSLLocalVariable) { |
| 2073 |
XSLLocalVariable var = (XSLLocalVariable) node; |
| 2074 |
SourceBinding sourceBinding = var.getSourceBinding(); |
| 2075 |
var.compileLocalVariable(compilation, decl); |
| 2076 |
|
| 2077 |
Expression tail = compileSequenceConstructor(compilation, decl, iter, includeParams); |
| 2078 |
if (tail == null || Literal.isEmptySequence(tail)) { |
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
} else { |
| 2083 |
LetExpression let = new LetExpression(); |
| 2084 |
let.setInstruction(true); |
| 2085 |
let.setRequiredType(var.getRequiredType()); |
| 2086 |
let.setVariableQName(sourceBinding.getVariableQName()); |
| 2087 |
let.setSequence(sourceBinding.getSelectExpression()); |
| 2088 |
let.setAction(tail); |
| 2089 |
sourceBinding.fixupBinding(let); |
| 2090 |
locationId = ((StyleElement) node).allocateLocation(); |
| 2091 |
let.setLocation(locationId); |
| 2092 |
if (getCompilation().getCompilerInfo().isCompileWithTracing()) { |
| 2093 |
TraceExpression t = new TraceExpression(let); |
| 2094 |
t.setConstructType(LocationKind.LET_EXPRESSION); |
| 2095 |
t.setObjectName(var.getSourceBinding().getVariableQName()); |
| 2096 |
t.setNamespaceResolver(getNamespaceResolver()); |
| 2097 |
contents.add(t); |
| 2098 |
} else { |
| 2099 |
contents.add(let); |
| 2100 |
} |
| 2101 |
if (var.changesRetainedStaticContext()) { |
| 2102 |
let.setRetainedStaticContext(makeRetainedStaticContext()); |
| 2103 |
} |
| 2104 |
|
| 2105 |
} |
| 2106 |
|
| 2107 |
|
| 2108 |
} else if (node instanceof StyleElement) { |
| 2109 |
StyleElement snode = (StyleElement) node; |
| 2110 |
int fp = snode.getFingerprint(); |
| 2111 |
if (fp == StandardNames.XSL_ON_EMPTY || fp == StandardNames.XSL_ON_NON_EMPTY) { |
| 2112 |
containsSpecials = true; |
| 2113 |
} |
| 2114 |
Expression child; |
| 2115 |
if (snode.validationError != null && !(snode instanceof AbsentExtensionElement)) { |
| 2116 |
if (snode.reportingCircumstances == REPORT_IF_INSTANTIATED) { |
| 2117 |
child = new ErrorExpression(snode.validationError); |
| 2118 |
} else { |
| 2119 |
child = fallbackProcessing(compilation, decl, snode); |
| 2120 |
} |
| 2121 |
|
| 2122 |
} else { |
| 2123 |
child = snode.compile(compilation, decl); |
| 2124 |
if (child != null) { |
| 2125 |
if (snode.changesRetainedStaticContext()) { |
| 2126 |
child.setRetainedStaticContext(snode.makeRetainedStaticContext()); |
| 2127 |
} |
| 2128 |
if ((includeParams || !(node instanceof XSLLocalParam)) |
| 2129 |
&& getCompilation().getCompilerInfo().isCompileWithTracing()) { |
| 2130 |
child = makeTraceInstruction(snode, child); |
| 2131 |
} |
| 2132 |
} |
| 2133 |
} |
| 2134 |
if (child != null) { |
| 2135 |
contents.add(child); |
| 2136 |
} |
| 2137 |
} |
| 2138 |
} |
| 2139 |
if (containsSpecials) { |
| 2140 |
return new ConditionalBlock(contents); |
| 2141 |
} |
| 2142 |
Expression block = Block.makeBlock(contents); |
| 2143 |
if (block.getLocation() == null) { |
| 2144 |
block.setLocation(locationId); |
| 2145 |
} |
| 2146 |
if (block.getLocalRetainedStaticContext() == null) { |
| 2147 |
block.setRetainedStaticContext(makeRetainedStaticContext()); |
| 2148 |
} |
| 2149 |
return block; |
| 2150 |
} |
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
public void compileContentValueTemplate(TextImpl node, List<Expression> contents) { |
| 2161 |
if (node instanceof TextValueTemplateNode) { |
| 2162 |
Expression exp = ((TextValueTemplateNode) node).getContentExpression(); |
| 2163 |
if (getConfiguration().getBooleanProperty(Feature.STRICT_STREAMABILITY) && !(exp instanceof Literal)) { |
| 2164 |
exp = new SequenceInstr(exp); |
| 2165 |
} |
| 2166 |
contents.add(exp); |
| 2167 |
} else { |
| 2168 |
contents.add(new StringLiteral(node.getStringValue())); |
| 2169 |
} |
| 2170 |
} |
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
protected static Expression makeTraceInstruction(StyleElement source, Expression child) { |
| 2182 |
if (child instanceof TraceExpression && !(source instanceof StylesheetComponent)) { |
| 2183 |
return child; |
| 2184 |
|
| 2185 |
} |
| 2186 |
if (source instanceof XSLOnEmpty || source instanceof XSLOnNonEmpty) { |
| 2187 |
|
| 2188 |
return child; |
| 2189 |
} |
| 2190 |
CodeInjector injector = source.getCompilation().getCompilerInfo().getCodeInjector(); |
| 2191 |
if (injector != null) { |
| 2192 |
int construct = source.getFingerprint(); |
| 2193 |
if (source instanceof LiteralResultElement) { |
| 2194 |
construct = LocationKind.LITERAL_RESULT_ELEMENT; |
| 2195 |
} |
| 2196 |
Expression tracer = injector.inject(child, source.getStaticContext(), construct, source.getObjectName()); |
| 2197 |
tracer.setLocation(source.allocateLocation()); |
| 2198 |
return tracer; |
| 2199 |
} |
| 2200 |
return child; |
| 2201 |
} |
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
protected Expression fallbackProcessing(Compilation exec, ComponentDeclaration decl, StyleElement instruction) |
| 2215 |
throws XPathException { |
| 2216 |
|
| 2217 |
|
| 2218 |
Expression fallback = null; |
| 2219 |
AxisIterator kids = instruction.iterateAxis(AxisInfo.CHILD); |
| 2220 |
NodeInfo child; |
| 2221 |
while ((child = kids.next()) != null) { |
| 2222 |
if (child instanceof XSLFallback) { |
| 2223 |
|
| 2224 |
|
| 2225 |
Expression b = ((XSLFallback) child).compileSequenceConstructor(exec, decl, true); |
| 2226 |
if (b == null) { |
| 2227 |
b = Literal.makeEmptySequence(); |
| 2228 |
} |
| 2229 |
if (fallback == null) { |
| 2230 |
fallback = b; |
| 2231 |
} else { |
| 2232 |
fallback = Block.makeBlock(fallback, b); |
| 2233 |
fallback.setLocation( |
| 2234 |
allocateLocation()); |
| 2235 |
} |
| 2236 |
} |
| 2237 |
} |
| 2238 |
if (fallback != null) { |
| 2239 |
return fallback; |
| 2240 |
} else { |
| 2241 |
return new ErrorExpression(instruction.validationError); |
| 2242 |
|
| 2243 |
|
| 2244 |
} |
| 2245 |
|
| 2246 |
} |
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
protected Location allocateLocation() { |
| 2255 |
if (savedLocation == null) { |
| 2256 |
savedLocation = new ExplicitLocation(this); |
| 2257 |
} |
| 2258 |
return savedLocation; |
| 2259 |
} |
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
public SortKeyDefinitionList makeSortKeys(Compilation compilation, ComponentDeclaration decl) throws XPathException { |
| 2272 |
|
| 2273 |
|
| 2274 |
int numberOfSortKeys = 0; |
| 2275 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 2276 |
NodeInfo child; |
| 2277 |
while ((child = kids.next()) != null) { |
| 2278 |
if (child instanceof XSLSortOrMergeKey) { |
| 2279 |
((XSLSortOrMergeKey) child).compile(compilation, decl); |
| 2280 |
if (child instanceof XSLSort) { |
| 2281 |
if (numberOfSortKeys != 0 && ((XSLSort) child).getStable() != null) { |
| 2282 |
compileError("stable attribute may appear only on the first xsl:sort element", "XTSE1017"); |
| 2283 |
} |
| 2284 |
} |
| 2285 |
numberOfSortKeys++; |
| 2286 |
} |
| 2287 |
} |
| 2288 |
|
| 2289 |
if (numberOfSortKeys > 0) { |
| 2290 |
SortKeyDefinition[] keys = new SortKeyDefinition[numberOfSortKeys]; |
| 2291 |
kids = iterateAxis(AxisInfo.CHILD); |
| 2292 |
int k = 0; |
| 2293 |
while ((child = kids.next()) != null) { |
| 2294 |
if (child instanceof XSLSortOrMergeKey) { |
| 2295 |
keys[k++] = (SortKeyDefinition) ((XSLSortOrMergeKey) child).getSortKeyDefinition().simplify(); |
| 2296 |
} |
| 2297 |
} |
| 2298 |
return new SortKeyDefinitionList(keys); |
| 2299 |
|
| 2300 |
} else { |
| 2301 |
return null; |
| 2302 |
} |
| 2303 |
} |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
protected StructuredQName[] getUsedAttributeSets(String use) { |
| 2315 |
|
| 2316 |
List<StructuredQName> nameList = new ArrayList<>(4); |
| 2317 |
StringTokenizer st = new StringTokenizer(use, " \t\n\r", false); |
| 2318 |
while (st.hasMoreTokens()) { |
| 2319 |
String asetname = st.nextToken(); |
| 2320 |
StructuredQName name; |
| 2321 |
try { |
| 2322 |
name = makeQName(asetname); |
| 2323 |
} catch (XPathException err) { |
| 2324 |
compileError(err.getMessage(), "XTSE0710"); |
| 2325 |
name = null; |
| 2326 |
} |
| 2327 |
nameList.add(name); |
| 2328 |
} |
| 2329 |
return nameList.toArray(new StructuredQName[0]); |
| 2330 |
} |
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
protected Visibility interpretVisibilityValue(String s, String flags) { |
| 2342 |
for (Visibility v : Visibility.values()) { |
| 2343 |
if (v.visibilityStr.equals(s) && |
| 2344 |
(flags.contains("h") || !s.equals("hidden")) && |
| 2345 |
(flags.contains("a") || !s.equals("absent"))) { |
| 2346 |
return v; |
| 2347 |
} |
| 2348 |
} |
| 2349 |
invalidAttribute("visibility", "public|final|private|abstract" + |
| 2350 |
(flags.contains("h") ? "|hidden" : "") + |
| 2351 |
(flags.contains("a") ? "|absent" : "") |
| 2352 |
); |
| 2353 |
return null; |
| 2354 |
} |
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
public WithParam[] getWithParamInstructions(Expression parent, Compilation compilation, ComponentDeclaration decl, boolean tunnel) |
| 2371 |
throws XPathException { |
| 2372 |
int count = 0; |
| 2373 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 2374 |
NodeInfo child; |
| 2375 |
while ((child = kids.next()) != null) { |
| 2376 |
if (child instanceof XSLWithParam) { |
| 2377 |
XSLWithParam wp = (XSLWithParam) child; |
| 2378 |
if (wp.getSourceBinding().hasProperty(SourceBinding.TUNNEL) == tunnel) { |
| 2379 |
count++; |
| 2380 |
} |
| 2381 |
} |
| 2382 |
} |
| 2383 |
if (count == 0) { |
| 2384 |
return WithParam.EMPTY_ARRAY; |
| 2385 |
} |
| 2386 |
WithParam[] array = new WithParam[count]; |
| 2387 |
count = 0; |
| 2388 |
kids = iterateAxis(AxisInfo.CHILD); |
| 2389 |
while ((child = kids.next()) != null) { |
| 2390 |
if (child instanceof XSLWithParam) { |
| 2391 |
XSLWithParam wp = (XSLWithParam) child; |
| 2392 |
if (wp.getSourceBinding().hasProperty(SourceBinding.TUNNEL) == tunnel) { |
| 2393 |
WithParam p = wp.compileWithParam(parent, compilation, decl); |
| 2394 |
array[count++] = p; |
| 2395 |
} |
| 2396 |
} |
| 2397 |
} |
| 2398 |
return array; |
| 2399 |
} |
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
public void compileError(XPathException error) { |
| 2408 |
error.setIsStaticError(true); |
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
if (error.getLocator() == null || |
| 2413 |
((error.getLocator() instanceof ExplicitLocation || |
| 2414 |
error.getLocator() instanceof Expression) && !(this instanceof StylesheetComponent))) { |
| 2415 |
error.setLocator(this); |
| 2416 |
} |
| 2417 |
|
| 2418 |
if (error.getLocator() instanceof AttributeLocation) { |
| 2419 |
((AttributeLocation) error.getLocator()).setElementNode(this); |
| 2420 |
} |
| 2421 |
if (error.getLocator() instanceof XPathParser.NestedLocation) { |
| 2422 |
Location container = ((XPathParser.NestedLocation) error.getLocator()).getContainingLocation(); |
| 2423 |
if (container instanceof AttributeLocation) { |
| 2424 |
((AttributeLocation) container).setElementNode(this); |
| 2425 |
} |
| 2426 |
} |
| 2427 |
getCompilation().reportError(error); |
| 2428 |
} |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
public void compileError(String message) { |
| 2437 |
compileError(message, "XTSE0010"); |
| 2438 |
} |
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
public void compileError(String message, StructuredQName errorCode) { |
| 2448 |
XPathException tce = new XPathException(message); |
| 2449 |
tce.setErrorCodeQName(errorCode); |
| 2450 |
tce.setLocator(this); |
| 2451 |
compileError(tce); |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
public void compileError(String message, String errorCode) { |
| 2462 |
compileError(new XPathException(message, errorCode, this)); |
| 2463 |
} |
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
public void compileErrorInAttribute(String message, String errorCode, String attributeName) { |
| 2477 |
StructuredQName att = StructuredQName.fromClarkName(attributeName); |
| 2478 |
Location location = new AttributeLocation(this, att); |
| 2479 |
compileError(new XPathException(message, errorCode, location)); |
| 2480 |
} |
| 2481 |
|
| 2482 |
protected void invalidAttribute(String attributeName, String allowedValues) { |
| 2483 |
compileErrorInAttribute("Attribute " + getDisplayName() + "/@" + attributeName + " must be " + allowedValues, |
| 2484 |
"XTSE0020", attributeName); |
| 2485 |
} |
| 2486 |
|
| 2487 |
protected void undeclaredNamespaceError(String prefix, String errorCode, String attributeName) { |
| 2488 |
if (errorCode == null) { |
| 2489 |
errorCode = "XTSE0280"; |
| 2490 |
} |
| 2491 |
compileErrorInAttribute("Undeclared namespace prefix " + Err.wrap(prefix), errorCode, attributeName); |
| 2492 |
} |
| 2493 |
|
| 2494 |
public void compileWarning(String message, StructuredQName errorCode) { |
| 2495 |
XPathException tce = new XPathException(message); |
| 2496 |
tce.setErrorCodeQName(errorCode); |
| 2497 |
tce.setLocator(this); |
| 2498 |
getCompilation().reportWarning(tce); |
| 2499 |
} |
| 2500 |
|
| 2501 |
public void compileWarning(String message, String errorCode) { |
| 2502 |
XPathException tce = new XPathException(message); |
| 2503 |
tce.setErrorCode(errorCode); |
| 2504 |
tce.setLocator(this); |
| 2505 |
getCompilation().reportWarning(tce); |
| 2506 |
} |
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
protected void issueWarning(XPathException error) { |
| 2515 |
if (error.getLocator() == null) { |
| 2516 |
error.setLocator(this); |
| 2517 |
} |
| 2518 |
getCompilation().reportWarning(error); |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
protected void issueWarning(String message, SourceLocator locator) { |
| 2529 |
XPathException tce = new XPathException(message); |
| 2530 |
if (locator == null) { |
| 2531 |
tce.setLocator(this); |
| 2532 |
} else { |
| 2533 |
tce.setLocator(locator); |
| 2534 |
} |
| 2535 |
issueWarning(tce); |
| 2536 |
} |
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
public boolean isTopLevel() { |
| 2545 |
return getParent() instanceof XSLModuleRoot; |
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
public boolean isConstructingComplexContent() { |
| 2558 |
if (!isInstruction()) { |
| 2559 |
return false; |
| 2560 |
} |
| 2561 |
NodeInfo parent = getParent(); |
| 2562 |
while (true) { |
| 2563 |
if (!(parent instanceof StyleElement && ((StyleElement) parent).isInstruction())) { |
| 2564 |
return false; |
| 2565 |
} |
| 2566 |
if (parent instanceof XSLGeneralVariable) { |
| 2567 |
return ((XSLGeneralVariable) parent).getAttributeValue("as") == null; |
| 2568 |
} |
| 2569 |
if (parent instanceof XSLElement || parent instanceof LiteralResultElement || parent instanceof XSLDocument || parent instanceof XSLCopy) { |
| 2570 |
return true; |
| 2571 |
} |
| 2572 |
parent = parent.getParent(); |
| 2573 |
} |
| 2574 |
} |
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
public SourceBinding getBindingInformation(StructuredQName name) { |
| 2585 |
return null; |
| 2586 |
} |
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
public SourceBinding bindVariable(StructuredQName qName) { |
| 2598 |
|
| 2599 |
SourceBinding decl = bindLocalVariable(qName); |
| 2600 |
if (decl != null) { |
| 2601 |
return decl; |
| 2602 |
} |
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
SourceBinding binding = getPrincipalStylesheetModule().getGlobalVariableBinding(qName); |
| 2607 |
if (binding == null || Navigator.isAncestorOrSelf(binding.getSourceElement(), this)) { |
| 2608 |
|
| 2609 |
return null; |
| 2610 |
} else { |
| 2611 |
return binding; |
| 2612 |
} |
| 2613 |
} |
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
public SourceBinding bindLocalVariable(StructuredQName qName) { |
| 2625 |
NodeInfo curr = this; |
| 2626 |
NodeInfo prev = this; |
| 2627 |
|
| 2628 |
SourceBinding implicit = hasImplicitBinding(qName); |
| 2629 |
if (implicit != null) { |
| 2630 |
return implicit; |
| 2631 |
} |
| 2632 |
|
| 2633 |
|
| 2634 |
if (!isTopLevel()) { |
| 2635 |
AxisIterator preceding = curr.iterateAxis(AxisInfo.PRECEDING_SIBLING); |
| 2636 |
while (true) { |
| 2637 |
curr = preceding.next(); |
| 2638 |
while (curr == null) { |
| 2639 |
curr = prev.getParent(); |
| 2640 |
if (curr instanceof StyleElement) { |
| 2641 |
implicit = ((StyleElement) curr).hasImplicitBinding(qName); |
| 2642 |
if (implicit != null) { |
| 2643 |
return implicit; |
| 2644 |
} |
| 2645 |
} |
| 2646 |
while (curr instanceof StyleElement && !((StyleElement) curr).seesAvuncularVariables()) { |
| 2647 |
|
| 2648 |
curr = curr.getParent(); |
| 2649 |
} |
| 2650 |
prev = curr; |
| 2651 |
if (curr.getParent() instanceof XSLModuleRoot) { |
| 2652 |
break; |
| 2653 |
} |
| 2654 |
preceding = curr.iterateAxis(AxisInfo.PRECEDING_SIBLING); |
| 2655 |
curr = preceding.next(); |
| 2656 |
} |
| 2657 |
if (curr.getParent() instanceof XSLModuleRoot) { |
| 2658 |
break; |
| 2659 |
} |
| 2660 |
if (curr instanceof XSLGeneralVariable) { |
| 2661 |
SourceBinding sourceBinding = ((XSLGeneralVariable) curr).getBindingInformation(qName); |
| 2662 |
if (sourceBinding != null) { |
| 2663 |
return sourceBinding; |
| 2664 |
} |
| 2665 |
} |
| 2666 |
|
| 2667 |
} |
| 2668 |
} |
| 2669 |
return null; |
| 2670 |
} |
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
protected boolean seesAvuncularVariables() { |
| 2679 |
return true; |
| 2680 |
} |
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
protected SourceBinding hasImplicitBinding(StructuredQName name) { |
| 2687 |
return null; |
| 2688 |
} |
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
public int getConstructType() { |
| 2696 |
return getFingerprint(); |
| 2697 |
} |
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
public StructuredQName getObjectName() { |
| 2708 |
return objectName; |
| 2709 |
} |
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
public void setObjectName(StructuredQName qName) { |
| 2718 |
objectName = qName; |
| 2719 |
} |
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
public Object getProperty(String name) { |
| 2732 |
return getAttributeValue("", name); |
| 2733 |
} |
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
public Iterator<String> getProperties() { |
| 2742 |
List<String> list = new ArrayList<>(10); |
| 2743 |
iterateAxis(AxisInfo.ATTRIBUTE).forEach(a -> |
| 2744 |
list.add(NameOfNode.makeName(a).getStructuredQName().getClarkName()) |
| 2745 |
); |
| 2746 |
return list.iterator(); |
| 2747 |
} |
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
public boolean isActionCompleted(int action) { |
| 2757 |
return (actionsCompleted & action) != 0; |
| 2758 |
} |
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
public void setActionCompleted(int action) { |
| 2767 |
actionsCompleted |= action; |
| 2768 |
} |
| 2769 |
|
| 2770 |
} |
| 2771 |
|