Project

General

Profile

« Previous | Next » 

Revision 2076

Added by Matt Jones about 20 years ago

Excluded the update of the xml_index table in insert,update, and delete if the usexmlindex option is set to false.

View differences:

src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
28 28

  
29 29
package edu.ucsb.nceas.metacat;
30 30

  
31
import java.sql.*;
32 31
import java.io.BufferedReader;
33
import java.io.IOException;
34 32
import java.io.File;
35 33
import java.io.FileReader;
36 34
import java.io.FileWriter;
35
import java.io.IOException;
37 36
import java.io.Reader;
38
import java.io.StringReader;
37
import java.sql.PreparedStatement;
38
import java.sql.ResultSet;
39
import java.sql.SQLException;
40
import java.sql.Statement;
41
import java.util.EmptyStackException;
42
import java.util.Enumeration;
43
import java.util.Hashtable;
39 44
import java.util.Stack;
40 45
import java.util.Vector;
41
import java.util.Hashtable;
42
import java.util.Enumeration;
43
import java.util.EmptyStackException;
44 46

  
45 47
import org.xml.sax.Attributes;
46 48
import org.xml.sax.SAXException;
47
import org.xml.sax.SAXParseException;
48
import org.xml.sax.ext.DeclHandler;
49
import org.xml.sax.ext.LexicalHandler;
50
import org.xml.sax.helpers.DefaultHandler;
51 49

  
52 50
/**
53 51
 * A database aware Class implementing callback bethods for the SAX parser to
......
1479 1477
   
1480 1478
     // Starting new thread for writing XML Index.
1481 1479
     // It calls the run method of the thread.
1482
     try 
1483
     {
1484
       xmlIndex.start();
1485
     } 
1486
     catch (NullPointerException e) 
1487
     {
1488
       xmlIndex = null;
1489
       throw new
1490
       SAXException("Problem with starting thread for writing XML Index. " +
1491
                    e.getMessage());
1480
     boolean useXMLIndex = 
1481
         (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
1482
     if (useXMLIndex) {
1483
            try {
1484
                xmlIndex.start();
1485
            } catch (NullPointerException e) {
1486
                xmlIndex = null;
1487
                throw new SAXException(
1488
                        "Problem with starting thread for writing XML Index. "
1489
                                + e.getMessage());
1490
            }
1492 1491
     }
1493
   
1494 1492
   }
1495 1493
   
1496
  /* The method to write all access rule intodb */
1494
  /* The method to write all access rule into db */
1497 1495
  private void writeAccessRuleToDB() throws SAXException
1498 1496
  {
1499 1497
    //Delete old permssion
src/edu/ucsb/nceas/metacat/DBSAXHandler.java
28 28

  
29 29
package edu.ucsb.nceas.metacat;
30 30

  
31
import java.sql.PreparedStatement;
32
import java.sql.ResultSet;
33
import java.sql.SQLException;
34
import java.sql.Statement;
35
import java.util.EmptyStackException;
36
import java.util.Enumeration;
37
import java.util.Hashtable;
38
import java.util.Stack;
39
import java.util.Vector;
40

  
31 41
import edu.ucsb.nceas.morpho.datapackage.Triple;
32 42
import edu.ucsb.nceas.morpho.datapackage.TripleCollection;
33 43

  
34
import java.sql.*;
35
import java.io.StringReader;
36
import java.util.Stack;
37
import java.util.Vector;
38
import java.util.Hashtable;
39
import java.util.Enumeration;
40
import java.util.EmptyStackException;
41

  
42 44
import org.xml.sax.Attributes;
43 45
import org.xml.sax.SAXException;
44 46
import org.xml.sax.SAXParseException;
......
48 50

  
49 51
/**
50 52
 * A database aware Class implementing callback bethods for the SAX parser to
51
 * call when processing the XML stream and generating events
53
 * call when processing the XML stream and generating events.
52 54
 */
53
public class DBSAXHandler extends DefaultHandler
54
                          implements LexicalHandler, DeclHandler, Runnable {
55
public class DBSAXHandler extends DefaultHandler implements LexicalHandler,
56
        DeclHandler, Runnable
57
{
55 58

  
56
   protected boolean	atFirstElement;
57
   protected boolean	processingDTD;
58
   protected String 	docname = null;
59
   protected String 	doctype;
60
   protected String 	systemid;
61
   private boolean 	stackCreated = false;
62
   protected Stack 	  nodeStack;
63
   protected Vector   nodeIndex;
64
   protected DBConnection	  connection = null;
65
   protected DocumentImpl currentDocument;
66
   protected DBSAXNode    rootNode;
67
   protected String   action = null;
68
   protected String   docid = null;
69
   protected String   revision = null;
70
   protected String   user = null;
71
   protected String[] groups = null;
72
   protected String   pub = null;
73
   protected Thread   xmlIndex;
74
   private boolean endDocument = false;
75
   protected int serverCode = 1;
76
   protected Hashtable namespaces = new Hashtable();
77
   protected boolean hitTextNode = false; // a flag to hit text node
78
   // a buffer to keep all text nodes for same element
79
   // it is for element was splited
80
   protected StringBuffer textBuffer = new StringBuffer();
81
   protected Stack textBufferStack = new Stack();
59
    protected boolean atFirstElement;
82 60

  
83
   protected static final int MAXDATACHARS = 4000;
84
   //protected static final int MAXDATACHARS = 50;
85
   protected static final long INDEXDELAY = 10000;
86
   // methods writeChildNodeToDB, setAttribute, setNamespace, 
87
   // writeTextForDBSAXNode will increase endNodeId.
88
   protected long  endNodeId = -1;    // The end node id for a substree
89
// DOCTITLE attr cleared from the db
90
//   private static final int MAXTITLELEN = 1000;
91
   //HandlerTriple stuff
92
   TripleCollection tripleList = new TripleCollection();
93
   Triple currentTriple        = new Triple();
94
   boolean startParseTriple    = false;
95
   boolean hasTriple           = false;
61
    protected boolean processingDTD;
96 62

  
97
   /** Construct an instance of the handler class
98
    *
99
    * @param conn the JDBC connection to which information is written
100
    */
101
   public DBSAXHandler(DBConnection conn) {
102
     this.connection = conn;
103
     this.atFirstElement = true;
104
     this.processingDTD = false;
63
    protected String docname = null;
105 64

  
106
     // Create the stack for keeping track of node context
107
     // if it doesn't already exist
108
     if (!stackCreated) {
109
       nodeStack = new Stack();
110
       nodeIndex = new Vector();
111
       stackCreated = true;
112
     }
113
   }
65
    protected String doctype;
114 66

  
115
  /** Construct an instance of the handler class
116
    *
117
    * @param conn the JDBC connection to which information is written
118
    * @param action - "INSERT" or "UPDATE"
119
    * @param docid to be inserted or updated into JDBC connection
120
    * @param user the user connected to MetaCat servlet and owns the document
121
    * @param groups the groups to which user belongs
122
    * @param pub flag for public "read" access on document
123
    * @param serverCode the serverid from xml_replication on which this document
124
    *        resides.
125
    *
126
    */
127
   public DBSAXHandler(DBConnection conn, String action, String docid,
128
                      String user, String[] groups, String pub, int serverCode)
129
   {
130
     this(conn);
131
     this.action = action;
132
     this.docid = docid;
133
     this.user = user;
134
     this.groups = groups;
135
     this.pub = pub;
136
     this.serverCode = serverCode;
137
     this.xmlIndex = new Thread(this);
138
   }
67
    protected String systemid;
139 68

  
140
  /** Construct an instance of the handler class
141
    * In this constructor, user can specify the version need to upadate
142
    *
143
    * @param conn the JDBC connection to which information is written
144
    * @param action - "INSERT" or "UPDATE"
145
    * @param docid to be inserted or updated into JDBC connection
146
    * @param revision, the user specified the revision need to be update
147
    * @param user the user connected to MetaCat servlet and owns the document
148
    * @param groups the groups to which user belongs
149
    * @param pub flag for public "read" access on document
150
    * @param serverCode the serverid from xml_replication on which this document
151
    *        resides.
152
    *
153
    */
154
   public DBSAXHandler(DBConnection conn, String action, String docid,
155
     String revision, String user, String[] groups, String pub, int serverCode)
156
   {
157
     this(conn);
158
     this.action = action;
159
     this.docid = docid;
160
     this.revision = revision;
161
     this.user = user;
162
     this.groups = groups;
163
     this.pub = pub;
164
     this.serverCode = serverCode;
165
     this.xmlIndex = new Thread(this);
166
   }
69
    private boolean stackCreated = false;
167 70

  
168
   /** SAX Handler that receives notification of beginning of the document */
169
   public void startDocument() throws SAXException {
170
     MetaCatUtil.debugMessage("start Document", 50);
71
    protected Stack nodeStack;
171 72

  
172
     // Create the document node representation as root
173
     rootNode = new DBSAXNode(connection, this.docid);
174
     // Add the node to the stack, so that any text data can be
175
     // added as it is encountered
176
     nodeStack.push(rootNode);
177
   }
73
    protected Vector nodeIndex;
178 74

  
179
   /** SAX Handler that receives notification of end of the document */
180
   public void endDocument() throws SAXException {
181
     MetaCatUtil.debugMessage("end Document", 50);
182
     // Starting new thread for writing XML Index.
183
     // It calls the run method of the thread.
184
     
185
     //if it is data package insert triple into relationtion table;
186
     if ( doctype != null && 
187
         MetaCatUtil.getOptionList(MetaCatUtil.getOption("packagedoctype")).
188
         contains(doctype) && hasTriple)
189
      {
190
        try
191
        {
192
          //initial handler and write into relationdb
193
          RelationHandler handler = 
194
                        new RelationHandler(docid,doctype, connection, tripleList);
75
    protected DBConnection connection = null;
76

  
77
    protected DocumentImpl currentDocument;
78

  
79
    protected DBSAXNode rootNode;
80

  
81
    protected String action = null;
82

  
83
    protected String docid = null;
84

  
85
    protected String revision = null;
86

  
87
    protected String user = null;
88

  
89
    protected String[] groups = null;
90

  
91
    protected String pub = null;
92

  
93
    protected Thread xmlIndex;
94

  
95
    private boolean endDocument = false;
96

  
97
    protected int serverCode = 1;
98

  
99
    protected Hashtable namespaces = new Hashtable();
100

  
101
    protected boolean hitTextNode = false; // a flag to hit text node
102

  
103
    // a buffer to keep all text nodes for same element
104
    // it is for element was splited
105
    protected StringBuffer textBuffer = new StringBuffer();
106

  
107
    protected Stack textBufferStack = new Stack();
108

  
109
    protected static final int MAXDATACHARS = 4000;
110

  
111
    //protected static final int MAXDATACHARS = 50;
112
    protected static final long INDEXDELAY = 10000;
113

  
114
    // methods writeChildNodeToDB, setAttribute, setNamespace,
115
    // writeTextForDBSAXNode will increase endNodeId.
116
    protected long endNodeId = -1; // The end node id for a substree
117
    // DOCTITLE attr cleared from the db
118
    //   private static final int MAXTITLELEN = 1000;
119

  
120
    //HandlerTriple stuff
121
    TripleCollection tripleList = new TripleCollection();
122

  
123
    Triple currentTriple = new Triple();
124

  
125
    boolean startParseTriple = false;
126

  
127
    boolean hasTriple = false;
128

  
129
    /**
130
     * Construct an instance of the handler class
131
     * 
132
     * @param conn the JDBC connection to which information is written
133
     */
134
    private DBSAXHandler(DBConnection conn)
135
    {
136
        this.connection = conn;
137
        this.atFirstElement = true;
138
        this.processingDTD = false;
139

  
140
        // Create the stack for keeping track of node context
141
        // if it doesn't already exist
142
        if (!stackCreated) {
143
            nodeStack = new Stack();
144
            nodeIndex = new Vector();
145
            stackCreated = true;
195 146
        }
196
        catch (Exception e)
197
        {
198
          MetaCatUtil.debugMessage
199
                            ("Failed to write triples into relation table" + 
200
                                                           e.getMessage(), 30);
201
          throw new SAXException("Failed to write triples into relation table "+ e.getMessage());
147
    }
148

  
149
    /**
150
     * Construct an instance of the handler class
151
     * 
152
     * @param conn the JDBC connection to which information is written
153
     * @param action - "INSERT" or "UPDATE"
154
     * @param docid to be inserted or updated into JDBC connection
155
     * @param user the user connected to MetaCat servlet and owns the document
156
     * @param groups the groups to which user belongs
157
     * @param pub flag for public "read" access on document
158
     * @param serverCode the serverid from xml_replication on which this
159
     *            document resides.
160
     *  
161
     */
162
/* TODO excise this constructor because not used anywhere in project 
163
    public DBSAXHandler(DBConnection conn, String action, String docid,
164
            String user, String[] groups, String pub, int serverCode)
165
    {
166
        this(conn);
167
        this.action = action;
168
        this.docid = docid;
169
        this.user = user;
170
        this.groups = groups;
171
        this.pub = pub;
172
        this.serverCode = serverCode;
173
        this.xmlIndex = new Thread(this);
174
    }
175
*/
176
    /**
177
     * Construct an instance of the handler class In this constructor, user can
178
     * specify the version need to upadate
179
     * 
180
     * @param conn the JDBC connection to which information is written
181
     * @param action - "INSERT" or "UPDATE"
182
     * @param docid to be inserted or updated into JDBC connection
183
     * @param revision, the user specified the revision need to be update
184
     * @param user the user connected to MetaCat servlet and owns the document
185
     * @param groups the groups to which user belongs
186
     * @param pub flag for public "read" access on document
187
     * @param serverCode the serverid from xml_replication on which this
188
     *            document resides.
189
     *  
190
     */
191
    public DBSAXHandler(DBConnection conn, String action, String docid,
192
            String revision, String user, String[] groups, String pub,
193
            int serverCode)
194
    {
195
        this(conn);
196
        this.action = action;
197
        this.docid = docid;
198
        this.revision = revision;
199
        this.user = user;
200
        this.groups = groups;
201
        this.pub = pub;
202
        this.serverCode = serverCode;
203
        this.xmlIndex = new Thread(this);
204
    }
205

  
206
    /** SAX Handler that receives notification of beginning of the document */
207
    public void startDocument() throws SAXException
208
    {
209
        MetaCatUtil.debugMessage("start Document", 50);
210

  
211
        // Create the document node representation as root
212
        rootNode = new DBSAXNode(connection, this.docid);
213
        // Add the node to the stack, so that any text data can be
214
        // added as it is encountered
215
        nodeStack.push(rootNode);
216
    }
217

  
218
    /** SAX Handler that receives notification of end of the document */
219
    public void endDocument() throws SAXException
220
    {
221
        MetaCatUtil.debugMessage("end Document", 50);
222
        // Starting new thread for writing XML Index.
223
        // It calls the run method of the thread.
224

  
225
        //if it is data package insert triple into relationtion table;
226
        if (doctype != null
227
                && MetaCatUtil.getOptionList(
228
                        MetaCatUtil.getOption("packagedoctype")).contains(
229
                        doctype) && hasTriple) {
230
            try {
231
                //initial handler and write into relationdb
232
                RelationHandler handler = new RelationHandler(docid, doctype,
233
                        connection, tripleList);
234
            } catch (Exception e) {
235
                MetaCatUtil.debugMessage(
236
                        "Failed to write triples into relation table"
237
                                + e.getMessage(), 30);
238
                throw new SAXException(
239
                        "Failed to write triples into relation table "
240
                                + e.getMessage());
241
            }
202 242
        }
203
      }
204
     
205
     
206
     try {
207
       xmlIndex.start();
208
     } catch (NullPointerException e) {
209
       xmlIndex = null;
210
       throw new
211
       SAXException("Problem with starting thread for writing XML Index. " +
212
                    e.getMessage());
213
     }
214
   }
243
        boolean useXMLIndex = 
244
            (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
245
        if (useXMLIndex) {
246
            try {
247
                xmlIndex.start();
248
            } catch (NullPointerException e) {
249
                xmlIndex = null;
250
                throw new SAXException(
251
                        "Problem with starting thread for writing XML Index. "
252
                                + e.getMessage());
253
            }   
254
        }
255
    }
215 256

  
216
   /** SAX Handler that is called at the start of Namespace */
217
   public void startPrefixMapping(String prefix, String uri)
218
                                          throws SAXException
219
   {
220
    MetaCatUtil.debugMessage("NAMESPACE", 50);
257
    /** SAX Handler that is called at the start of Namespace */
258
    public void startPrefixMapping(String prefix, String uri)
259
            throws SAXException
260
    {
261
        MetaCatUtil.debugMessage("NAMESPACE", 50);
221 262

  
222
    namespaces.put(prefix, uri);
223
   }
263
        namespaces.put(prefix, uri);
264
    }
224 265

  
225
   /** SAX Handler that is called at the start of each XML element */
226
   public void startElement(String uri, String localName,
227
                            String qName, Attributes atts)
228
               throws SAXException {
229
     // for element <eml:eml...> qname is "eml:eml", local name is "eml"            
230
     // for element <acl....> both qname and local name is "eml"
231
     // uri is namesapce
232
     MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
233
     MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
234
     MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
235
     
236
     DBSAXNode parentNode = null;
237
     DBSAXNode currentNode = null;
266
    /** SAX Handler that is called at the start of each XML element */
267
    public void startElement(String uri, String localName, String qName,
268
            Attributes atts) throws SAXException
269
    {
270
        // for element <eml:eml...> qname is "eml:eml", local name is "eml"
271
        // for element <acl....> both qname and local name is "eml"
272
        // uri is namesapce
273
        MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
274
        MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
275
        MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
238 276

  
239
     // Get a reference to the parent node for the id
240
     try {
241
       parentNode = (DBSAXNode)nodeStack.peek();
242
     } catch (EmptyStackException e) {
243
       parentNode = null;
244
     }
245
     
246
     // If hit a text node, we need write this text for current's parent node
247
     // This will happend if the element is mixted
248
     if (hitTextNode && parentNode != null)
249
     {
250
       // write the textbuffer into db for parent node.
251
        endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, parentNode);
252
        // rest hitTextNode
253
        hitTextNode =false;
254
        // reset textbuffer
255
        textBuffer = null;
256
        textBuffer = new StringBuffer();
257
       
258
     }
277
        DBSAXNode parentNode = null;
278
        DBSAXNode currentNode = null;
259 279

  
260
     // Document representation that points to the root document node
261
     if (atFirstElement) 
262
     {
263
       atFirstElement = false;
264
       // If no DOCTYPE declaration: docname = root element
265
       // doctype = root element name or name space
266
       if (docname == null) 
267
       {
268
         docname = localName;
269
         // if uri isn't null doctype = uri(namespace)
270
         // othewise root element
271
         if (uri != null && !(uri.trim()).equals(""))
272
         {
273
           doctype = uri;
274
         }
275
         else
276
         {
277
           doctype = docname;
278
         }
279
         MetaCatUtil.debugMessage("DOCNAME-a: " + docname, 30);
280
         MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype, 30);
281
       } 
282
       else if (doctype == null) 
283
       {
284
         // because docname is not null and it is declared in dtd
285
         // so could not be in schema, no namespace
286
         doctype = docname;
287
         MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
288
       }
289
       rootNode.writeNodename(docname);
290
       try {
291
         // for validated XML Documents store a reference to XML DB Catalog
292
         // Because this is select statement and it needn't to roll back if
293
         // insert document action fialed.
294
         // In order to decrease DBConnection usage count, we get a new
295
         // dbconnection from pool
296
         String catalogid = null;
297
         DBConnection dbConn = null;
298
         int serialNumber = -1;
280
        // Get a reference to the parent node for the id
281
        try {
282
            parentNode = (DBSAXNode) nodeStack.peek();
283
        } catch (EmptyStackException e) {
284
            parentNode = null;
285
        }
299 286

  
300
         if ( systemid != null ) {
301
           try
302
           {
303
            // Get dbconnection
304
            dbConn=DBConnectionPool.getDBConnection
305
                                          ("DBSAXHandler.startElement");
306
            serialNumber=dbConn.getCheckOutSerialNumber();
287
        // If hit a text node, we need write this text for current's parent
288
        // node
289
        // This will happend if the element is mixted
290
        if (hitTextNode && parentNode != null) {
291
            // write the textbuffer into db for parent node.
292
            endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, parentNode);
293
            // rest hitTextNode
294
            hitTextNode = false;
295
            // reset textbuffer
296
            textBuffer = null;
297
            textBuffer = new StringBuffer();
307 298

  
308
            Statement stmt = dbConn.createStatement();
309
            ResultSet rs = stmt.executeQuery(
310
                          "SELECT catalog_id FROM xml_catalog " +
311
                          "WHERE entry_type = 'DTD' " +
312
                          "AND public_id = '" + doctype + "'");
313
            boolean hasRow = rs.next();
314
            if ( hasRow ) {
315
              catalogid = rs.getString(1);
299
        }
300

  
301
        // Document representation that points to the root document node
302
        if (atFirstElement) {
303
            atFirstElement = false;
304
            // If no DOCTYPE declaration: docname = root element
305
            // doctype = root element name or name space
306
            if (docname == null) {
307
                docname = localName;
308
                // if uri isn't null doctype = uri(namespace)
309
                // othewise root element
310
                if (uri != null && !(uri.trim()).equals("")) {
311
                    doctype = uri;
312
                } else {
313
                    doctype = docname;
314
                }
315
                MetaCatUtil.debugMessage("DOCNAME-a: " + docname, 30);
316
                MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype, 30);
317
            } else if (doctype == null) {
318
                // because docname is not null and it is declared in dtd
319
                // so could not be in schema, no namespace
320
                doctype = docname;
321
                MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
316 322
            }
317
            stmt.close();
318
           }//try
319
           finally
320
           {
321
             // Return dbconnection
322
             DBConnectionPool.returnDBConnection(dbConn, serialNumber);
323
           }//finally
324
         }
323
            rootNode.writeNodename(docname);
324
            try {
325
                // for validated XML Documents store a reference to XML DB
326
                // Catalog
327
                // Because this is select statement and it needn't to roll back
328
                // if
329
                // insert document action fialed.
330
                // In order to decrease DBConnection usage count, we get a new
331
                // dbconnection from pool
332
                String catalogid = null;
333
                DBConnection dbConn = null;
334
                int serialNumber = -1;
325 335

  
326
         //create documentImpl object by the constructor which can specify
327
         //the revision
328
         currentDocument = new DocumentImpl(connection, rootNode.getNodeID(),
329
                               docname, doctype, docid, revision, action, user,
330
                               this.pub, catalogid, this.serverCode);
336
                if (systemid != null) {
337
                    try {
338
                        // Get dbconnection
339
                        dbConn = DBConnectionPool
340
                                .getDBConnection("DBSAXHandler.startElement");
341
                        serialNumber = dbConn.getCheckOutSerialNumber();
331 342

  
343
                        Statement stmt = dbConn.createStatement();
344
                        ResultSet rs = stmt
345
                                .executeQuery("SELECT catalog_id FROM xml_catalog "
346
                                        + "WHERE entry_type = 'DTD' "
347
                                        + "AND public_id = '" + doctype + "'");
348
                        boolean hasRow = rs.next();
349
                        if (hasRow) {
350
                            catalogid = rs.getString(1);
351
                        }
352
                        stmt.close();
353
                    }//try
354
                    finally {
355
                        // Return dbconnection
356
                        DBConnectionPool.returnDBConnection(dbConn,
357
                                serialNumber);
358
                    }//finally
359
                }
332 360

  
333
       } catch (Exception ane) {
334
         throw (new SAXException("Error in DBSaxHandler.startElement " +
335
                                 action, ane));
336
       }
337
     }
361
                //create documentImpl object by the constructor which can
362
                // specify
363
                //the revision
364
                currentDocument = new DocumentImpl(connection, rootNode
365
                        .getNodeID(), docname, doctype, docid, revision,
366
                        action, user, this.pub, catalogid, this.serverCode);
338 367

  
339
     // Create the current node representation
340
     currentNode = new DBSAXNode(connection, qName, localName, parentNode,
341
                                 currentDocument.getRootNodeID(),docid,
342
                                 currentDocument.getDoctype());
368
            } catch (Exception ane) {
369
                throw (new SAXException("Error in DBSaxHandler.startElement "
370
                        + action, ane));
371
            }
372
        }
343 373

  
344
     // Add all of the namespaces
345
     String prefix;
346
     String nsuri;
347
     Enumeration prefixes = namespaces.keys();
348
     while ( prefixes.hasMoreElements() ) {
349
       prefix = (String)prefixes.nextElement();
350
       nsuri = (String)namespaces.get(prefix);
351
       currentNode.setNamespace(prefix, nsuri, docid);
352
     }
353
     namespaces = null;
354
     namespaces = new Hashtable();
374
        // Create the current node representation
375
        currentNode = new DBSAXNode(connection, qName, localName, parentNode,
376
                currentDocument.getRootNodeID(), docid, currentDocument
377
                        .getDoctype());
355 378

  
356
     // Add all of the attributes
357
     for (int i=0; i<atts.getLength(); i++) 
358
     {
359
       String attributeName = atts.getQName(i);
360
       String attributeValue = atts.getValue(i);
361
       endNodeId = 
362
                currentNode.setAttribute(attributeName, attributeValue, docid);
363
       
364
       // To handle name space and schema location if the attribute name is
365
       // xsi:schemaLocation. If the name space is in not in catalog table
366
       // it will be regeistered.
367
       if (attributeName != null && 
368
           attributeName.indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1)
369
       {
370
         SchemaLocationResolver resolver = 
371
                                  new SchemaLocationResolver(attributeValue);
372
         resolver.resolveNameSpace();
373
         
374
       }
375
     }
379
        // Add all of the namespaces
380
        String prefix;
381
        String nsuri;
382
        Enumeration prefixes = namespaces.keys();
383
        while (prefixes.hasMoreElements()) {
384
            prefix = (String) prefixes.nextElement();
385
            nsuri = (String) namespaces.get(prefix);
386
            currentNode.setNamespace(prefix, nsuri, docid);
387
        }
388
        namespaces = null;
389
        namespaces = new Hashtable();
376 390

  
377
     // Add the node to the stack, so that any text data can be
378
     // added as it is encountered
379
     nodeStack.push(currentNode);
380
     // Add the node to the vector used by thread for writing XML Index
381
     nodeIndex.addElement(currentNode);
382
     // start parsing triple
383
     if ( doctype != null && 
384
         MetaCatUtil.getOptionList(MetaCatUtil.getOption("packagedoctype")).contains(doctype)
385
         && localName.equals("triple"))
386
      {
387
        startParseTriple = true;
388
        hasTriple = true;
389
        currentTriple = new Triple();
390
      }
391
  }
391
        // Add all of the attributes
392
        for (int i = 0; i < atts.getLength(); i++) {
393
            String attributeName = atts.getQName(i);
394
            String attributeValue = atts.getValue(i);
395
            endNodeId = currentNode.setAttribute(attributeName, attributeValue,
396
                    docid);
392 397

  
393
  /* The run method of xmlIndex thread. It writes XML Index for the document. */
394
  public void run () {
395
    DBSAXNode currNode = null;
396
    DBSAXNode prevNode = null;
397
    DBConnection dbConn = null;
398
    int serialNumber = -1;
399
    String doctype = currentDocument.getDoctype();
400
    int step = 0;
401
    int counter = 0;
398
            // To handle name space and schema location if the attribute name
399
            // is
400
            // xsi:schemaLocation. If the name space is in not in catalog table
401
            // it will be regeistered.
402
            if (attributeName != null
403
                    && attributeName
404
                            .indexOf(MetaCatServlet.SCHEMALOCATIONKEYWORD) != -1) {
405
                SchemaLocationResolver resolver = new SchemaLocationResolver(
406
                        attributeValue);
407
                resolver.resolveNameSpace();
402 408

  
403
    try 
409
            }
410
        }
411

  
412
        // Add the node to the stack, so that any text data can be
413
        // added as it is encountered
414
        nodeStack.push(currentNode);
415
        // Add the node to the vector used by thread for writing XML Index
416
        nodeIndex.addElement(currentNode);
417
        // start parsing triple
418
        if (doctype != null
419
                && MetaCatUtil.getOptionList(
420
                        MetaCatUtil.getOption("packagedoctype")).contains(
421
                        doctype) && localName.equals("triple")) {
422
            startParseTriple = true;
423
            hasTriple = true;
424
            currentTriple = new Triple();
425
        }
426
    }
427

  
428
    /* The run method of xmlIndex thread. It writes XML Index for the document. */
429
    public void run()
404 430
    {
405
      // stop 5 second
406
      Thread.sleep(5000);
407
      // Opening separate db connection for writing XML Index
408
      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.run");
409
      serialNumber=dbConn.getCheckOutSerialNumber();
410
      dbConn.setAutoCommit(false);
411
      //make sure record is done
412
      checkDocumentTable();   
413
      // Going through the elements of the document and writing its Index
414
      Enumeration nodes = nodeIndex.elements();
415
      while ( nodes.hasMoreElements() ) {
416
        currNode = (DBSAXNode)nodes.nextElement();
417
        currNode.updateNodeIndex(dbConn, docid, doctype);
418
      }
419
      dbConn.commit();
431
        DBSAXNode currNode = null;
432
        DBSAXNode prevNode = null;
433
        DBConnection dbConn = null;
434
        int serialNumber = -1;
435
        String doctype = currentDocument.getDoctype();
436
        int step = 0;
437
        int counter = 0;
420 438

  
421
    } catch (Exception e) {
422
      try {
423
        dbConn.rollback();
424
        //dbconn.close();
425
      } catch (SQLException sqle) {}
426
      MetaCatUtil.debugMessage("Error in DBSAXHandler.run " + 
427
                                e.getMessage(), 30);
428
      
439
        try {
440
            // stop 5 second
441
            Thread.sleep(5000);
442
            // Opening separate db connection for writing XML Index
443
            dbConn = DBConnectionPool.getDBConnection("DBSAXHandler.run");
444
            serialNumber = dbConn.getCheckOutSerialNumber();
445
            dbConn.setAutoCommit(false);
446
            //make sure record is done
447
            checkDocumentTable();
448
            // Going through the elements of the document and writing its Index
449
            Enumeration nodes = nodeIndex.elements();
450
            while (nodes.hasMoreElements()) {
451
                currNode = (DBSAXNode) nodes.nextElement();
452
                currNode.updateNodeIndex(dbConn, docid, doctype);
453
            }
454
            dbConn.commit();
455

  
456
        } catch (Exception e) {
457
            try {
458
                dbConn.rollback();
459
                //dbconn.close();
460
            } catch (SQLException sqle) {
461
            }
462
            MetaCatUtil.debugMessage("Error in DBSAXHandler.run "
463
                    + e.getMessage(), 30);
464

  
465
        } finally {
466
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
467
        }//finally
429 468
    }
430
    finally
469

  
470
    /*
471
     * method to make sure insert is finished before create index table If new
472
     * version of record is in xml_documents every thing will be fine
473
     */
474
    private void checkDocumentTable() throws Exception
431 475
    {
432
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
433
    }//finally
434
  }
435 476

  
436
  /* method to make sure insert is finished before create index table
437
   * If new version of record is in xml_documents every thing will be fine
438
   */
439
  private void checkDocumentTable() throws Exception
440
  {
441
    
442
    DBConnection dbConn = null;
443
    int serialNumber = -1;
444
   
445
    try 
477
        DBConnection dbConn = null;
478
        int serialNumber = -1;
479

  
480
        try {
481
            // Opening separate db connection for writing XML Index
482
            dbConn = DBConnectionPool
483
                    .getDBConnection("DBSAXHandler.checkDocumentTable");
484
            serialNumber = dbConn.getCheckOutSerialNumber();
485

  
486
            // the following while loop construct checks to make sure that 
487
            // the docid of the document that we are trying to index is already 
488
            // in the xml_documents table. if this is not the case, the foreign 
489
            // key relationship between xml_documents and xml_index is 
490
            // temporarily broken causing multiple problems.
491
            boolean inxmldoc = false;
492
            long startTime = System.currentTimeMillis();
493
            while (!inxmldoc) {
494
                String xmlDocumentsCheck = "select distinct docid from xml_documents"
495
                        + " where docid ='"
496
                        + docid
497
                        + "' and "
498
                        + " rev ='"
499
                        + revision + "'";
500

  
501
                PreparedStatement xmlDocCheck = dbConn
502
                        .prepareStatement(xmlDocumentsCheck);
503
                // Increase usage count
504
                dbConn.increaseUsageCount(1);
505
                xmlDocCheck.execute();
506
                ResultSet doccheckRS = xmlDocCheck.getResultSet();
507
                boolean tableHasRows = doccheckRS.next();
508
                if (tableHasRows) {
509
                    MetaCatUtil.debugMessage(
510
                            "=========== find the correct document", 35);
511
                    inxmldoc = true;
512
                }
513
                doccheckRS.close();
514
                xmlDocCheck.close();
515
                // make sure the while loop will be ended in reseaonable time
516
                long stopTime = System.currentTimeMillis();
517
                if ((stopTime - startTime) > INDEXDELAY) { throw new Exception(
518
                        "Couldn't find the docid for index build in"
519
                                + "reseaonable time!"); }
520
            }//while
521
        } catch (Exception e) {
522
            try {
523
                dbConn.rollback();
524
                //dbconn.close();
525
            } catch (SQLException sqle) {
526
            }
527
            MetaCatUtil.debugMessage("Error in DBSAXHandler.run "
528
                    + e.getMessage(), 30);
529

  
530
        } finally {
531
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
532
        }//finally
533

  
534
    }
535

  
536
    /** SAX Handler that is called for each XML text node */
537
    public void characters(char[] cbuf, int start, int len) throws SAXException
446 538
    {
447
       // Opening separate db connection for writing XML Index
448
      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.checkDocumentTable");
449
      serialNumber=dbConn.getCheckOutSerialNumber();
450
     
451
      //the following while loop construct checks to make sure that the docid
452
      //of the document that we are trying to index is already
453
      //in the xml_documents table.  if this is not the case, the foreign
454
      //key relationship between xml_documents and xml_index is temporarily
455
      //broken causing multiple problems.
456
      boolean inxmldoc = false;
457
      long startTime = System.currentTimeMillis();
458
      while(!inxmldoc)
459
      {
460
        String xmlDocumentsCheck = "select distinct docid from xml_documents" +
461
                                   " where docid ='" + docid + "' and " +
462
                                   " rev ='" + revision + "'";
463
       
464
        PreparedStatement xmlDocCheck =
465
                                 dbConn.prepareStatement(xmlDocumentsCheck);
466
        // Increase usage count
467
        dbConn.increaseUsageCount(1);
468
        xmlDocCheck.execute();
469
        ResultSet doccheckRS = xmlDocCheck.getResultSet();
470
        boolean tableHasRows = doccheckRS.next();
471
        if (tableHasRows)
472
        {
473
           MetaCatUtil.debugMessage("=========== find the correct document", 35);
474
           inxmldoc = true;
539
        MetaCatUtil.debugMessage("CHARACTERS", 50);
540
        // buffer all text nodes for same element. This is for text was splited
541
        // into different nodes
542
        textBuffer.append(new String(cbuf, start, len));
543
        // set hittextnode true
544
        hitTextNode = true;
545
        // if text buffer .size is greater than max, write it to db.
546
        // so we can save memory
547
        if (textBuffer.length() > MAXDATACHARS) {
548
            MetaCatUtil.debugMessage("Write text into DB in charaters"
549
                    + " when text buffer size is greater than maxmum number",
550
                    50);
551
            DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
552
            endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
553
                    currentNode);
554
            textBuffer = null;
555
            textBuffer = new StringBuffer();
475 556
        }
476
         doccheckRS.close();
477
         xmlDocCheck.close();
478
         // make sure the while loop will be ended in reseaonable time
479
         long stopTime = System.currentTimeMillis();
480
         if ((stopTime - startTime) > INDEXDELAY)
481
         {
482
           throw new Exception("Couldn't find the docid for index build in" +
483
                              "reseaonable time!");
484
         }
485
       }//while
486
    } 
487
    catch (Exception e) 
557
    }
558

  
559
    /**
560
     * SAX Handler that is called for each XML text node that is Ignorable
561
     * white space
562
     */
563
    public void ignorableWhitespace(char[] cbuf, int start, int len)
564
            throws SAXException
488 565
    {
489
      try 
490
      {
491
        dbConn.rollback();
492
        //dbconn.close();
493
      } 
494
      catch (SQLException sqle) 
495
      {}
496
      MetaCatUtil.debugMessage("Error in DBSAXHandler.run " + 
497
                                e.getMessage(), 30);
498
      
566
        // When validation is turned "on", white spaces are reported here
567
        // When validation is turned "off" white spaces are not reported here,
568
        // but through characters() callback
569
        MetaCatUtil.debugMessage("IGNORABLEWHITESPACE", 50);
570

  
571
        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
572
        String data = null;
573
        int leftover = len;
574
        int offset = start;
575
        boolean moredata = true;
576

  
577
        // This loop deals with the case where there are more characters
578
        // than can fit in a single database text field (limit is
579
        // MAXDATACHARS). If the text to be inserted exceeds MAXDATACHARS,
580
        // write a series of nodes that are MAXDATACHARS long, and then the
581
        // final node contains the remainder
582
        while (moredata) {
583
            if (leftover > MAXDATACHARS) {
584
                data = new String(cbuf, offset, MAXDATACHARS);
585
                leftover -= MAXDATACHARS;
586
                offset += MAXDATACHARS;
587
            } else {
588
                data = new String(cbuf, offset, leftover);
589
                moredata = false;
590
            }
591

  
592
            // Write the content of the node to the database
593
            endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data,
594
                    docid);
595
        }
499 596
    }
500
    finally
597

  
598
    /**
599
     * SAX Handler called once for each processing instruction found: node that
600
     * PI may occur before or after the root element.
601
     */
602
    public void processingInstruction(String target, String data)
603
            throws SAXException
501 604
    {
502
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
503
    }//finally
504
  
505
  }
