Project

General

Profile

« Previous | Next » 

Revision 86

Added by Matt Jones over 24 years ago

added XSL formatting to document display for metacat servlet

View differences:

DBReader.java
92 92
  }
93 93
  
94 94
  /**
95
   * Get the root node id for an XML document given a document id
96
   *
97
   * @param docid the document node contains the root of the document
98
   * @returns long the nodeid of the root node for this document
99
   */
100
  public long getRootNode(long docid) {
101
    // Now look up the root node id
102
    long rootnodeid = 0;
103

  
104
    try {
105
      PreparedStatement pstmt =
106
        conn.prepareStatement("SELECT rootnodeid " +
107
                "FROM xml_documents " +
108
                "WHERE docid = ?");
109
      // Bind the values to the query
110
      pstmt.setLong(1, docid);
111

  
112
      pstmt.execute();
113
      try {
114
        ResultSet rs = pstmt.getResultSet();
115
        try {
116
          boolean tableHasRows = rs.next();
117
          if (tableHasRows) {
118
            try {
119
              rootnodeid = rs.getLong(1);
120

  
121
            } catch (SQLException e) {
122
              System.out.println("Error with getLong: " + e.getMessage());
123
            }
124
          }
125
        } catch (SQLException e) {
126
          System.out.println("Error with next: " + e.getMessage());
127
        }
128
      } catch (SQLException e) {
129
        System.out.println("Error with getrset: " + e.getMessage());
130
      }
131
      pstmt.close();
132
    } catch (SQLException e) {
133
      System.out.println("Error getting id: " + e.getMessage());
134
    }
135

  
136
    return rootnodeid;
137
  }
138

  
139
  /**
95 140
   * Create an XML document from the database starting with the element 
96 141
   * having element_id nodeid
97 142
   *
98
   * @param nodeid the node that will represent the root of the document
143
   * @param docid the document that we want retrieved
99 144
   */
100
  public String readXMLDocument(long nodeid) {
145
  public String readXMLDocument(long docid) {
101 146
    StringBuffer doc = new StringBuffer();
102 147

  
103
    ReaderElement element = new ReaderElement(conn, nodeid);
148
    ReaderElement element = new ReaderElement(conn, getRootNode(docid));
104 149
    doc.append("<?xml version=\"1.0\"?>\n");
105 150
    doc.append(element.toString());
106 151

  

Also available in: Unified diff