1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.tika.parser.html;
18
19 import javax.xml.XMLConstants;
20
21 import org.apache.tika.sax.ContentHandlerDecorator;
22 import org.xml.sax.Attributes;
23 import org.xml.sax.ContentHandler;
24 import org.xml.sax.SAXException;
25 import org.xml.sax.helpers.AttributesImpl;
26
27
28
29
30
31
32
33
34 class XHTMLDowngradeHandler extends ContentHandlerDecorator {
35
36 public XHTMLDowngradeHandler(ContentHandler handler) {
37 super(handler);
38 }
39
40 @Override
41 public void startElement(
42 String uri, String localName, String name, Attributes atts)
43 throws SAXException {
44 String upper = localName.toUpperCase();
45
46 AttributesImpl attributes = new AttributesImpl();
47 for (int i = 0; i < atts.getLength(); i++) {
48 String local = atts.getLocalName(i);
49 String qname = atts.getQName(i);
50 if (!XMLConstants.NULL_NS_URI.equals(atts.getURI(i).length())
51 && !local.equals(XMLConstants.XMLNS_ATTRIBUTE)
52 && !qname.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
53 attributes.addAttribute(
54 atts.getURI(i), local, qname,
55 atts.getType(i), atts.getValue(i));
56 }
57 }
58
59 super.startElement(XMLConstants.NULL_NS_URI, upper, upper, attributes);
60 }
61
62 @Override
63 public void endElement(String uri, String localName, String name)
64 throws SAXException {
65 String upper = localName.toUpperCase();
66 super.endElement(XMLConstants.NULL_NS_URI, upper, upper);
67 }
68
69 @Override
70 public void startPrefixMapping(String prefix, String uri) {
71 }
72
73 @Override
74 public void endPrefixMapping(String prefix) {
75 }
76
77 }