Project

General

Profile

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: sgarg $'
11
 *     '$Date: 2005-10-10 11:06:55 -0700 (Mon, 10 Oct 2005) $'
12
 * '$Revision: 2663 $'
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.apache.log4j.Logger;
42
import org.xml.sax.Attributes;
43
import org.xml.sax.SAXException;
44
import org.xml.sax.SAXParseException;
45
import org.xml.sax.ext.DeclHandler;
46
import org.xml.sax.ext.LexicalHandler;
47
import org.xml.sax.helpers.DefaultHandler;
48

    
49
/**
50
 * A database aware Class implementing callback bethods for the SAX parser to
51
 * call when processing the XML stream and generating events
52
 */
53
public class AddMissedSubTreeSAXHandler extends DefaultHandler
54
{
55
   String    docId;
56
   Hashtable unReadableSubTreeHash;
57
   Vector    unReadableSubTreeList = new Vector();
58
   
59
   // Constant
60
   private static final String DESCRIBES = "describes";
61
   private static final String ADDITIONALMETADATA = "additionalMetadata";
62
   private static final String ORDER = "order";
63
   private static final String ID ="id";
64
   private static final String REFERENCES = "references";
65
   public  static final String INLINE = "inline";
66
   private Logger logMetacat = Logger.getLogger(AddMissedSubTreeSAXHandler.class);
67
   
68
  
69
    /** Construct an instance of the handler class
70
    * In this constructor, user can specify the version need to upadate
71
    *
72
    * @param myDocid  the docid for these subtree
73
    * @param myUnReadableTree  the tree couldn't be read
74
    */
75
   public AddMissedSubTreeSAXHandler(Hashtable myUnReadableTree) 
76
                                                           throws SAXException
77
   {
78
     unReadableSubTreeHash = myUnReadableTree;
79
     getUnReadableSubTreeList();
80
   }
81
   
82
   /* Get the unreadable tree list (every tree has the noderecorder stack)*/
83
   private void getUnReadableSubTreeList() throws SAXException
84
   {
85
     Enumeration en = unReadableSubTreeHash.elements();
86
     
87
     try
88
     {
89
       // go though the unreadable subtree list
90
       while (en.hasMoreElements())
91
       {
92
         // Get  a subtree without node record list
93
         SubTree treeWithoutStack = (SubTree)en.nextElement();
94
         String subTreeId   = treeWithoutStack.getSubTreeId();
95
         long   startNodeId = treeWithoutStack.getStartNodeId();
96
         long   endNodeId   = treeWithoutStack.getEndNodeId();
97
         // Get a subtree has the nodelist
98
         SubTree tree       = new SubTree(docId, subTreeId, 
99
                                          startNodeId, endNodeId);
100
         // add this tree to the vector
101
         unReadableSubTreeList.add(tree);
102
       }//while
103
     }//try
104
     catch (Exception e)
105
     {
106
       throw new SAXException(e.getMessage());
107
     }
108
   }
109
   
110
   /** SAX Handler that is called at the start of each XML element */
111
   public void startElement(String uri, String localName,
112
                            String qName, Attributes atts)
113
               throws SAXException 
114
  {
115
    
116
  }
117
  
118
   
119
  /** SAX Handler that is called at the end of each XML element */
120
   public void endElement(String uri, String localName,
121
                          String qName) throws SAXException 
122
  {
123
     logMetacat.info("End ELEMENT " + qName);
124
   }
125
   
126
}
(9-9/63)