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.w3c.dom.Document ; 36 37 import javax.xml.parsers.DocumentBuilder ; 38 import java.io.IOException ; 39 import java.io.InputStream ; 40 41 public class DocumentBuilderEcmaWrap { 42 public static Document parse(DocumentBuilder parser, Call call, int length) 43 throws Throwable 44 { 45 Object obj = call.getArgObject(0, length); 46 String systemId = null; 47 48 if (length > 1) 49 systemId = call.getArgString(1, length); 50 51 if (obj instanceof InputStream ) 52 return parser.parse((InputStream ) obj, systemId); 53 else if (obj instanceof Path) { 54 Path path = (Path) obj; 55 ReadStream is = path.openRead(); 56 try { 57 return parser.parse(is); 58 } finally { 59 is.close(); 60 } 61 } 62 else if (obj instanceof String ) { 63 return parser.parse((String ) obj); 64 } 65 else 66 throw new IOException (); 67 } 68 } 69 | Popular Tags |