Project

General

Profile

1 17 jones
/**
2 203 jones
 *  '$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 349 jones
 *    Release: @release@
9 17 jones
 *
10 203 jones
 *   '$Author$'
11
 *     '$Date$'
12
 * '$Revision$'
13 669 jones
 *
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 17 jones
 */
28
29 75 jones
package edu.ucsb.nceas.metacat;
30 51 jones
31 17 jones
import java.sql.*;
32 638 bojilova
import java.io.StringReader;
33 17 jones
import java.util.Stack;
34 471 bojilova
import java.util.Vector;
35 821 bojilova
import java.util.Hashtable;
36 471 bojilova
import java.util.Enumeration;
37 18 jones
import java.util.EmptyStackException;
38 17 jones
39 185 jones
import org.xml.sax.Attributes;
40
import org.xml.sax.SAXException;
41 204 jones
import org.xml.sax.SAXParseException;
42 186 jones
import org.xml.sax.ext.DeclHandler;
43 185 jones
import org.xml.sax.ext.LexicalHandler;
44
import org.xml.sax.helpers.DefaultHandler;
45 17 jones
46 1359 tao
/**
47 31 jones
 * A database aware Class implementing callback bethods for the SAX parser to
48
 * call when processing the XML stream and generating events
49
 */
50 1359 tao
public class DBSAXHandler extends DefaultHandler
51 471 bojilova
                          implements LexicalHandler, DeclHandler, Runnable {
52 17 jones
53 204 jones
   private boolean	atFirstElement;
54 243 jones
   private boolean	processingDTD;
55 204 jones
   private String 	docname = null;
56 135 jones
   private String 	doctype;
57
   private String 	systemid;
58 17 jones
   private boolean 	stackCreated = false;
59 471 bojilova
   private Stack 	  nodeStack;
60
   private Vector   nodeIndex;
61 1217 tao
   private DBConnection	  connection = null;
62 396 jones
   private DocumentImpl currentDocument;
63 185 jones
   private DBSAXNode    rootNode;
64 471 bojilova
   private String   action = null;
65
   private String   docid = null;
66 955 tao
   private String   revision = null;
67 471 bojilova
   private String   user = null;
68 802 bojilova
   private String[] groups = null;
69 680 bojilova
   private String   pub = null;
70 471 bojilova
   private Thread   xmlIndex;
71
   private boolean endDocument = false;
72 549 berkley
   private int serverCode = 1;
73 821 bojilova
   private Hashtable namespaces = new Hashtable();
74 17 jones
75 220 jones
   private static final int MAXDATACHARS = 4000;
76 691 bojilova
// DOCTITLE attr cleared from the db
77
//   private static final int MAXTITLELEN = 1000;
78 220 jones
79 1359 tao
   /** Construct an instance of the handler class
80 31 jones
    *
81
    * @param conn the JDBC connection to which information is written
82
    */
83 1217 tao
   public DBSAXHandler(DBConnection conn) {
84
     this.connection = conn;
85 204 jones
     this.atFirstElement = true;
86 243 jones
     this.processingDTD = false;
87 17 jones
88 185 jones
     // Create the stack for keeping track of node context
89
     // if it doesn't already exist
90
     if (!stackCreated) {
91
       nodeStack = new Stack();
92 471 bojilova
       nodeIndex = new Vector();
93 185 jones
       stackCreated = true;
94
     }
95 17 jones
   }
96 1359 tao
97
  /** Construct an instance of the handler class
98 203 jones
    *
99
    * @param conn the JDBC connection to which information is written
100 425 bojilova
    * @param action - "INSERT" or "UPDATE"
101
    * @param docid to be inserted or updated into JDBC connection
102 680 bojilova
    * @param user the user connected to MetaCat servlet and owns the document
103 802 bojilova
    * @param groups the groups to which user belongs
104 680 bojilova
    * @param pub flag for public "read" access on document
105
    * @param serverCode the serverid from xml_replication on which this document
106
    *        resides.
107
    *
108 203 jones
    */
109 1359 tao
   public DBSAXHandler(DBConnection conn, String action, String docid,
110 955 tao
                      String user, String[] groups, String pub, int serverCode)
111 425 bojilova
   {
112 203 jones
     this(conn);
113
     this.action = action;
114
     this.docid = docid;
115 425 bojilova
     this.user = user;
116 802 bojilova
     this.groups = groups;
117 680 bojilova
     this.pub = pub;
118
     this.serverCode = serverCode;
119 471 bojilova
     this.xmlIndex = new Thread(this);
120 1359 tao
   }
121
122 955 tao
  /** Construct an instance of the handler class
123
    * In this constructor, user can specify the version need to upadate
124
    *
125
    * @param conn the JDBC connection to which information is written
126
    * @param action - "INSERT" or "UPDATE"
127
    * @param docid to be inserted or updated into JDBC connection
128
    * @param revision, the user specified the revision need to be update
129
    * @param user the user connected to MetaCat servlet and owns the document
130
    * @param groups the groups to which user belongs
131
    * @param pub flag for public "read" access on document
132
    * @param serverCode the serverid from xml_replication on which this document
133
    *        resides.
134
    *
135
    */
136 1359 tao
   public DBSAXHandler(DBConnection conn, String action, String docid,
137 955 tao
     String revision, String user, String[] groups, String pub, int serverCode)
138
   {
139
     this(conn);
140
     this.action = action;
141
     this.docid = docid;
142
     this.revision = revision;
143
     this.user = user;
144
     this.groups = groups;
145
     this.pub = pub;
146
     this.serverCode = serverCode;
147
     this.xmlIndex = new Thread(this);
148 203 jones
   }
149 1359 tao
150 72 bojilova
   /** SAX Handler that receives notification of beginning of the document */
151 122 jones
   public void startDocument() throws SAXException {
152 1062 tao
     MetaCatUtil.debugMessage("start Document", 50);
153 203 jones
154 185 jones
     // Create the document node representation as root
155 1217 tao
     rootNode = new DBSAXNode(connection, this.docid);
156 1359 tao
     // Add the node to the stack, so that any text data can be
157 185 jones
     // added as it is encountered
158
     nodeStack.push(rootNode);
159 72 bojilova
   }
160
161
   /** SAX Handler that receives notification of end of the document */
162 122 jones
   public void endDocument() throws SAXException {
163 1062 tao
     MetaCatUtil.debugMessage("end Document", 50);
164 471 bojilova
     // Starting new thread for writing XML Index.
165
     // It calls the run method of the thread.
166
     try {
167
       xmlIndex.start();
168
     } catch (NullPointerException e) {
169
       xmlIndex = null;
170 1359 tao
       throw new
171 471 bojilova
       SAXException("Problem with starting thread for writing XML Index. " +
172
                    e.getMessage());
173
     }
174 72 bojilova
   }
175
176 821 bojilova
   /** SAX Handler that is called at the start of Namespace */
177 1359 tao
   public void startPrefixMapping(String prefix, String uri)
178 821 bojilova
                                          throws SAXException
179
   {
180 1062 tao
    MetaCatUtil.debugMessage("NAMESPACE", 50);
181 821 bojilova
182
    namespaces.put(prefix, uri);
183
   }
184 1359 tao
185 185 jones
   /** SAX Handler that is called at the start of each XML element */
186
   public void startElement(String uri, String localName,
187 1359 tao
                            String qName, Attributes atts)
188 185 jones
               throws SAXException {
189 1389 tao
     // for element <eml:eml...> qname is "eml:eml", local name is "eml"
190
     // for element <acl....> both qname and local name is "eml"
191
     // uri is namesapce
192
     MetaCatUtil.debugMessage("Start ELEMENT(qName) " + qName, 50);
193
     MetaCatUtil.debugMessage("Start ELEMENT(localName) " + localName, 50);
194
     MetaCatUtil.debugMessage("Start ELEMENT(uri) " + uri, 50);
195
196
197 203 jones
     DBSAXNode parentNode = null;
198
     DBSAXNode currentNode = null;
199 17 jones
200 203 jones
     // Get a reference to the parent node for the id
201
     try {
202
       parentNode = (DBSAXNode)nodeStack.peek();
203
     } catch (EmptyStackException e) {
204 408 jones
       parentNode = null;
205 203 jones
     }
206 18 jones
207 203 jones
     // Document representation that points to the root document node
208 1389 tao
     if (atFirstElement)
209
     {
210 204 jones
       atFirstElement = false;
211 1389 tao
       // If no DOCTYPE declaration: docname = root element
212
       // doctype = root element name or name space
213
       if (docname == null)
214
       {
215 203 jones
         docname = localName;
216 1389 tao
         // if uri isn't null doctype = uri(namespace)
217
         // othewise root element
218
         if (uri != null && !(uri.trim()).equals(""))
219
         {
220
           doctype = uri;
221
         }
222
         else
223
         {
224
           doctype = docname;
225
         }
226
         MetaCatUtil.debugMessage("DOCNAME-a: " + docname, 30);
227
         MetaCatUtil.debugMessage("DOCTYPE-a: " + doctype, 30);
228
       }
229
       else if (doctype == null)
230
       {
231
         // because docname is not null and it is declared in dtd
232
         // so could not be in schema, no namespace
233 204 jones
         doctype = docname;
234 1389 tao
         MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
235 203 jones
       }
236
       rootNode.writeNodename(docname);
237
       try {
238 697 bojilova
         // for validated XML Documents store a reference to XML DB Catalog
239 1217 tao
         // Because this is select statement and it needn't to roll back if
240
         // insert document action fialed.
241 1359 tao
         // In order to decrease DBConnection usage count, we get a new
242 1217 tao
         // dbconnection from pool
243 697 bojilova
         String catalogid = null;
244 1217 tao
         DBConnection dbConn = null;
245
         int serialNumber = -1;
246 1359 tao
247 697 bojilova
         if ( systemid != null ) {
248 1217 tao
           try
249
           {
250
            // Get dbconnection
251
            dbConn=DBConnectionPool.getDBConnection
252
                                          ("DBSAXHandler.startElement");
253
            serialNumber=dbConn.getCheckOutSerialNumber();
254 1359 tao
255 1217 tao
            Statement stmt = dbConn.createStatement();
256
            ResultSet rs = stmt.executeQuery(
257 697 bojilova
                          "SELECT catalog_id FROM xml_catalog " +
258 1359 tao
                          "WHERE entry_type = 'DTD' " +
259 697 bojilova
                          "AND public_id = '" + doctype + "'");
260 1217 tao
            boolean hasRow = rs.next();
261
            if ( hasRow ) {
262
              catalogid = rs.getString(1);
263
            }
264
            stmt.close();
265
           }//try
266
           finally
267
           {
268
             // Return dbconnection
269
             DBConnectionPool.returnDBConnection(dbConn, serialNumber);
270
           }//finally
271 697 bojilova
         }
272 1359 tao
273 955 tao
         //create documentImpl object by the constructor which can specify
274
         //the revision
275 1359 tao
         currentDocument = new DocumentImpl(connection, rootNode.getNodeID(),
276
                               docname, doctype, docid, revision, action, user,
277 697 bojilova
                               this.pub, catalogid, this.serverCode);
278 1359 tao
279
280 457 bojilova
       } catch (Exception ane) {
281 1359 tao
         throw (new SAXException("Error in DBSaxHandler.startElement " +
282 675 berkley
                                 action, ane));
283 408 jones
       }
284 1359 tao
     }
285 135 jones
286 203 jones
     // Create the current node representation
287 1217 tao
     currentNode = new DBSAXNode(connection, qName, localName, parentNode,
288 457 bojilova
                                 currentDocument.getRootNodeID(),docid,
289
                                 currentDocument.getDoctype());
290 1359 tao
291 821 bojilova
     // Add all of the namespaces
292
     String prefix;
293
     String nsuri;
294
     Enumeration prefixes = namespaces.keys();
295
     while ( prefixes.hasMoreElements() ) {
296
       prefix = (String)prefixes.nextElement();
297
       nsuri = (String)namespaces.get(prefix);
298
       currentNode.setNamespace(prefix, nsuri, docid);
299
     }
300
     namespaces = null;
301
     namespaces = new Hashtable();
302
303 203 jones
     // Add all of the attributes
304
     for (int i=0; i<atts.getLength(); i++) {
305 821 bojilova
       currentNode.setAttribute(atts.getQName(i), atts.getValue(i), docid);
306 1359 tao
     }
307 17 jones
308 1359 tao
     // Add the node to the stack, so that any text data can be
309 203 jones
     // added as it is encountered
310
     nodeStack.push(currentNode);
311 471 bojilova
     // Add the node to the vector used by thread for writing XML Index
312
     nodeIndex.addElement(currentNode);
313
314 203 jones
  }
315 1359 tao
316 819 bojilova
  /* The run method of xmlIndex thread. It writes XML Index for the document. */
317 471 bojilova
  public void run () {
318
    DBSAXNode currNode = null;
319
    DBSAXNode prevNode = null;
320 1217 tao
    DBConnection dbConn = null;
321
    int serialNumber = -1;
322 638 bojilova
    String doctype = currentDocument.getDoctype();
323 471 bojilova
    int step = 0;
324
    int counter = 0;
325 17 jones
326 471 bojilova
    try {
327 1359 tao
328 471 bojilova
      // Opening separate db connection for writing XML Index
329 1217 tao
      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.run");
330
      serialNumber=dbConn.getCheckOutSerialNumber();
331
      dbConn.setAutoCommit(false);
332 1359 tao
333 899 berkley
      //the following while loop construct checks to make sure that the docid
334
      //of the document that we are trying to index is already
335
      //in the xml_documents table.  if this is not the case, the foreign
336
      //key relationship between xml_documents and xml_index is temporarily
337
      //broken causing multiple problems.
338
      boolean inxmldoc = false;
339
      while(!inxmldoc)
340
      {
341
        String xmlDocumentsCheck = "select distinct docid from xml_documents";
342 1359 tao
        PreparedStatement xmlDocCheck =
343 1217 tao
                                 dbConn.prepareStatement(xmlDocumentsCheck);
344
        // Increase usage count
345
        dbConn.increaseUsageCount(1);
346 899 berkley
        xmlDocCheck.execute();
347
        ResultSet doccheckRS = xmlDocCheck.getResultSet();
348
        boolean tableHasRows = doccheckRS.next();
349
        Vector docids = new Vector();
350 1359 tao
        while(tableHasRows)
351 899 berkley
        {
352
          docids.add(doccheckRS.getString(1).trim());
353
          tableHasRows = doccheckRS.next();
354
        }
355 1359 tao
356 899 berkley
        for(int i=0; i<docids.size(); i++)
357
        {
358
          String d = ((String)docids.elementAt(i)).trim();
359
          if(docid.trim().equals(d))
360
          {
361
            inxmldoc = true;
362
          }
363
        }
364
        xmlDocCheck.close();
365
      }
366 1359 tao
367 471 bojilova
      // Going through the elements of the document and writing its Index
368
      Enumeration nodes = nodeIndex.elements();
369
      while ( nodes.hasMoreElements() ) {
370
        currNode = (DBSAXNode)nodes.nextElement();
371 1217 tao
        currNode.updateNodeIndex(dbConn, docid, doctype);
372 471 bojilova
      }
373 1359 tao
374
375 1217 tao
      dbConn.commit();
376 1359 tao
377 819 bojilova
      //if this is a package file
378 1217 tao
      String packagedoctype = MetaCatUtil.getOption("packagedoctype");
379 887 berkley
      Vector packagedoctypes = new Vector();
380 1359 tao
381 887 berkley
      packagedoctypes = MetaCatUtil.getOptionList(packagedoctype);
382 1359 tao
383 887 berkley
      if ( packagedoctypes.contains(doctype) )
384 638 bojilova
      {
385 819 bojilova
        // write the package info to xml_relation table
386 1217 tao
        RelationHandler rth = new RelationHandler(docid, dbConn);
387 819 bojilova
        // from the relations get the access file id for that package
388
        String aclid = rth.getAccessFileID(docid);
389
        // if there are access file, write ACL for that package
390
        if ( aclid != null ) {
391 1217 tao
          runAccessControlList(dbConn, aclid);
392 645 bojilova
        }
393 1359 tao
394 638 bojilova
      }
395 1359 tao
396 819 bojilova
      // if it is an access file
397 887 berkley
      else if ( MetaCatUtil.getOptionList(
398 1217 tao
                     MetaCatUtil.getOption("accessdoctype")).contains(doctype) )
399 819 bojilova
      {
400
        // write ACL for the package
401 1329 tao
        //runAccessControlList(dbConn, docid);
402 1359 tao
403 819 bojilova
      }
404 1359 tao
405
406 1217 tao
      //dbconn.close();
407 483 berkley
408 471 bojilova
    } catch (Exception e) {
409
      try {
410 1217 tao
        dbConn.rollback();
411
        //dbconn.close();
412 471 bojilova
      } catch (SQLException sqle) {}
413 819 bojilova
      System.out.println("Error in DBSAXHandler.run " + e.getMessage());
414
      e.printStackTrace();
415 1217 tao
    }
416
    finally
417
    {
418
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
419 1359 tao
    }//finally
420 471 bojilova
  }
421 1359 tao
422 819 bojilova
  // It runs in xmlIndex thread. It writes ACL for a package.
423 1217 tao
  private void runAccessControlList (DBConnection conn, String aclid)
424 819 bojilova
                                                throws Exception
425
  {
426
    // read the access file from xml_nodes
427
    // parse the access file and store the access info into xml_access
428 1359 tao
    AccessControlList aclobj =
429 819 bojilova
    new AccessControlList(conn, aclid, //new StringReader(xml),
430
                          user, groups, serverCode);
431
    conn.commit();
432
  }
433 471 bojilova
434 819 bojilova
435 460 bojilova
  /** SAX Handler that is called for each XML text node */
436
  public void characters(char[] cbuf, int start, int len) throws SAXException {
437 1062 tao
     MetaCatUtil.debugMessage("CHARACTERS", 50);
438 186 jones
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
439 220 jones
     String data = null;
440
     int leftover = len;
441
     int offset = start;
442
     boolean moredata = true;
443 1359 tao
444
     // This loop deals with the case where there are more characters
445
     // than can fit in a single database text field (limit is
446 220 jones
     // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
447
     // write a series of nodes that are MAXDATACHARS long, and then the
448
     // final node contains the remainder
449
     while (moredata) {
450
       if (leftover > MAXDATACHARS) {
451
         data = new String(cbuf, offset, MAXDATACHARS);
452
         leftover -= MAXDATACHARS;
453
         offset += MAXDATACHARS;
454
       } else {
455
         data = new String(cbuf, offset, leftover);
456
         moredata = false;
457
       }
458 122 jones
459 220 jones
       // Write the content of the node to the database
460 457 bojilova
       currentNode.writeChildNodeToDB("TEXT", null, data, docid);
461 220 jones
     }
462 17 jones
   }
463
464 1359 tao
   /**
465 660 bojilova
    * SAX Handler that is called for each XML text node that is
466
    * Ignorable white space
467 31 jones
    */
468 660 bojilova
   public void ignorableWhitespace(char[] cbuf, int start, int len)
469
               throws SAXException {
470
     // When validation is turned "on", white spaces are reported here
471
     // When validation is turned "off" white spaces are not reported here,
472
     // but through characters() callback
473 1062 tao
     MetaCatUtil.debugMessage("IGNORABLEWHITESPACE", 50);
474 660 bojilova
475 1359 tao
476 660 bojilova
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
477
     String data = null;
478
     int leftover = len;
479
     int offset = start;
480
     boolean moredata = true;
481 1359 tao
482
     // This loop deals with the case where there are more characters
483
     // than can fit in a single database text field (limit is
484 660 bojilova
     // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
485
     // write a series of nodes that are MAXDATACHARS long, and then the
486
     // final node contains the remainder
487
     while (moredata) {
488
       if (leftover > MAXDATACHARS) {
489
         data = new String(cbuf, offset, MAXDATACHARS);
490
         leftover -= MAXDATACHARS;
491
         offset += MAXDATACHARS;
492
       } else {
493
         data = new String(cbuf, offset, leftover);
494
         moredata = false;
495
       }
496
497
       // Write the content of the node to the database
498
       currentNode.writeChildNodeToDB("TEXT", null, data, docid);
499
     }
500 17 jones
   }
501
502 1359 tao
   /**
503
    * SAX Handler called once for each processing instruction found:
504 122 jones
    * node that PI may occur before or after the root element.
505
    */
506 1359 tao
   public void processingInstruction(String target, String data)
507 122 jones
          throws SAXException {
508 1062 tao
     MetaCatUtil.debugMessage("PI", 50);
509 186 jones
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
510 457 bojilova
     currentNode.writeChildNodeToDB("PI", target, data, docid);
511 92 bojilova
   }
512 72 bojilova
513 31 jones
   /** SAX Handler that is called at the end of each XML element */
514 185 jones
   public void endElement(String uri, String localName,
515
                          String qName) throws SAXException {
516 1062 tao
     MetaCatUtil.debugMessage("End ELEMENT " + qName, 50);
517 17 jones
518 185 jones
     // Get the node from the stack
519
     DBSAXNode currentNode = (DBSAXNode)nodeStack.pop();
520 17 jones
   }
521
522 185 jones
   //
523
   // the next section implements the LexicalHandler interface
524
   //
525
526
   /** SAX Handler that receives notification of DOCTYPE. Sets the DTD */
527 1359 tao
   public void startDTD(String name, String publicId, String systemId)
528 185 jones
               throws SAXException {
529
     docname = name;
530
     doctype = publicId;
531
     systemid = systemId;
532
533 1359 tao
     processingDTD = true;
534
535 1062 tao
     MetaCatUtil.debugMessage("Start DTD", 50);
536 1359 tao
     MetaCatUtil.debugMessage("Setting processingDTD to true", 50);
537 1062 tao
     MetaCatUtil.debugMessage("DOCNAME: " + docname, 50);
538
     MetaCatUtil.debugMessage("DOCTYPE: " + doctype, 50);
539
     MetaCatUtil.debugMessage("  SYSID: " + systemid, 50);
540 185 jones
   }
541
542 1359 tao
   /**
543
    * SAX Handler that receives notification of end of DTD
544 185 jones
    */
545
   public void endDTD() throws SAXException {
546 1359 tao
547 1364 tao
     processingDTD = false;
548 1359 tao
     MetaCatUtil.debugMessage("Setting processingDTD to false", 50);
549 1062 tao
     MetaCatUtil.debugMessage("end DTD", 50);
550 185 jones
   }
551
552 1359 tao
   /**
553 185 jones
    * SAX Handler that receives notification of comments in the DTD
554
    */
555
   public void comment(char[] ch, int start, int length) throws SAXException {
556 1062 tao
     MetaCatUtil.debugMessage("COMMENT", 50);
557 660 bojilova
     if ( !processingDTD ) {
558
       DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
559
       currentNode.writeChildNodeToDB("COMMENT", null, new String(ch), docid);
560
     }
561 185 jones
   }
562
563 1359 tao
   /**
564 185 jones
    * SAX Handler that receives notification of the start of CDATA sections
565
    */
566
   public void startCDATA() throws SAXException {
567 1062 tao
     MetaCatUtil.debugMessage("start CDATA", 50);
568 185 jones
   }
569
570 1359 tao
   /**
571 185 jones
    * SAX Handler that receives notification of the end of CDATA sections
572
    */
573
   public void endCDATA() throws SAXException {
574 1062 tao
     MetaCatUtil.debugMessage("end CDATA", 50);
575 185 jones
   }
576
577 1359 tao
   /**
578 185 jones
    * SAX Handler that receives notification of the start of entities
579
    */
580
   public void startEntity(String name) throws SAXException {
581 1062 tao
     MetaCatUtil.debugMessage("start ENTITY: " + name, 50);
582 697 bojilova
//System.out.println("start ENTITY: " + name);
583 243 jones
     if (name.equals("[dtd]")) {
584
       processingDTD = true;
585
     }
586 185 jones
   }
587
588 1359 tao
   /**
589 185 jones
    * SAX Handler that receives notification of the end of entities
590
    */
591
   public void endEntity(String name) throws SAXException {
592 1062 tao
     MetaCatUtil.debugMessage("end ENTITY: " + name, 50);
593 697 bojilova
//System.out.println("end ENTITY: " + name);
594 243 jones
     if (name.equals("[dtd]")) {
595
       processingDTD = false;
596
     }
597 185 jones
   }
598 186 jones
599 1359 tao
   /**
600 186 jones
    * SAX Handler that receives notification of element declarations
601
    */
602
   public void elementDecl(String name, String model)
603
                        throws org.xml.sax.SAXException {
604 697 bojilova
//System.out.println("ELEMENTDECL: " + name + " " + model);
605 1062 tao
     MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model, 50);
606 186 jones
   }
