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

Method process

src/main/java/com/adobe/epubcheck/xml/XMLParser.java:129–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127 }
128
129 public void process()
130 {
131 try (InputStream in = context.resourceProvider.openStream(context.url);
132 InputStream buffered = new BufferedInputStream(in))
133 {
134 if (in == null)
135 {
136 // Abort processing.
137 // Missing required files are reported elsewhere.
138 return;
139 }
140
141 // Create the InputSource based on the encoding
142 final InputSource source;
143 String encoding = XMLEncodingSniffer.sniffEncoding(buffered);
144 if (encoding != null && !encoding.equals("UTF-8"))
145 {
146 if (encoding.equals("UTF-16"))
147 {
148 // XHTML requires UTF-8, UTF-16 is reported as an error
149 if (MIMEType.XHTML.is(context.mimeType))
150 {
151 report.message(MessageId.HTM_058, EPUBLocation.of(context));
152 }
153 // For other XML types, UTF-16 is reported as a warning
154 else
155 {
156 report.message(MessageId.RSC_027, EPUBLocation.of(context));
157 }
158 }
159 else
160 {
161 report.message(MessageId.RSC_028, EPUBLocation.of(context), encoding);
162 }
163
164 // We do not set the source encoding name, but instead let the SAXParser
165 // apply its own encoding-sniffing logic, as it can report useful errors
166 // (for instance a mismatch between a BOM and the XML declaration)
167 source = new InputSource(buffered);
168
169 }
170 else
171 {
172 // Decode the UTF-8 stream with java.io instead of letting Xerces
173 // do it, to work around Xerces issue #1668
174 // (see https://issues.apache.org/jira/browse/XERCESJ-1668),
175 // skipping any UTF-8 BOM first (disallowed by that constructor)
176 if (XMLEncodingSniffer.hasUTF8BOM(buffered))
177 {
178 buffered.skip(3);
179 }
180 source = new InputSource(new InputStreamReader(buffered, StandardCharsets.UTF_8));
181 }
182
183 // Set the source's system ID
184 source.setSystemId(url.toString());
185
186 // Set the error handler

Callers 12

validateMethod · 0.95
checkContentMethod · 0.95
checkContentMethod · 0.95
checkContentMethod · 0.95
checkMethod · 0.95
checkMethod · 0.95
checkMethod · 0.95
checkMethod · 0.95
peekMethod · 0.95
checkContentMethod · 0.95
checkContentMethod · 0.95
checkContentMethod · 0.95

Calls 14

sniffEncodingMethod · 0.95
ofMethod · 0.95
hasUTF8BOMMethod · 0.95
isMethod · 0.80
skipMethod · 0.80
addErrorHandlerMethod · 0.80
openStreamMethod · 0.65
messageMethod · 0.65
buildMethod · 0.65
getFatalErrorCountMethod · 0.65
getMessageMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected