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 72 bojilova
 *
9 203 jones
 *   '$Author$'
10
 *     '$Date$'
11
 * '$Revision$'
12 72 bojilova
 */
13
14 74 jones
package edu.ucsb.nceas.metacat;
15 72 bojilova
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 122 jones
 * 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 72 bojilova
 */
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 92 bojilova
    System.out.print(name);
48
    System.out.print(publicId);
49
    System.out.print(systemId);
50 72 bojilova
    return;
51
   }
52
53 122 jones
   /** 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 72 bojilova
            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 204 jones
    //String doctype = DBEntityResolver.doctype;
66 92 bojilova
    //if ( getEntitySystemID(conn, doctype, publicId) == "" )
67
    //    registerEntityPublicID(conn, doctype, publicId, systemId);
68 72 bojilova
    return;
69
   }
70
71 122 jones
   /**
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 72 bojilova
   {
80
        String system_id = "";
81
        Statement stmt;
82
        try {
83
          stmt = conn.createStatement();
84 92 bojilova
          stmt.execute("SELECT system_id FROM xml_catalog " +
85 122 jones
                       "WHERE entry_type = 'ENTITY' AND source_doctype = '" +
86
                        doctype + "' AND public_id = '" + publicId + "'");
87 72 bojilova
          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 122 jones
                  System.out.println("DBDTDHandler.getEntitySystemID() " +
96
                         "- Error with getString: " + e.getMessage());
97 72 bojilova
                }
98
              }
99
            } catch (SQLException e) {
100 122 jones
              System.out.println("DBDTDHandler.getEntitySystemID() " +
101
                         "- Error with next: " + e.getMessage());
102 72 bojilova
            }
103
          } catch (SQLException e) {
104 122 jones
            System.out.println("DBDTDHandler.getEntitySystemID() " +
105
                         "- Error with getrset: " + e.getMessage());
106 72 bojilova
          }
107
          stmt.close();
108
        } catch (SQLException e) {
109 122 jones
          System.out.println("DBDTDHandler.getEntitySystemID() " +
110
                         "- Error getting id: " + e.getMessage());
111 72 bojilova
        }
112
113
        // return the selected System ID
114
        return system_id;
115
   }
116 122 jones
*/
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 72 bojilova
   {
124
        try {
125
          PreparedStatement pstmt;
126
          pstmt = conn.prepareStatement(
127 122 jones
                "INSERT INTO xml_catalog (entity_id, entity_name, " +
128
                "entry_type, source_doctype, public_id, system_id) " +
129 72 bojilova
                "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 122 jones
*/
142
143 72 bojilova
}
144 203 jones
145
/**
146
 * '$Log$
147 204 jones
 * 'Revision 1.9  2000/06/26 10:35:04  jones
148
 * 'Merged in substantial changes to DBWriter and associated classes and to
149
 * 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE
150
 * 'functions.  The command line tools and the parameters for the
151
 * 'servlet have changed substantially.
152
 * '
153 203 jones
 * 'Revision 1.8.2.2  2000/06/25 23:38:16  jones
154
 * 'Added RCSfile keyword
155
 * '
156
 * 'Revision 1.8.2.1  2000/06/25 23:34:17  jones
157
 * 'Changed documentation formatting, added log entries at bottom of source files
158
 * ''
159
 */