607
608 1359 tao
   /**
609 186 jones
    * SAX Handler that receives notification of attribute declarations
610
    */
611
   public void attributeDecl(String eName, String aName,
612
                        String type, String valueDefault, String value)
613
                        throws org.xml.sax.SAXException {
614 821 bojilova
615 1359 tao
//System.out.println("ATTRIBUTEDECL: " + eName + " "
616 697 bojilova
//                        + aName + " " + type + " " + valueDefault + " "
617
//                        + value);
618 1359 tao
     MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " "
619 243 jones
                        + aName + " " + type + " " + valueDefault + " "
620 1062 tao
                        + value, 50);
621 186 jones
   }
622
623 1359 tao
   /**
624 186 jones
    * SAX Handler that receives notification of internal entity declarations
625
    */
626
   public void internalEntityDecl(String name, String value)
627
                        throws org.xml.sax.SAXException {
628 697 bojilova
//System.out.println("INTERNENTITYDECL: " + name + " " + value);
629 1062 tao
     MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value, 50);
630 186 jones
   }
631
632 1359 tao
   /**
633 186 jones
    * SAX Handler that receives notification of external entity declarations
634
    */
635
   public void externalEntityDecl(String name, String publicId,
636
                        String systemId)
637
                        throws org.xml.sax.SAXException {
638 1359 tao
//System.out.println("EXTERNENTITYDECL: " + name + " " + publicId
639 697 bojilova
//                              + " " + systemId);
640 1359 tao
     MetaCatUtil.debugMessage("EXTERNENTITYDECL: " + name + " " + publicId
641 1062 tao
                              + " " + systemId, 50);
642 831 bojilova
     // it processes other external entity, not the DTD;
643
     // it doesn't signal for the DTD here
644
     processingDTD = false;
645 186 jones
   }
