|
25 | 25 | import java.util.Locale; |
26 | 26 | import java.util.Stack; |
27 | 27 |
|
| 28 | +import org.w3c.epubcheck.constants.MIMEType; |
28 | 29 | import org.w3c.epubcheck.core.references.Reference; |
| 30 | +import org.w3c.epubcheck.core.references.Reference.Type; |
| 31 | +import org.xml.sax.SAXException; |
29 | 32 |
|
30 | 33 | import com.adobe.epubcheck.api.EPUBLocation; |
31 | 34 | import com.adobe.epubcheck.css.CSSChecker; |
|
40 | 43 | import com.adobe.epubcheck.xml.model.XMLElement; |
41 | 44 |
|
42 | 45 | import io.mola.galimatias.URL; |
| 46 | +import net.sf.saxon.trans.XPathException; |
| 47 | +import net.sf.saxon.tree.util.ProcInstParser; |
43 | 48 |
|
44 | 49 | public class OPSHandler extends XMLHandler |
45 | 50 | { |
@@ -190,6 +195,10 @@ public void startElement() |
190 | 195 | Reference.Type resourceType = Reference.Type.GENERIC; |
191 | 196 | if (ns != null) |
192 | 197 | { |
| 198 | + if (name.equals("style")) |
| 199 | + { |
| 200 | + textNode = new StringBuilder(); |
| 201 | + } |
193 | 202 | if (ns.equals("http://www.w3.org/2000/svg")) |
194 | 203 | { |
195 | 204 | if (name.equals("lineargradient") || name.equals("radialgradient") |
@@ -246,10 +255,6 @@ else if (name.equals("link")) |
246 | 255 | { |
247 | 256 | checkLink(); |
248 | 257 | } |
249 | | - else if (name.equals("style")) |
250 | | - { |
251 | | - textNode = new StringBuilder(); |
252 | | - } |
253 | 258 | else if (name.equals("iframe")) |
254 | 259 | { |
255 | 260 | checkIFrame(); |
@@ -341,20 +346,21 @@ public void endElement() |
341 | 346 |
|
342 | 347 | EPUBLocation currentLocation = elementLocationStack.pop(); |
343 | 348 |
|
344 | | - if (EpubConstants.HtmlNamespaceUri.equals(ns)) |
| 349 | + if ("style".equals(name)) |
345 | 350 | { |
346 | | - |
347 | | - if ("style".equals(name)) |
| 351 | + String style = textNode.toString(); |
| 352 | + if (style.length() > 0) |
348 | 353 | { |
349 | | - String style = textNode.toString(); |
350 | | - if (style.length() > 0) |
351 | | - { |
352 | | - this.hasCSS = true; |
353 | | - new CSSChecker(context, style, currentLocation.getLine(), false).check(); |
354 | | - } |
355 | | - textNode = null; |
| 354 | + this.hasCSS = true; |
| 355 | + new CSSChecker(context, style, currentLocation.getLine(), false).check(); |
356 | 356 | } |
357 | | - else if ("table".equals(name)) |
| 357 | + textNode = null; |
| 358 | + } |
| 359 | + |
| 360 | + if (EpubConstants.HtmlNamespaceUri.equals(ns)) |
| 361 | + { |
| 362 | + |
| 363 | + if ("table".equals(name)) |
358 | 364 | { |
359 | 365 | if (tableDepth > 0) |
360 | 366 | { |
@@ -392,4 +398,39 @@ public void characters(char[] chars, int start, int length) |
392 | 398 | } |
393 | 399 | } |
394 | 400 |
|
| 401 | + @Override |
| 402 | + public void processingInstruction(String target, String data) |
| 403 | + throws SAXException |
| 404 | + { |
| 405 | + super.processingInstruction(target, data); |
| 406 | + |
| 407 | + // for SVG documents, parse 'xml-stylesheet' processing instructions |
| 408 | + if (MIMEType.SVG.is(context.mimeType) && "xml-stylesheet".equals(target)) |
| 409 | + { |
| 410 | + checkXMLStylesheetPI(data); |
| 411 | + } |
| 412 | + } |
| 413 | + |
| 414 | + protected void checkXMLStylesheetPI(String data) |
| 415 | + { |
| 416 | + assert data != null; |
| 417 | + try |
| 418 | + { |
| 419 | + String type = ProcInstParser.getPseudoAttribute(data, "type"); |
| 420 | + if (type == null || MIMEType.CSS.is(type)) |
| 421 | + { |
| 422 | + String href = ProcInstParser.getPseudoAttribute(data, "href"); |
| 423 | + URL url = checkURL(href); |
| 424 | + if (url != null) |
| 425 | + { |
| 426 | + hasCSS = true; |
| 427 | + registerReference(url, Type.STYLESHEET); |
| 428 | + } |
| 429 | + } |
| 430 | + } catch (XPathException e1) |
| 431 | + { |
| 432 | + // ignore invalid declaration, must have been reported earlier |
| 433 | + } |
| 434 | + } |
| 435 | + |
395 | 436 | } |
0 commit comments