1 13 14 30 31 package net.sf.saxon.aelfred; 32 33 import java.io.InputStreamReader ; 34 import java.io.IOException ; 35 import java.io.Reader ; 36 import java.io.File ; 37 import java.util.Enumeration ; 38 import java.util.Hashtable ; 39 import java.util.Locale ; 40 import java.util.Stack ; 41 import java.util.Vector ; 42 import java.net.URL ; 43 import java.net.MalformedURLException ; 44 45 import org.xml.sax.*; 46 import org.xml.sax.ext.*; 47 import org.xml.sax.helpers.NamespaceSupport ; 48 49 import net.sf.saxon.aelfred.DefaultHandler; 51 52 53 55 117 public class SAXDriver 118 implements Locator, Attributes, XMLReader, Parser, AttributeList 119 { 120 private final DefaultHandler base = new DefaultHandler (); 121 private XmlParser parser; 122 123 private EntityResolver entityResolver = base; 124 private ContentHandler contentHandler = base; 125 private DTDHandler dtdHandler = base; 126 private ErrorHandler errorHandler = base; 127 private DeclHandler declHandler = base; 128 private LexicalHandler lexicalHandler = base; 129 130 private String elementName = null; 131 private Stack entityStack = new Stack (); 132 133 private Vector attributeNames = new Vector (); 134 private Vector attributeNamespaces = new Vector (); 135 private Vector attributeLocalNames = new Vector (); 136 private Vector attributeValues = new Vector (); 137 138 private boolean namespaces = true; 139 private boolean xmlNames = false; 140 private boolean nspending = false; 143 private int attributeCount = 0; 144 private String nsTemp [] = new String [3]; 145 private NamespaceSupport prefixStack = new NamespaceSupport (); 146 147 private Hashtable features; 148 private Hashtable properties; 149 150 151 155 156 public SAXDriver () {} 157 158 159 163 168 public void setLocale (Locale locale) 169 throws SAXException 170 { 171 if ("en".equals (locale.getLanguage ())) 172 return ; 173 174 throw new SAXException ("AElfred only supports English locales."); 175 } 176 177 178 182 public EntityResolver getEntityResolver () 183 { 184 return entityResolver; 185 } 186 187 191 public void setEntityResolver (EntityResolver resolver) 192 { 193 if (resolver == null) 194 resolver = base; 195 this.entityResolver = resolver; 196 } 197 198 199 203 public DTDHandler getDTDHandler () 204 { 205 return dtdHandler; 206 } 207 208 212 public void setDTDHandler (DTDHandler handler) 213 { 214 if (handler == null) 215 handler = base; 216 this.dtdHandler = handler; 217 } 218 219 220 232 public void setDocumentHandler (DocumentHandler handler) 233 { 234 contentHandler = new Adapter (handler); 235 xmlNames = true; 236 } 237 238 242 public ContentHandler getContentHandler () 243 { 244 return contentHandler; 245 } 246 247 253 public void setContentHandler (ContentHandler handler) 254 { 255 if (handler == null) 256 handler = base; 257 contentHandler = handler; 258 } 259 260 264 public void setErrorHandler (ErrorHandler handler) 265 { 266 if (handler == null) 267 handler = base; 268 this.errorHandler = handler; 269 } 270 271 275 public ErrorHandler getErrorHandler () 276 { 277 return errorHandler; 278 } 279 280 281 297 298 public void parse (InputSource source) throws SAXException, IOException 299 { 300 synchronized (base) { 301 parser = new XmlParser (); 302 parser.setHandler (this); 303 304 try { 305 String systemId = source.getSystemId (); 306 310 systemId = tryToExpand(systemId); 311 312 316 entityStack.push (systemId); 318 321 parser.doParse (systemId, 322 source.getPublicId (), 323 source.getCharacterStream (), 324 source.getByteStream (), 325 source.getEncoding ()); 326 } catch (SAXException e) { 327 throw e; 328 } catch (IOException e) { 329 throw e; 330 } catch (RuntimeException e) { 331 throw e; 332 } catch (Exception e) { 333 throw new SAXException (e.getMessage (), e); 334 } finally { 335 contentHandler.endDocument (); 336 entityStack.removeAllElements (); 337 } 338 } 339 } 340 341 342 346 347 public void parse (String systemId) throws SAXException, IOException 348 { 349 parse (new InputSource (systemId)); 350 } 351 352 static final String FEATURE = "http://xml.org/sax/features/"; 356 static final String HANDLER = "http://xml.org/sax/properties/"; 357 358 364 public boolean getFeature (String featureId) 365 throws SAXNotRecognizedException 366 { 367 if ((FEATURE + "validation").equals (featureId)) 368 return false; 369 370 if ((FEATURE + "external-general-entities").equals (featureId) 372 || (FEATURE + "external-parameter-entities").equals (featureId)) 373 return true; 374 375 if ((FEATURE + "namespace-prefixes").equals (featureId)) 377 return xmlNames; 378 379 if ((FEATURE + "namespaces").equals (featureId)) 381 return namespaces; 382 383 385 if ((FEATURE + "string-interning").equals (featureId)) 387 return true; 388 389 if (features != null && features.containsKey (featureId)) 390 return ((Boolean )features.get (featureId)).booleanValue (); 391 392 throw new SAXNotRecognizedException (featureId); 393 } 394 395 401 public Object getProperty (String propertyId) 402 throws SAXNotRecognizedException 403 { 404 if ((HANDLER + "declaration-handler").equals (propertyId)) 405 return declHandler; 406 407 if ((HANDLER + "lexical-handler").equals (propertyId)) 408 return lexicalHandler; 409 410 if (properties != null && properties.containsKey (propertyId)) 411 return properties.get (propertyId); 412 413 throw new SAXNotRecognizedException (propertyId); 415 } 416 417 422 public void setFeature (String featureId, boolean state) 423 throws SAXNotRecognizedException, SAXNotSupportedException 424 { 425 boolean value; 426 427 try { 428 value = getFeature (featureId); 430 431 if (state == value) 432 return; 433 434 if ((FEATURE + "namespace-prefixes").equals (featureId)) { 435 xmlNames = state; 437 return; 438 } 439 440 if ((FEATURE + "namespaces").equals (featureId)) { 441 if (true) { 443 namespaces = state; 444 return; 445 } 446 } 448 449 if (features == null || !features.containsKey (featureId)) 451 throw new SAXNotSupportedException (featureId); 452 453 } catch (SAXNotRecognizedException e) { 454 if (features == null) 456 features = new Hashtable (5); 457 } 458 459 features.put (featureId, 461 state 462 ? Boolean.TRUE 463 : Boolean.FALSE); 464 } 465 466 470 public void setProperty (String propertyId, Object property) 471 throws SAXNotRecognizedException, SAXNotSupportedException 472 { 473 Object value; 474 475 try { 476 value = getProperty (propertyId); 478 479 if ((HANDLER + "declaration-handler").equals (propertyId)) { 480 if (property == null) 481 declHandler = base; 482 else if (! (property instanceof DeclHandler)) 483 throw new SAXNotSupportedException (propertyId); 484 else 485 declHandler = (DeclHandler) property; 486 return ; 487 } 488 489 if ((HANDLER + "lexical-handler").equals (propertyId) || 490 "http://xml.org/sax/handlers/LexicalHandler".equals(propertyId)) { 491 if (property == null) 493 lexicalHandler = base; 494 else if (! (property instanceof LexicalHandler)) 495 throw new SAXNotSupportedException (propertyId); 496 else 497 lexicalHandler = (LexicalHandler) property; 498 return ; 499 } 500 501 if (properties == null || !properties.containsKey (propertyId)) 503 throw new SAXNotSupportedException (propertyId); 504 505 } catch (SAXNotRecognizedException e) { 506 if (properties == null) 508 properties = new Hashtable (5); 509 } 510 511 properties.put (propertyId, property); 513 } 514 515 516 522 526 void startDocument () throws SAXException 527 { 528 contentHandler.setDocumentLocator (this); 529 contentHandler.startDocument (); 530 attributeNames.removeAllElements (); 531 attributeValues.removeAllElements (); 532 } 533 534 void endDocument () throws SAXException 535 { 536 } 539 540 Object resolveEntity (String publicId, String systemId) 541 throws SAXException, IOException 542 { 543 InputSource source = entityResolver.resolveEntity (publicId, 544 systemId); 545 546 if (source == null) { 547 return null; 548 } else if (source.getCharacterStream () != null) { 549 return source.getCharacterStream (); 550 } else if (source.getByteStream () != null) { 551 if (source.getEncoding () == null) 552 return source.getByteStream (); 553 else try { 554 return new InputStreamReader ( 555 source.getByteStream (), 556 source.getEncoding () 557 ); 558 } catch (IOException e) { 559 return source.getByteStream (); 560 } 561 } else { 562 String sysId = source.getSystemId (); 563 return tryToExpand(sysId); } 565 } 569 570 void startExternalEntity (String systemId) 571 throws SAXException 572 { 573 entityStack.push (systemId); 574 } 575 576 void endExternalEntity (String systemId) 577 throws SAXException 578 { 579 entityStack.pop (); 580 } 581 582 void doctypeDecl (String name, String publicId, String systemId) 583 throws SAXException 584 { 585 lexicalHandler.startDTD (name, publicId, systemId); 586 587 590 } 594 595 void endDoctype () throws SAXException 596 { 597 602 deliverDTDEvents (); 603 lexicalHandler.endDTD (); 604 } 605 606 607 void attribute (String aname, String value, boolean isSpecified) 608 throws SAXException 609 { 610 616 if (attributeCount++ == 0) { 617 if (namespaces) { 618 prefixStack.pushContext (); 619 } 620 } 621 622 if (value == null) { 625 return; 629 } 630 631 if (namespaces && aname.startsWith("xmlns")) { 632 if (aname.length() == 5) { 633 prefixStack.declarePrefix ("", value); 634 contentHandler.startPrefixMapping ("", value); 636 637 } else if (aname.charAt(5)==':' && !aname.equals("xmlns:xml")) { 638 639 if (aname.length() == 6) { 640 errorHandler.error (new SAXParseException ( 641 "Missing namespace prefix in namespace declaration: " + aname, 642 this)); 643 return; 644 } 645 String prefix = aname.substring (6); 646 647 if (value.length() == 0) { 648 errorHandler.error (new SAXParseException ( 649 "Missing URI in namespace declaration: " + aname, 650 this)); 651 return; 652 } 653 prefixStack.declarePrefix (prefix, value); 654 contentHandler.startPrefixMapping (prefix, value); 656 } 657 658 if (!xmlNames) { 659 return; 662 } 663 } 664 665 attributeNames.addElement (aname); 666 attributeValues.addElement (value); 667 } 668 669 void startElement (String elname) 670 throws SAXException 671 { 672 ContentHandler handler = contentHandler; 673 674 if (attributeCount == 0) 675 prefixStack.pushContext (); 676 677 elementName = elname; 679 if (namespaces) { 680 681 if (attributeCount > 0) { 683 for (int i=0; i<attributeNames.size(); i++) { 684 String aname = (String )attributeNames.elementAt(i); 685 if (aname.indexOf(':')>0) { 686 if (xmlNames && aname.startsWith("xmlns:")) { 687 attributeNamespaces.addElement(""); 688 attributeLocalNames.addElement(aname); 689 690 } else if (prefixStack.processName (aname, nsTemp, true) == null) { 691 errorHandler.error (new SAXParseException ( 692 "undeclared name prefix in: " + aname, 693 this)); 694 attributeNamespaces.addElement(""); 696 attributeLocalNames.addElement(aname.substring(aname.indexOf(':'))); 697 } else { 698 attributeNamespaces.addElement(nsTemp[0]); 699 attributeLocalNames.addElement(nsTemp[1]); 700 } 701 } else { 702 attributeNamespaces.addElement(""); 703 attributeLocalNames.addElement(aname); 704 } 705 for (int j=0; j<i; j++) { 707 if (attributeNamespaces.elementAt(i) == attributeNamespaces.elementAt(j) && 708 attributeLocalNames.elementAt(i) == attributeLocalNames.elementAt(j)) { 709 errorHandler.error( new SAXParseException ( 710 "duplicate attribute name: " + attributeLocalNames.elementAt(j), 711 this)); 712 } 713 } 714 } 715 } 716 717 if (prefixStack.processName (elname, nsTemp, false) == null) { 718 errorHandler.error (new SAXParseException ( 719 "undeclared name prefix in: " + elname, 720 this)); 721 nsTemp [0] = nsTemp [1] = ""; 722 elname = elname.substring(elname.indexOf(':')); 724 } 725 handler.startElement (nsTemp [0], nsTemp [1], elname, this); 726 } else 727 handler.startElement ("", "", elname, this); 728 730 if (attributeCount != 0) { 732 attributeNames.removeAllElements (); 733 attributeNamespaces.removeAllElements (); 734 attributeLocalNames.removeAllElements (); 735 attributeValues.removeAllElements (); 736 attributeCount = 0; 737 } 738 nspending = false; 739 } 740 741 void endElement (String elname) 742 throws SAXException 743 { 744 ContentHandler handler = contentHandler; 745 746 if (!namespaces) { 747 handler.endElement("", "", elname); 748 return; 749 } 750 751 if (prefixStack.processName (elname, nsTemp, false) == null) { 753 errorHandler.error (new SAXParseException ( 755 "undeclared name prefix in: " + elname, this)); 756 nsTemp [0] = nsTemp [1] = ""; 757 elname = elname.substring(elname.indexOf(':')); 758 } 759 760 handler.endElement (nsTemp[0], nsTemp[1], elname); 761 762 764 766 767 Enumeration prefixes = prefixStack.getDeclaredPrefixes (); 768 769 while (prefixes.hasMoreElements ()) 770 handler.endPrefixMapping ((String ) prefixes.nextElement ()); 771 prefixStack.popContext (); 772 } 773 774 void startCDATA () 775 throws SAXException 776 { 777 lexicalHandler.startCDATA (); 778 } 779 780 void charData (char ch[], int start, int length) 781 throws SAXException 782 { 783 contentHandler.characters (ch, start, length); 784 } 785 786 void endCDATA () 787 throws SAXException 788 { 789 lexicalHandler.endCDATA (); 790 } 791 792 void ignorableWhitespace (char ch[], int start, int length) 793 throws SAXException 794 { 795 contentHandler.ignorableWhitespace (ch, start, length); 796 } 797 798 void processingInstruction (String target, String data) 799 throws SAXException 800 { 801 805 contentHandler.processingInstruction (target, data); 806 } 807 808 void comment (char ch[], int start, int length) 809 throws SAXException 810 { 811 815 if (lexicalHandler != base) 816 lexicalHandler.comment (ch, start, length); 817 } 818 819 void error (String message, String url, int line, int column) 821 throws SAXException 822 { 823 SAXParseException fatal; 824 825 fatal = new SAXParseException (message, null, url, line, column); 826 errorHandler.fatalError (fatal); 827 828 throw fatal; 830 } 831 832 833 private void deliverDTDEvents () 837 throws SAXException 838 { 839 String ename; 840 String nname; 841 String publicId; 842 String systemId; 843 844 if (dtdHandler != base) { 846 Enumeration notationNames = parser.declaredNotations (); 847 848 while (notationNames.hasMoreElements ()) { 849 nname = (String ) notationNames.nextElement (); 850 publicId = parser.getNotationPublicId (nname); 851 systemId = parser.getNotationSystemId (nname); 852 dtdHandler.notationDecl (nname, publicId, systemId); 853 } 854 } 855 856 if (dtdHandler != base || declHandler != base) { 858 Enumeration entityNames = parser.declaredEntities (); 859 int type; 860 861 while (entityNames.hasMoreElements ()) { 862 ename = (String ) entityNames.nextElement (); 863 type = parser.getEntityType (ename); 864 865 if (ename.charAt (0) == '%') 866 continue; 867 868 if (type == XmlParser.ENTITY_NDATA) { 870 publicId = parser.getEntityPublicId (ename); 871 systemId = parser.getEntitySystemId (ename); 872 nname = parser.getEntityNotationName (ename); 873 dtdHandler.unparsedEntityDecl (ename, 874 publicId, systemId, nname); 875 876 } 878 else if (type == XmlParser.ENTITY_TEXT) { 879 publicId = parser.getEntityPublicId (ename); 880 systemId = parser.getEntitySystemId (ename); 881 declHandler.externalEntityDecl (ename, 882 publicId, systemId); 883 884 } 886 else if (type == XmlParser.ENTITY_INTERNAL) { 887 if ("lt".equals (ename) || "gt".equals (ename) 890 || "quot".equals (ename) 891 || "apos".equals (ename) 892 || "amp".equals (ename)) 893 continue; 894 declHandler.internalEntityDecl (ename, 895 parser.getEntityValue (ename)); 896 } 897 } 898 } 899 900 if (declHandler != base) { 902 Enumeration elementNames = parser.declaredElements (); 903 Enumeration attNames; 904 905 while (elementNames.hasMoreElements ()) { 906 String model = null; 907 908 ename = (String ) elementNames.nextElement (); 909 switch (parser.getElementContentType (ename)) { 910 case XmlParser.CONTENT_ANY: 911 model = "ANY"; 912 break; 913 case XmlParser.CONTENT_EMPTY: 914 model = "EMPTY"; 915 break; 916 case XmlParser.CONTENT_MIXED: 917 case XmlParser.CONTENT_ELEMENTS: 918 model = parser.getElementContentModel (ename); 919 break; 920 case XmlParser.CONTENT_UNDECLARED: 921 default: 922 model = null; 923 break; 924 } 925 if (model != null) 926 declHandler.elementDecl (ename, model); 927 928 attNames = parser.declaredAttributes (ename); 929 while (attNames != null && attNames.hasMoreElements ()) { 930 String aname = (String ) attNames.nextElement (); 931 String type; 932 String valueDefault; 933 String value; 934 935 switch (parser.getAttributeType (ename, aname)) { 936 case XmlParser.ATTRIBUTE_CDATA: 937 type = "CDATA"; 938 break; 939 case XmlParser.ATTRIBUTE_ENTITY: 940 type = "ENTITY"; 941 break; 942 case XmlParser.ATTRIBUTE_ENTITIES: 943 type = "ENTITIES"; 944 break; 945 case XmlParser.ATTRIBUTE_ENUMERATED: 946 type = parser.getAttributeEnumeration (ename, aname); 947 break; 948 case XmlParser.ATTRIBUTE_ID: 949 type = "ID"; 950 break; 951 case XmlParser.ATTRIBUTE_IDREF: 952 type = "IDREF"; 953 break; 954 case XmlParser.ATTRIBUTE_IDREFS: 955 type = "IDREFS"; 956 break; 957 case XmlParser.ATTRIBUTE_NMTOKEN: 958 type = "NMTOKEN"; 959 break; 960 case XmlParser.ATTRIBUTE_NMTOKENS: 961 type = "NMTOKENS"; 962 break; 963 964 case XmlParser.ATTRIBUTE_NOTATION: 969 type = "NOTATION"; 970 break; 971 972 default: 973 errorHandler.fatalError (new SAXParseException ( 974 "internal error, att type", this)); 975 type = null; 976 } 977 978 switch (parser.getAttributeDefaultValueType ( 979 ename, aname)) { 980 case XmlParser.ATTRIBUTE_DEFAULT_IMPLIED: 981 valueDefault = "#IMPLIED"; 982 break; 983 case XmlParser.ATTRIBUTE_DEFAULT_REQUIRED: 984 valueDefault = "#REQUIRED"; 985 break; 986 case XmlParser.ATTRIBUTE_DEFAULT_FIXED: 987 valueDefault = "#FIXED"; 988 break; 989 case XmlParser.ATTRIBUTE_DEFAULT_SPECIFIED: 990 valueDefault = null; 991 break; 992 993 default: 994 errorHandler.fatalError (new SAXParseException ( 995 "internal error, att default", this)); 996 valueDefault = null; 997 } 998 999 value = parser.getAttributeDefaultValue (ename, aname); 1000 1001 declHandler.attributeDecl (ename, aname, 1002 type, valueDefault, value); 1003 } 1004 } 1005 } 1006 } 1007 1008 1009 1013 1017 public int getLength () 1018 { 1019 return attributeNames.size (); 1020 } 1021 1022 1025 public String getURI (int index) 1026 { 1027 return (String ) (attributeNamespaces.elementAt (index)); 1028 } 1029 1030 1033 public String getLocalName (int index) 1034 { 1035 return (String ) (attributeLocalNames.elementAt (index)); 1036 } 1037 1038 1041 public String getQName (int i) 1042 { 1043 return (String ) (attributeNames.elementAt (i)); 1044 } 1045 1046 1049 public String getName (int i) 1050 { 1051 return (String ) (attributeNames.elementAt (i)); 1052 } 1053 1054 1058 public String getType (int i) 1059 { 1060 switch (parser.getAttributeType (elementName, getQName (i))) { 1061 1062 case XmlParser.ATTRIBUTE_UNDECLARED: 1063 case XmlParser.ATTRIBUTE_CDATA: 1064 return "CDATA"; 1065 case XmlParser.ATTRIBUTE_ID: 1066 return "ID"; 1067 case XmlParser.ATTRIBUTE_IDREF: 1068 return "IDREF"; 1069 case XmlParser.ATTRIBUTE_IDREFS: 1070 return "IDREFS"; 1071 case XmlParser.ATTRIBUTE_ENTITY: 1072 return "ENTITY"; 1073 case XmlParser.ATTRIBUTE_ENTITIES: 1074 return "ENTITIES"; 1075 case XmlParser.ATTRIBUTE_ENUMERATED: 1076 case XmlParser.ATTRIBUTE_NMTOKEN: 1079 return "NMTOKEN"; 1080 case XmlParser.ATTRIBUTE_NMTOKENS: 1081 return "NMTOKENS"; 1082 case XmlParser.ATTRIBUTE_NOTATION: 1083 return "NOTATION"; 1086 1087 } 1088 1089 return null; 1090 } 1091 1092 1093 1097 public String getValue (int i) 1098 { 1099 return (String ) (attributeValues.elementAt (i)); 1100 } 1101 1102 1103 1106 public int getIndex (String uri, String local) 1107 { 1108 int length = getLength (); 1109 1110 for (int i = 0; i < length; i++) { 1111 if (!getURI (i).equals (uri)) 1112 continue; 1113 if (getLocalName (i).equals (local)) 1114 return i; 1115 } 1116 return -1; 1117 } 1118 1119 1120 1123 public int getIndex (String xmlName) 1124 { 1125 int length = getLength (); 1126 1127 for (int i = 0; i < length; i++) { 1128 if (getQName (i).equals (xmlName)) 1129 return i; 1130 } 1131 return -1; 1132 } 1133 1134 1135 1138 public String getType (String uri, String local) 1139 { 1140 int index = getIndex (uri, local); 1141 1142 if (index < 0) 1143 return null; 1144 return getType (index); 1145 } 1146 1147 1148 1152 public String getType (String xmlName) 1153 { 1154 int index = getIndex (xmlName); 1155 1156 if (index < 0) 1157 return null; 1158 return getType (index); 1159 } 1160 1161 1162 1165 public String getValue (String uri, String local) 1166 { 1167 int index = getIndex (uri, local); 1168 1169 if (index < 0) 1170 return null; 1171 return getValue (index); 1172 } 1173 1174 1175 1179 public String getValue (String xmlName) 1180 { 1181 int index = getIndex (xmlName); 1182 1183 if (index < 0) 1184 return null; 1185 return getValue (index); 1186 } 1187 1188 1189 1193 1196 public String getPublicId () 1197 { 1198 return null; } 1200 1201 1204 public String getSystemId () 1205 { 1206 return (String ) entityStack.peek (); 1207 } 1208 1209 1212 public int getLineNumber () 1213 { 1214 return parser.getLineNumber (); 1215 } 1216 1217 1220 public int getColumnNumber () 1221 { 1222 return parser.getColumnNumber (); 1223 } 1224 1225 1227 private static class Adapter implements ContentHandler 1228 { 1229 private DocumentHandler docHandler; 1230 1231 Adapter (DocumentHandler dh) 1232 { docHandler = dh; } 1233 1234 1235 public void setDocumentLocator (Locator l) 1236 { docHandler.setDocumentLocator (l); } 1237 1238 public void startDocument () throws SAXException 1239 { docHandler.startDocument (); } 1240 1241 public void processingInstruction (String target, String data) 1242 throws SAXException 1243 { docHandler.processingInstruction (target, data); } 1244 1245 public void startPrefixMapping (String prefix, String uri) 1246 { } 1247 1248 public void startElement ( 1249 String namespace, 1250 String local, 1251 String name, 1252 Attributes attrs ) throws SAXException 1253 { 1254 docHandler.startElement (name, (AttributeList) attrs); 1255 } 1256 1257 public void characters (char buf [], int offset, int len) 1258 throws SAXException 1259 { 1260 docHandler.characters (buf, offset, len); 1261 } 1262 1263 public void ignorableWhitespace (char buf [], int offset, int len) 1264 throws SAXException 1265 { 1266 docHandler.ignorableWhitespace (buf, offset, len); 1267 } 1268 1269 public void skippedEntity (String name) 1270 { } 1271 1272 public void endElement (String u, String l, String name) 1273 throws SAXException 1274 { docHandler.endElement (name); } 1275 1276 public void endPrefixMapping (String prefix) 1277 { } 1278 1279 public void endDocument () throws SAXException 1280 { docHandler.endDocument (); } 1281 } 1282 1283 public static String tryToExpand(String systemId) { 1284 if (systemId==null) { 1285 systemId = ""; 1286 } 1287 try { 1288 URL u = new URL (systemId); 1289 return systemId; } catch (MalformedURLException err) { 1291 String dir; 1292 try { 1293 dir = System.getProperty("user.dir"); 1294 } catch (Exception geterr) { 1295 return systemId; 1297 } 1298 if (!(dir.endsWith("/") || systemId.startsWith("/"))) { 1299 dir = dir + "/"; 1300 } 1301 1302 try { 1303 URL currentDirectoryURL = new File (dir).toURL(); URL baseURL = new URL (currentDirectoryURL, systemId); 1305 return baseURL.toString(); 1307 } catch (MalformedURLException err2) { 1308 return systemId; 1310 } 1311 } 1312 } 1313 1314} 1315 | Popular Tags |