1
|
/**
|
2
|
* Name: DBSAXElement.java
|
3
|
* Purpose: A Class that represents an XML element and its contents
|
4
|
* Institution: National Center for Ecological Analysis and Synthesis
|
5
|
* Copyright: 2000
|
6
|
* Authors: Matt Jones
|
7
|
*
|
8
|
* Version: '$Id: DBSAXElement.java 15 2000-04-11 02:12:25Z jones $'
|
9
|
*/
|
10
|
|
11
|
//package project;
|
12
|
|
13
|
import java.sql.*;
|
14
|
import java.io.IOException;
|
15
|
import java.util.Hashtable;
|
16
|
import java.util.Enumeration;
|
17
|
|
18
|
public class DBSAXElement {
|
19
|
|
20
|
private long element_id;
|
21
|
private String tagname;
|
22
|
private StringBuffer content;
|
23
|
private boolean isEmpty;
|
24
|
private long parent_id;
|
25
|
private Hashtable attributes;
|
26
|
|
27
|
public DBSAXElement (long element_id, String tagname,
|
28
|
boolean isEmpty, long parent_id) {
|
29
|
this.element_id = element_id;
|
30
|
this.tagname = tagname;
|
31
|
this.isEmpty = isEmpty;
|
32
|
this.parent_id = parent_id;
|
33
|
content = new StringBuffer();
|
34
|
attributes = new Hashtable();
|
35
|
};
|
36
|
|
37
|
// used by JTree to display this node
|
38
|
public String toString ()
|
39
|
{
|
40
|
StringBuffer value = new StringBuffer ();
|
41
|
value.append ('<');
|
42
|
value.append (getTagName ());
|
43
|
value.append (getAttributes ().toString ());
|
44
|
value.append ('>');
|
45
|
return value.toString ();
|
46
|
}
|
47
|
|
48
|
/** Get the name of this element */
|
49
|
public String getTagName() { return tagname; }
|
50
|
|
51
|
/** Get the attributes as a string */
|
52
|
public String getAttributes() {
|
53
|
StringBuffer buf = new StringBuffer();
|
54
|
String attName = null;
|
55
|
String attValue = null;
|
56
|
|
57
|
Enumeration attList = attributes.keys();
|
58
|
while (attList.hasMoreElements()) {
|
59
|
attName = (String)attList.nextElement();
|
60
|
attValue = (String)attributes.get(attName);
|
61
|
buf.append(" ").append(attName).append("=").append(attValue);
|
62
|
}
|
63
|
return buf.toString();
|
64
|
}
|
65
|
|
66
|
/** Add a new attribute to this element, or set its value */
|
67
|
public void setAttribute(String attName, String attValue) {
|
68
|
if (attName != null) {
|
69
|
attributes.put(attName, attValue);
|
70
|
} else {
|
71
|
System.err.println("Attribute name must not be null!");
|
72
|
}
|
73
|
}
|
74
|
|
75
|
/** Get an attribute value by name */
|
76
|
public String getAttribute(String attName) {
|
77
|
return (String)attributes.get(attName);
|
78
|
}
|
79
|
|
80
|
/** Append to the content of the element */
|
81
|
public void appendContent(char[] cbuf, int start, int len) {
|
82
|
this.content.append( cbuf, start, len );
|
83
|
}
|
84
|
|
85
|
/** Append to the content of the element */
|
86
|
public void appendContent(String new_content) {
|
87
|
this.content.append( new_content );
|
88
|
}
|
89
|
|
90
|
/** Get the content of the element */
|
91
|
public String getContent() {
|
92
|
return this.content.toString();
|
93
|
}
|
94
|
}
|