1 package net.sf.saxon.style; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.PreparedStylesheet; 5 import net.sf.saxon.event.SaxonOutputKeys; 6 import net.sf.saxon.value.Whitespace; 7 import net.sf.saxon.expr.ComputedExpression; 8 import net.sf.saxon.expr.Expression; 9 import net.sf.saxon.functions.*; 10 import net.sf.saxon.instruct.Executable; 11 import net.sf.saxon.instruct.LocationMap; 12 import net.sf.saxon.om.*; 13 import net.sf.saxon.query.XQueryFunction; 14 import net.sf.saxon.query.XQueryFunctionLibrary; 15 import net.sf.saxon.sort.CodepointCollator; 16 import net.sf.saxon.trans.*; 17 import net.sf.saxon.type.SchemaException; 18 import net.sf.saxon.type.Type; 19 20 import java.util.*; 21 22 27 28 public class XSLStylesheet extends StyleElement { 29 30 Executable exec = new Executable(); 31 32 private LocationMap locationMap = new LocationMap(); 34 35 private HashMap globalVariableIndex = new HashMap(20); 39 40 private NamePool targetNamePool; 43 44 private boolean wasIncluded = false; 47 48 private int precedence = 0; 50 51 private int minImportPrecedence = 0; 53 54 private XSLStylesheet importer = null; 56 57 private PreparedStylesheet stylesheet; 59 60 private List topLevel; 62 63 private HashMap templateIndex = new HashMap(20); 66 67 private int inputAnnotations = 0; 71 public static final int ANNOTATION_STRIP = 1; 72 public static final int ANNOTATION_PRESERVE = 2; 73 74 private HashSet schemaIndex = new HashSet(10); 76 77 private XQueryFunctionLibrary queryFunctions; 79 80 private FunctionLibrary javaFunctions; 82 83 86 private int numberOfAliases = 0; 88 private ArrayList namespaceAliasList = new ArrayList(5); 89 private short[] aliasSCodes; 90 private int[] aliasNCodes; 91 92 private int largestPatternStackFrame = 0; 94 95 private int defaultValidation = Validation.STRIP; 97 98 private FunctionLibraryList functionLibrary; 100 101 104 105 public void setPreparedStylesheet(PreparedStylesheet sheet) { 106 Configuration config = sheet.getConfiguration(); 107 stylesheet = sheet; 108 targetNamePool = sheet.getTargetNamePool(); 109 exec.setConfiguration(config); 110 exec.setRuleManager(new RuleManager()); 111 exec.setLocationMap(locationMap); 112 exec.setHostLanguage(Configuration.XSLT); 113 114 functionLibrary = new FunctionLibraryList(); 115 functionLibrary.addFunctionLibrary(new SystemFunctionLibrary(SystemFunctionLibrary.FULL_XSLT)); 116 functionLibrary.addFunctionLibrary(new StylesheetFunctionLibrary(this, true)); 117 functionLibrary.addFunctionLibrary(config.getVendorFunctionLibrary()); 118 functionLibrary.addFunctionLibrary(new ConstructorFunctionLibrary(config)); 119 queryFunctions = new XQueryFunctionLibrary(config, false); 120 functionLibrary.addFunctionLibrary(queryFunctions); 121 if (config.isAllowExternalFunctions()) { 122 javaFunctions = config.getExtensionBinder(); 123 functionLibrary.addFunctionLibrary(javaFunctions); 124 } 125 functionLibrary.addFunctionLibrary(new StylesheetFunctionLibrary(this, false)); 126 127 } 128 129 132 133 public PreparedStylesheet getPreparedStylesheet() { 134 if (importer != null) { 135 return importer.getPreparedStylesheet(); 136 } 137 return stylesheet; 138 } 139 140 143 144 public Executable getExecutable() { 145 return exec; 146 } 147 148 151 152 public FunctionLibrary getFunctionLibrary() { 153 return functionLibrary; 154 } 155 156 159 160 public LocationMap getLocationMap() { 161 return locationMap; 162 } 163 164 168 169 public NamePool getTargetNamePool() { 170 return targetNamePool; 171 } 172 173 176 177 public RuleManager getRuleManager() { 178 return exec.getRuleManager(); 179 } 180 181 184 185 protected Mode getStripperRules() { 186 if (exec.getStripperRules() == null) { 187 exec.setStripperRules(new Mode(Mode.STRIPPER_MODE)); 188 } 189 return exec.getStripperRules(); 190 } 191 192 195 196 public boolean stripsWhitespace() { 197 for (int i = 0; i < topLevel.size(); i++) { 198 NodeInfo s = (NodeInfo) topLevel.get(i); 199 if (s.getFingerprint() == StandardNames.XSL_STRIP_SPACE) { 200 return true; 201 } 202 } 203 return false; 204 } 205 206 209 210 public KeyManager getKeyManager() { 211 if (exec.getKeyManager() == null) { 212 exec.setKeyManager(new KeyManager(getConfiguration())); 213 } 214 return exec.getKeyManager(); 215 } 216 217 220 221 public DecimalFormatManager getDecimalFormatManager() { 222 if (exec.getDecimalFormatManager() == null) { 223 exec.setDecimalFormatManager(new DecimalFormatManager()); 224 } 225 return exec.getDecimalFormatManager(); 226 } 227 228 231 232 public void setCollation(String name, Comparator collation, boolean isDefault) { 233 if (exec.getCollationTable() == null) { 234 exec.setCollationTable(new HashMap(20)); 235 } 236 exec.getCollationTable().put(name, collation); 237 if (isDefault) { 238 exec.setDefaultCollationName(name); 239 } 240 } 241 242 249 250 protected Comparator findCollation(String name) { 251 252 if (name.equals(NamespaceConstant.CODEPOINT_COLLATION_URI)) { 253 return CodepointCollator.getInstance(); 254 } 255 256 258 Comparator c = null; 259 if (name == null) { 260 name = exec.getDefaultCollationName(); 261 } 262 if (exec.getCollationTable() != null) { 263 c = (Comparator) exec.getCollationTable().get(name); 264 } 265 if (c != null) return c; 266 267 269 XSLStylesheet stylesheet = getPrincipalStylesheet(); 270 List toplevel = stylesheet.getTopLevel(); 271 272 for (int i = toplevel.size() - 1; i >= 0; i--) { 275 if (toplevel.get(i) instanceof SaxonCollation) { 276 SaxonCollation t = (SaxonCollation) toplevel.get(i); 277 if (name == null && t.isDefaultCollation()) { 278 exec.setDefaultCollationName(t.getCollationName()); 279 return t.getCollator(); 280 } else if (t.getCollationName().equals(name)) { 281 return t.getCollator(); 282 } 283 } 284 } 285 286 288 if (name == null) { 289 return null; 290 } 291 292 Configuration config = getConfiguration(); 293 return config.getCollationURIResolver().resolve(name, getBaseURI(), config); 294 } 295 296 299 300 public String getDefaultCollationName() { 301 return exec.getDefaultCollationName(); 302 } 303 304 311 312 public XSLCharacterMap getCharacterMap(int fingerprint) { 313 for (int i = topLevel.size() - 1; i >= 0; i--) { 314 if (topLevel.get(i) instanceof XSLCharacterMap) { 315 XSLCharacterMap t = (XSLCharacterMap) topLevel.get(i); 316 if (t.getCharacterMapFingerprint() == fingerprint) { 317 return t; 318 } 319 } 320 } 321 return null; 322 } 323 324 327 328 public void setPrecedence(int prec) { 329 precedence = prec; 330 } 331 332 335 336 public int getPrecedence() { 337 if (wasIncluded) return importer.getPrecedence(); 338 return precedence; 339 } 340 341 345 346 public int getMinImportPrecedence() { 347 return minImportPrecedence; 348 } 349 350 354 355 public void setMinImportPrecedence(int precedence) { 356 minImportPrecedence = precedence; 357 } 358 359 362 363 public void setImporter(XSLStylesheet importer) { 364 this.importer = importer; 365 } 366 367 371 372 public XSLStylesheet getImporter() { 373 return importer; 374 } 375 376 380 381 public void setWasIncluded() { 382 wasIncluded = true; 383 } 384 385 388 389 public List getTopLevel() { 390 return topLevel; 391 } 392 393 396 397 public int allocateGlobalSlot(int fingerprint) { 398 return exec.getGlobalVariableMap().allocateSlotNumber(fingerprint); 399 } 400 401 405 406 public void allocatePatternSlots(int n) { 407 if (n > largestPatternStackFrame) { 408 largestPatternStackFrame = n; 409 } 410 } 411 412 415 416 public void prepareAttributes() throws XPathException { 417 418 String inputTypeAnnotationsAtt = null; 419 AttributeCollection atts = getAttributeList(); 420 for (int a = 0; a < atts.getLength(); a++) { 421 422 int nc = atts.getNameCode(a); 423 String f = getNamePool().getClarkName(nc); 424 if (f == StandardNames.VERSION) { 425 processVersionAttribute(f); 426 } else if (f == StandardNames.ID) { 427 } else if (f == StandardNames.EXTENSION_ELEMENT_PREFIXES) { 429 } else if (f == StandardNames.EXCLUDE_RESULT_PREFIXES) { 431 } else if (f == StandardNames.DEFAULT_VALIDATION) { 433 defaultValidation = Validation.getCode(atts.getValue(a)); 434 if (defaultValidation == Validation.INVALID) { 435 compileError("Invalid value for default-validation attribute. " + 436 "Permitted values are (strict, lax, preserve, strip)", "XTSE0020"); 437 } 438 } else if (f == StandardNames.INPUT_TYPE_ANNOTATIONS) { 439 inputTypeAnnotationsAtt = atts.getValue("", f); 440 } else { 441 checkUnknownAttribute(nc); 442 } 443 } 444 if (version == null) { 445 reportAbsence("version"); 446 } 447 448 if (inputTypeAnnotationsAtt != null) { 449 if (inputTypeAnnotationsAtt.equals("strip")) { 450 setInputTypeAnnotations(ANNOTATION_STRIP); 451 } else if (inputTypeAnnotationsAtt.equals("preserve")) { 452 setInputTypeAnnotations(ANNOTATION_PRESERVE); 453 } else if (inputTypeAnnotationsAtt.equals("unspecified")) { 454 } else { 456 compileError("Invalid value for input-type-annotations attribute. " + 457 "Permitted values are (strip, preserve, unspecified)", "XTSE0020"); 458 } 459 } 460 } 461 462 465 466 public int getDefaultValidation() { 467 return defaultValidation; 468 } 469 470 471 476 477 public int getInputTypeAnnotationsAttribute() throws XPathException { 478 String inputTypeAnnotationsAtt = getAttributeValue(StandardNames.INPUT_TYPE_ANNOTATIONS); 479 if (inputTypeAnnotationsAtt != null) { 480 if (inputTypeAnnotationsAtt.equals("strip")) { 481 setInputTypeAnnotations(ANNOTATION_STRIP); 482 } else if (inputTypeAnnotationsAtt.equals("preserve")) { 483 setInputTypeAnnotations(ANNOTATION_PRESERVE); 484 } else if (inputTypeAnnotationsAtt.equals("unspecified")) { 485 } else { 487 compileError("Invalid value for input-type-annotations attribute. " + 488 "Permitted values are (strip, preserve, unspecified)", "XTSE0020"); 489 } 490 } 491 return inputAnnotations; 492 } 493 494 495 500 501 public int getInputTypeAnnotations() { 502 return inputAnnotations; 503 } 504 505 510 511 public void setInputTypeAnnotations(int annotations) throws XPathException { 512 inputAnnotations |= annotations; 513 if (inputAnnotations == (ANNOTATION_STRIP | ANNOTATION_PRESERVE)) { 514 compileError("One stylesheet module specifies input-type-annotations='strip', " + 515 "another specifies input-type-annotations='preserve'", "XTSE0265"); 516 } 517 } 518 519 526 527 protected int getNamespaceAlias(short uriCode) { 528 529 for (int i = 0; i < numberOfAliases; i++) { 532 if (uriCode == aliasSCodes[i]) { 533 return aliasNCodes[i]; 534 } 535 } 536 return uriCode; 537 } 538 539 542 543 protected boolean isAliasResultNamespace(short uriCode) { 544 for (int i = 0; i < numberOfAliases; i++) { 545 if (uriCode == (aliasNCodes[i] & 0xffff)) { 546 return true; 547 } 548 } 549 return false; 550 } 551 552 555 556 public void validate() throws XPathException { 557 if (validationError != null) { 558 compileError(validationError); 559 } 560 if (!(getParent() instanceof DocumentInfo)) { 561 compileError(getDisplayName() + " must be the outermost element", "XTSE0010"); 562 } 563 564 AxisIterator kids = iterateAxis(Axis.CHILD); 565 while(true) { 566 NodeInfo curr = (NodeInfo)kids.next(); 567 if (curr == null) break; 568 if (curr.getNodeKind() == Type.TEXT || 569 curr instanceof XSLTemplate || 570 curr instanceof XSLImport || 571 curr instanceof XSLInclude || 572 curr instanceof XSLAttributeSet || 573 curr instanceof XSLCharacterMap || 574 curr instanceof XSLDecimalFormat || 575 curr instanceof XSLFunction || 576 curr instanceof XSLImportSchema || 577 curr instanceof XSLKey || 578 curr instanceof XSLNamespaceAlias || 579 curr instanceof XSLOutput || 580 curr instanceof XSLParam || 581 curr instanceof XSLPreserveSpace || 582 curr instanceof XSLVariable || 583 curr instanceof XSLParam || 584 curr instanceof DataElement) { 585 } else if (!NamespaceConstant.XSLT.equals(curr.getURI()) && !"".equals(curr.getURI())) { 587 } else if (curr instanceof AbsentExtensionElement && ((StyleElement)curr).forwardsCompatibleModeIsEnabled()) { 589 } else { 591 ((StyleElement)curr).compileError("Element " + curr.getDisplayName() + 592 " must not appear directly within " + getDisplayName(), "XTSE0010"); 593 } 594 } 595 } 596 597 603 604 public void preprocess() throws XPathException { 605 606 608 spliceIncludes(); 609 610 612 buildIndexes(); 613 614 616 processAllAttributes(); 617 618 620 collectNamespaceAliases(); 621 622 624 for (int i = 0; i < topLevel.size(); i++) { 625 Object node = topLevel.get(i); 626 if (node instanceof StyleElement) { 627 ((StyleElement) node).fixupReferences(); 628 } 629 } 630 631 633 validate(); 634 for (int i = 0; i < topLevel.size(); i++) { 635 Object node = topLevel.get(i); 636 if (node instanceof StyleElement) { 637 ((StyleElement) node).validateSubtree(); 638 } 639 } 640 } 641 642 645 646 public void spliceIncludes() throws XPathException { 647 648 boolean foundNonImport = false; 649 topLevel = new ArrayList(50); 650 minImportPrecedence = precedence; 651 StyleElement previousElement = this; 652 653 AxisIterator kids = iterateAxis(Axis.CHILD); 654 655 while (true) { 656 NodeInfo child = (NodeInfo) kids.next(); 657 if (child == null) { 658 break; 659 } 660 if (child.getNodeKind() == Type.TEXT) { 661 if (!Whitespace.isWhite(child.getStringValueCS())) { 663 previousElement.compileError( 664 "No character data is allowed between top-level elements", "XTSE0010"); 665 } 666 667 } else if (child instanceof DataElement) { 668 foundNonImport = true; 669 } else { 670 previousElement = (StyleElement) child; 671 if (child instanceof XSLGeneralIncorporate) { 672 XSLGeneralIncorporate xslinc = (XSLGeneralIncorporate) child; 673 xslinc.processAttributes(); 674 675 if (xslinc.isImport()) { 676 if (foundNonImport) { 677 xslinc.compileError("xsl:import elements must come first", "XTSE0010"); 678 } 679 } else { 680 foundNonImport = true; 681 } 682 683 686 XSLStylesheet inc = 687 xslinc.getIncludedStylesheet(this, precedence); 688 if (inc == null) return; 690 693 if (xslinc.isImport()) { 694 precedence = inc.getPrecedence() + 1; 695 } else { 696 precedence = inc.getPrecedence(); 697 inc.setMinImportPrecedence(minImportPrecedence); 698 inc.setWasIncluded(); 699 } 700 701 709 List incchildren = inc.topLevel; 710 for (int j = 0; j < incchildren.size(); j++) { 711 StyleElement elem = (StyleElement) incchildren.get(j); 712 int last = topLevel.size() - 1; 713 if (last < 0 || elem.getPrecedence() >= ((StyleElement) topLevel.get(last)).getPrecedence()) { 714 topLevel.add(elem); 715 } else { 716 while (last >= 0 && elem.getPrecedence() < ((StyleElement) topLevel.get(last)).getPrecedence()) { 717 last--; 718 } 719 topLevel.add(last + 1, elem); 720 } 721 } 722 } else { 723 foundNonImport = true; 724 topLevel.add(child); 725 } 726 } 727 } 728 } 729 730 733 734 private void buildIndexes() throws XPathException { 735 for (int i = topLevel.size() - 1; i >= 0; i--) { 737 Object node = topLevel.get(i); 738 if (node instanceof XSLTemplate) { 739 indexNamedTemplate((XSLTemplate) node); 740 } else if (node instanceof XSLVariableDeclaration) { 741 indexVariableDeclaration((XSLVariableDeclaration) node); 742 } else if (node instanceof XSLNamespaceAlias) { 743 namespaceAliasList.add(node); 744 numberOfAliases++; 745 } else if (node instanceof XSLImportSchema) { 746 try { 747 ((XSLImportSchema) node).readSchema(); 748 } catch (SchemaException e) { 749 throw StaticError.makeStaticError(e); 750 } 751 } else if (node instanceof XSLDecimalFormat) { 752 ((XSLDecimalFormat) node).register(); 753 } else if (node instanceof SaxonImportQuery) { 754 ((SaxonImportQuery) node).importModule(); 755 } 756 } 757 } 758 759 764 765 private void indexVariableDeclaration(XSLVariableDeclaration var) throws XPathException { 766 int fingerprint = var.getVariableFingerprint(); 767 if (fingerprint != -1) { 769 Integer key = new Integer (fingerprint); 770 XSLVariableDeclaration other = (XSLVariableDeclaration) globalVariableIndex.get(key); 772 if (other == null) { 773 globalVariableIndex.put(key, var); 775 } else { 776 int thisPrecedence = var.getPrecedence(); 778 int otherPrecedence = other.getPrecedence(); 779 if (thisPrecedence == otherPrecedence) { 780 var.compileError("Duplicate global variable declaration (see line " + 781 other.getLineNumber() + " of " + other.getSystemId() + ')', "XTSE0630"); 782 } else if (thisPrecedence < otherPrecedence) { 783 var.setRedundant(); 784 } else { 785 other.setRedundant(); 787 globalVariableIndex.put(key, var); 788 } 789 } 790 } 791 } 792 793 798 private void indexNamedTemplate(XSLTemplate template) throws XPathException { 799 int fingerprint = template.getTemplateFingerprint(); 800 if (fingerprint != -1) { 801 Integer key = new Integer (fingerprint); 802 XSLTemplate other = (XSLTemplate) templateIndex.get(key); 804 if (other == null) { 805 templateIndex.put(key, template); 807 } else { 808 int thisPrecedence = template.getPrecedence(); 810 int otherPrecedence = other.getPrecedence(); 811 if (thisPrecedence == otherPrecedence) { 812 template.compileError("Duplicate named template (see line " + 813 other.getLineNumber() + " of " + other.getSystemId() + ')', "XTSE0660"); 814 } else if (thisPrecedence < otherPrecedence) { 815 } else { 817 templateIndex.put(key, template); 820 } 821 } 822 exec.getNamedTemplateTable().put(key, template.getCompiledTemplate()); 823 } 824 } 825 826 829 830 private void collectNamespaceAliases() throws XPathException { 831 aliasSCodes = new short[numberOfAliases]; 832 aliasNCodes = new int[numberOfAliases]; 833 int precedenceBoundary = 0; 834 int currentPrecedence = -1; 835 for (int i = 0; i < numberOfAliases; i++) { 838 XSLNamespaceAlias xna = (XSLNamespaceAlias) namespaceAliasList.get(i); 839 short scode = xna.getStylesheetURICode(); 840 int ncode = xna.getResultNamespaceCode(); 841 int prec = xna.getPrecedence(); 842 843 846 if (currentPrecedence != prec) { 847 currentPrecedence = prec; 848 precedenceBoundary = i; 849 } 850 851 for (int j = precedenceBoundary; j < i; j++) { 852 if (scode == aliasSCodes[j]) { 853 if ((ncode & 0xffff) != (aliasNCodes[j] & 0xffff)) { 854 xna.compileError("More than one alias is defined for the same namespace prefix", "XTSE0810"); 855 } 856 } 857 } 858 859 aliasSCodes[i] = scode; 860 aliasNCodes[i] = ncode; 861 } 862 namespaceAliasList = null; } 864 865 protected boolean hasNamespaceAliases() { 866 return numberOfAliases > 0; 867 } 868 869 872 873 public void processAllAttributes() throws XPathException { 874 prepareAttributes(); 875 if (topLevel == null) return; for (int i = 0; i < topLevel.size(); i++) { 877 Object s = topLevel.get(i); 878 if (s instanceof StyleElement) { 879 try { 880 ((StyleElement) s).processAllAttributes(); 881 } catch (XPathException err) { 882 ((StyleElement) s).compileError(err); 883 } 884 } 885 } 886 } 887 888 892 893 public XSLVariableDeclaration getGlobalVariable(int fingerprint) { 894 return (XSLVariableDeclaration) globalVariableIndex.get(new Integer (fingerprint)); 895 } 896 897 905 906 public Properties gatherOutputProperties(int fingerprint) throws XPathException { 907 boolean found = (fingerprint == -1); 908 Properties details = new Properties(); 909 HashMap precedences = new HashMap(10); 910 for (int i = topLevel.size()-1; i >= 0; i--) { 911 Object s = topLevel.get(i); 912 if (s instanceof XSLOutput) { 913 XSLOutput xo = (XSLOutput) s; 914 if (xo.getOutputFingerprint() == fingerprint) { 915 found = true; 916 xo.gatherOutputProperties(details, precedences); 917 } 918 } 919 } 920 if (!found) { 921 throw new StaticError("Requested output format has not been defined"); 922 } 923 return details; 924 } 925 926 929 930 protected void declareXQueryFunction(XQueryFunction function) throws XPathException { 931 queryFunctions.declareFunction(function); 932 } 933 934 937 938 protected void declareJavaClass(String uri, Class theClass) { 939 if (javaFunctions instanceof JavaExtensionLibrary) { 940 ((JavaExtensionLibrary)javaFunctions).declareJavaClass(uri, theClass); 941 } else { 942 throw new IllegalStateException ("saxon:script cannot be used with a custom extension library factory"); 943 } 944 } 945 946 952 953 protected boolean isImportedSchema(String targetNamespace) { 954 return schemaIndex.contains(targetNamespace); 955 } 956 957 protected void addImportedSchema(String targetNamespace) { 958 schemaIndex.add(targetNamespace); 959 } 960 961 964 965 public Executable compileStylesheet() throws XPathException { 966 967 try { 968 969 try { 972 queryFunctions.bindUnboundFunctionCalls(); 973 Iterator qf = queryFunctions.getFunctionDefinitions(); 974 while (qf.hasNext()) { 975 XQueryFunction f = (XQueryFunction) qf.next(); 976 f.fixupReferences(getStaticContext()); 977 } 978 } catch (XPathException e) { 979 compileError(e); 980 } 981 982 984 for (int i = 0; i < topLevel.size(); i++) { 985 NodeInfo node = (NodeInfo) topLevel.get(i); 986 if (node instanceof StyleElement) { 987 StyleElement snode = (StyleElement) node; 988 Expression inst = snode.compile(exec); 990 991 if (inst instanceof ComputedExpression) { 992 ((ComputedExpression) inst).setLocationId(allocateLocationId(getSystemId(), snode.getLineNumber())); 993 } 994 } 995 } 996 997 999 if (exec.getDecimalFormatManager() != null) { 1000 try { 1001 exec.getDecimalFormatManager().fixupDefaultDefault(); 1002 } catch (StaticError err) { 1003 compileError(err.getMessage(), err.getErrorCodeLocalPart()); 1004 } 1005 } 1006 1007 exec.setStripsWhitespace(stripsWhitespace()); 1008 Properties props = gatherOutputProperties(-1); 1009 props.setProperty(SaxonOutputKeys.STYLESHEET_VERSION, getVersion().toString()); 1010 exec.setDefaultOutputProperties(props); 1011 exec.setPatternSlotSpace(largestPatternStackFrame); 1012 exec.setStripsInputTypeAnnotations(inputAnnotations == ANNOTATION_STRIP); 1013 1014 1016 for (int i = 0; i < topLevel.size(); i++) { 1017 if (topLevel.get(i) instanceof XSLCharacterMap) { 1018 XSLCharacterMap t = (XSLCharacterMap) topLevel.get(i); 1019 if (!t.isRedundant()) { 1020 int fp = t.getCharacterMapFingerprint(); 1021 HashMap map = new HashMap(20); 1022 t.assemble(map); 1023 if (exec.getCharacterMapIndex() == null) { 1024 exec.setCharacterMapIndex(new HashMap(20)); 1025 } 1026 exec.getCharacterMapIndex().put(new Integer (fp), map); 1027 } 1028 } 1029 } 1030 1031 1034 ExecutableFunctionLibrary overriding = new ExecutableFunctionLibrary(getConfiguration()); 1035 ExecutableFunctionLibrary underriding = new ExecutableFunctionLibrary(getConfiguration()); 1036 1037 List toplevel = getTopLevel(); 1038 for (int i=0; i<toplevel.size(); i++) { 1039 Object child = toplevel.get(i); 1040 if (child instanceof XSLFunction) { 1041 XSLFunction func = (XSLFunction)child; 1042 if (func.isOverriding()) { 1043 overriding.addFunction(func.getCompiledFunction()); 1044 } else { 1045 underriding.addFunction(func.getCompiledFunction()); 1046 } 1047 } 1048 } 1049 1050 FunctionLibraryList libraryList = new FunctionLibraryList(); 1051 libraryList.addFunctionLibrary(new SystemFunctionLibrary(SystemFunctionLibrary.FULL_XSLT)); 1052 libraryList.addFunctionLibrary(overriding); 1053 libraryList.addFunctionLibrary(getConfiguration().getVendorFunctionLibrary()); 1054 libraryList.addFunctionLibrary(new ConstructorFunctionLibrary(getConfiguration())); 1055 libraryList.addFunctionLibrary(queryFunctions); 1056 if (getConfiguration().isAllowExternalFunctions()) { 1057 libraryList.addFunctionLibrary(javaFunctions); 1058 } 1059 libraryList.addFunctionLibrary(underriding); 1060 exec.setFunctionLibrary(libraryList); 1061 1062 1063 return exec; 1064 1065 } catch (RuntimeException err) { 1066 if (getPreparedStylesheet().getErrorCount() > 0) { 1070 return exec; 1072 } else { 1073 throw err; 1075 } 1076 } 1077 1078 } 1079 1080 1083 1084 public Expression compile(Executable exec) { 1085 return null; 1086 } 1087 1088} 1089 1090 | Popular Tags |