| 1 | package com.thaiopensource.relaxng.jarv; |
| 2 | |
| 3 | import com.thaiopensource.datatype.DatatypeLibraryLoader; |
| 4 | import com.thaiopensource.relaxng.parse.IllegalSchemaException; |
| 5 | import com.thaiopensource.relaxng.parse.Parseable; |
| 6 | import com.thaiopensource.relaxng.parse.sax.SAXParseable; |
| 7 | import com.thaiopensource.relaxng.pattern.SchemaBuilderImpl; |
| 8 | import com.thaiopensource.relaxng.pattern.SchemaPatternBuilder; |
| 9 | import com.thaiopensource.relaxng.pattern.Pattern; |
| 10 | import com.thaiopensource.relaxng.pattern.NameClass; |
| 11 | import com.thaiopensource.relaxng.pattern.CommentListImpl; |
| 12 | import com.thaiopensource.relaxng.pattern.AnnotationsImpl; |
| 13 | import com.thaiopensource.resolver.Resolver; |
| 14 | import com.thaiopensource.resolver.xml.sax.SAX; |
| 15 | import com.thaiopensource.resolver.xml.sax.SAXResolver; |
| 16 | import com.thaiopensource.xml.sax.DraconianErrorHandler; |
| 17 | import com.thaiopensource.util.VoidValue; |
| 18 | import org.iso_relax.verifier.Schema; |
| 19 | import org.iso_relax.verifier.VerifierFactory; |
| 20 | import org.relaxng.datatype.DatatypeLibraryFactory; |
| 21 | import org.xml.sax.EntityResolver; |
| 22 | import org.xml.sax.ErrorHandler; |
| 23 | import org.xml.sax.InputSource; |
| 24 | import org.xml.sax.SAXException; |
| 25 | import org.xml.sax.Locator; |
| 26 | |
| 27 | import javax.xml.transform.sax.SAXSource; |
| 28 | import java.io.IOException; |
| 29 | |
| 30 | public class VerifierFactoryImpl extends VerifierFactory { |
| 31 | private final DatatypeLibraryFactory dlf = new DatatypeLibraryLoader(); |
| 32 | private final ErrorHandler eh = new DraconianErrorHandler(); |
| 33 | |
| 34 | public VerifierFactoryImpl() { } |
| 35 | |
| 36 | public Schema compileSchema(InputSource inputSource) throws SAXException, IOException { |
| 37 | SchemaPatternBuilder spb = new SchemaPatternBuilder(); |
| 38 | Resolver resolver = null; |
| 39 | EntityResolver entityResolver = getEntityResolver(); |
| 40 | if (entityResolver != null) |
| 41 | resolver = SAX.createResolver(entityResolver, true); |
| 42 | SAXResolver saxResolver = new SAXResolver(resolver); |
| 43 | Parseable<Pattern, NameClass, Locator, VoidValue, CommentListImpl, AnnotationsImpl> parseable |
| 44 | = new SAXParseable<Pattern, NameClass, Locator, VoidValue, CommentListImpl, AnnotationsImpl>(new SAXSource(saxResolver.createXMLReader(), inputSource), |
| 45 | saxResolver, |
| 46 | eh); |
| 47 | try { |
| 48 | return new SchemaImpl(SchemaBuilderImpl.parse(parseable, eh, dlf, spb, false), spb); |
| 49 | } |
| 50 | catch (IllegalSchemaException e) { |
| 51 | throw new SAXException("unreported schema error"); |
| 52 | } |
| 53 | } |
| 54 | } |