Project

General

Profile

1 72 bojilova
/**
2 203 jones
 *  '$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 349 jones
 *    Release: @release@
9 72 bojilova
 *
10 203 jones
 *   '$Author$'
11
 *     '$Date$'
12
 * '$Revision$'
13 72 bojilova
 */
14
15 74 jones
package edu.ucsb.nceas.metacat;
16 72 bojilova
17
import org.xml.sax.*;
18
19
import java.sql.*;
20
import java.net.URL;
21
import java.net.MalformedURLException;
22
import java.util.Stack;
23
import java.util.EmptyStackException;
24
25
/**
26 122 jones
 * A database aware Class implementing DTDHandler interface for the SAX
27
 * parser to call when processing the XML stream and intercepting notations
28
 * and unparsed entities
29 72 bojilova
 */
30
public class DBDTDHandler implements DTDHandler
31
{
32
   private Connection	conn = null;
33
34
   /** Construct an instance of the DBDTDHandler clas
35
    *
36
    * @param conn the JDBC connection to which information is written
37
    */
38
   public DBDTDHandler(Connection conn)
39
   {
40
      this.conn = conn;
41
   }
42
43
   /** Notation declarations are not signaled */
44
   public void notationDecl(String name, String publicId, String systemId)
45
            throws SAXException
46
   {
47
    System.out.println("from DBDTDHandler.notationDecl");
48 92 bojilova
    System.out.print(name);
49
    System.out.print(publicId);
50
    System.out.print(systemId);
51 72 bojilova
    return;
52
   }
53
54 122 jones
   /** All are reported after startDocument and before first
55
    * startElement event
56
    */
57
   public void unparsedEntityDecl(String name, String publicId,
58
                                  String systemId, String notationName)
59 72 bojilova
            throws SAXException
60
   {
61
    System.out.println("from DBDTDHandler.unparsedEntityDecl");
62
    System.out.print(name);
63
    System.out.print(publicId);
64
    System.out.print(systemId);
65
    System.out.println(notationName);
66 204 jones
    //String doctype = DBEntityResolver.doctype;
67 92 bojilova
    //if ( getEntitySystemID(conn, doctype, publicId) == "" )
68
    //    registerEntityPublicID(conn, doctype, publicId, systemId);
69 72 bojilova
    return;
70
   }
71
72 122 jones
   /**
73
    * Look at db XML Catalog to get System ID (if any) for that Public ID
74
    * and doctype.
75
    * Return empty string if there are not
76
    */
77
/*
78
   private String getEntitySystemID (Connection conn, String doctype,
79
                                     String publicId)
80 72 bojilova
   {
81
        String system_id = "";
82
        Statement stmt;
83
        try {
84
          stmt = conn.createStatement();
85 92 bojilova
          stmt.execute("SELECT system_id FROM xml_catalog " +
86 122 jones
                       "WHERE entry_type = 'ENTITY' AND source_doctype = '" +
87
                        doctype + "' AND public_id = '" + publicId + "'");
88 72 bojilova
          try {
89
            ResultSet rs = stmt.getResultSet();
90
            try {
91
              boolean tableHasRows = rs.next();
92
              if (tableHasRows) {
93
                try {
94
                  system_id = rs.getString(1);
95
                } catch (SQLException e) {
96 122 jones
                  System.out.println("DBDTDHandler.getEntitySystemID() " +
97
                         "- Error with getString: " + e.getMessage());
98 72 bojilova
                }
99
              }
100
            } catch (SQLException e) {
101 122 jones
              System.out.println("DBDTDHandler.getEntitySystemID() " +
102
                         "- Error with next: " + e.getMessage());
103 72 bojilova
            }
104
          } catch (SQLException e) {
105 122 jones
            System.out.println("DBDTDHandler.getEntitySystemID() " +
106
                         "- Error with getrset: " + e.getMessage());
107 72 bojilova
          }
108
          stmt.close();
109
        } catch (SQLException e) {
110 122 jones
          System.out.println("DBDTDHandler.getEntitySystemID() " +
111
                         "- Error getting id: " + e.getMessage());
112 72 bojilova
        }
113
114
        // return the selected System ID
115
        return system_id;
116
   }
117 122 jones
*/
118
   /**
119
    * Register Public ID in db XML Catalog
120
    */
121
/*
122
   private void registerEntityPublicID (Connection conn, String doctype,
123
                                        String publicId, String systemId)
124 72 bojilova
   {
125
        try {
126
          PreparedStatement pstmt;
127
          pstmt = conn.prepareStatement(
128 122 jones
                "INSERT INTO xml_catalog (entity_id, entity_name, " +
129
                "entry_type, source_doctype, public_id, system_id) " +
130 72 bojilova
                "VALUES (null, null, 'ENTITY', ?, ?, ?)");
131
          // Bind the values to the query
132
          pstmt.setString(1, doctype);
133
          pstmt.setString(2, publicId);
134
          pstmt.setString(3, systemId);
135
          // Do the insertion
136
          pstmt.execute();
137
          pstmt.close();
138
        } catch (SQLException e) {
139
          System.out.println(e.getMessage());
140
        }
141
   }
142 122 jones
*/
143
144 72 bojilova
}
145 203 jones
146
/**
147
 * '$Log$
148 349 jones
 * 'Revision 1.10  2000/06/27 04:31:07  jones
149
 * 'Fixed bugs associated with the new UPDATE and DELETE functions of
150
 * 'DBWriter.  There were problematic interactions between some static
151
 * 'variables used in DBEntityResolver and the way in which the
152
 * 'Servlet objects are re-used across multiple client invocations.
153
 * '
154
 * 'Generally cleaned up error reporting.  Now all errors and success
155
 * 'results are reported as XML documents from MetaCatServlet.  Need
156
 * 'to make the command line tools do the same.
157
 * '
158 204 jones
 * 'Revision 1.9  2000/06/26 10:35:04  jones
159
 * 'Merged in substantial changes to DBWriter and associated classes and to
160
 * 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE
161
 * 'functions.  The command line tools and the parameters for the
162
 * 'servlet have changed substantially.
163
 * '
164 203 jones
 * 'Revision 1.8.2.2  2000/06/25 23:38:16  jones
165
 * 'Added RCSfile keyword
166
 * '
167
 * 'Revision 1.8.2.1  2000/06/25 23:34:17  jones
168
 * 'Changed documentation formatting, added log entries at bottom of source files
169
 * ''
170
 */