Repository navigation
Expand file tree
/
Copy pathStringHandler.java
More file actions
96 lines (79 loc) · 2.48 KB
/
Copy pathStringHandler.java
File metadata and controls
96 lines (79 loc) · 2.48 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
package com.carl.java.excel;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* @author: Peichen Xu
* @since: 2016-8-10
*/
public class StringHandler extends DefaultHandler {
private static final String TAG = StringHandler.class.getSimpleName();
private List<Entry> mList;
private Entry mEntryCur;
private StringBuilder mSb;
public StringHandler() {
// TODO Auto-generated constructor stub
}
public List<Entry> getList() {
return mList;
}
@Override
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
super.endDocument();
// System.out.println("endDocument");
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(uri, localName, qName);
// System.out.println("end---uri=" + uri + ",localName=" + localName + ",qName=" + qName);
if ("string".equals(qName)) {
if (mEntryCur != null) {
mEntryCur.setValue(mSb.toString());
mList.add(mEntryCur);
mEntryCur = null;
mSb.delete(0, mSb.length());
}
}
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
super.startDocument();
// System.out.println("startDocument");
mList = new ArrayList<Entry>();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
super.startElement(uri, localName, qName, attributes);
// System.out.println("start---uri=" + uri + ",localName=" + localName + ",qName=" + qName);
// System.out.println("attributes=" + attributes.getValue("name"));
if ("string".equals(qName)) {
mEntryCur = new Entry();
mEntryCur.setName(attributes.getValue("name"));
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// System.out.println("characters=" + new String(ch, start, length));
if (mSb == null) {
mSb = new StringBuilder();
}
if (mEntryCur != null) {
String value = new String(ch, start, length);
value = value.replace("&", "&");
// value = value.replace(" ", " ");
value = value.replace("<", "<");
value = value.replace(">", ">");
mSb.append(value);
}
}
}