506
  
507
  /** SAX Handler that is called for each XML text node */
508
  public void characters(char[] cbuf, int start, int len) throws SAXException 
509
  {
510
     MetaCatUtil.debugMessage("CHARACTERS", 50);
511
     // buffer all text nodes for same element. This is for text was splited
512
     // into different nodes
513
     textBuffer.append(new String(cbuf, start,len));
514
     // set hittextnode true
515
     hitTextNode = true;
516
     // if text buffer .size is greater than max, write it to db. 
517
     // so we can save memory
518
     if (textBuffer.length() > MAXDATACHARS)
519
     {
520
       MetaCatUtil.debugMessage("Write text into DB in charaters" + 
521
                   " when text buffer size is greater than maxmum number", 50);
522
       DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
523
       endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode);
524
       textBuffer = null;
525
       textBuffer = new StringBuffer();
526
     }
527
  }
605
        MetaCatUtil.debugMessage("PI", 50);
606
        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
607
        endNodeId = currentNode.writeChildNodeToDB("PI", target, data, docid);
608
    }
528 609

  
529
   /**
530
    * SAX Handler that is called for each XML text node that is
531
    * Ignorable white space
532
    */
533
   public void ignorableWhitespace(char[] cbuf, int start, int len)
534
               throws SAXException {
535
     // When validation is turned "on", white spaces are reported here
536
     // When validation is turned "off" white spaces are not reported here,
537
     // but through characters() callback
538
     MetaCatUtil.debugMessage("IGNORABLEWHITESPACE", 50);
610
    /** SAX Handler that is called at the end of each XML element */
611
    public void endElement(String uri, String localName, String qName)
612
            throws SAXException
613
    {
614
        MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
539 615

  
616
        // write buffered text nodes into db (so no splited)
617
        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
540 618

  
541
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
542
     String data = null;
543
     int leftover = len;
544
     int offset = start;
545
     boolean moredata = true;
619
        // If before the end element, the parser hit text nodes and store them
620
        // into the buffer, write the buffer to data base. The reason we put
621
        // write database here is for xerces some time split text node
622
        if (hitTextNode) {
623
            MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
624
            endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer,
625
                    currentNode);
546 626

  
547
     // This loop deals with the case where there are more characters
548
     // than can fit in a single database text field (limit is
549
     // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
550
     // write a series of nodes that are MAXDATACHARS long, and then the
551
     // final node contains the remainder
552
     while (moredata) {
553
       if (leftover > MAXDATACHARS) {
554
         data = new String(cbuf, offset, MAXDATACHARS);
555
         leftover -= MAXDATACHARS;
556
         offset += MAXDATACHARS;
557
       } else {
558
         data = new String(cbuf, offset, leftover);
559
         moredata = false;
560
       }
627
            //if it is triple parsing process
628
            if (startParseTriple) {
561 629

  
562
       // Write the content of the node to the database
563
       endNodeId = currentNode.writeChildNodeToDB("TEXT", null, data, docid);
564
     }
565
   }
630
                String content = textBuffer.toString().trim();
631
                if (localName.equals("subject")) { //get the subject content
632
                    currentTriple.setSubject(content);
633
                } else if (localName.equals("relationship")) { //get the
634
                                                               // relationship
635
                                                               // content
636
                    currentTriple.setRelationship(content);
637
                } else if (localName.equals("object")) { //get the object
638
                                                         // content
639
                    currentTriple.setObject(content);
640
                }
641
            }
566 642

  
567
   /**
568
    * SAX Handler called once for each processing instruction found:
569
    * node that PI may occur before or after the root element.
570
    */
571
   public void processingInstruction(String target, String data)
572
          throws SAXException {
573
     MetaCatUtil.debugMessage("PI", 50);
574
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
575
     endNodeId = currentNode.writeChildNodeToDB("PI", target, data, docid);
576
   }
643
        }//if
