1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that handles the SAX XML events as they
|
4
|
* are generated from XML documents
|
5
|
* Copyright: 2000 Regents of the University of California and the
|
6
|
* National Center for Ecological Analysis and Synthesis
|
7
|
* Authors: Matt Jones, Jivka Bojilova
|
8
|
* Release: @release@
|
9
|
*
|
10
|
* '$Author: tao $'
|
11
|
* '$Date: 2003-04-02 09:58:39 -0800 (Wed, 02 Apr 2003) $'
|
12
|
* '$Revision: 1508 $'
|
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.io.File;
|
33
|
import java.io.FileWriter;
|
34
|
import java.io.StringReader;
|
35
|
import java.util.Stack;
|
36
|
import java.util.Vector;
|
37
|
import java.util.Hashtable;
|
38
|
import java.util.Enumeration;
|
39
|
import java.util.EmptyStackException;
|
40
|
|
41
|
import org.xml.sax.Attributes;
|
42
|
import org.xml.sax.SAXException;
|
43
|
import org.xml.sax.SAXParseException;
|
44
|
import org.xml.sax.ext.DeclHandler;
|
45
|
import org.xml.sax.ext.LexicalHandler;
|
46
|
import org.xml.sax.helpers.DefaultHandler;
|
47
|
|
48
|
/**
|
49
|
* A database aware Class implementing callback bethods for the SAX parser to
|
50
|
* call when processing the XML stream and generating events
|
51
|
*/
|
52
|
public class AddMissedSubTreeSAXHandler extends DefaultHandler
|
53
|
{
|
54
|
String docId;
|
55
|
Hashtable unReadableSubTreeHash;
|
56
|
Vector unReadableSubTreeList = new Vector();
|
57
|
|
58
|
// Constant
|
59
|
private static final String DESCRIBES = "describes";
|
60
|
private static final String ADDITIONALMETADATA = "additionalMetadata";
|
61
|
private static final String ORDER = "order";
|
62
|
private static final String ID ="id";
|
63
|
private static final String REFERENCES = "references";
|
64
|
public static final String INLINE = "inline";
|
65
|
|
66
|
|
67
|
/** Construct an instance of the handler class
|
68
|
* In this constructor, user can specify the version need to upadate
|
69
|
*
|
70
|
* @param myDocid the docid for these subtree
|
71
|
* @param myUnReadableTree the tree couldn't be read
|
72
|
*/
|
73
|
public AddMissedSubTreeSAXHandler(Hashtable myUnReadableTree)
|
74
|
throws SAXException
|
75
|
{
|
76
|
unReadableSubTreeHash = myUnReadableTree;
|
77
|
getUnReadableSubTreeList();
|
78
|
}
|
79
|
|
80
|
/* Get the unreadable tree list (every tree has the noderecorder stack)*/
|
81
|
private void getUnReadableSubTreeList() throws SAXException
|
82
|
{
|
83
|
Enumeration en = unReadableSubTreeHash.elements();
|
84
|
|
85
|
try
|
86
|
{
|
87
|
// go though the unreadable subtree list
|
88
|
while (en.hasMoreElements())
|
89
|
{
|
90
|
// Get a subtree without node record list
|
91
|
SubTree treeWithoutStack = (SubTree)en.nextElement();
|
92
|
String subTreeId = treeWithoutStack.getSubTreeId();
|
93
|
long startNodeId = treeWithoutStack.getStartNodeId();
|
94
|
long endNodeId = treeWithoutStack.getEndNodeId();
|
95
|
// Get a subtree has the nodelist
|
96
|
SubTree tree = new SubTree(docId, subTreeId,
|
97
|
startNodeId, endNodeId);
|
98
|
// add this tree to the vector
|
99
|
unReadableSubTreeList.add(tree);
|
100
|
}//while
|
101
|
}//try
|
102
|
catch (Exception e)
|
103
|
{
|
104
|
throw new SAXException(e.getMessage());
|
105
|
}
|
106
|
}
|
107
|
|
108
|
/** SAX Handler that is called at the start of each XML element */
|
109
|
public void startElement(String uri, String localName,
|
110
|
String qName, Attributes atts)
|
111
|
throws SAXException
|
112
|
{
|
113
|
|
114
|
}
|
115
|
|
116
|
|
117
|
/** SAX Handler that is called at the end of each XML element */
|
118
|
public void endElement(String uri, String localName,
|
119
|
String qName) throws SAXException
|
120
|
{
|
121
|
MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
|
122
|
|
123
|
|
124
|
}
|
125
|
|
126
|
}
|