1 57 58 package org.enhydra.apache.xerces.parsers; 59 60 import org.enhydra.apache.xerces.framework.XMLAttrList; 61 import org.enhydra.apache.xerces.framework.XMLContentSpec; 62 import org.enhydra.apache.xerces.framework.XMLDocumentHandler; 63 import org.enhydra.apache.xerces.framework.XMLParser; 64 import org.enhydra.apache.xerces.readers.XMLEntityHandler; 65 import org.enhydra.apache.xerces.utils.QName; 66 import org.enhydra.apache.xerces.utils.StringPool; 67 import org.enhydra.apache.xerces.validators.common.XMLAttributeDecl; 68 import org.enhydra.apache.xerces.validators.common.XMLElementDecl; 69 import org.xml.sax.AttributeList ; 70 import org.xml.sax.ContentHandler ; 71 import org.xml.sax.DocumentHandler ; 72 import org.xml.sax.Parser ; 73 import org.xml.sax.SAXException ; 74 import org.xml.sax.SAXNotRecognizedException ; 75 import org.xml.sax.SAXNotSupportedException ; 76 import org.xml.sax.XMLReader ; 77 import org.xml.sax.ext.DeclHandler ; 78 import org.xml.sax.ext.LexicalHandler ; 79 import org.xml.sax.helpers.AttributesImpl ; 80 81 83 89 public class SAXParser 90 extends XMLParser 91 implements XMLDocumentHandler, XMLDocumentHandler.DTDHandler, 92 Parser, XMLReader { 93 94 98 100 101 private static final String RECOGNIZED_FEATURES[] = { 102 104 105 "http://xml.org/sax/features/namespace-prefixes", 106 "http://xml.org/sax/features/string-interning", 107 }; 109 110 111 private static final String RECOGNIZED_PROPERTIES[] = { 112 "http://xml.org/sax/properties/lexical-handler", 114 "http://xml.org/sax/properties/declaration-handler", 115 "http://xml.org/sax/properties/dom-node", 116 }; 118 119 121 122 private static final boolean DEBUG_CALLBACKS = false; 123 124 128 130 131 private DocumentHandler fDocumentHandler; 132 133 135 136 private org.xml.sax.DTDHandler fDTDHandler; 137 138 140 141 private ContentHandler fContentHandler; 142 143 144 private DeclHandler fDeclHandler; 145 146 147 private LexicalHandler fLexicalHandler; 148 149 private boolean fNamespacePrefixes = false; 150 151 153 private transient AttributesImpl fAttributes = new AttributesImpl (); 154 155 159 160 public SAXParser() { 161 initHandlers(true, this, this); 162 } 163 164 protected SAXParser(StringPool stringPool) { 165 super(stringPool); 166 initHandlers(true, this, this); 167 } 168 169 173 175 184 public String [] getFeaturesRecognized() { 185 186 String superRecognized[] = super.getFeaturesRecognized(); 188 String thisRecognized[] = RECOGNIZED_FEATURES; 189 190 int thisLength = thisRecognized.length; 192 if (thisLength == 0) { 193 return superRecognized; 194 } 195 int superLength = superRecognized.length; 196 if (superLength == 0) { 197 return thisRecognized; 198 } 199 200 String recognized[] = new String [superLength + thisLength]; 202 System.arraycopy(superRecognized, 0, recognized, 0, superLength); 203 System.arraycopy(thisRecognized, 0, recognized, superLength, thisLength); 204 return recognized; 205 206 } 208 217 public String [] getPropertiesRecognized() { 218 219 String superRecognized[] = super.getPropertiesRecognized(); 221 String thisRecognized[] = RECOGNIZED_PROPERTIES; 222 223 int thisLength = thisRecognized.length; 225 if (thisLength == 0) { 226 return superRecognized; 227 } 228 int superLength = superRecognized.length; 229 if (superLength == 0) { 230 return thisRecognized; 231 } 232 233 String recognized[] = new String [superLength + thisLength]; 235 System.arraycopy(superRecognized, 0, recognized, 0, superLength); 236 System.arraycopy(thisRecognized, 0, recognized, superLength, thisLength); 237 return recognized; 238 239 } 240 241 245 247 265 273 274 283 289 290 305 313 314 321 327 328 330 343 protected void setDeclHandler(DeclHandler handler) 344 throws SAXNotRecognizedException , SAXNotSupportedException { 345 if (fParseInProgress) { 346 throw new SAXNotSupportedException ( 347 "PAR011 Feature: http://xml.org/sax/properties/declaration-handler" 348 +" is not supported during parse." 349 +"\nhttp://xml.org/sax/properties/declaration-handler"); 350 } 351 fDeclHandler = handler; 352 } 353 354 359 protected DeclHandler getDeclHandler() 360 throws SAXNotRecognizedException , SAXNotSupportedException { 361 return fDeclHandler; 362 } 363 364 377 protected void setLexicalHandler(LexicalHandler handler) 378 throws SAXNotRecognizedException , SAXNotSupportedException { 379 if (fParseInProgress) { 380 throw new SAXNotSupportedException ( 381 "PAR011 Feature: http://xml.org/sax/properties/lexical-handler" 382 +" is not supported during parse." 383 +"\nhttp://xml.org/sax/properties/lexical-handler"); 384 } 385 fLexicalHandler = handler; 386 } 387 388 393 protected LexicalHandler getLexicalHandler() 394 throws SAXNotRecognizedException , SAXNotSupportedException { 395 return fLexicalHandler; 396 } 397 398 402 403 public void setDocumentHandler(DocumentHandler handler) { 404 fDocumentHandler = handler; 405 } 406 407 411 426 public void setDTDHandler(org.xml.sax.DTDHandler handler) { 427 fDTDHandler = handler; 428 } 429 430 437 public org.xml.sax.DTDHandler getDTDHandler() { 438 return fDTDHandler; 439 } 440 441 455 protected void setNamespacePrefixes(boolean process) 456 throws SAXNotRecognizedException , SAXNotSupportedException { 457 if (fParseInProgress) { 458 throw new SAXNotSupportedException ("PAR004 Cannot setFeature(http://xml.org/sax/features/namespace-prefixes): parse is in progress.\n"+ 459 "http://xml.org/sax/features/namespace-prefixes"); 460 } 461 fNamespacePrefixes = process; 462 } 463 464 470 protected boolean getNamespacePrefixes() 471 throws SAXNotRecognizedException , SAXNotSupportedException { 472 return fNamespacePrefixes; 473 } 474 475 476 480 494 public void setFeature(String featureId, boolean state) 495 throws SAXNotRecognizedException , SAXNotSupportedException { 496 497 501 if (featureId.startsWith(SAX2_FEATURES_PREFIX)) { 502 String feature = featureId.substring(SAX2_FEATURES_PREFIX.length()); 503 504 516 527 528 if (feature.equals("namespace-prefixes")) { 535 setNamespacePrefixes(state); 536 return; 537 } 538 if (feature.equals("string-interning")) { 543 if (state) { 544 throw new SAXNotSupportedException ( 545 "PAR018 "+state+" state for feature \""+featureId+"\" is not supported.\n"+ 546 state+'\t'+featureId 547 ); 548 } 549 return; 550 } 551 552 } 556 557 561 569 570 574 super.setFeature(featureId, state); 575 576 } 578 592 public boolean getFeature(String featureId) 593 throws SAXNotRecognizedException , SAXNotSupportedException { 594 595 599 if (featureId.startsWith(SAX2_FEATURES_PREFIX)) { 600 String feature = featureId.substring(SAX2_FEATURES_PREFIX.length()); 601 602 613 623 624 if (feature.equals("namespace-prefixes")) { 631 return getNamespacePrefixes(); 632 } 633 if (feature.equals("string-interning")) { 638 return false; 639 } 640 641 } 645 646 650 657 658 662 return super.getFeature(featureId); 663 664 } 666 681 public void setProperty(String propertyId, Object value) 682 throws SAXNotRecognizedException , SAXNotSupportedException { 683 684 688 if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) { 689 String property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length()); 690 if (property.equals("lexical-handler")) { 697 try { 698 setLexicalHandler((LexicalHandler )value); 699 } 700 catch (ClassCastException e) { 701 throw new SAXNotSupportedException ( 702 "PAR012 For propertyID \"" 703 +propertyId+"\", the value \"" 704 +value+"\" cannot be cast to LexicalHandler." 705 +'\n'+propertyId+'\t'+value+"\tLexicalHandler"); 706 } 707 return; 708 } 709 if (property.equals("declaration-handler")) { 716 try { 717 setDeclHandler((DeclHandler )value); 718 } 719 catch (ClassCastException e) { 720 throw new SAXNotSupportedException ( 721 "PAR012 For propertyID \"" 722 +propertyId+"\", the value \"" 723 +value+"\" cannot be cast to DeclHandler." 724 +'\n'+propertyId+'\t'+value+"\tDeclHandler" 725 ); 726 } 727 return; 728 } 729 if (property.equals("dom-node")) { 740 throw new SAXNotSupportedException ( 741 "PAR013 Property \""+propertyId+"\" is read only." 742 +'\n'+propertyId 743 ); } 745 } 749 750 754 761 762 766 super.setProperty(propertyId, value); 767 768 } 770 784 public Object getProperty(String propertyId) 785 throws SAXNotRecognizedException , SAXNotSupportedException { 786 787 791 if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) { 792 String property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length()); 793 if (property.equals("lexical-handler")) { 800 return getLexicalHandler(); 801 } 802 if (property.equals("declaration-handler")) { 809 return getDeclHandler(); 810 } 811 if (property.equals("dom-node")) { 822 throw new SAXNotSupportedException ( 823 "PAR014 Cannot getProperty(\""+propertyId 824 +"\". No DOM Tree exists.\n"+propertyId 825 ); } 827 } 831 832 836 843 844 848 return super.getProperty(propertyId); 849 850 } 852 868 public void setContentHandler(ContentHandler handler) { 869 if (handler == null) { 870 throw new NullPointerException (); 871 } 872 fContentHandler = handler; 873 } 874 875 882 public ContentHandler getContentHandler() { 883 return fContentHandler; 884 } 885 886 890 894 public void startDTD(QName rootElement, int publicId, int systemId) throws Exception { 895 if (fLexicalHandler != null || DEBUG_CALLBACKS) { 896 897 String name = fStringPool.toString(rootElement.rawname); 899 String pubid = fStringPool.toString(publicId); 900 String sysid = fStringPool.toString(systemId); 901 902 if (DEBUG_CALLBACKS) { 904 System.err.println("startDTD(" + name + ", " + pubid + ", " + sysid + ")"); 905 } 906 if (fLexicalHandler != null) { 907 fLexicalHandler.startDTD(name, pubid, sysid); 908 } 909 } 910 } 911 912 915 public void endDTD() throws Exception { 916 if (DEBUG_CALLBACKS) { 917 System.err.println("endDTD()"); 918 } 919 if (fLexicalHandler != null) { 920 fLexicalHandler.endDTD(); 921 } 922 } 923 924 936 public void elementDecl(QName elementDecl, 937 int contentSpecType, 938 int contentSpecIndex, 939 XMLContentSpec.Provider contentSpecProvider) throws Exception { 940 941 if (fDeclHandler != null || DEBUG_CALLBACKS) { 942 943 String name = fStringPool.toString(elementDecl.rawname); 945 String contentModel; 946 if (contentSpecType == XMLElementDecl.TYPE_ANY) { 947 contentModel = "ANY"; 948 } 949 else if (contentSpecType == XMLElementDecl.TYPE_EMPTY) { 950 contentModel = "EMPTY"; 951 } 952 else { 953 contentModel = XMLContentSpec.toString(contentSpecProvider, 954 fStringPool, 955 contentSpecIndex); 956 } 957 958 if (DEBUG_CALLBACKS) { 960 System.err.println("elementDecl(" + name + ", " + contentModel + ")"); 961 } 962 if (fDeclHandler != null) { 963 fDeclHandler.elementDecl(name, contentModel); 964 } 965 } 966 967 } 968 969 988 public void attlistDecl(QName elementDecl, QName attributeDecl, 989 int attType, boolean attList, String enumString, 990 int attDefaultType, 991 int attDefaultValue) throws Exception 992 { 993 if (fDeclHandler != null || DEBUG_CALLBACKS) { 994 995 String eName = fStringPool.toString(elementDecl.rawname); 997 String aName = fStringPool.toString(attributeDecl.rawname); 998 String aType = enumString; 999 if (attType != XMLAttributeDecl.TYPE_ENUMERATION) { 1000 switch (attType) { 1001 case XMLAttributeDecl.TYPE_CDATA: { 1002 aType = "CDATA"; 1003 break; 1004 } 1005 case XMLAttributeDecl.TYPE_ENTITY: { 1006 aType = attList ? "ENTITIES" : "ENTITY"; 1007 break; 1008 } 1009 case XMLAttributeDecl.TYPE_ID: { 1010 aType = "ID"; 1011 break; 1012 } 1013 case XMLAttributeDecl.TYPE_IDREF: { 1014 aType = attList ? "IDREFS" : "IDREF"; 1015 break; 1016 } 1017 case XMLAttributeDecl.TYPE_NMTOKEN: { 1018 aType = attList ? "NMTOKENS" : "NMTOKEN"; 1019 break; 1020 } 1021 case XMLAttributeDecl.TYPE_NOTATION: { 1022 aType = "NOTATION "+enumString; 1023 break; 1024 } 1025 } 1026 } 1027 String aDefaultType = null; 1028 switch (attDefaultType) { 1029 case XMLAttributeDecl.DEFAULT_TYPE_FIXED: { 1030 aDefaultType = "#FIXED"; 1031 break; 1032 } 1033 case XMLAttributeDecl.DEFAULT_TYPE_IMPLIED: { 1034 aDefaultType = "#IMPLIED"; 1035 break; 1036 } 1037 case XMLAttributeDecl.DEFAULT_TYPE_REQUIRED: { 1038 aDefaultType = "#REQUIRED"; 1039 break; 1040 } 1041 } 1042 String aDefaultValue = fStringPool.toString(attDefaultValue); 1043 1044 if (DEBUG_CALLBACKS) { 1046 System.err.println("attributeDecl(" + 1047 eName + ", " + 1048 aName + ", " + 1049 aType + ", " + 1050 aDefaultType + ", " + 1051 aDefaultValue + ")"); 1052 } 1053 if (fDeclHandler != null) { 1054 fDeclHandler.attributeDecl(eName, aName, aType, aDefaultType, aDefaultValue); 1055 } 1056 } 1057 } 1058 1059 1062 public void internalPEDecl(int entityName, int entityValue) throws Exception { 1063 1064 if (fDeclHandler != null || DEBUG_CALLBACKS) { 1065 1066 String name = "%" + fStringPool.toString(entityName); 1068 String value = fStringPool.toString(entityValue); 1069 1070 if (DEBUG_CALLBACKS) { 1072 System.err.println("internalEntityDecl(" + name + ", " + value + ")"); 1073 } 1074 if (fDeclHandler != null) { 1075 fDeclHandler.internalEntityDecl(name, value); 1076 } 1077 } 1078 1079 } 1080 1081 1084 public void externalPEDecl(int entityName, int publicId, int systemId) throws Exception { 1085 1086 if (fDeclHandler != null || DEBUG_CALLBACKS) { 1087 1088 String name = "%" + fStringPool.toString(entityName); 1090 String pubid = fStringPool.toString(publicId); 1091 String sysid = fStringPool.toString(systemId); 1092 1093 if (DEBUG_CALLBACKS) { 1095 System.err.println("externalEntityDecl(" + name + ", " + pubid + ", " + sysid + ")"); 1096 } 1097 if (fDeclHandler != null) { 1098 fDeclHandler.externalEntityDecl(name, pubid, sysid); 1099 } 1100 } 1101 1102 } 1103 1104 1107 public void internalEntityDecl(int entityName, int entityValue) throws Exception { 1108 1109 if (fDeclHandler != null || DEBUG_CALLBACKS) { 1110 1111 String name = fStringPool.toString(entityName); 1113 String value = fStringPool.toString(entityValue); 1114 1115 if (DEBUG_CALLBACKS) { 1117 System.err.println("internalEntityDecl(" + name + ", " + value + ")"); 1118 } 1119 if (fDeclHandler != null) { 1120 fDeclHandler.internalEntityDecl(name, value); 1121 } 1122 } 1123 1124 } 1125 1126 1129 public void externalEntityDecl(int entityName, int publicId, int systemId) throws Exception { 1130 1131 if (fDeclHandler != null || DEBUG_CALLBACKS) { 1132 1133 String name = fStringPool.toString(entityName); 1135 String pubid = fStringPool.toString(publicId); 1136 String sysid = fStringPool.toString(systemId); 1137 1138 if (DEBUG_CALLBACKS) { 1140 System.err.println("externalEntityDecl(" + name + ", " + pubid + ", " + sysid + ")"); 1141 } 1142 if (fDeclHandler != null) { 1143 fDeclHandler.externalEntityDecl(name, pubid, sysid); 1144 } 1145 } 1146 1147 } 1148 1149 1152 public void unparsedEntityDecl(int entityName, int publicId, int systemId, int notationName) throws Exception { 1153 1154 if (fDTDHandler != null || DEBUG_CALLBACKS) { 1155 1156 String name = fStringPool.toString(entityName); 1158 String pubid = fStringPool.toString(publicId); 1159 String sysid = fStringPool.toString(systemId); 1160 String notation = fStringPool.toString(notationName); 1161 1162 if (DEBUG_CALLBACKS) { 1164 System.err.println("unparsedEntityDecl(" + name + ", " + pubid + ", " + sysid + ", " + notation + ")"); 1165 } 1166 if (fDTDHandler != null) { 1167 fDTDHandler.unparsedEntityDecl(name, pubid, sysid, notation); 1168 } 1169 } 1170 1171 } 1172 1173 1176 public void notationDecl(int notationName, int publicId, int systemId) throws Exception { 1177 1178 if (fDTDHandler != null || DEBUG_CALLBACKS) { 1179 1180 String name = fStringPool.toString(notationName); 1182 String pubid = fStringPool.toString(publicId); 1183 String sysid = fStringPool.toString(systemId); 1184 1185 if (DEBUG_CALLBACKS) { 1187 System.err.println("notationDecl(" + name + ", " + pubid + ", " + sysid + ")"); 1188 } 1189 if (fDTDHandler != null) { 1190 fDTDHandler.notationDecl(name, pubid, sysid); 1191 } 1192 } 1193 1194 } 1195 1196 1197 public void startDocument() throws Exception { 1198 1199 if (DEBUG_CALLBACKS) { 1201 System.err.println("setDocumentLocator(<locator>)"); 1202 System.err.println("startDocument()"); 1203 } 1204 if (fDocumentHandler != null) { 1205 fDocumentHandler.setDocumentLocator(getLocator()); 1206 fDocumentHandler.startDocument(); 1207 } 1208 if (fContentHandler != null) { 1209 fContentHandler.setDocumentLocator(getLocator()); 1210 fContentHandler.startDocument(); 1211 } 1212 1213 } 1215 1216 public void endDocument() throws Exception { 1217 1218 if (DEBUG_CALLBACKS) { 1220 System.err.println("endDocument()"); 1221 } 1222 if (fDocumentHandler != null) { 1223 fDocumentHandler.endDocument(); 1224 } 1225 if (fContentHandler != null) { 1226 fContentHandler.endDocument(); 1227 } 1228 1229 } 1231 1232 public void xmlDecl(int versionIndex, int encodingIndex, int standaloneIndex) throws Exception { 1233 1234 if (DEBUG_CALLBACKS) { 1236 String notes = ""; 1237 if (versionIndex != -1) 1238 notes += " version='" + fStringPool.toString(versionIndex) + "'"; 1239 if (encodingIndex != -1) 1240 notes += " encoding='" + fStringPool.toString(encodingIndex) + "'"; 1241 if (standaloneIndex != -1) 1242 notes += " standalone='" + fStringPool.toString(standaloneIndex) + "'"; 1243 System.err.println("xmlDecl(<?xml" + notes + "?>)"); 1244 } 1245 1246 fStringPool.releaseString(versionIndex); 1248 fStringPool.releaseString(encodingIndex); 1249 fStringPool.releaseString(standaloneIndex); 1250 1251 } 1252 1253 1254 public void textDecl(int versionIndex, int encodingIndex) throws Exception { 1255 1256 if (DEBUG_CALLBACKS) { 1258 String notes = ""; 1259 if (versionIndex != -1) 1260 notes += " version='" + fStringPool.toString(versionIndex) + "'"; 1261 if (encodingIndex != -1) 1262 notes += " encoding='" + fStringPool.toString(encodingIndex) + "'"; 1263 System.err.println("textDecl(<?xml" + notes + "?>)"); 1264 } 1265 1266 fStringPool.releaseString(versionIndex); 1268 fStringPool.releaseString(encodingIndex); 1269 } 1270 1271 1274 public void startNamespaceDeclScope(int prefix, int uri) throws Exception { 1275 1276 if (fContentHandler != null || DEBUG_CALLBACKS) { 1277 1278 String p = fStringPool.toString(prefix); 1280 String ns = fStringPool.toString(uri); 1281 1282 if (DEBUG_CALLBACKS) { 1284 System.err.println("startNamespaceDeclScope(" + p + ", " + ns + ")"); 1285 } 1286 if (fContentHandler != null) { 1287 fContentHandler.startPrefixMapping(p, ns); 1288 } 1289 } 1290 1291 } 1292 1293 1296 public void endNamespaceDeclScope(int prefix) throws Exception { 1297 1298 if (fContentHandler != null || DEBUG_CALLBACKS) { 1299 1300 String p = fStringPool.toString(prefix); 1302 1303 if (DEBUG_CALLBACKS) { 1305 System.err.println("endNamespaceDeclScope(" + p + ")"); 1306 } 1307 if (fContentHandler != null) { 1308 fContentHandler.endPrefixMapping(p); 1309 } 1310 } 1311 1312 } 1313 1314 1315 public void internalSubset(int internalSubset) { 1316 } 1317 1318 1319 public void startElement(QName element, 1320 XMLAttrList attrList, int attrListIndex) 1321 throws Exception { 1322 1323 String name = fStringPool.toString(element.rawname); 1325 AttributeList attrs = attrList.getAttributeList(attrListIndex); 1326 1327 if (DEBUG_CALLBACKS) { 1329 String atts = attrs.getLength() > 0 ? "" : " "; 1330 for (int i = 0; i < attrs.getLength(); i++) { 1331 atts += " " + attrs.getName(i) + "='" + attrs.getValue(i) + "'"; 1332 } 1333 System.err.println("startElement(" + name + "," + atts + ")"); 1334 } 1335 if (fDocumentHandler != null) { 1336 fDocumentHandler.startElement(name, attrs); 1337 } 1338 if (fContentHandler != null) { 1339 boolean namespaces = getNamespaces(); 1340 int uriIndex = element.uri; 1341 String uri = uriIndex != StringPool.EMPTY_STRING && namespaces 1342 ? fStringPool.toString(uriIndex) : ""; 1343 int localIndex = element.localpart; 1344 String local = localIndex != -1 && namespaces 1345 ? fStringPool.toString(localIndex) : ""; 1346 String raw = name; 1347 fAttributes.clear(); 1348 for (int attrIndex = attrList.getFirstAttr(attrListIndex); 1349 attrIndex != -1; 1350 attrIndex = attrList.getNextAttr(attrIndex)) { 1351 int attrNameIndex = attrList.getAttrName(attrIndex); 1352 int attrUriIndex = attrList.getAttrURI(attrIndex); 1353 String attrUri = attrUriIndex != -1 && namespaces 1354 ? fStringPool.toString(attrUriIndex) : ""; 1355 int attrLocalIndex = attrList.getAttrLocalpart(attrIndex); 1356 String attrLocal = attrLocalIndex != -1 && namespaces 1357 ? fStringPool.toString(attrLocalIndex) : ""; 1358 String attrRaw = fStringPool.toString(attrNameIndex); 1359 String attrType = fStringPool.toString(attrList.getAttType(attrIndex)); 1360 String attrValue = fStringPool.toString(attrList.getAttValue(attrIndex)); 1361 int attrPrefix = attrList.getAttrPrefix(attrIndex); 1363 boolean namespacePrefixes = getNamespacePrefixes(); 1364 if (!namespaces || namespacePrefixes || 1365 (attrPrefix != fStringPool.addSymbol("xmlns") 1366 && attrLocalIndex != fStringPool.addSymbol("xmlns") 1367 )) 1368 fAttributes.addAttribute(attrUri, attrLocal, attrRaw, 1369 attrType, attrValue); 1370 1371 } 1372 fContentHandler.startElement(uri, local, raw, fAttributes); 1373 } 1374 1375 attrList.releaseAttrList(attrListIndex); 1377 1378 } 1380 1381 public void endElement(QName element) throws Exception { 1382 1383 if (DEBUG_CALLBACKS) { 1385 System.err.println("endElement(" + fStringPool.toString(element.rawname) + ")"); 1386 } 1387 if (fDocumentHandler != null) { 1388 fDocumentHandler.endElement(fStringPool.toString(element.rawname)); 1389 } 1390 if (fContentHandler != null) { 1391 boolean namespaces = getNamespaces(); 1392 int uriIndex = element.uri; 1393 String uri = uriIndex != StringPool.EMPTY_STRING && namespaces 1394 ? fStringPool.toString(uriIndex) : ""; 1395 int localIndex = element.localpart; 1396 String local = localIndex != -1 && namespaces 1397 ? fStringPool.toString(localIndex) : ""; 1398 String raw = fStringPool.toString(element.rawname); 1399 fContentHandler.endElement(uri, local, raw); 1400 } 1401 1402 } 1404 1405 public void startEntityReference(int entityName, int entityType, int entityContext) throws Exception { 1406 if (fLexicalHandler != null || DEBUG_CALLBACKS) { 1407 switch (entityType) { 1408 case XMLEntityHandler.ENTITYTYPE_INTERNAL_PE: 1409 case XMLEntityHandler.ENTITYTYPE_EXTERNAL_PE: 1410 if (DEBUG_CALLBACKS) { 1411 System.err.println("startEntity(%" + fStringPool.toString(entityName) + ")"); 1412 } 1413 if (fLexicalHandler != null) { 1414 fLexicalHandler.startEntity("%" + fStringPool.toString(entityName)); 1415 } 1416 break; 1417 case XMLEntityHandler.ENTITYTYPE_INTERNAL: 1418 case XMLEntityHandler.ENTITYTYPE_EXTERNAL: 1419 if (DEBUG_CALLBACKS) { 1420 System.err.println("startEntity(" + fStringPool.toString(entityName) + ")"); 1421 } 1422 if (fLexicalHandler != null) { 1423 fLexicalHandler.startEntity(fStringPool.toString(entityName)); 1424 } 1425 break; 1426 case XMLEntityHandler.ENTITYTYPE_UNPARSED: throw new RuntimeException ( 1428 "PAR015 startEntityReference(): ENTITYTYPE_UNPARSED"); 1429 case XMLEntityHandler.ENTITYTYPE_DOCUMENT: 1430 break; case XMLEntityHandler.ENTITYTYPE_EXTERNAL_SUBSET: 1432 if (DEBUG_CALLBACKS) { 1433 System.err.println("startEntity(\"[dtd]\")"); 1434 } 1435 if (fLexicalHandler != null) { 1436 fLexicalHandler.startEntity("[dtd]"); 1437 } 1438 break; 1439 } 1440 } 1441 } 1442 1443 1444 public void endEntityReference(int entityName, int entityType, int entityContext) throws Exception { 1445 if (fLexicalHandler != null || DEBUG_CALLBACKS) { 1446 switch (entityType) { 1447 case XMLEntityHandler.ENTITYTYPE_INTERNAL_PE: 1448 case XMLEntityHandler.ENTITYTYPE_EXTERNAL_PE: 1449 if (DEBUG_CALLBACKS) { 1450 System.err.println("endEntity(%" + fStringPool.toString(entityName) + ")"); 1451 } 1452 if (fLexicalHandler != null) { 1453 fLexicalHandler.endEntity("%" + fStringPool.toString(entityName)); 1454 } 1455 break; 1456 case XMLEntityHandler.ENTITYTYPE_INTERNAL: 1457 case XMLEntityHandler.ENTITYTYPE_EXTERNAL: 1458 if (DEBUG_CALLBACKS) { 1459 System.err.println("endEntity(" + fStringPool.toString(entityName) + ")"); 1460 } 1461 if (fLexicalHandler != null) { 1462 fLexicalHandler.endEntity(fStringPool.toString(entityName)); 1463 } 1464 break; 1465 case XMLEntityHandler.ENTITYTYPE_UNPARSED: throw new RuntimeException ("PAR016 endEntityReference(): ENTITYTYPE_UNPARSED"); 1467 case XMLEntityHandler.ENTITYTYPE_DOCUMENT: 1468 break; case XMLEntityHandler.ENTITYTYPE_EXTERNAL_SUBSET: 1470 if (DEBUG_CALLBACKS) { 1471 System.err.println("endEntity(\"[dtd]\")"); 1472 } 1473 if (fLexicalHandler != null) { 1474 fLexicalHandler.endEntity("[dtd]"); 1475 } 1476 break; 1477 } 1478 } 1479 } 1480 1481 1482 public void startCDATA() throws Exception { 1483 if (DEBUG_CALLBACKS) { 1484 System.err.println("startCDATA()"); 1485 } 1486 if (fLexicalHandler != null) { 1487 fLexicalHandler.startCDATA(); 1488 } 1489 } 1490 1491 1492 public void endCDATA() throws Exception { 1493 if (DEBUG_CALLBACKS) { 1494 System.err.println("endCDATA()"); 1495 } 1496 if (fLexicalHandler != null) { 1497 fLexicalHandler.endCDATA(); 1498 } 1499 } 1500 1501 1502 public void characters(int dataIndex) throws Exception { 1503 throw new RuntimeException ("PAR017 cannot happen 5\n5"); 1504 } 1505 1506 1507 public void ignorableWhitespace(int dataIndex) throws Exception { 1508 throw new RuntimeException ("PAR017 cannot happen 6\n6"); 1509 } 1510 1511 1512 public void processingInstruction(int piTarget, int piData) throws Exception { 1513 1514 if (fDocumentHandler != null || fContentHandler != null || DEBUG_CALLBACKS) { 1515 1521 String target = fStringPool.orphanString(piTarget); 1523 String data = piData == -1 ? "" : fStringPool.orphanString(piData); 1524 1525 if (DEBUG_CALLBACKS) { 1527 System.err.println("processingInstruction(" + target + ", " + data + ")"); 1528 } 1529 if (fDocumentHandler != null) { 1530 fDocumentHandler.processingInstruction(target, data); 1531 } 1532 if (fContentHandler != null) { 1533 fContentHandler.processingInstruction(target, data); 1534 } 1535 1536 } 1537 else { 1538 fStringPool.releaseString(piTarget); 1539 fStringPool.releaseString(piData); 1540 } 1541 1542 } 1543 1544 1545 public void comment(int dataIndex) throws Exception { 1546 1547 if (fLexicalHandler != null || DEBUG_CALLBACKS) { 1548 1549 String data = fStringPool.orphanString(dataIndex); 1551 1552 if (DEBUG_CALLBACKS) { 1554 System.err.println("comment(" + data + ")"); 1555 } 1556 if (fLexicalHandler != null) { 1557 fLexicalHandler.comment(data.toCharArray(), 0, data.length()); 1558 } 1559 } else { 1560 fStringPool.releaseString(dataIndex); 1561 } 1562 } 1563 1564 1565 public void characters(char ch[], int start, int length) throws Exception { 1566 1567 if (DEBUG_CALLBACKS) { 1569 System.err.println("characters(<char-data>) length " + length); 1570 } 1571 if (fDocumentHandler != null) { 1572 fDocumentHandler.characters(ch, start, length); 1573 } 1574 if (fContentHandler != null) { 1575 fContentHandler.characters(ch, start, length); 1576 } 1577 1578 } 1579 1580 1581 public void ignorableWhitespace(char ch[], int start, int length) throws Exception { 1582 1583 if (DEBUG_CALLBACKS) { 1585 System.err.println("ignorableWhitespace(<white-space>)"); 1586 } 1587 if (fDocumentHandler != null) { 1588 fDocumentHandler.ignorableWhitespace(ch, start, length); 1589 } 1590 if (fContentHandler != null) { 1591 fContentHandler.ignorableWhitespace(ch, start, length); 1592 } 1593 1594 } 1595 1596} | Popular Tags |