[jdom-interest] Moving elements
Bradley S. Huffman
hip at a.cs.okstate.edu
Wed Apr 30 21:00:17 PDT 2003
Jason Hunter writes:
> 2) We could have a new method like this on Element and Document:
>
> List element.getContentDetached()
>
> It would return a list of the detached content. Then you could do this:
>
> heading.setContent(anchorList.getContentDetached());
Definitely +1, but I'd just go ahead and name it removeContent().
> 3) We could change the add semantics. David Flanagan suggested this,
> and it's how DOM does things. If you add an element somewhere and the
> element already has a parent, the new parent just trumps it. Compare
> that to right now we throw an IllegalAddException. If we changed
> behaviors, it would make nice code:
Better documentation is also a solution :) But if the remove/add sequence is
not convenient enough, I'd prefer a moveContent(...) on Element instead of
changing the add semantics.
heading.moveContent(textNode); // Move textNode to end of heading's
// content list.
> heading.setContent(anchorList.getContent());
Hmmm, does that a) detach the content from anchorList or b) make
a copy of anchorList before setting heading's content. It's not clear just
by looking at it. I like
heading.setContent(anchorList.removeContent());
> Sorting works naturally also. The big issue is whether you expect this
> sort of auto-detachment. I guess I wouldn't, but maybe I've used JDOM
> too long. :-)
I wouldn't either, and besides
List list = anchorList.removeContent();
// do the sort
heading.setContent(list);
is very clear about what is actual being done.
Brad
More information about the jdom-interest
mailing list