MCPcopy Create free account
hub / github.com/w3c/epubcheck / XMLParser

Method XMLParser

src/main/java/com/adobe/epubcheck/xml/XMLParser.java:67–107  ·  view source on GitHub ↗
(ValidationContext context)

Source from the content-addressed store, hash-verified

65 private boolean reporting = true;
66
67 public XMLParser(ValidationContext context)
68 {
69 this.context = context;
70 this.report = context.report;
71 this.url = context.url;
72
73 SAXParserFactory factory = SAXParserFactory.newInstance();
74
75 try
76 {
77 factory.setNamespaceAware(true);
78 factory.setValidating(false);
79 factory.setFeature("http://xml.org/sax/features/validation", false);
80 factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
81 factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
82 if (context.version == EPUBVersion.VERSION_3)
83 {
84 factory.setXIncludeAware(false);
85 }
86 } catch (Exception ignored)
87 {
88 }
89
90 try
91 {
92 parser = factory.newSAXParser();
93 handler.setEntityResolver(new DefaultResolver(context.version));
94
95 XMLReader reader = parser.getXMLReader();
96 DeclarationHandler docTypeHandler = new DeclarationHandler(context, parser);
97 reader.setProperty("http://xml.org/sax/properties/lexical-handler", docTypeHandler);
98 reader.setProperty("http://xml.org/sax/properties/declaration-handler", docTypeHandler);
99 // add the declaration handler as a content handler
100 // to check for skipped entities
101 handler.addContentHandler(docTypeHandler);
102
103 } catch (Exception e)
104 {
105 throw new AssertionError("Could not configure the XML parser", e);
106 }
107 }
108
109 public void setReporting(boolean reporting)
110 {

Callers

nothing calls this directly

Calls 3

newInstanceMethod · 0.80
setEntityResolverMethod · 0.80
addContentHandlerMethod · 0.45

Tested by

no test coverage detected