1 16 19 package org.apache.xalan.templates; 20 21 import java.io.IOException ; 22 import java.io.ObjectInputStream ; 23 import java.io.ObjectOutputStream ; 24 import java.util.Hashtable ; 25 import java.util.Stack ; 26 import java.util.Vector ; 27 28 import javax.xml.transform.SourceLocator ; 29 import javax.xml.transform.TransformerException ; 30 31 import org.apache.xml.dtm.DTM; 32 import org.apache.xml.utils.QName; 33 import org.apache.xml.utils.StringVector; 34 import org.apache.xml.utils.SystemIDResolver; 35 36 79 public class Stylesheet extends ElemTemplateElement 80 implements java.io.Serializable 81 { 82 83 87 public Stylesheet(Stylesheet parent) 88 { 89 90 if (null != parent) 91 { 92 m_stylesheetParent = parent; 93 m_stylesheetRoot = parent.getStylesheetRoot(); 94 } 95 } 96 97 104 public Stylesheet getStylesheet() 105 { 106 return this; 107 } 108 109 115 public boolean isAggregatedType() 116 { 117 return false; 118 } 119 120 125 public boolean isRoot() 126 { 127 return false; 128 } 129 130 133 public static final String STYLESHEET_EXT = ".lxc"; 134 135 143 private void readObject(ObjectInputStream stream) 144 throws IOException , TransformerException 145 { 146 147 try 149 { 150 stream.defaultReadObject(); 151 } 152 catch (ClassNotFoundException cnfe) 153 { 154 throw new TransformerException (cnfe); 155 } 156 157 } 159 160 168 private void writeObject(ObjectOutputStream stream) throws IOException 169 { 170 171 stream.defaultWriteObject(); 173 174 } 176 177 179 183 private String m_XmlnsXsl; 184 185 191 public void setXmlnsXsl(String v) 192 { 193 m_XmlnsXsl = v; 194 } 195 196 202 public String getXmlnsXsl() 203 { 204 return m_XmlnsXsl; 205 } 206 207 211 private StringVector m_ExtensionElementURIs; 212 213 220 public void setExtensionElementPrefixes(StringVector v) 221 { 222 m_ExtensionElementURIs = v; 223 } 224 225 235 public String getExtensionElementPrefix(int i) 236 throws ArrayIndexOutOfBoundsException 237 { 238 239 if (null == m_ExtensionElementURIs) 240 throw new ArrayIndexOutOfBoundsException (); 241 242 return m_ExtensionElementURIs.elementAt(i); 243 } 244 245 251 public int getExtensionElementPrefixCount() 252 { 253 return (null != m_ExtensionElementURIs) 254 ? m_ExtensionElementURIs.size() : 0; 255 } 256 257 265 public boolean containsExtensionElementURI(String uri) 266 { 267 268 if (null == m_ExtensionElementURIs) 269 return false; 270 271 return m_ExtensionElementURIs.contains(uri); 272 } 273 274 278 private StringVector m_ExcludeResultPrefixs; 279 280 292 public void setExcludeResultPrefixes(StringVector v) 293 { 294 m_ExcludeResultPrefixs = v; 295 } 296 297 313 public String getExcludeResultPrefix(int i) 314 throws ArrayIndexOutOfBoundsException 315 { 316 317 if (null == m_ExcludeResultPrefixs) 318 throw new ArrayIndexOutOfBoundsException (); 319 320 return m_ExcludeResultPrefixs.elementAt(i); 321 } 322 323 329 public int getExcludeResultPrefixCount() 330 { 331 return (null != m_ExcludeResultPrefixs) 332 ? m_ExcludeResultPrefixs.size() : 0; 333 } 334 335 345 public boolean containsExcludeResultPrefix(String prefix, String uri) 346 { 347 348 if (null == m_ExcludeResultPrefixs || uri == null ) 349 return false; 350 351 for (int i =0; i< m_ExcludeResultPrefixs.size(); i++) 354 { 355 if (uri.equals(getNamespaceForPrefix(m_ExcludeResultPrefixs.elementAt(i)))) 356 return true; 357 } 358 359 return false; 360 361 365 } 366 367 371 private String m_Id; 372 373 379 public void setId(String v) 380 { 381 m_Id = v; 382 } 383 384 390 public String getId() 391 { 392 return m_Id; 393 } 394 395 399 private String m_Version; 400 401 405 private boolean m_isCompatibleMode = false; 406 407 413 public void setVersion(String v) 414 { 415 m_Version = v; 416 m_isCompatibleMode = (Double.valueOf(v).doubleValue() > Constants.XSLTVERSUPPORTED); 417 } 418 419 424 public boolean getCompatibleMode() 425 { 426 return m_isCompatibleMode; 427 } 428 429 435 public String getVersion() 436 { 437 return m_Version; 438 } 439 440 444 private Vector m_imports; 445 446 452 public void setImport(StylesheetComposed v) 453 { 454 455 if (null == m_imports) 456 m_imports = new Vector (); 457 458 m_imports.addElement(v); 461 } 462 463 473 public StylesheetComposed getImport(int i) 474 throws ArrayIndexOutOfBoundsException 475 { 476 477 if (null == m_imports) 478 throw new ArrayIndexOutOfBoundsException (); 479 480 return (StylesheetComposed) m_imports.elementAt(i); 481 } 482 483 489 public int getImportCount() 490 { 491 return (null != m_imports) ? m_imports.size() : 0; 492 } 493 494 498 private Vector m_includes; 499 500 506 public void setInclude(Stylesheet v) 507 { 508 509 if (null == m_includes) 510 m_includes = new Vector (); 511 512 m_includes.addElement(v); 513 } 514 515 525 public Stylesheet getInclude(int i) throws ArrayIndexOutOfBoundsException 526 { 527 528 if (null == m_includes) 529 throw new ArrayIndexOutOfBoundsException (); 530 531 return (Stylesheet) m_includes.elementAt(i); 532 } 533 534 540 public int getIncludeCount() 541 { 542 return (null != m_includes) ? m_includes.size() : 0; 543 } 544 545 550 Stack m_DecimalFormatDeclarations; 551 552 557 public void setDecimalFormat(DecimalFormatProperties edf) 558 { 559 560 if (null == m_DecimalFormatDeclarations) 561 m_DecimalFormatDeclarations = new Stack (); 562 563 m_DecimalFormatDeclarations.push(edf); 566 } 567 568 578 public DecimalFormatProperties getDecimalFormat(QName name) 579 { 580 581 if (null == m_DecimalFormatDeclarations) 582 return null; 583 584 int n = getDecimalFormatCount(); 585 586 for (int i = (n - 1); i >= 0; i++) 587 { 588 DecimalFormatProperties dfp = getDecimalFormat(i); 589 590 if (dfp.getName().equals(name)) 591 return dfp; 592 } 593 594 return null; 595 } 596 597 608 public DecimalFormatProperties getDecimalFormat(int i) 609 throws ArrayIndexOutOfBoundsException 610 { 611 612 if (null == m_DecimalFormatDeclarations) 613 throw new ArrayIndexOutOfBoundsException (); 614 615 return (DecimalFormatProperties) m_DecimalFormatDeclarations.elementAt(i); 616 } 617 618 624 public int getDecimalFormatCount() 625 { 626 return (null != m_DecimalFormatDeclarations) 627 ? m_DecimalFormatDeclarations.size() : 0; 628 } 629 630 635 private Vector m_whitespaceStrippingElements; 636 637 643 public void setStripSpaces(WhiteSpaceInfo wsi) 644 { 645 646 if (null == m_whitespaceStrippingElements) 647 { 648 m_whitespaceStrippingElements = new Vector (); 649 } 650 651 m_whitespaceStrippingElements.addElement(wsi); 652 } 653 654 664 public WhiteSpaceInfo getStripSpace(int i) throws ArrayIndexOutOfBoundsException 665 { 666 667 if (null == m_whitespaceStrippingElements) 668 throw new ArrayIndexOutOfBoundsException (); 669 670 return (WhiteSpaceInfo) m_whitespaceStrippingElements.elementAt(i); 671 } 672 673 679 public int getStripSpaceCount() 680 { 681 return (null != m_whitespaceStrippingElements) 682 ? m_whitespaceStrippingElements.size() : 0; 683 } 684 685 690 private Vector m_whitespacePreservingElements; 691 692 698 public void setPreserveSpaces(WhiteSpaceInfo wsi) 699 { 700 701 if (null == m_whitespacePreservingElements) 702 { 703 m_whitespacePreservingElements = new Vector (); 704 } 705 706 m_whitespacePreservingElements.addElement(wsi); 707 } 708 709 719 public WhiteSpaceInfo getPreserveSpace(int i) throws ArrayIndexOutOfBoundsException 720 { 721 722 if (null == m_whitespacePreservingElements) 723 throw new ArrayIndexOutOfBoundsException (); 724 725 return (WhiteSpaceInfo) m_whitespacePreservingElements.elementAt(i); 726 } 727 728 734 public int getPreserveSpaceCount() 735 { 736 return (null != m_whitespacePreservingElements) 737 ? m_whitespacePreservingElements.size() : 0; 738 } 739 740 744 private Vector m_output; 745 746 753 public void setOutput(OutputProperties v) 754 { 755 if (null == m_output) 756 { 757 m_output = new Vector (); 758 } 759 760 m_output.addElement(v); 761 } 762 763 773 public OutputProperties getOutput(int i) throws ArrayIndexOutOfBoundsException 774 { 775 776 if (null == m_output) 777 throw new ArrayIndexOutOfBoundsException (); 778 779 return (OutputProperties) m_output.elementAt(i); 780 } 781 782 788 public int getOutputCount() 789 { 790 return (null != m_output) 791 ? m_output.size() : 0; 792 } 793 794 798 private Vector m_keyDeclarations; 799 800 806 public void setKey(KeyDeclaration v) 807 { 808 809 if (null == m_keyDeclarations) 810 m_keyDeclarations = new Vector (); 811 812 m_keyDeclarations.addElement(v); 813 } 814 815 825 public KeyDeclaration getKey(int i) throws ArrayIndexOutOfBoundsException 826 { 827 828 if (null == m_keyDeclarations) 829 throw new ArrayIndexOutOfBoundsException (); 830 831 return (KeyDeclaration) m_keyDeclarations.elementAt(i); 832 } 833 834 840 public int getKeyCount() 841 { 842 return (null != m_keyDeclarations) ? m_keyDeclarations.size() : 0; 843 } 844 845 849 private Vector m_attributeSets; 850 851 857 public void setAttributeSet(ElemAttributeSet attrSet) 858 { 859 860 if (null == m_attributeSets) 861 { 862 m_attributeSets = new Vector (); 863 } 864 865 m_attributeSets.addElement(attrSet); 866 } 867 868 878 public ElemAttributeSet getAttributeSet(int i) 879 throws ArrayIndexOutOfBoundsException 880 { 881 882 if (null == m_attributeSets) 883 throw new ArrayIndexOutOfBoundsException (); 884 885 return (ElemAttributeSet) m_attributeSets.elementAt(i); 886 } 887 888 894 public int getAttributeSetCount() 895 { 896 return (null != m_attributeSets) ? m_attributeSets.size() : 0; 897 } 898 899 903 private Vector m_topLevelVariables; 904 905 911 public void setVariable(ElemVariable v) 912 { 913 914 if (null == m_topLevelVariables) 915 m_topLevelVariables = new Vector (); 916 917 m_topLevelVariables.addElement(v); 918 } 919 920 928 public ElemVariable getVariableOrParam(QName qname) 929 { 930 931 if (null != m_topLevelVariables) 932 { 933 int n = getVariableOrParamCount(); 934 935 for (int i = 0; i < n; i++) 936 { 937 ElemVariable var = (ElemVariable) getVariableOrParam(i); 938 939 if (var.getName().equals(qname)) 940 return var; 941 } 942 } 943 944 return null; 945 } 946 947 948 956 public ElemVariable getVariable(QName qname) 957 { 958 959 if (null != m_topLevelVariables) 960 { 961 int n = getVariableOrParamCount(); 962 963 for (int i = 0; i < n; i++) 964 { 965 ElemVariable var = getVariableOrParam(i); 966 if((var.getXSLToken() == Constants.ELEMNAME_VARIABLE) && 967 (var.getName().equals(qname))) 968 return var; 969 } 970 } 971 972 return null; 973 } 974 975 985 public ElemVariable getVariableOrParam(int i) throws ArrayIndexOutOfBoundsException 986 { 987 988 if (null == m_topLevelVariables) 989 throw new ArrayIndexOutOfBoundsException (); 990 991 return (ElemVariable) m_topLevelVariables.elementAt(i); 992 } 993 994 1000 public int getVariableOrParamCount() 1001 { 1002 return (null != m_topLevelVariables) ? m_topLevelVariables.size() : 0; 1003 } 1004 1005 1011 public void setParam(ElemParam v) 1012 { 1013 setVariable(v); 1014 } 1015 1016 1024 public ElemParam getParam(QName qname) 1025 { 1026 1027 if (null != m_topLevelVariables) 1028 { 1029 int n = getVariableOrParamCount(); 1030 1031 for (int i = 0; i < n; i++) 1032 { 1033 ElemVariable var = getVariableOrParam(i); 1034 if((var.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE) && 1035 (var.getName().equals(qname))) 1036 return (ElemParam)var; 1037 } 1038 } 1039 1040 return null; 1041 } 1042 1043 1047 private Vector m_templates; 1048 1049 1055 public void setTemplate(ElemTemplate v) 1056 { 1057 1058 if (null == m_templates) 1059 m_templates = new Vector (); 1060 1061 m_templates.addElement(v); 1062 v.setStylesheet(this); 1063 } 1064 1065 1075 public ElemTemplate getTemplate(int i) throws TransformerException 1076 { 1077 1078 if (null == m_templates) 1079 throw new ArrayIndexOutOfBoundsException (); 1080 1081 return (ElemTemplate) m_templates.elementAt(i); 1082 } 1083 1084 1090 public int getTemplateCount() 1091 { 1092 return (null != m_templates) ? m_templates.size() : 0; 1093 } 1094 1095 1099 private Vector m_prefix_aliases; 1100 1101 1107 public void setNamespaceAlias(NamespaceAlias na) 1108 { 1109 1110 if (m_prefix_aliases == null) 1111 m_prefix_aliases = new Vector (); 1112 1113 m_prefix_aliases.addElement(na); 1114 } 1115 1116 1126 public NamespaceAlias getNamespaceAlias(int i) 1127 throws ArrayIndexOutOfBoundsException 1128 { 1129 1130 if (null == m_prefix_aliases) 1131 throw new ArrayIndexOutOfBoundsException (); 1132 1133 return (NamespaceAlias) m_prefix_aliases.elementAt(i); 1134 } 1135 1136 1142 public int getNamespaceAliasCount() 1143 { 1144 return (null != m_prefix_aliases) ? m_prefix_aliases.size() : 0; 1145 } 1146 1147 1151 private Hashtable m_NonXslTopLevel; 1152 1153 1160 public void setNonXslTopLevel(QName name, Object obj) 1161 { 1162 1163 if (null == m_NonXslTopLevel) 1164 m_NonXslTopLevel = new Hashtable (); 1165 1166 m_NonXslTopLevel.put(name, obj); 1167 } 1168 1169 1177 public Object getNonXslTopLevel(QName name) 1178 { 1179 return (null != m_NonXslTopLevel) ? m_NonXslTopLevel.get(name) : null; 1180 } 1181 1182 1184 1188 private String m_href = null; 1189 1190 1192 private String m_publicId; 1193 1194 1196 private String m_systemId; 1197 1198 1203 public String getHref() 1204 { 1205 return m_href; 1206 } 1207 1208 1213 public void setHref(String baseIdent) 1214 { 1215 m_href = baseIdent; 1216 } 1217 1218 1223 public void setLocaterInfo(SourceLocator locator) 1224 { 1225 1226 if (null != locator) 1227 { 1228 m_publicId = locator.getPublicId(); 1229 m_systemId = locator.getSystemId(); 1230 1231 if (null != m_systemId) 1232 { 1233 try 1234 { 1235 m_href = SystemIDResolver.getAbsoluteURI(m_systemId, null); 1236 } 1237 catch (TransformerException se) 1238 { 1239 1240 } 1242 } 1243 1244 super.setLocaterInfo(locator); 1245 } 1246 } 1247 1248 1253 private StylesheetRoot m_stylesheetRoot; 1254 1255 1261 public StylesheetRoot getStylesheetRoot() 1262 { 1263 return m_stylesheetRoot; 1264 } 1265 1266 1272 public void setStylesheetRoot(StylesheetRoot v) 1273 { 1274 m_stylesheetRoot = v; 1275 } 1276 1277 1282 private Stylesheet m_stylesheetParent; 1283 1284 1290 public Stylesheet getStylesheetParent() 1291 { 1292 return m_stylesheetParent; 1293 } 1294 1295 1301 public void setStylesheetParent(Stylesheet v) 1302 { 1303 m_stylesheetParent = v; 1304 } 1305 1306 1312 public StylesheetComposed getStylesheetComposed() 1313 { 1314 1315 Stylesheet sheet = this; 1316 1317 while (!sheet.isAggregatedType()) 1318 { 1319 sheet = sheet.getStylesheetParent(); 1320 } 1321 1322 return (StylesheetComposed) sheet; 1323 } 1324 1325 1330 public short getNodeType() 1331 { 1332 return DTM.DOCUMENT_NODE; 1333 } 1334 1335 1342 public int getXSLToken() 1343 { 1344 return Constants.ELEMNAME_STYLESHEET; 1345 } 1346 1347 1352 public String getNodeName() 1353 { 1354 return Constants.ELEMNAME_STYLESHEET_STRING; 1355 } 1356 1357 1369 public void replaceTemplate(ElemTemplate v, int i) throws TransformerException 1370 { 1371 1372 if (null == m_templates) 1373 throw new ArrayIndexOutOfBoundsException (); 1374 1375 replaceChild(v, (ElemTemplateElement)m_templates.elementAt(i)); 1376 m_templates.setElementAt(v, i); 1377 v.setStylesheet(this); 1378 } 1379 1380 1384 protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs) 1385 { 1386 int s = getImportCount(); 1387 for (int j = 0; j < s; j++) 1388 { 1389 getImport(j).callVisitors(visitor); 1390 } 1391 1392 s = getIncludeCount(); 1393 for (int j = 0; j < s; j++) 1394 { 1395 getInclude(j).callVisitors(visitor); 1396 } 1397 1398 s = getOutputCount(); 1399 for (int j = 0; j < s; j++) 1400 { 1401 visitor.visitTopLevelInstruction(getOutput(j)); 1402 } 1403 1404 1406 s = getAttributeSetCount(); 1407 for (int j = 0; j < s; j++) 1408 { 1409 ElemAttributeSet attrSet = getAttributeSet(j); 1410 if (visitor.visitTopLevelInstruction(attrSet)) 1411 { 1412 attrSet.callChildVisitors(visitor); 1413 } 1414 } 1415 1417 s = getDecimalFormatCount(); 1418 for (int j = 0; j < s; j++) 1419 { 1420 visitor.visitTopLevelInstruction(getDecimalFormat(j)); 1421 } 1422 1423 1425 s = getKeyCount(); 1426 for (int j = 0; j < s; j++) 1427 { 1428 visitor.visitTopLevelInstruction(getKey(j)); 1429 } 1430 1431 1433 s = getNamespaceAliasCount(); 1434 for (int j = 0; j < s; j++) 1435 { 1436 visitor.visitTopLevelInstruction(getNamespaceAlias(j)); 1437 } 1438 1439 1441 s = getTemplateCount(); 1442 for (int j = 0; j < s; j++) 1443 { 1444 try 1445 { 1446 ElemTemplate template = getTemplate(j); 1447 if (visitor.visitTopLevelInstruction(template)) 1448 { 1449 template.callChildVisitors(visitor); 1450 } 1451 } 1452 catch (TransformerException te) 1453 { 1454 throw new org.apache.xml.utils.WrappedRuntimeException(te); 1455 } 1456 } 1457 1458 1460 s = getVariableOrParamCount(); 1461 for (int j = 0; j < s; j++) 1462 { 1463 ElemVariable var = getVariableOrParam(j); 1464 if (visitor.visitTopLevelVariableOrParamDecl(var)) 1465 { 1466 var.callChildVisitors(visitor); 1467 } 1468 } 1469 1470 1472 s = getStripSpaceCount(); 1473 for (int j = 0; j < s; j++) 1474 { 1475 visitor.visitTopLevelInstruction(getStripSpace(j)); 1476 } 1477 1478 s = getPreserveSpaceCount(); 1479 for (int j = 0; j < s; j++) 1480 { 1481 visitor.visitTopLevelInstruction(getPreserveSpace(j)); 1482 } 1483 1484 if(null != m_NonXslTopLevel) 1485 { 1486 java.util.Enumeration elements = m_NonXslTopLevel.elements(); 1487 while(elements.hasMoreElements()) 1488 { 1489 ElemTemplateElement elem = (ElemTemplateElement)elements.nextElement(); 1490 if (visitor.visitTopLevelInstruction(elem)) 1491 { 1492 elem.callChildVisitors(visitor); 1493 } 1494 1495 } 1496 } 1497 } 1498 1499 1500 1507 protected boolean accept(XSLTVisitor visitor) 1508 { 1509 return visitor.visitStylesheet(this); 1510 } 1511 1512 1513} 1514 | Popular Tags |