[jdom-interest] moving an Element

Robert Koberg rob at koberg.com
Wed Jan 21 09:12:14 PST 2004


Jason Hunter wrote:
> Did you read the FAQ entry about this?

Did now :) (I think I did in the past). However, I need to place it 
after a preceding sibling, not simply append it. I am using it for an 
HTML UI were users can reorder folder/page like elements in the tree.

Or are you just saying that I should be using detach() (don't know why I 
am not using it...)?

thanks,
-Rob


> 
> -jh-
> 
> Robert Koberg wrote:
> 
>> Hi,
>>
>> What is the best way to move an org.jdom.Element with jdom?
>>
>> I am using the method below. What do you think about it?
>>
>> public final void moveElement(Element elem, String parentIdref, String 
>> prevSiblIdref) {
>>   String focusIdref = elem.getAttributeValue("id");
>>   Element parent = this.getElement(parentIdref);
>>   List children = parent.getChildren();
>>   List _children = new ArrayList(children.size() + 1);
>>   for (ListIterator i = children.listIterator(); i.hasNext();) {
>>     Element child = (Element) i.next();
>>
>>     String id = child.getAttributeValue("id");
>>     if (null == id) {
>>       _children.add(child);
>>     } else if (!id.equals(focusIdref)) {
>>       _children.add(child);
>>     }
>>
>>     if (null != id && id.equals(prevSiblIdref)) {
>>       _children.add(elem);
>>     }
>>   }
>>   if ("null".equals(prevSiblIdref)) {
>>     _children.add(0, elem);
>>   }
>>   children.clear();
>>   parent.setContent(_children);
>> }
>>
>> thanks,
>> -Rob
>> _______________________________________________
>> 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