source: other-projects/ir-harvest/trunk/oai-download/org/waikato/harvest/OAIListSAXHandler.java@ 31698

Last change on this file since 31698 was 31698, checked in by davidb, 7 years ago

Some initial work on dowloading over OAI

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1package org.waikato.harvest;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.InputStream;
6import java.io.InputStreamReader;
7import java.io.Reader;
8import java.util.ArrayList;
9
10import javax.xml.parsers.SAXParser;
11import javax.xml.parsers.SAXParserFactory;
12import org.xml.sax.Attributes;
13import org.xml.sax.InputSource;
14import org.xml.sax.SAXException;
15import org.xml.sax.helpers.DefaultHandler;
16
17
18public 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
Note: See TracBrowser for help on using the repository browser.