Debian Codegraph @

mod/rng-parse/src/main/com/thaiopensource/relaxng/parse/sax/SAXParseable.java

raw
1 package com.thaiopensource.relaxng.parse.sax;
2
3 import com.thaiopensource.relaxng.parse.Annotations;
4 import com.thaiopensource.relaxng.parse.BuildException;
5 import com.thaiopensource.relaxng.parse.CommentList;
6 import com.thaiopensource.relaxng.parse.IllegalSchemaException;
7 import com.thaiopensource.relaxng.parse.IncludedGrammar;
8 import com.thaiopensource.relaxng.parse.SchemaBuilder;
9 import com.thaiopensource.relaxng.parse.Scope;
10 import com.thaiopensource.relaxng.parse.SubParseable;
11 import com.thaiopensource.resolver.xml.sax.SAXResolver;
12 import com.thaiopensource.util.Uri;
13 import org.xml.sax.ErrorHandler;
14 import org.xml.sax.SAXException;
15 import org.xml.sax.XMLReader;
16
17 import javax.xml.transform.sax.SAXSource;
18 import java.io.IOException;
19
20 public class SAXParseable<P, NC, L, EA, CL extends CommentList<L>, A extends Annotations<L, EA, CL>>
21 extends SAXSubParser<P, NC, L, EA, CL, A> implements SubParseable<P, NC, L, EA, CL, A> {
22 private final SAXSource source;
23
24 /**
25 *
26 * @param source XMLReader must be non-null
27 * @param resolver
28 * @param eh
29 */
30 public SAXParseable(SAXSource source, SAXResolver resolver, ErrorHandler eh) {
31 super(resolver, eh);
32 this.source = source;
33 }
34
35 public P parse(SchemaBuilder<P, NC, L, EA, CL, A> schemaBuilder, Scope<P, L, EA, CL, A> scope) throws BuildException, IllegalSchemaException {
36 try {
37 XMLReader xr = source.getXMLReader();
38 SchemaParser<P, NC, L, EA, CL, A> sp = new SchemaParser<P, NC, L, EA, CL, A>(xr, eh, schemaBuilder, null, scope);
39 xr.parse(source.getInputSource());
40 return sp.getParsedPattern();
41 }
42 catch (SAXException e) {
43 throw BuildException.fromSAXException(e);
44 }
45 catch (IOException e) {
46 throw new BuildException(e);
47 }
48 }
49
50 public P parseAsInclude(SchemaBuilder<P, NC, L, EA, CL, A> schemaBuilder, IncludedGrammar<P, L, EA, CL, A> g)
51 throws BuildException, IllegalSchemaException {
52 try {
53 XMLReader xr = source.getXMLReader();
54 SchemaParser<P, NC, L, EA, CL, A> sp = new SchemaParser<P, NC, L, EA, CL, A>(xr, eh, schemaBuilder, g, g);
55 xr.parse(source.getInputSource());
56 return sp.getParsedPattern();
57 }
58 catch (SAXException e) {
59 throw BuildException.fromSAXException(e);
60 }
61 catch (IOException e) {
62 throw new BuildException(e);
63 }
64 }
65
66 public String getUri() {
67 final String uri = source.getInputSource().getSystemId();
68 if (uri == null)
69 return null;
70 return Uri.escapeDisallowedChars(uri);
71 }
72 }