577 644

  
578
   /** SAX Handler that is called at the end of each XML element */
579
   public void endElement(String uri, String localName,
580
                          String qName) throws SAXException {
581
     MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
582
     
583
     // write buffered text nodes into db (so no splited)
584
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
585
      
586
     // If before the end element, the parser hit text nodes and store them
587
     // into the buffer, write the buffer to data base. The reason we put
588
     // write database here is for xerces some time split text node
589
     if (hitTextNode)
590
     {
591
       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
592
       endNodeId = writeTextForDBSAXNode(endNodeId, textBuffer, currentNode);
593
       
594
       //if it is triple parsing process
595
       if (startParseTriple)
596
       {
597
         
598
          String content = textBuffer.toString().trim();
599
          if(localName.equals("subject"))
600
          { //get the subject content
601
            currentTriple.setSubject(content);
602
          }
603
          else if(localName.equals("relationship"))
604
          { //get the relationship content
605
            currentTriple.setRelationship(content);
606
          }
607
          else if(localName.equals("object"))
608
          { //get the object content
609
            currentTriple.setObject(content);
610
          }
611
       }
612
       
613
     }//if
614
     
615
     //set hitText false
616
     hitTextNode = false;
617
     // reset textbuff
618
     textBuffer = null;
619
     textBuffer = new StringBuffer();
645
        //set hitText false
646
        hitTextNode = false;
647
        // reset textbuff
648
        textBuffer = null;
649
        textBuffer = new StringBuffer();
620 650

  
621
     // Get the node from the stack
622
     currentNode = (DBSAXNode)nodeStack.pop();
623
     //finishing parsing single triple
624
     if (startParseTriple && localName.equals("triple"))
625
      {
626
        // add trip to triple collection
627
        tripleList.addTriple(currentTriple);
628
        //rest variable
629
        currentTriple = null;
630
        startParseTriple = false;   
631
      }
632
   }
