Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements org.xml.sax.DTDHandler interface
4
 *             for resolving external entities
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Jivka Bojilova
8
 *
9
 *   '$Author: jones $'
10
 *     '$Date: 2000-06-26 03:35:05 -0700 (Mon, 26 Jun 2000) $'
11
 * '$Revision: 203 $'
12
 */
13

    
14
package edu.ucsb.nceas.metacat;
15

    
16
import org.xml.sax.*;
17

    
18
import java.sql.*;
19
import java.net.URL;
20
import java.net.MalformedURLException;
21
import java.util.Stack;
22
import java.util.EmptyStackException;
23

    
24
/** 
25
 * A database aware Class implementing DTDHandler interface for the SAX 
26
 * parser to call when processing the XML stream and intercepting notations 
27
 * and unparsed entities
28
 */
29
public class DBDTDHandler implements DTDHandler
30
{
31
   private Connection	conn = null;
32

    
33
   /** Construct an instance of the DBDTDHandler clas
34
    *
35
    * @param conn the JDBC connection to which information is written
36
    */
37
   public DBDTDHandler(Connection conn)
38
   {
39
      this.conn = conn;
40
   }
41
   
42
   /** Notation declarations are not signaled */
43
   public void notationDecl(String name, String publicId, String systemId)
44
            throws SAXException
45
   {
46
    System.out.println("from DBDTDHandler.notationDecl");
47
    System.out.print(name);
48
    System.out.print(publicId);
49
    System.out.print(systemId);
50
    return;
51
   }
52
   
53
   /** All are reported after startDocument and before first 
54
    * startElement event
55
    */
56
   public void unparsedEntityDecl(String name, String publicId, 
57
                                  String systemId, String notationName)
58
            throws SAXException
59
   {
60
    System.out.println("from DBDTDHandler.unparsedEntityDecl");
61
    System.out.print(name);
62
    System.out.print(publicId);
63
    System.out.print(systemId);
64
    System.out.println(notationName);
65
    String doctype = DBEntityResolver.doctype;
66
    //if ( getEntitySystemID(conn, doctype, publicId) == "" ) 
67
    //    registerEntityPublicID(conn, doctype, publicId, systemId);
68
    return;
69
   }
70

    
71
   /** 
72
    * Look at db XML Catalog to get System ID (if any) for that Public ID 
73
    * and doctype.
74
    * Return empty string if there are not 
75
    */
76
/*
77
   private String getEntitySystemID (Connection conn, String doctype, 
78
                                     String publicId)
79
   {
80
        String system_id = "";
81
        Statement stmt;
82
        try {
83
          stmt = conn.createStatement();
84
          stmt.execute("SELECT system_id FROM xml_catalog " + 
85
                       "WHERE entry_type = 'ENTITY' AND source_doctype = '" + 
86
                        doctype + "' AND public_id = '" + publicId + "'");
87
          try {
88
            ResultSet rs = stmt.getResultSet();
89
            try {
90
              boolean tableHasRows = rs.next();
91
              if (tableHasRows) {
92
                try {
93
                  system_id = rs.getString(1);
94
                } catch (SQLException e) {
95
                  System.out.println("DBDTDHandler.getEntitySystemID() " +
96
                         "- Error with getString: " + e.getMessage());
97
                }
98
              }
99
            } catch (SQLException e) {
100
              System.out.println("DBDTDHandler.getEntitySystemID() " +
101
                         "- Error with next: " + e.getMessage());
102
            }
103
          } catch (SQLException e) {
104
            System.out.println("DBDTDHandler.getEntitySystemID() " +
105
                         "- Error with getrset: " + e.getMessage());
106
          }
107
          stmt.close();
108
        } catch (SQLException e) {
109
          System.out.println("DBDTDHandler.getEntitySystemID() " +
110
                         "- Error getting id: " + e.getMessage());
111
        }
112

    
113
        // return the selected System ID
114
        return system_id;
115
   }
116
*/
117
   /** 
118
    * Register Public ID in db XML Catalog 
119
    */
120
/*
121
   private void registerEntityPublicID (Connection conn, String doctype, 
122
                                        String publicId, String systemId)
123
   {
124
        try {
125
          PreparedStatement pstmt;
126
          pstmt = conn.prepareStatement(
127
                "INSERT INTO xml_catalog (entity_id, entity_name, " +
128
                "entry_type, source_doctype, public_id, system_id) " +
129
                "VALUES (null, null, 'ENTITY', ?, ?, ?)");
130
          // Bind the values to the query
131
          pstmt.setString(1, doctype);
132
          pstmt.setString(2, publicId);
133
          pstmt.setString(3, systemId);
134
          // Do the insertion
135
          pstmt.execute();
136
          pstmt.close();
137
        } catch (SQLException e) {
138
          System.out.println(e.getMessage());
139
        }
140
   }
141
*/
142

    
143
}
144

    
145
/**
146
 * '$Log$
147
 * 'Revision 1.8.2.2  2000/06/25 23:38:16  jones
148
 * 'Added RCSfile keyword
149
 * '
150
 * 'Revision 1.8.2.1  2000/06/25 23:34:17  jones
151
 * 'Changed documentation formatting, added log entries at bottom of source files
152
 * ''
153
 */
(4-4/19)