1 |
522
|
berkley
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
669
|
jones
|
* Purpose: A class that handles xml messages passed by the
|
4 |
|
|
* replication handler
|
5 |
522
|
berkley
|
* 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$'
|
11 |
|
|
* '$Date$'
|
12 |
|
|
* '$Revision$'
|
13 |
669
|
jones
|
*
|
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 |
522
|
berkley
|
*/
|
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 |
561
|
berkley
|
* A Class implementing callback bethods for the SAX parser to
|
46 |
522
|
berkley
|
* 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 |
554
|
berkley
|
private Vector indivDelete = new Vector();
|
53 |
|
|
private Vector deletes = new Vector();
|
54 |
532
|
berkley
|
private String server;
|
55 |
1036
|
tao
|
private String dataFile;
|
56 |
554
|
berkley
|
private boolean update = false;
|
57 |
|
|
private boolean delete = false;
|
58 |
522
|
berkley
|
String currentTag = new String();
|
59 |
|
|
|
60 |
|
|
public ReplMessageHandler()
|
61 |
|
|
{
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* This method starts a new vector for each updatedDocument tag.
|
66 |
|
|
*/
|
67 |
|
|
public void startElement(String uri, String localName, String qName,
|
68 |
|
|
Attributes attributes) throws SAXException
|
69 |
|
|
{
|
70 |
|
|
currentTag = localName;
|
71 |
|
|
if(localName.equals("updatedDocument"))
|
72 |
|
|
{
|
73 |
|
|
indivUpdate = new Vector();
|
74 |
554
|
berkley
|
update = true;
|
75 |
522
|
berkley
|
}
|
76 |
554
|
berkley
|
else if(localName.equals("deletedDocument"))
|
77 |
|
|
{
|
78 |
|
|
indivDelete = new Vector();
|
79 |
|
|
delete = true;
|
80 |
|
|
}
|
81 |
522
|
berkley
|
}
|
82 |
|
|
|
83 |
|
|
/**
|
84 |
|
|
* This method write the indivUpdate to updates when it finds the end of
|
85 |
|
|
*/
|
86 |
|
|
public void endElement(String uri, String localName, String qName)
|
87 |
|
|
throws SAXException
|
88 |
|
|
{
|
89 |
|
|
if(localName.equals("updatedDocument"))
|
90 |
|
|
{
|
91 |
|
|
updates.add(new Vector(indivUpdate));
|
92 |
554
|
berkley
|
update = false;
|
93 |
522
|
berkley
|
}
|
94 |
554
|
berkley
|
else if(localName.equals("deletedDocument"))
|
95 |
|
|
{
|
96 |
|
|
deletes.add(new Vector(indivDelete));
|
97 |
|
|
delete = false;
|
98 |
|
|
}
|
99 |
522
|
berkley
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Take the data out of the docid and date_updated fields
|
103 |
|
|
*/
|
104 |
|
|
public void characters(char[] ch, int start, int length) throws SAXException
|
105 |
|
|
{
|
106 |
554
|
berkley
|
if(currentTag.equals("docid") && update)
|
107 |
522
|
berkley
|
{
|
108 |
|
|
indivUpdate.add(new String(ch, start, length));
|
109 |
|
|
}
|
110 |
554
|
berkley
|
else if(currentTag.equals("docid") && delete)
|
111 |
522
|
berkley
|
{
|
112 |
554
|
berkley
|
indivDelete.add(new String(ch, start, length));
|
113 |
|
|
}
|
114 |
|
|
|
115 |
577
|
berkley
|
if(currentTag.equals("rev") && update)
|
116 |
|
|
{
|
117 |
|
|
indivUpdate.add(new String(ch, start, length));
|
118 |
|
|
indivUpdate.add(server);
|
119 |
|
|
}
|
120 |
|
|
else if(currentTag.equals("rev") && delete)
|
121 |
|
|
{
|
122 |
|
|
indivDelete.add(new String(ch, start, length));
|
123 |
|
|
indivDelete.add(server);
|
124 |
|
|
}
|
125 |
|
|
|
126 |
554
|
berkley
|
if(currentTag.equals("date_updated") && update)
|
127 |
|
|
{
|
128 |
522
|
berkley
|
indivUpdate.add(new String(ch, start, length));
|
129 |
532
|
berkley
|
indivUpdate.add(server);
|
130 |
522
|
berkley
|
}
|
131 |
554
|
berkley
|
else if(currentTag.equals("date_updated") && delete)
|
132 |
|
|
{
|
133 |
|
|
indivDelete.add(new String(ch, start, length));
|
134 |
|
|
indivDelete.add(server);
|
135 |
|
|
}
|
136 |
|
|
|
137 |
532
|
berkley
|
if(currentTag.equals("server"))
|
138 |
|
|
{
|
139 |
|
|
server = new String(ch, start, length);
|
140 |
|
|
}
|
141 |
1036
|
tao
|
|
142 |
|
|
//Adding data file attribute into indivUpdate vector
|
143 |
|
|
if (currentTag.equals("datafile"))
|
144 |
|
|
{
|
145 |
|
|
dataFile = new String(ch, start, length);
|
146 |
|
|
indivUpdate.add(dataFile);
|
147 |
|
|
}
|
148 |
522
|
berkley
|
}
|
149 |
|
|
|
150 |
554
|
berkley
|
public Vector getUpdatesVect()
|
151 |
522
|
berkley
|
{
|
152 |
|
|
return updates;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
554
|
berkley
|
public Vector getDeletesVect()
|
156 |
|
|
{
|
157 |
|
|
return deletes;
|
158 |
|
|
}
|
159 |
522
|
berkley
|
}
|