651
        // Get the node from the stack
652
        currentNode = (DBSAXNode) nodeStack.pop();
653
        //finishing parsing single triple
654
        if (startParseTriple && localName.equals("triple")) {
655
            // add trip to triple collection
656
            tripleList.addTriple(currentTriple);
657
            //rest variable
658
            currentTriple = null;
659
            startParseTriple = false;
660
        }
661
    }
633 662

  
634
   //
635
   // the next section implements the LexicalHandler interface
636
   //
663
    //
664
    // the next section implements the LexicalHandler interface
665
    //
637 666

  
638
   /** SAX Handler that receives notification of DOCTYPE. Sets the DTD */
639
   public void startDTD(String name, String publicId, String systemId)
640
               throws SAXException {
641
     docname = name;
642
     doctype = publicId;
643
     systemid = systemId;
667
    /** SAX Handler that receives notification of DOCTYPE. Sets the DTD */
668
    public void startDTD(String name, String publicId, String systemId)
669
            throws SAXException
670
    {
671
        docname = name;
672
        doctype = publicId;
673
        systemid = systemId;
644 674

  
645
     processingDTD = true;
646
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
647
     //create a DTD node and write docname,publicid and system id into db
648
     // we don't put the dtd node into node stack
649
     DBSAXNode dtdNode = new DBSAXNode (connection, name, publicId, systemId, 
650
                               currentNode, currentNode.getRootNodeID(), docid);
651
     MetaCatUtil.debugMessage("Start DTD", 50);
652
     MetaCatUtil.debugMessage("Setting processingDTD to true", 50);
653
     MetaCatUtil.debugMessage("DOCNAME: " + docname, 50);
654
     MetaCatUtil.debugMessage("DOCTYPE: " + doctype, 50);
655
     MetaCatUtil.debugMessage("  SYSID: " + systemid, 50);
656
   }
675
        processingDTD = true;
676
        DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
677
        //create a DTD node and write docname,publicid and system id into db
678
        // we don't put the dtd node into node stack
679
        DBSAXNode dtdNode = new DBSAXNode(connection, name, publicId, systemId,
680
                currentNode, currentNode.getRootNodeID(), docid);
681
        MetaCatUtil.debugMessage("Start DTD", 50);
682
        MetaCatUtil.debugMessage("Setting processingDTD to true", 50);
683
        MetaCatUtil.debugMessage("DOCNAME: " + docname, 50);
684
        MetaCatUtil.debugMessage("DOCTYPE: " + doctype, 50);
685
        MetaCatUtil.debugMessage("  SYSID: " + systemid, 50);
686
    }
