Project

General

Profile

« Previous | Next » 

Revision 132

Added by Matt Jones about 24 years ago

improved error handling when docid not found

View differences:

src/edu/ucsb/nceas/metacat/ElementNode.java
65 65
      setTagName(nodename);
66 66
      setNodeType(nodetype);
67 67

  
68
      
68 69
      // Create child nodes (elements or attributes)
69 70
      setChildrenNodes(nodeid);
70 71
    }
......
105 106
              } catch (SQLException e) {
106 107
                System.out.println("Error with getInt: " + e.getMessage());
107 108
              }
109
            } else {
110
              System.err.println("Error: no rows for nodeid: " + nodeid);
108 111
            }
109 112
          } catch (SQLException e) {
110 113
            System.out.println("Error with next: " + e.getMessage());
......
120 123
      // Record our node type
121 124
      setNodeType(nodetype);
122 125

  
126
      try {
123 127
      if (nodetype.equals("ELEMENT") || nodetype.equals("DOCUMENT") ) {
124 128
        setElementID(element_id);
125 129
        setParentID(parentnodeid);
126 130
        setTagName(nodename);
127 131
      }
132
      } catch (NullPointerException npe) {
133
        System.err.println("Error with nodetype: " + 
134
                           nodetype + npe.getMessage());
135
        System.err.println("Nodeid: " + element_id);
136
      } 
128 137
    }
129 138

  
130 139
    /** Look up each child node from the DB and and create it */
src/edu/ucsb/nceas/metacat/DBReader.java
145 145
  public String readXMLDocument(long docid) {
146 146
    StringBuffer doc = new StringBuffer();
147 147
    DoctypeInfo dti = getDoctypeInfo(docid);
148
    String docname = dti.getDocname();
149
    String doctype = dti.getDoctype();
150
    String sysid = dti.getSystemID();
151 148

  
152
    ElementNode element = new ElementNode(conn, getRootNode(docid));
153
    doc.append("<?xml version=\"1.0\"?>\n");
154
    
155
    if (docname != null) {
156
      if ((doctype != null) && (sysid != null)) {
157
        doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
158
                   "\" \"" + sysid + "\">\n");
159
      } else {
160
        doc.append("<!DOCTYPE " + docname + ">\n");
149
    if (dti != null) {
150
      String docname = dti.getDocname();
151
      String doctype = dti.getDoctype();
152
      String sysid = dti.getSystemID();
153
  
154
      ElementNode element = new ElementNode(conn, getRootNode(docid));
155
      doc.append("<?xml version=\"1.0\"?>\n");
156
      
157
      if (docname != null) {
158
        if ((doctype != null) && (sysid != null)) {
159
          doc.append("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
160
                     "\" \"" + sysid + "\">\n");
161
        } else {
162
          doc.append("<!DOCTYPE " + docname + ">\n");
163
        }
161 164
      }
165
      doc.append(element.toString());
166
    } else {
167
      doc.append("<error>Document " + docid + " not found.</error>");
162 168
    }
163
    doc.append(element.toString());
164 169

  
165 170
    return (doc.toString());
166 171
  }
......
194 199
      } 
195 200
      pstmt.close();
196 201

  
197
      pstmt =
198
        conn.prepareStatement("SELECT system_id " +
199
                                "FROM xml_catalog " +
200
                               "WHERE public_id = ?");
201
      // Bind the values to the query
202
      pstmt.setString(1, doctype);
203

  
204
      pstmt.execute();
205
      rs = pstmt.getResultSet();
206
      tableHasRows = rs.next();
207
      if (tableHasRows) {
208
        sysid  = rs.getString(1);
209
      } 
210
      pstmt.close();
202
      if (doctype != null) {
203
        pstmt =
204
          conn.prepareStatement("SELECT system_id " +
205
                                  "FROM xml_catalog " +
206
                                 "WHERE public_id = ?");
207
        // Bind the values to the query
208
        pstmt.setString(1, doctype);
209
  
210
        pstmt.execute();
211
        rs = pstmt.getResultSet();
212
        tableHasRows = rs.next();
213
        if (tableHasRows) {
214
          sysid  = rs.getString(1);
215
        } 
216
        pstmt.close();
217
      }
211 218
    } catch (SQLException e) {
212 219
      System.out.println("Error getting id: " + e.getMessage());
213 220
    }
214 221

  
215
    dti = new DoctypeInfo(docname, doctype, sysid);
222
    if (docname != null) {
223
      dti = new DoctypeInfo(docname, doctype, sysid);
224
    } else {
225
      dti = null;
226
    }
227

  
216 228
    return dti;
217 229
  }
218 230

  

Also available in: Unified diff