XMLParserImpl.java
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.text.markup;
import com.adobe.xfa.text.markup.XMLParserBase;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
class XMLParserImpl
implements ContentHandler,
ErrorHandler {
private final XMLParserBase mClient;
XMLParserImpl(XMLParserBase client) {
this.mClient = client;
}
public void processText(String sText) {
try {
StringReader stringReader = new StringReader(sText);
InputSource inputSource = new InputSource(stringReader);
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setContentHandler(this);
xmlReader.setErrorHandler(this);
xmlReader.parse(inputSource);
}
catch (SAXException e) {
}
catch (ParserConfigurationException e) {
}
catch (IOException e) {
// empty catch block
}
}
@Override
public void characters(char[] content, int start, int length) throws SAXException {
this.mClient.onContent(new String(content, start, length));
}
@Override
public void endDocument() throws SAXException {
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
this.mClient.onEndTag(this.resolveElement(uri, localName, qName));
}
@Override
public void endPrefixMapping(String arg0) throws SAXException {
}
@Override
public void ignorableWhitespace(char[] content, int start, int length) throws SAXException {
this.characters(content, start, length);
}
@Override
public void processingInstruction(String arg0, String arg1) throws SAXException {
}
@Override
public void setDocumentLocator(Locator arg0) {
}
@Override
public void skippedEntity(String arg0) throws SAXException {
}
@Override
public void startDocument() throws SAXException {
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
this.mClient.onStartTag(this.resolveElement(uri, localName, qName), attributes);
}
@Override
public void startPrefixMapping(String arg0, String arg1) {
}
@Override
public void error(SAXParseException exception) throws SAXException {
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void warning(SAXParseException exception) throws SAXException {
}
private String resolveElement(String uri, String localName, String qName) {
if (localName != null && localName.length() > 0) {
return localName;
}
if (qName != null && qName.length() > 0) {
return qName;
}
return uri;
}
}