1 | package org.waikato.harvest;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FileInputStream;
|
---|
5 | import java.io.InputStream;
|
---|
6 | import java.io.InputStreamReader;
|
---|
7 | import java.io.Reader;
|
---|
8 | import java.util.ArrayList;
|
---|
9 |
|
---|
10 | import javax.xml.parsers.SAXParser;
|
---|
11 | import javax.xml.parsers.SAXParserFactory;
|
---|
12 | import org.xml.sax.Attributes;
|
---|
13 | import org.xml.sax.InputSource;
|
---|
14 | import org.xml.sax.SAXException;
|
---|
15 | import org.xml.sax.helpers.DefaultHandler;
|
---|
16 |
|
---|
17 |
|
---|
18 | public class OAIListSAXHandler extends DefaultHandler
|
---|
19 | {
|
---|
20 | boolean identifier_tag_open_ = false;
|
---|
21 | String identifier_text_ = null;
|
---|
22 |
|
---|
23 | boolean resumptionToken_tag_open_ = false;
|
---|
24 | String resumptionToken_text_ = null;
|
---|
25 |
|
---|
26 | ArrayList<String> identifiers_;
|
---|
27 |
|
---|
28 | public OAIListSAXHandler()
|
---|
29 | {
|
---|
30 | identifiers_ = new ArrayList<String>();
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void startElement(String uri, String localName,
|
---|
34 | String qName, Attributes attributes) throws SAXException
|
---|
35 | {
|
---|
36 | if (qName.equalsIgnoreCase("identifier")) {
|
---|
37 | identifier_tag_open_ = true;
|
---|
38 | }
|
---|
39 | else if (qName.equalsIgnoreCase("resumptionToken")) {
|
---|
40 | resumptionToken_tag_open_ = true;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void characters(char ch[], int start, int length) throws SAXException
|
---|
45 | {
|
---|
46 | if (identifier_tag_open_) {
|
---|
47 | identifier_text_ = new String(ch, start, length);
|
---|
48 | }
|
---|
49 | else if (resumptionToken_tag_open_) {
|
---|
50 | resumptionToken_text_ = new String(ch, start, length);
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void endElement(String uri, String localName, String qName) throws SAXException
|
---|
56 | {
|
---|
57 | if (qName.equalsIgnoreCase("identifier")) {
|
---|
58 | identifiers_.add(identifier_text_);
|
---|
59 | identifier_text_ = null;
|
---|
60 | identifier_tag_open_ = false;
|
---|
61 | }
|
---|
62 | else if (qName.equalsIgnoreCase("resumptionToken")) {
|
---|
63 | resumptionToken_tag_open_ = false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|
67 |
|
---|
68 | public void printIdentifiers()
|
---|
69 | {
|
---|
70 | for (String id: identifiers_) {
|
---|
71 | System.out.println("id: " + id);
|
---|
72 | }
|
---|
73 |
|
---|
74 | System.out.println("Resumption token: " + resumptionToken_text_);
|
---|
75 | }
|
---|
76 |
|
---|
77 | public ArrayList<String> getIdentifiers()
|
---|
78 | {
|
---|
79 | return identifiers_;
|
---|
80 | }
|
---|
81 |
|
---|
82 | public String getResumptionToken()
|
---|
83 | {
|
---|
84 | return resumptionToken_text_;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|