[jdom-interest] getChildTextNormalize()

Kent C. Johnson kentyman23 at hotmail.com
Tue Oct 2 11:55:48 PDT 2001


You are completely right.  I must have misread the code somewhere.  Let me 
adapt my argument towards a different point. :)

> > Since it doesn't just call getChild().getText(), it
> > can be said that it has it's own functionality, namely returning "" if
> > getChild() == null, and if not, returning the wrap of 
>getChild().getText().

The above would be make more sense if I had said:

> > Since it doesn't just call getChild().getText(), it
> > can be said that it has it's own functionality, namely returning *null* 
>if
> > getChild() == null, and if not, returning the wrap of 
>getChild().getText().

This way you don't have to worry about the NullPointerException that can 
occur with getChild().getText().

However, if any of these get*Text*() methods do return null, people will 
still have to see if they're null before they use the text.  What is the 
right way to handle this?  I'm finding it hard to figure out what *I* think 
is the best solution, so I can imagine we need some more input from others 
until we can find what *we* think is the best solution.

(Also, can someone explain what the stuff in jdom-contrib is for?  Is this 
just a branch addons and stuff that don't go in the final release, or?)

Thanks for the input,
Kent

>From: rpcee <rpcee at operamail.com>
>To: "Kent C. Johnson" <kentyman23 at hotmail.com>,    jdom-interest 
><jdom-interest at jdom.org>
>CC: arosen <arosen at silverstream.com>
>Subject: RE: [jdom-interest] getChildTextNormalize()
>Date: Tue, 2 Oct 2001 12:49:16 -0400
>
>The source seems to indicate getChildText*() methods return null rather 
>than
>"" if getChild() returns null, whereas the getText*() methods don't appear 
>to
>return null. ie
>
>   Element e = getChild("c");
>   if (e == null) {
>     return "";
>   }  else {
>     return e.getTextTrim();
>   }
>
>is actually equivalent to:
>
>   String childText = e.getChildTextTrim("c");
>   if (e == null) {
>     return "";
>   } else {
>     return childText;
>   }
>
>Obviously you might be happy to return null but presumably at some point 
>there
>would have to be a null test?
>
>
> >===== Original Message From "Kent C. Johnson" <kentyman23 at hotmail.com> 
>=====
> >Alex (and All),
> >
> >Agreed about the trimText(), it was just a thought.
> >
> >I too agree it's bad to have methods in a parent that merely call methods 
>in
> >a child.  However, there is something to be said for the null-checking
> >getChildText() does.  Since it doesn't just call getChild().getText(), it
> >can be said that it has it's own functionality, namely returning "" if
> >getChild() == null, and if not, returning the wrap of 
>getChild().getText().
> >Sounds a lot like a loop-hole too keep it in, but that may be a good 
>thing.
> >I think if everyone wanted the EXACT right OOP way to do things, they 
>might
> >lean more towards DOM.  But it seems to me (through my occasional use) 
>that
> >JDOM is more about convenience.  Not convenience to the point of 
>excessive
> >clutter, but a happy medium.
> >
> >Do you agree?
> >
> >Regards, and sorry to open this "Pandora's Box" as Jason called it, :)
> >Kent
> >
> >
> >>From: "Alex Rosen" <arosen at silverstream.com>
> >>To: "'Kent C. Johnson'" <kentyman23 at hotmail.com>, 
><jdom-interest at jdom.org>
> >>Subject: RE: [jdom-interest] getChildTextNormalize()
> >>Date: Tue, 2 Oct 2001 10:57:43 -0400
> >>
> >>I could live with any of this either way. I agree that consistency is a
> >>good
> >>thing, but I'm not sure I see the value of a trimText() that just calls
> >>String.trim(). philip.nelson (Phil?) didn't seem to like the idea of
> >>getChildText() because it's mixing levels inappropriately. I tend to 
>agree,
> >>but I don't feel very strongly about it.
> >>
> >>Alex
> >>
> >
> >
> >_________________________________________________________________
> >Get your FREE download of MSN Explorer at 
>http://explorer.msn.com/intl.asp
> >
> >_______________________________________________
> >To control your jdom-interest membership:
> >http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost
>.com
>


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the jdom-interest mailing list