Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A class that handles xml messages  passed by  the replication handler
4
 *  Copyright: 2000 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Chad Berkley
7
 *    Release: @release@
8
 *
9
 *   '$Author: berkley $'
10
 *     '$Date: 2000-11-22 14:55:19 -0800 (Wed, 22 Nov 2000) $'
11
 * '$Revision: 561 $'
12
 */
13

    
14
package edu.ucsb.nceas.metacat;
15

    
16
import java.sql.*;
17
import java.util.Stack;
18
import java.util.Vector;
19
import java.util.Enumeration;
20
import java.util.EmptyStackException;
21

    
22
import org.xml.sax.Attributes;
23
import org.xml.sax.SAXException;
24
import org.xml.sax.SAXParseException;
25
import org.xml.sax.ext.DeclHandler;
26
import org.xml.sax.ext.LexicalHandler;
27
import org.xml.sax.helpers.DefaultHandler;
28

    
29
/** 
30
 * A Class implementing callback bethods for the SAX parser to
31
 * call when processing the XML messages from the replication handler
32
 */
33
public class ReplMessageHandler extends DefaultHandler 
34
{
35
  private Vector updates = new Vector();
36
  private Vector indivUpdate = new Vector();
37
  private Vector indivDelete = new Vector();
38
  private Vector deletes = new Vector();
39
  private String server;
40
  private boolean update = false;
41
  private boolean delete = false;
42
  String currentTag = new String();
43
  
44
  public ReplMessageHandler()
45
  {
46
  }
47
  
48
  /**
49
   * This method starts a new vector for each updatedDocument tag.
50
   */
51
  public void startElement(String uri, String localName, String qName, 
52
                           Attributes attributes) throws SAXException
53
  {
54
    currentTag = localName;
55
    if(localName.equals("updatedDocument"))
56
    {
57
      indivUpdate = new Vector();
58
      update = true;
59
    }
60
    else if(localName.equals("deletedDocument"))
61
    {
62
      indivDelete = new Vector();
63
      delete = true;
64
    }
65
  }
66
  
67
  /**
68
   * This method write the indivUpdate to updates when it finds the end of
69
   */
70
  public void endElement(String uri, String localName, String qName) 
71
              throws SAXException
72
  {
73
    if(localName.equals("updatedDocument"))
74
    {
75
      updates.add(new Vector(indivUpdate));
76
      update = false;
77
    }
78
    else if(localName.equals("deletedDocument"))
79
    {
80
      deletes.add(new Vector(indivDelete));
81
      delete = false;
82
    }
83
  }
84
  
85
  /**
86
   * Take the data out of the docid and date_updated fields
87
   */
88
  public void characters(char[] ch, int start, int length) throws SAXException
89
  {
90
    if(currentTag.equals("docid") && update)
91
    {
92
      indivUpdate.add(new String(ch, start, length));
93
    }
94
    else if(currentTag.equals("docid") && delete)
95
    {
96
      indivDelete.add(new String(ch, start, length));
97
    }
98
    
99
    if(currentTag.equals("date_updated") && update)
100
    {
101
      indivUpdate.add(new String(ch, start, length));
102
      indivUpdate.add(server);
103
    }
104
    else if(currentTag.equals("date_updated") && delete)
105
    {
106
      indivDelete.add(new String(ch, start, length));
107
      indivDelete.add(server);
108
    }
109
    
110
    if(currentTag.equals("server"))
111
    {
112
      server = new String(ch, start, length);
113
    }
114
  }
115
  
116
  public Vector getUpdatesVect()
117
  {
118
    return updates;
119
  }
120
  
121
  public Vector getDeletesVect()
122
  {
123
    return deletes;
124
  }
125
  
126
}
(33-33/35)