Repository navigation
Expand file tree
/
Copy pathArrayHandler.java
More file actions
100 lines (83 loc) · 2.62 KB
/
Copy pathArrayHandler.java
File metadata and controls
100 lines (83 loc) · 2.62 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
package com.carl.java.excel;
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 ArrayHandler extends DefaultHandler {
private static final String TAG = ArrayHandler.class.getSimpleName();
private List<Entry> mList;
private Entry mEntryCur;
private StringBuilder mSb;
private String mArrayName;
public ArrayHandler() {
// 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-array".equals(qName)) {
mArrayName = null;
} else if ("item".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-array".equals(qName)) {
mArrayName = attributes.getValue("name");
} else if ("item".equals(qName)) {
mEntryCur = new Entry();
mEntryCur.setName("[array]" + mArrayName);
}
}
@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);
}
}
}