Project

General

Profile

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: daigle $'
10
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
11
 * '$Revision: 4080 $'
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

    
31
import java.util.Vector;
32

    
33
import org.xml.sax.Attributes;
34
import org.xml.sax.SAXException;
35
import org.xml.sax.helpers.DefaultHandler;
36

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