657 687

  
658
   /**
659
    * SAX Handler that receives notification of end of DTD
660
    */
661
   public void endDTD() throws SAXException {
688
    /**
689
     * SAX Handler that receives notification of end of DTD
690
     */
691
    public void endDTD() throws SAXException
692
    {
662 693

  
663
     processingDTD = false;
664
     MetaCatUtil.debugMessage("Setting processingDTD to false", 50);
665
     MetaCatUtil.debugMessage("end DTD", 50);
666
   }
694
        processingDTD = false;
695
        MetaCatUtil.debugMessage("Setting processingDTD to false", 50);
696
        MetaCatUtil.debugMessage("end DTD", 50);
697
    }
667 698

  
668
   /**
669
    * SAX Handler that receives notification of comments in the DTD
670
    */
671
   public void comment(char[] ch, int start, int length) throws SAXException {
672
     MetaCatUtil.debugMessage("COMMENT", 50);
673
     if ( !processingDTD ) {
674
       DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
675
       endNodeId = 
676
        currentNode.writeChildNodeToDB("COMMENT", null, 
677
                                       new String(ch, start, length), docid);
678
     }
679
   }
699
    /**
700
     * SAX Handler that receives notification of comments in the DTD
701
     */
702
    public void comment(char[] ch, int start, int length) throws SAXException
