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: 2003-04-18 20:29:06 -0700 (Fri, 18 Apr 2003) $'
|
12
|
* '$Revision: 1581 $'
|
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 CatalogMessageHandler extends DefaultHandler
|
49
|
{
|
50
|
private Vector updates = new Vector();
|
51
|
private Vector indivUpdate = new Vector();
|
52
|
String currentTag = new String();
|
53
|
StringBuffer textBuffer = new StringBuffer();
|
54
|
|
55
|
/**
|
56
|
* This method starts a new vector for each updatedDocument tag.
|
57
|
*/
|
58
|
public void startElement(String uri, String localName, String qName,
|
59
|
Attributes attributes) throws SAXException
|
60
|
{
|
61
|
currentTag = localName;
|
62
|
if(localName.equals("row"))
|
63
|
{
|
64
|
indivUpdate = new Vector();
|
65
|
}
|
66
|
textBuffer = new StringBuffer();
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* This method write the indivUpdate to updates when it finds the end of
|
71
|
*/
|
72
|
public void endElement(String uri, String localName, String qName)
|
73
|
throws SAXException
|
74
|
{
|
75
|
if(currentTag.equals("entry_type") || currentTag.equals("source_doctype")
|
76
|
|| currentTag.equals("target_doctype") || currentTag.equals("public_id")
|
77
|
|| currentTag.equals("system_id"))
|
78
|
{
|
79
|
|
80
|
indivUpdate.add((textBuffer.toString()).trim());
|
81
|
}
|
82
|
if(localName.equals("row"))
|
83
|
{
|
84
|
updates.add(new Vector(indivUpdate));
|
85
|
}
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Take the data out of the docid and date_updated fields
|
90
|
*/
|
91
|
public void characters(char[] ch, int start, int length) throws SAXException
|
92
|
{
|
93
|
textBuffer.append(new String(ch, start,length));
|
94
|
}
|
95
|
|
96
|
public Vector getCatalogVect()
|
97
|
{
|
98
|
return updates;
|
99
|
}
|
100
|
|
101
|
}
|