Revision 519
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/replMessageHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A class that handles xml messages passed by the replication handler |
|
4 |
* Copyright: 2000 Regents of the University of California and the |
|
5 |
* National Center for Ecological Analysis and Synthesis |
|
6 |
* Authors: Chad Berkley |
|
7 |
* Release: @release@ |
|
8 |
* |
|
9 |
* '$Author$' |
|
10 |
* '$Date$' |
|
11 |
* '$Revision$' |
|
12 |
*/ |
|
13 |
|
|
14 |
package edu.ucsb.nceas.metacat; |
|
15 |
|
|
16 |
import java.sql.*; |
|
17 |
import java.util.Stack; |
|
18 |
import java.util.Vector; |
|
19 |
import java.util.Enumeration; |
|
20 |
import java.util.EmptyStackException; |
|
21 |
|
|
22 |
import org.xml.sax.Attributes; |
|
23 |
import org.xml.sax.SAXException; |
|
24 |
import org.xml.sax.SAXParseException; |
|
25 |
import org.xml.sax.ext.DeclHandler; |
|
26 |
import org.xml.sax.ext.LexicalHandler; |
|
27 |
import org.xml.sax.helpers.DefaultHandler; |
|
28 |
|
|
29 |
/** |
|
30 |
* A database aware Class implementing callback bethods for the SAX parser to |
|
31 |
* call when processing the XML messages from the replication handler |
|
32 |
*/ |
|
33 |
public class replMessageHandler extends DefaultHandler |
|
34 |
{ |
|
35 |
private Vector updates = new Vector(); |
|
36 |
private Vector indivUpdate = new Vector(); |
|
37 |
String currentTag = new String(); |
|
38 |
|
|
39 |
public replMessageHandler() |
|
40 |
{ |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* This method starts a new vector for each updatedDocument tag. |
|
45 |
*/ |
|
46 |
public void startElement(String uri, String localName, String qName, |
|
47 |
Attributes attributes) throws SAXException |
|
48 |
{ |
|
49 |
currentTag = localName; |
|
50 |
if(localName.equals("updatedDocument")) |
|
51 |
{ |
|
52 |
indivUpdate = new Vector(); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* This method write the indivUpdate to updates when it finds the end of |
|
58 |
*/ |
|
59 |
public void endElement(String uri, String localName, String qName) |
|
60 |
throws SAXException |
|
61 |
{ |
|
62 |
if(localName.equals("updatedDocument")) |
|
63 |
{ |
|
64 |
updates.add(new Vector(indivUpdate)); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Take the data out of the docid and date_updated fields |
|
70 |
*/ |
|
71 |
public void characters(char[] ch, int start, int length) throws SAXException |
|
72 |
{ |
|
73 |
if(currentTag.equals("docid")) |
|
74 |
{ |
|
75 |
indivUpdate.add(new String(ch, start, length)); |
|
76 |
} |
|
77 |
if(currentTag.equals("date_updated")) |
|
78 |
{ |
|
79 |
indivUpdate.add(new String(ch, start, length)); |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
public Vector getResultVect() |
|
84 |
{ |
|
85 |
return updates; |
|
86 |
} |
|
87 |
|
|
88 |
} |
|
0 | 89 |
Also available in: Unified diff
a parser to handle replication xml messages