703
    {
704
        MetaCatUtil.debugMessage("COMMENT", 50);
705
        if (!processingDTD) {
706
            DBSAXNode currentNode = (DBSAXNode) nodeStack.peek();
707
            endNodeId = currentNode.writeChildNodeToDB("COMMENT", null,
708
                    new String(ch, start, length), docid);
709
        }
710
    }
680 711

  
681
   /**
682
    * SAX Handler that receives notification of the start of CDATA sections
683
    */
684
   public void startCDATA() throws SAXException {
685
     MetaCatUtil.debugMessage("start CDATA", 50);
686
   }
712
    /**
713
     * SAX Handler that receives notification of the start of CDATA sections
714
     */
715
    public void startCDATA() throws SAXException
716
    {
717
        MetaCatUtil.debugMessage("start CDATA", 50);
718
    }
687 719

  
688
   /**
689
    * SAX Handler that receives notification of the end of CDATA sections
690
    */
691
   public void endCDATA() throws SAXException {
692
     MetaCatUtil.debugMessage("end CDATA", 50);
693
   }
720
    /**
721
     * SAX Handler that receives notification of the end of CDATA sections
722
     */
723
    public void endCDATA() throws SAXException
724
    {
725
        MetaCatUtil.debugMessage("end CDATA", 50);
726
    }
