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
|
*
|
9
|
* '$Author: jones $'
|
10
|
* '$Date: 2006-11-10 10:25:38 -0800 (Fri, 10 Nov 2006) $'
|
11
|
* '$Revision: 3077 $'
|
12
|
*
|
13
|
* This program is free software; you can redistribute it and/or modify
|
14
|
* it under the terms of the GNU General Public License as published by
|
15
|
* the Free Software Foundation; either version 2 of the License, or
|
16
|
* (at your option) any later version.
|
17
|
*
|
18
|
* This program is distributed in the hope that it will be useful,
|
19
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
* GNU General Public License for more details.
|
22
|
*
|
23
|
* You should have received a copy of the GNU General Public License
|
24
|
* along with this program; if not, write to the Free Software
|
25
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26
|
*/
|
27
|
|
28
|
package edu.ucsb.nceas.metacat;
|
29
|
|
30
|
import java.sql.*;
|
31
|
import java.util.Stack;
|
32
|
import java.util.Vector;
|
33
|
import java.util.Enumeration;
|
34
|
import java.util.EmptyStackException;
|
35
|
|
36
|
import org.xml.sax.Attributes;
|
37
|
import org.xml.sax.SAXException;
|
38
|
import org.xml.sax.SAXParseException;
|
39
|
import org.xml.sax.ext.DeclHandler;
|
40
|
import org.xml.sax.ext.LexicalHandler;
|
41
|
import org.xml.sax.helpers.DefaultHandler;
|
42
|
|
43
|
/**
|
44
|
* A Class implementing callback bethods for the SAX parser to
|
45
|
* call when processing the XML messages from the replication handler
|
46
|
*/
|
47
|
public class CatalogMessageHandler extends DefaultHandler
|
48
|
{
|
49
|
private Vector updates = new Vector();
|
50
|
private Vector indivUpdate = new Vector();
|
51
|
String currentTag = new String();
|
52
|
StringBuffer textBuffer = new StringBuffer();
|
53
|
|
54
|
/**
|
55
|
* This method starts a new vector for each updatedDocument tag.
|
56
|
*/
|
57
|
public void startElement(String uri, String localName, String qName,
|
58
|
Attributes attributes) throws SAXException
|
59
|
{
|
60
|
currentTag = localName;
|
61
|
if(localName.equals("row"))
|
62
|
{
|
63
|
indivUpdate = new Vector();
|
64
|
}
|
65
|
textBuffer = new StringBuffer();
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* This method write the indivUpdate to updates when it finds the end of
|
70
|
*/
|
71
|
public void endElement(String uri, String localName, String qName)
|
72
|
throws SAXException
|
73
|
{
|
74
|
if(currentTag.equals("entry_type") || currentTag.equals("source_doctype")
|
75
|
|| currentTag.equals("target_doctype") || currentTag.equals("public_id")
|
76
|
|| currentTag.equals("system_id"))
|
77
|
{
|
78
|
|
79
|
indivUpdate.add((textBuffer.toString()).trim());
|
80
|
}
|
81
|
if(localName.equals("row"))
|
82
|
{
|
83
|
updates.add(new Vector(indivUpdate));
|
84
|
}
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Take the data out of the docid and date_updated fields
|
89
|
*/
|
90
|
public void characters(char[] ch, int start, int length) throws SAXException
|
91
|
{
|
92
|
textBuffer.append(new String(ch, start,length));
|
93
|
}
|
94
|
|
95
|
public Vector getCatalogVect()
|
96
|
{
|
97
|
return updates;
|
98
|
}
|
99
|
|
100
|
}
|