1 28 29 package com.caucho.eswrap.javax.xml.parsers; 30 31 import com.caucho.es.Call; 32 import com.caucho.vfs.Path; 33 import com.caucho.vfs.ReadStream; 34 35 import org.xml.sax.HandlerBase ; 36 import org.xml.sax.InputSource ; 37 import org.xml.sax.helpers.DefaultHandler ; 38 39 import javax.xml.parsers.SAXParser ; 40 import java.io.IOException ; 41 import java.io.InputStream ; 42 43 public class SAXParserEcmaWrap { 44 public static void parse(SAXParser parser, Call call, int length) 45 throws Throwable 46 { 47 Object obj = call.getArgObject(0, length); 48 Object objBase = call.getArgObject(1, length); 49 50 if (objBase instanceof HandlerBase ) { 51 HandlerBase base = (HandlerBase ) objBase; 52 if (obj instanceof InputStream ) 53 parser.parse((InputStream ) obj, base); 54 else if (obj instanceof Path) { 55 Path path = (Path) obj; 56 ReadStream is = path.openRead(); 57 try { 58 parser.parse(is, base); 59 } finally { 60 is.close(); 61 } 62 } 63 else if (obj instanceof String ) { 64 parser.parse((String ) obj, base); 65 } 66 else 67 throw new IOException (); 68 } 69 else { 70 DefaultHandler base = (DefaultHandler ) objBase; 71 if (obj instanceof InputStream ) 72 parser.parse((InputStream ) obj, base); 73 else if (obj instanceof Path) { 74 Path path = (Path) obj; 75 ReadStream is = path.openRead(); 76 try { 77 parser.parse(is, base); 78 } finally { 79 is.close(); 80 } 81 } 82 else if (obj instanceof String ) { 83 parser.parse((String ) obj, base); 84 } 85 else if (obj instanceof InputSource ) { 86 parser.parse((InputSource ) obj, base); 87 } 88 else 89 throw new IOException (); 90 } 91 } 92 } 93 | Popular Tags |