Revision 21
Added by Matt Jones over 24 years ago
DBSAXElement.java | ||
---|---|---|
15 | 15 |
import java.util.Hashtable; |
16 | 16 |
import java.util.Enumeration; |
17 | 17 |
|
18 |
public class DBSAXElement { |
|
18 |
public class DBSAXElement extends BasicElement {
|
|
19 | 19 |
|
20 |
private long element_id; |
|
21 |
private String tagname; |
|
22 |
private StringBuffer content; |
|
23 |
private long parent_id; |
|
24 |
private Hashtable attributes; |
|
25 | 20 |
private Connection conn; |
26 | 21 |
|
27 | 22 |
public DBSAXElement (Connection conn, String tagname, |
28 | 23 |
long parent_id) { |
24 |
|
|
25 |
super(tagname, parent_id); |
|
26 |
|
|
29 | 27 |
this.conn = conn; |
30 |
|
|
31 |
this.tagname = tagname; |
|
32 |
this.parent_id = parent_id; |
|
33 |
content = new StringBuffer(); |
|
34 |
attributes = new Hashtable(); |
|
35 | 28 |
writeElementToDB(); |
36 | 29 |
}; |
37 | 30 |
|
... | ... | |
100 | 93 |
return assigned_id; |
101 | 94 |
} |
102 | 95 |
|
103 |
// used by JTree to display this node |
|
104 |
public String toString () |
|
105 |
{ |
|
106 |
StringBuffer value = new StringBuffer (); |
|
107 |
value.append ('<'); |
|
108 |
value.append (getTagName ()); |
|
109 |
value.append (getAttributes ().toString ()); |
|
110 |
value.append ('>'); |
|
111 |
return value.toString (); |
|
112 |
} |
|
113 |
|
|
114 |
/** Get the id of this element */ |
|
115 |
public long getElementID() { return element_id; } |
|
116 |
|
|
117 |
/** Get the name of this element */ |
|
118 |
public String getTagName() { return tagname; } |
|
119 |
|
|
120 |
/** Get the attributes as a string */ |
|
121 |
public String getAttributes() { |
|
122 |
StringBuffer buf = new StringBuffer(); |
|
123 |
String attName = null; |
|
124 |
String attValue = null; |
|
125 |
|
|
126 |
Enumeration attList = attributes.keys(); |
|
127 |
while (attList.hasMoreElements()) { |
|
128 |
attName = (String)attList.nextElement(); |
|
129 |
attValue = (String)attributes.get(attName); |
|
130 |
buf.append(" ").append(attName).append("=").append(attValue); |
|
131 |
} |
|
132 |
return buf.toString(); |
|
133 |
} |
|
134 |
|
|
135 | 96 |
/** Add a new attribute to this element, or set its value */ |
136 | 97 |
public void setAttribute(String attName, String attValue) { |
137 | 98 |
if (attName != null) { |
... | ... | |
162 | 123 |
} |
163 | 124 |
} |
164 | 125 |
|
165 |
/** Get an attribute value by name */ |
|
166 |
public String getAttribute(String attName) { |
|
167 |
return (String)attributes.get(attName); |
|
168 |
} |
|
169 |
|
|
170 |
/** Append to the content of the element */ |
|
171 |
public void appendContent(char[] cbuf, int start, int len) { |
|
172 |
this.content.append( cbuf, start, len ); |
|
173 |
} |
|
174 |
|
|
175 |
/** Append to the content of the element */ |
|
176 |
public void appendContent(String new_content) { |
|
177 |
this.content.append( new_content ); |
|
178 |
} |
|
179 |
|
|
180 |
/** Get the content of the element */ |
|
181 |
public String getContent() { |
|
182 |
return this.content.toString(); |
|
183 |
} |
|
184 |
|
|
185 | 126 |
/** Write the element content to the db connection */ |
186 | 127 |
public void writeContentToDB() { |
187 | 128 |
try { |
... | ... | |
200 | 141 |
System.out.println(e.getMessage()); |
201 | 142 |
} |
202 | 143 |
} |
203 |
|
|
204 | 144 |
} |
Also available in: Unified diff
created code to read XML doc from db source and emit it as an XML stream