646
647 204 jones
   //
648
   // the next section implements the ErrorHandler interface
649
   //
650 186 jones
651 1359 tao
   /**
652 204 jones
    * SAX Handler that receives notification of fatal parsing errors
653
    */
654
   public void fatalError(SAXParseException exception) throws SAXException {
655 1062 tao
     MetaCatUtil.debugMessage("FATALERROR", 50);
656 204 jones
     throw (new SAXException("Fatal processing error.", exception));
657
   }
658
659 1359 tao
   /**
660 204 jones
    * SAX Handler that receives notification of recoverable parsing errors
661
    */
662
   public void error(SAXParseException exception) throws SAXException {
663 1062 tao
     MetaCatUtil.debugMessage("ERROR", 50);
664 660 bojilova
     throw (new SAXException("Processing error.", exception));
665 204 jones
   }
666
667 1359 tao
   /**
668 204 jones
    * SAX Handler that receives notification of warnings
669
    */
670
   public void warning(SAXParseException exception) throws SAXException {
671 1062 tao
     MetaCatUtil.debugMessage("WARNING", 50);
672 660 bojilova
     throw (new SAXException("Warning.", exception));
673 204 jones
   }
674
675 1359 tao
   //
676 204 jones
   // Helper, getter and setter methods
677
   //
678 1359 tao
679 204 jones
   /**
680
    * get the document name
681
    */
682
   public String getDocname() {
683
     return docname;
684
   }
685
686
   /**
687
    * get the document processing state
688
    */
689 243 jones
   public boolean processingDTD() {
690
     return processingDTD;
691 204 jones
   }
692 17 jones
}