Revision 3752
Added by Jing Tao over 16 years ago
src/edu/ucsb/nceas/metacat/AddMissedSubTreeSAXHandler.java | ||
---|---|---|
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 |
* |
|
9 |
* '$Author$' |
|
10 |
* '$Date$' |
|
11 |
* '$Revision$' |
|
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.io.File; |
|
32 |
import java.io.FileWriter; |
|
33 |
import java.io.StringReader; |
|
34 |
import java.util.Stack; |
|
35 |
import java.util.Vector; |
|
36 |
import java.util.Hashtable; |
|
37 |
import java.util.Enumeration; |
|
38 |
import java.util.EmptyStackException; |
|
39 |
|
|
40 |
import org.apache.log4j.Logger; |
|
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 |
private Logger logMetacat = Logger.getLogger(AddMissedSubTreeSAXHandler.class); |
|
66 |
|
|
67 |
|
|
68 |
/** Construct an instance of the handler class |
|
69 |
* In this constructor, user can specify the version need to upadate |
|
70 |
* |
|
71 |
* @param myDocid the docid for these subtree |
|
72 |
* @param myUnReadableTree the tree couldn't be read |
|
73 |
*/ |
|
74 |
public AddMissedSubTreeSAXHandler(Hashtable myUnReadableTree) |
|
75 |
throws SAXException |
|
76 |
{ |
|
77 |
unReadableSubTreeHash = myUnReadableTree; |
|
78 |
getUnReadableSubTreeList(); |
|
79 |
} |
|
80 |
|
|
81 |
/* Get the unreadable tree list (every tree has the noderecorder stack)*/ |
|
82 |
private void getUnReadableSubTreeList() throws SAXException |
|
83 |
{ |
|
84 |
Enumeration en = unReadableSubTreeHash.elements(); |
|
85 |
|
|
86 |
try |
|
87 |
{ |
|
88 |
// go though the unreadable subtree list |
|
89 |
while (en.hasMoreElements()) |
|
90 |
{ |
|
91 |
// Get a subtree without node record list |
|
92 |
SubTree treeWithoutStack = (SubTree)en.nextElement(); |
|
93 |
String subTreeId = treeWithoutStack.getSubTreeId(); |
|
94 |
long startNodeId = treeWithoutStack.getStartNodeId(); |
|
95 |
long endNodeId = treeWithoutStack.getEndNodeId(); |
|
96 |
// Get a subtree has the nodelist |
|
97 |
SubTree tree = new SubTree(docId, subTreeId, |
|
98 |
startNodeId, endNodeId); |
|
99 |
// add this tree to the vector |
|
100 |
unReadableSubTreeList.add(tree); |
|
101 |
}//while |
|
102 |
}//try |
|
103 |
catch (Exception e) |
|
104 |
{ |
|
105 |
throw new SAXException(e.getMessage()); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/** SAX Handler that is called at the start of each XML element */ |
|
110 |
public void startElement(String uri, String localName, |
|
111 |
String qName, Attributes atts) |
|
112 |
throws SAXException |
|
113 |
{ |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
|
|
118 |
/** SAX Handler that is called at the end of each XML element */ |
|
119 |
public void endElement(String uri, String localName, |
|
120 |
String qName) throws SAXException |
|
121 |
{ |
|
122 |
logMetacat.info("End ELEMENT " + qName); |
|
123 |
} |
|
124 |
|
|
125 |
} |
|
126 | 0 |
Also available in: Unified diff
Remove an obsolete class.