[jdom-interest] Feature request: Default values for getters

Jason Hunter jhunter at acm.org
Wed Nov 28 16:01:48 PST 2001


The leg work isn't too hard, it's just deciding what should be done. 
You're right about getText() that all elements have some text, although
it might be "".  A <foo></foo> is equivalent to <foo/> in other words. 
For attributes you can be sure one doesn't exist, but the type
conversion methods are on Attribute itself, so by the time you're there
a default value would have to apply if the conversion failed and not if
there was no attribute present.

-jh-

Matt Sanchez wrote:
> 
> I would gladly do the leg work for this one if it was going to be made
> official.  I'll take a look at the source for Element and Attribute.  How
> easy is it to distinguish between empty Elements/Attributes and non-existent
> Elements/Attributes.  If this can not be done effectively, then default
> values may be hard to implement.
> 
> Matt B. Sanchez
> Software Engineer
> Liaison Technology
> msanchez at liaison.com
> 512.345.0020 ext 196
> 512.659.8265 mobile
> 
> > Powering the e-Catalog content connection
> www.liaison.com
> 
> -----Original Message-----
> From: Jason Hunter [mailto:jhunter at acm.org]
> Sent: Wednesday, November 28, 2001 4:36 PM
> To: Matt Sanchez
> Cc: 'jdom-interest at jdom.org'
> Subject: Re: [jdom-interest] Feature request: Default values for getters
> 
> Personally I like the idea, and in fact we had default attrib getters in
> the past.  But they were removed so that the API might be simpler and
> not "mask errors".  To argue that side for a minute, the utility method
> you show is trivial and if we made it official we'd have to add three
> new methods for each of getText(), getTextTrim(), and
> getTextNormalize().  I'm easy either way.
> 
> -jh-
> 
> Matt Sanchez wrote:
> >
> > As a new user to JDOM, I must admit I am very impressed and pleased to see
> > such an intuitive interface for XML access.  One thing I have noticed is
> > that the Element.getText() and Attribute.getXXXValue() methods do not have
> > versions that allow for default values to be passed in.
> >
> > For example, it would be nice to be able to do the following:
> >
> > Element root = doc.getRootElement();
> > String s = root.getChild("foo").getText("default value");
> >
> > Element.getText(String default) could be implemented as follows:
> >
> > public String getText(String default)
> > {
> >     String retVal = getText();
> >
> >     if (retVal.equals(""))
> >         return default;
> >
> >     return retVal;
> > }
> >
> > Likewise, all the Attribute.getXXXValue() methods could be implemented in
> a
> > similar fashion.  I am sure this issue has been brought up before, so
> please
> > excuse my ignorance.  Thanks.
> >
> > Matt B. Sanchez
> > Software Engineer
> > Liaison Technology
> > msanchez at liaison.com
> >
> > > Powering the e-Catalog content connection
> > www.liaison.com
> > _______________________________________________
> > 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