1 28 29 package com.caucho.relaxng; 30 31 import com.caucho.vfs.Path; 32 import com.caucho.vfs.ReadStream; 33 import com.caucho.vfs.Vfs; 34 import com.caucho.xml.Xml; 35 36 import org.xml.sax.InputSource ; 37 import org.xml.sax.SAXException ; 38 import org.xml.sax.XMLReader ; 39 40 import java.io.IOException ; 41 42 45 public class VerifierFactoryImpl implements VerifierFactory { 46 49 public Schema compileSchema(String url) 50 throws SAXException , IOException 51 { 52 Path path = Vfs.lookup(url); 53 54 ReadStream is = path.openRead(); 55 try { 56 InputSource source = new InputSource (is); 57 source.setSystemId(url); 58 59 return compileSchema(source); 60 } finally { 61 is.close(); 62 } 63 } 64 65 66 69 public Schema compileSchema(InputSource is) 70 throws SAXException , IOException 71 { 72 try { 73 RelaxBuilder builder = new RelaxBuilder(); 74 75 XMLReader reader = new Xml(); 76 77 reader.setContentHandler(builder); 78 79 reader.parse(is); 80 81 return new SchemaImpl(builder.getGrammar()); 82 } catch (RelaxException e) { 83 throw new SAXException (e); 84 } 85 } 86 } 87 | Popular Tags |