| 1 24 package org.riotfamily.forms.element.collection; 25 26 import java.util.Iterator ; 27 28 import org.riotfamily.common.xml.XmlUtils; 29 import org.springframework.util.Assert; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 33 public class XmlSequence extends ListEditor { 34 35 private String name; 36 37 private Node node; 38 39 public void setName(String name) { 40 this.name = name; 41 } 42 43 protected void afterBindingSet() { 44 if (name == null) { 45 name = getEditorBinding().getProperty(); 46 } 47 } 48 49 52 public void setValue(Object value) { 53 if (value != null) { 54 Assert.isInstanceOf(Node .class, value, 55 "Value must implement the org.w3c.Node interface"); 56 57 node = (Node ) value; 58 NodeList childNodes = node.getChildNodes(); 59 for (int i = 0; i < childNodes.getLength(); i++) { 60 Node child = childNodes.item(i); 61 ListItem item = addItem(); 62 item.getElement().setValue(child); 63 } 64 } 65 } 66 67 public Object getValue() { 68 if (node != null) { 69 XmlUtils.removeAllChildNodes(node); 70 } 71 else { 72 node = XmlUtils.createDocument().createElement(name); 73 } 74 Iterator it = getItems().getElements().iterator(); 75 while (it.hasNext()) { 76 ListItem item = (ListItem) it.next(); 77 if (item.getElement().getValue() != null) { 78 Object value = item.getElement().getValue(); 79 Assert.isInstanceOf(Node .class, value, 80 "Value must implement the org.w3c.Node interface"); 81 82 XmlUtils.importAndAppend((Node ) value, node); 83 } 84 } 85 return node; 86 } 87 88 protected void validate() { 89 } 90 91 } 92 | Popular Tags |