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: tao $'
|
11
|
* '$Date: 2005-09-30 12:48:59 -0700 (Fri, 30 Sep 2005) $'
|
12
|
* '$Revision: 2608 $'
|
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
|
|
32
|
import java.util.Vector;
|
33
|
|
34
|
import org.xml.sax.Attributes;
|
35
|
import org.xml.sax.SAXException;
|
36
|
import org.xml.sax.helpers.DefaultHandler;
|
37
|
|
38
|
/**
|
39
|
* A Class implementing callback bethods for the SAX parser to
|
40
|
* call when processing the XML messages from the replication handler
|
41
|
*/
|
42
|
public class ReplMessageHandler extends DefaultHandler
|
43
|
{
|
44
|
private Vector updates = new Vector();
|
45
|
private Vector indivUpdate = new Vector();
|
46
|
private Vector indivDelete = new Vector();
|
47
|
private Vector indivRevision = new Vector();
|
48
|
private Vector deletes = new Vector();
|
49
|
private Vector revisions = new Vector();
|
50
|
private String server;
|
51
|
private String dataFile;
|
52
|
private boolean update = false;
|
53
|
private boolean delete = false;
|
54
|
private boolean revision = false;
|
55
|
String currentTag = new String();
|
56
|
StringBuffer textBuffer = null;
|
57
|
|
58
|
public ReplMessageHandler()
|
59
|
{
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* This method starts a new vector for each updatedDocument tag.
|
64
|
*/
|
65
|
public void startElement(String uri, String localName, String qName,
|
66
|
Attributes attributes) throws SAXException
|
67
|
{
|
68
|
textBuffer = new StringBuffer();
|
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
|
else if (localName.equals("revisionDocument"))
|
81
|
{
|
82
|
indivRevision = new Vector();
|
83
|
revision = true;
|
84
|
}
|
85
|
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* This method write the indivUpdate to updates when it finds the end of
|
90
|
*/
|
91
|
public void endElement(String uri, String localName, String qName)
|
92
|
throws SAXException
|
93
|
{
|
94
|
if(currentTag.equals("docid") && update)
|
95
|
{
|
96
|
indivUpdate.add(textBuffer.toString());
|
97
|
}
|
98
|
else if(currentTag.equals("docid") && delete)
|
99
|
{
|
100
|
indivDelete.add(textBuffer.toString());
|
101
|
}
|
102
|
else if (currentTag.equals("docid") && revision)
|
103
|
{
|
104
|
indivRevision.add(textBuffer.toString());
|
105
|
}
|
106
|
|
107
|
if(currentTag.equals("rev") && update)
|
108
|
{
|
109
|
indivUpdate.add(textBuffer.toString());
|
110
|
indivUpdate.add(server);
|
111
|
}
|
112
|
else if(currentTag.equals("rev") && delete)
|
113
|
{
|
114
|
indivDelete.add(textBuffer.toString());
|
115
|
indivDelete.add(server);
|
116
|
}
|
117
|
else if(currentTag.equals("rev") && revision)
|
118
|
{
|
119
|
indivRevision.add(textBuffer.toString());
|
120
|
indivRevision.add(server);
|
121
|
}
|
122
|
|
123
|
if(currentTag.equals("date_updated") && update)
|
124
|
{
|
125
|
indivUpdate.add(textBuffer.toString());
|
126
|
indivUpdate.add(server);
|
127
|
}
|
128
|
else if(currentTag.equals("date_updated") && delete)
|
129
|
{
|
130
|
indivDelete.add(textBuffer.toString());
|
131
|
indivDelete.add(server);
|
132
|
}
|
133
|
else if(currentTag.equals("date_updated") && revision)
|
134
|
{
|
135
|
indivRevision.add(textBuffer.toString());
|
136
|
indivRevision.add(server);
|
137
|
}
|
138
|
|
139
|
if(currentTag.equals("server"))
|
140
|
{
|
141
|
server = textBuffer.toString();
|
142
|
}
|
143
|
|
144
|
//Adding data file attribute into indivUpdate vector
|
145
|
if (currentTag.equals("datafile"))
|
146
|
{
|
147
|
dataFile = textBuffer.toString();
|
148
|
if (update)
|
149
|
{
|
150
|
indivUpdate.add(dataFile);
|
151
|
}
|
152
|
else if (revision)
|
153
|
{
|
154
|
indivRevision.add(dataFile);
|
155
|
}
|
156
|
|
157
|
|
158
|
}
|
159
|
|
160
|
if(localName.equals("updatedDocument"))
|
161
|
{
|
162
|
updates.add(new Vector(indivUpdate));
|
163
|
update = false;
|
164
|
}
|
165
|
else if(localName.equals("deletedDocument"))
|
166
|
{
|
167
|
deletes.add(new Vector(indivDelete));
|
168
|
delete = false;
|
169
|
}
|
170
|
else if (localName.equals("revisionDocument"))
|
171
|
{
|
172
|
revisions.add(new Vector(indivRevision));
|
173
|
revision = false;
|
174
|
}
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* Take the data out of the docid and date_updated fields
|
179
|
*/
|
180
|
public void characters(char[] ch, int start, int length) throws SAXException
|
181
|
{
|
182
|
textBuffer.append(new String(ch, start,length));
|
183
|
}
|
184
|
|
185
|
public Vector getUpdatesVect()
|
186
|
{
|
187
|
return updates;
|
188
|
}
|
189
|
|
190
|
public Vector getDeletesVect()
|
191
|
{
|
192
|
return deletes;
|
193
|
}
|
194
|
|
195
|
public Vector getRevisionsVect()
|
196
|
{
|
197
|
return revisions;
|
198
|
}
|
199
|
}
|