Project

General

Profile

« Previous | Next » 

Revision 128

Added by Matt Jones over 24 years ago

continuing work on changing to DOM Text node model

View differences:

src/edu/ucsb/nceas/metacat/ElementNode.java
166 166
                nodedata = rs.getString(5);
167 167

  
168 168
                if ( (nodetype.equals("ELEMENT")) ||
169
                     (nodetype.equals("DOCUMENT")) 
169
                     (nodetype.equals("DOCUMENT"))
170 170
                   ) {
171 171
                  ReaderElement child = new ReaderElement(conn,
172 172
                                element_id,parentnodeid,nodename, nodetype);
173 173
                  addChildNode(child);
174 174
                } else if (nodetype.equals("ATTRIBUTE")) {
175 175
                  setAttribute(nodename,nodedata);
176
                } else if (nodetype.equals("TEXT")) {
177
                  TextNode child = new TextNode(conn,
178
                                element_id,parentnodeid,nodedata,nodetype);
179
                  addChildNode(child);
176 180
                } 
177
                //else if (nodetype.equals("TEXT")) {
178
                  //appendContent(nodedata);
179
                //}
180 181

  
181 182
              } catch (SQLException e) {
182 183
                System.out.println("Error with getInt: " + e.getMessage());
......
202 203
     * String representation for display purposes (recursively descends through
203 204
     * children to create an XML subtree)
204 205
     */
205
    public String toString ()
206
    {
206
    public String toString () {
207

  
207 208
        StringBuffer value = new StringBuffer();
209
        String nodetype = getNodeType();
208 210

  
209
        String nodetype = getNodeType();
210
        String nodename = getTagName();
211
        System.out.println("NODETYPE  ====>  " + nodetype + 
212
                           "(" + nodename +")");
213 211
        if (nodetype.equals("ELEMENT")) {
214 212
          value.append('<');
215 213
          value.append(getTagName());
216 214
          value.append(getAttributes().toString());
217 215
          value.append('>');
218 216
        } 
219
        //else { value.append(getNodeType()); }
220 217

  
221 218
        // Process children recursively here
222
        ReaderElement child = null;
219
        BasicElement child = null;
223 220
        Enumeration e = getChildren();
224 221
        while (e.hasMoreElements()) {
225
          child = (ReaderElement)e.nextElement(); 
226
          try {
227
            value.append(child);
228
          } catch (NullPointerException npe) {
229
value.append("M");
230
          }
222
          child = (BasicElement)e.nextElement(); 
223
          value.append(child);
231 224
        }
232 225

  
233
        //String cont = getContent();
234
        //if (!cont.equals("null")) {
235
          //value.append(cont);
236
        //}
237

  
238 226
        if (nodetype.equals("ELEMENT")) {
239 227
          value.append("</");
240 228
          value.append(getTagName());
241 229
          value.append('>');
242 230
        }
243
        //else { value.append(getNodeType()); }
244 231

  
245 232
        return value.toString();
246 233
    }
src/edu/ucsb/nceas/metacat/ReaderElement.java
166 166
                nodedata = rs.getString(5);
167 167

  
168 168
                if ( (nodetype.equals("ELEMENT")) ||
169
                     (nodetype.equals("DOCUMENT")) 
169
                     (nodetype.equals("DOCUMENT"))
170 170
                   ) {
171 171
                  ReaderElement child = new ReaderElement(conn,
172 172
                                element_id,parentnodeid,nodename, nodetype);
173 173
                  addChildNode(child);
174 174
                } else if (nodetype.equals("ATTRIBUTE")) {
175 175
                  setAttribute(nodename,nodedata);
176
                } else if (nodetype.equals("TEXT")) {
177
                  TextNode child = new TextNode(conn,
178
                                element_id,parentnodeid,nodedata,nodetype);
179
                  addChildNode(child);
176 180
                } 
177
                //else if (nodetype.equals("TEXT")) {
178
                  //appendContent(nodedata);
179
                //}
180 181

  
181 182
              } catch (SQLException e) {
182 183
                System.out.println("Error with getInt: " + e.getMessage());
......
202 203
     * String representation for display purposes (recursively descends through
203 204
     * children to create an XML subtree)
204 205
     */
205
    public String toString ()
206
    {
206
    public String toString () {
207

  
207 208
        StringBuffer value = new StringBuffer();
209
        String nodetype = getNodeType();
208 210

  
209
        String nodetype = getNodeType();
210
        String nodename = getTagName();
211
        System.out.println("NODETYPE  ====>  " + nodetype + 
212
                           "(" + nodename +")");
213 211
        if (nodetype.equals("ELEMENT")) {
214 212
          value.append('<');
215 213
          value.append(getTagName());
216 214
          value.append(getAttributes().toString());
217 215
          value.append('>');
218 216
        } 
219
        //else { value.append(getNodeType()); }
220 217

  
221 218
        // Process children recursively here
222
        ReaderElement child = null;
219
        BasicElement child = null;
223 220
        Enumeration e = getChildren();
224 221
        while (e.hasMoreElements()) {
225
          child = (ReaderElement)e.nextElement(); 
226
          try {
227
            value.append(child);
228
          } catch (NullPointerException npe) {
229
value.append("M");
230
          }
222
          child = (BasicElement)e.nextElement(); 
223
          value.append(child);
231 224
        }
232 225

  
233
        //String cont = getContent();
234
        //if (!cont.equals("null")) {
235
          //value.append(cont);
236
        //}
237

  
238 226
        if (nodetype.equals("ELEMENT")) {
239 227
          value.append("</");
240 228
          value.append(getTagName());
241 229
          value.append('>');
242 230
        }
243
        //else { value.append(getNodeType()); }
244 231

  
245 232
        return value.toString();
246 233
    }
src/edu/ucsb/nceas/metacat/TextNode.java
1
/**
2
 *        Name: TextNode.java
3
 *     Purpose: A Class that represents an XML Text node and its contents,
4
 *              and can build itself from a database connection
5
 *   Copyright: 2000 Regents of the University of California and the
6
 *              National Center for Ecological Analysis and Synthesis
7
 *     Authors: Matt Jones
8
 *
9
 *     Version: '$Id$'
10
 */
11

  
12
package edu.ucsb.nceas.metacat;
13

  
14
import java.sql.*;
15

  
16
/**
17
 * A Class that represents an XML element and its contents,
18
 * and can build itself from a database connection
19
 */
20
public class TextNode extends BasicElement {
21

  
22
    private Connection	conn;
23
    private String      nodeData = null;
24

  
25
    /** 
26
     * Construct a new TextNode instance
27
     *
28
     * @param conn the database connection to use to initialize 
29
     * @param nodeid the element_id for the node to be created
30
     * @param parentnodeid the id of the parent node
31
     * @param nodedata the text of the node
32
     * @param nodetype the type of the node
33
     */
34
    public TextNode (Connection conn, long nodeid, long parentnodeid,
35
                          String nodedata, String nodetype) {
36
      this.conn = conn;
37
      setElementID(nodeid);
38
      setParentID(parentnodeid);
39
      setNodeData(nodedata);
40
      setNodeType(nodetype);
41
    }
42

  
43
    /** Set the node data to the given string */
44
    public void setNodeData(String nodedata) {
45
      this.nodeData = nodedata;
46
    }
47

  
48
    /** Get the node data as a string value */
49
    public String getNodeData() {
50
      return nodeData;
51
    }
52

  
53
    /** 
54
     * String representation of this text node
55
     */
56
    public String toString () {
57
        return nodeData;
58
    }
59
}
0 60

  

Also available in: Unified diff