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

Jason Hunter jhunter at acm.org
Wed Nov 28 14:36:04 PST 2001


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@yourhost.com



More information about the jdom-interest mailing list