1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A class that handles xml messages passed by the
|
4
|
* replication handler
|
5
|
* Copyright: 2000 Regents of the University of California and the
|
6
|
* National Center for Ecological Analysis and Synthesis
|
7
|
* Authors: Chad Berkley
|
8
|
* Release: @release@
|
9
|
*
|
10
|
* '$Author: jones $'
|
11
|
* '$Date: 2001-01-18 11:52:00 -0800 (Thu, 18 Jan 2001) $'
|
12
|
* '$Revision: 669 $'
|
13
|
*
|
14
|
* This program is free software; you can redistribute it and/or modify
|
15
|
* it under the terms of the GNU General Public License as published by
|
16
|
* the Free Software Foundation; either version 2 of the License, or
|
17
|
* (at your option) any later version.
|
18
|
*
|
19
|
* This program is distributed in the hope that it will be useful,
|
20
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
* GNU General Public License for more details.
|
23
|
*
|
24
|
* You should have received a copy of the GNU General Public License
|
25
|
* along with this program; if not, write to the Free Software
|
26
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
27
|
*/
|
28
|
|
29
|
package edu.ucsb.nceas.metacat;
|
30
|
|
31
|
import java.sql.*;
|
32
|
import java.util.Stack;
|
33
|
import java.util.Vector;
|
34
|
import java.util.Enumeration;
|
35
|
import java.util.EmptyStackException;
|
36
|
|
37
|
import org.xml.sax.Attributes;
|
38
|
import org.xml.sax.SAXException;
|
39
|
import org.xml.sax.SAXParseException;
|
40
|
import org.xml.sax.ext.DeclHandler;
|
41
|
import org.xml.sax.ext.LexicalHandler;
|
42
|
import org.xml.sax.helpers.DefaultHandler;
|
43
|
|
44
|
/**
|
45
|
* A Class implementing callback bethods for the SAX parser to
|
46
|
* call when processing the XML messages from the replication handler
|
47
|
*/
|
48
|
public class ReplMessageHandler extends DefaultHandler
|
49
|
{
|
50
|
private Vector updates = new Vector();
|
51
|
private Vector indivUpdate = new Vector();
|
52
|
private Vector indivDelete = new Vector();
|
53
|
private Vector deletes = new Vector();
|
54
|
private String server;
|
55
|
private boolean update = false;
|
56
|
private boolean delete = false;
|
57
|
String currentTag = new String();
|
58
|
|
59
|
public ReplMessageHandler()
|
60
|
{
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* This method starts a new vector for each updatedDocument tag.
|
65
|
*/
|
66
|
public void startElement(String uri, String localName, String qName,
|
67
|
Attributes attributes) throws SAXException
|
68
|
{
|
69
|
currentTag = localName;
|
70
|
if(localName.equals("updatedDocument"))
|
71
|
{
|
72
|
indivUpdate = new Vector();
|
73
|
update = true;
|
74
|
}
|
75
|
else if(localName.equals("deletedDocument"))
|
76
|
{
|
77
|
indivDelete = new Vector();
|
78
|
delete = true;
|
79
|
}
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* This method write the indivUpdate to updates when it finds the end of
|
84
|
*/
|
85
|
public void endElement(String uri, String localName, String qName)
|
86
|
throws SAXException
|
87
|
{
|
88
|
if(localName.equals("updatedDocument"))
|
89
|
{
|
90
|
updates.add(new Vector(indivUpdate));
|
91
|
update = false;
|
92
|
}
|
93
|
else if(localName.equals("deletedDocument"))
|
94
|
{
|
95
|
deletes.add(new Vector(indivDelete));
|
96
|
delete = false;
|
97
|
}
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* Take the data out of the docid and date_updated fields
|
102
|
*/
|
103
|
public void characters(char[] ch, int start, int length) throws SAXException
|
104
|
{
|
105
|
if(currentTag.equals("docid") && update)
|
106
|
{
|
107
|
indivUpdate.add(new String(ch, start, length));
|
108
|
}
|
109
|
else if(currentTag.equals("docid") && delete)
|
110
|
{
|
111
|
indivDelete.add(new String(ch, start, length));
|
112
|
}
|
113
|
|
114
|
if(currentTag.equals("rev") && update)
|
115
|
{
|
116
|
indivUpdate.add(new String(ch, start, length));
|
117
|
indivUpdate.add(server);
|
118
|
}
|
119
|
else if(currentTag.equals("rev") && delete)
|
120
|
{
|
121
|
indivDelete.add(new String(ch, start, length));
|
122
|
indivDelete.add(server);
|
123
|
}
|
124
|
|
125
|
if(currentTag.equals("date_updated") && update)
|
126
|
{
|
127
|
indivUpdate.add(new String(ch, start, length));
|
128
|
indivUpdate.add(server);
|
129
|
}
|
130
|
else if(currentTag.equals("date_updated") && delete)
|
131
|
{
|
132
|
indivDelete.add(new String(ch, start, length));
|
133
|
indivDelete.add(server);
|
134
|
}
|
135
|
|
136
|
if(currentTag.equals("server"))
|
137
|
{
|
138
|
server = new String(ch, start, length);
|
139
|
}
|
140
|
}
|
141
|
|
142
|
public Vector getUpdatesVect()
|
143
|
{
|
144
|
return updates;
|
145
|
}
|
146
|
|
147
|
public Vector getDeletesVect()
|
148
|
{
|
149
|
return deletes;
|
150
|
}
|
151
|
}
|