694 727

  
695
   /**
696
    * SAX Handler that receives notification of the start of entities
697
    */
698
   public void startEntity(String name) throws SAXException {
699
     MetaCatUtil.debugMessage("start ENTITY: " + name, 50);
700
//System.out.println("start ENTITY: " + name);
701
     if (name.equals("[dtd]")) {
702
       processingDTD = true;
703
     }
704
   }
728
    /**
729
     * SAX Handler that receives notification of the start of entities
730
     */
731
    public void startEntity(String name) throws SAXException
732
    {
733
        MetaCatUtil.debugMessage("start ENTITY: " + name, 50);
734
        //System.out.println("start ENTITY: " + name);
735
        if (name.equals("[dtd]")) {
736
            processingDTD = true;
737
        }
738
    }
705 739

  
706
   /**
707
    * SAX Handler that receives notification of the end of entities
708
    */
709
   public void endEntity(String name) throws SAXException {
710
     MetaCatUtil.debugMessage("end ENTITY: " + name, 50);
711
//System.out.println("end ENTITY: " + name);
712
     if (name.equals("[dtd]")) {
713
       processingDTD = false;
714
     }
715
   }
740
    /**
741
     * SAX Handler that receives notification of the end of entities
742
     */
743
    public void endEntity(String name) throws SAXException
744
    {
745
        MetaCatUtil.debugMessage("end ENTITY: " + name, 50);
746
        //System.out.println("end ENTITY: " + name);
747
        if (name.equals("[dtd]")) {
748
            processingDTD = false;
749
        }
750
    }
716 751

  
717
   /**
718
    * SAX Handler that receives notification of element declarations
719
    */
720
   public void elementDecl(String name, String model)
721
                        throws org.xml.sax.SAXException {
722
//System.out.println("ELEMENTDECL: " + name + " " + model);
723
     MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model, 50);
724
   }
752
    /**
753
     * SAX Handler that receives notification of element declarations
754
     */
755
    public void elementDecl(String name, String model)
756
            throws org.xml.sax.SAXException
757
    {
758
        //System.out.println("ELEMENTDECL: " + name + " " + model);
759
        MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model, 50);
760
    }
725 761

  
726
   /**
727
    * SAX Handler that receives notification of attribute declarations
728
    */
729
   public void attributeDecl(String eName, String aName,
730
                        String type, String valueDefault, String value)
731
                        throws org.xml.sax.SAXException {
762
    /**
763
     * SAX Handler that receives notification of attribute declarations
764
     */
765
    public void attributeDecl(String eName, String aName, String type,
766
            String valueDefault, String value) throws org.xml.sax.SAXException
767
    {
732 768

  
733
//System.out.println("ATTRIBUTEDECL: " + eName + " "
734
//                        + aName + " " + type + " " + valueDefault + " "
735
//                        + value);
736
     MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " "
737
                        + aName + " " + type + " " + valueDefault + " "
738
                        + value, 50);
739
   }
769
        //System.out.println("ATTRIBUTEDECL: " + eName + " "
770
        //                        + aName + " " + type + " " + valueDefault + " "
771
        //                        + value);
772
        MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " " + aName + " "
773
                + type + " " + valueDefault + " " + value, 50);
774
    }
740 775

  
741
   /**
742
    * SAX Handler that receives notification of internal entity declarations
743
    */
744
   public void internalEntityDecl(String name, String value)
745
                        throws org.xml.sax.SAXException {
746
//System.out.println("INTERNENTITYDECL: " + name + " " + value);
747
     MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value, 50);
748
   }
776
    /**
777
     * SAX Handler that receives notification of internal entity declarations
778
     */
779
    public void internalEntityDecl(String name, String value)
780
            throws org.xml.sax.SAXException
781
    {
782
        //System.out.println("INTERNENTITYDECL: " + name + " " + value);
783
        MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value, 50);
784
    }
749 785

  
750
   /**
751
    * SAX Handler that receives notification of external entity declarations
752
    */
753
   public void externalEntityDecl(String name, String publicId,
754
                        String systemId)
755
                        throws org.xml.sax.SAXException {
756
//System.out.println("EXTERNENTITYDECL: " + name + " " + publicId
757
//                              + " " + systemId);
758
     MetaCatUtil.debugMessage("EXTERNENTITYDECL: " + name + " " + publicId
759
                              + " " + systemId, 50);
760
     // it processes other external entity, not the DTD;
761
     // it doesn't signal for the DTD here
762
     processingDTD = false;
763
   }
786
    /**
787
     * SAX Handler that receives notification of external entity declarations
788
     */
789
    public void externalEntityDecl(String name, String publicId, String systemId)
790
            throws org.xml.sax.SAXException
791
    {
792
        //System.out.println("EXTERNENTITYDECL: " + name + " " + publicId
793
        //                              + " " + systemId);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff