Project

General

Profile

« Previous | Next » 

Revision 142

Added by Matt Jones over 24 years ago

reincorporated Title registration code for documents

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
39 39
   private boolean 	stackCreated = false;
40 40
   private Stack 	nodeStack;
41 41
   private Connection	conn = null;
42
   private DBSAXDocument currentDocument;
42 43

  
43 44
   /** Construct an instance of the handler class 
44 45
    *
......
70 71

  
71 72
   /** SAX Handler that receives notification of end of the document */
72 73
   public void endDocument() throws SAXException {
74
    currentDocument.setTitleFromChildElement();
73 75
    if (debug) {
74 76
      System.out.println("end Document");
75 77
    }
......
139 141
        }
140 142
        DBSAXNode documentNode = (DBSAXNode)nodeStack.peek();
141 143
        documentNode.writeNodename(docname);
142
        new DBSAXDocument(conn, documentNode.getNodeID(), docname, doctype);
144
        currentDocument = new DBSAXDocument(conn, documentNode.getNodeID(), 
145
                                            docname, doctype);
143 146
      }      
144 147

  
145 148
      // Create the current node representation
src/edu/ucsb/nceas/metacat/DBSAXDocument.java
20 20
 */
21 21
public class DBSAXDocument {
22 22

  
23
    private Connection		conn;
23
    private Connection      conn;
24 24
    private long            rootnodeid;
25 25
    private String          docname;
26 26
    private String          doctype;
27
    private String          doctitle;
28
    private long            docid;
27 29

  
28 30
    /** 
29 31
     * Construct a new document instance
......
65 67
          // Do the insertion
66 68
          pstmt.execute();
67 69
          pstmt.close();
70

  
71
          long assigned_id=0;
72
          Statement stmt;
73
          stmt = conn.createStatement();
74
          stmt.execute("SELECT xml_documents_id_seq.currval FROM dual");
75
          ResultSet rs = stmt.getResultSet();
76
          boolean tableHasRows = rs.next();
77
          if (tableHasRows) {
78
            assigned_id = rs.getLong(1);
79
            this.docid = assigned_id;
80
          }
81
          stmt.close();
82

  
68 83
          conn.commit();
69 84
          conn.setAutoCommit(true);
70 85
        } catch (SQLException e) {
......
72 87
        }
73 88
    }
74 89

  
90
    /**
91
     * Get the document title
92
     */
93
    public String getTitle() {
94
      return doctitle;
95
    }
96

  
97
    /**
98
     * Set the document title
99
     *
100
     * @param title the new title for the document
101
     */
102
    public void setTitle( String title ) {
103
      this.doctitle = title;
104
      try {
105
        PreparedStatement pstmt;
106
        pstmt = conn.prepareStatement(
107
              "UPDATE xml_documents " +
108
              " SET doctitle = ? " +
109
              "WHERE docid = ?");
110

  
111
        // Bind the values to the query
112
        pstmt.setString(1, doctitle);
113
        pstmt.setLong(2, docid);
114

  
115
        // Do the insertion
116
        pstmt.execute();
117
        pstmt.close();
118
      } catch (SQLException e) {
119
        System.out.println(e.getMessage());
120
      }
121
    }
122

  
123
    /**
124
     * Look up the title of the first child element named "title"
125
     * and record it as the document title
126
     */
127
    public void setTitleFromChildElement() {
128
        String title = null;
129
        long assigned_id=0;
130
        PreparedStatement pstmt;
131
        try {
132
          pstmt = conn.prepareStatement(
133
                  "SELECT nodedata FROM xml_nodes " +
134
                  "WHERE nodetype = 'TEXT' " +
135
                  "AND parentnodeid IN " +
136
                  "(SELECT nodeid FROM xml_nodes " +
137
                  "WHERE nodename = 'title' " +
138
                  "START WITH nodeid = ? " +
139
                  "CONNECT BY PRIOR nodeid = parentnodeid)");
140
/*
141
                    "SELECT nodeid " +
142
                    "FROM xml_nodes " +
143
                    "START WITH nodeid = ? " +
144
                    "CONNECT BY PRIOR nodeid = parentnodeid " +
145
                    "AND PRIOR nodename = 'title' " );
146

  
147
          pstmt = conn.prepareStatement("SELECT nodedata " +
148
                    "FROM xml_nodes " +
149
                    "WHERE nodetype = 'TEXT' " +
150
                    "  AND nodeid in " +
151
                    "(SELECT nodeid FROM xml_nodes " +
152
                    "  WHERE nodename = 'title' " +
153
                    "  START WITH nodeid = ? " +
154
                    "  CONNECT BY PRIOR nodeid = parentnodeid ");
155
*/
156

  
157
          // Bind the values to the query
158
          pstmt.setLong(1, rootnodeid);
159

  
160
          pstmt.execute();
161
          ResultSet rs = pstmt.getResultSet();
162
          boolean tableHasRows = rs.next();
163
          if (tableHasRows) {
164
            title = rs.getString(1);
165
          }
166
          pstmt.close();
167
        } catch (SQLException e) {
168
          System.out.println("Error getting id: " + e.getMessage());
169
        }
170

  
171
        // assign the new title
172
        this.setTitle(title);
173
    }
75 174
}
src/edu/ucsb/nceas/metacat/DBEntityResolver.java
58 58
     
59 59
     if (publicId != null) {
60 60
        pIdCounter += 1;
61
/*
61 62
        System.out.println("from DBEntityResolver: current element is " + 
62 63
                           DBSAXHandler.elementNo);
63 64
        System.out.println("from DBEntityResolver: " + pIdCounter + " " + 
64 65
                           publicId);
66
*/
65 67
        // look at the db XML Catalog and get dbSystemId by this publicId
66 68
        if (currentElementNo == 0) {
67 69
            doctype = publicId;

Also available in: Unified diff