[jdom-interest] StringBufferAttribute
Brett McLaughlin
brett at newInstance.com
Mon Jul 9 10:53:56 PDT 2001
I'm not really sure why you would want to do this... What's wrong with the
basic Attribute class that you need to extend it?
-Brett
----- Original Message -----
From: "Noam Tamim" <noamt at yahoo.com>
To: <jdom-interest at jdom.org>
Sent: Sunday, July 08, 2001 3:48 PM
Subject: [jdom-interest] StringBufferAttribute
> Hi there.
>
> What do you guys think about this idea: extending the Attribute class to
use
> (and expose!) a StringBuffer object for the value.
> I'm not suggesting to replace the existing Attribute, I just want comments
> on the idea:
>
> public class SBAttribute extends Attribute {
> protected StringBuffer value;
>
> public SBAttribute(String name, StringBuffer value, Namespace ns) {
> super(); // avoid setting the original String value.
> setName(name);
> setValue(value);
> setNamespace(ns);
> }
>
> public SBAttribute(String name, StringBuffer value) {
> this(name,value,Namespace.NO_NAMESPACE);
> }
>
> // return the actual StringBuffer used by this attribute.
> public StringBuffer getBuffer() {
> return value;
> }
>
> public String getValue() {
> return value.toString();
> }
>
> public Attribute setValue(String value) {
> return setValue(new StringBuffer(value));
> }
>
> public SBAttribute setValue(StringBuffer value) {
> // here should probably come some verifications.
> this.value=value;
> return this;
> }
> }
>
>
>
> And here's an example of using it:
> void main() throws IOException {
> Element root=new Element("root");
> StringBuffer name=new StringBuffer("noam");
> root.addContent(new Element("user").setAttribute(new
> SBAttribute("name",name)));
> root.addContent(new Element("user").setAttribute(new
> SBAttribute("name",name)));
> root.addContent(new Element("user").setAttribute(new
> SBAttribute("name",name)));
> Document doc=new Document(root);
>
> XMLOutputter xout=new XMLOutputter(" ",true);
>
> System.out.println("name="+name);
> xout.output(doc,System.out);
>
> name.reverse();
> System.out.println("name="+name);
> xout.output(doc,System.out);
> }
>
>
> - Noam.
>
>
>
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
More information about the jdom-interest
mailing list