1 19 package org.openharmonise.webdav.client.value; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.openharmonise.commons.xml.namespace.*; 25 import org.openharmonise.vfs.metadata.*; 26 import org.openharmonise.vfs.metadata.value.*; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.NodeList ; 31 import org.w3c.dom.Text ; 32 33 34 41 public class DAVStringValue extends StringValue { 42 43 48 public DAVStringValue(String sValue) { 49 super(sValue); 50 } 51 52 55 public DAVStringValue() { 56 super(); 57 } 58 59 66 public static void toXML(Document xmlDoc, Element propEl, List aValues) { 67 if(aValues.size()==1) { 68 Text txt = xmlDoc.createTextNode( ((DAVStringValue)aValues.get(0)).getValue() ); 69 propEl.appendChild(txt); 70 } else if(aValues.size()>1) { 71 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" ); 72 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) ); 73 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.XML_SCHEMA.getPrefix()+":string"); 74 Iterator itor = aValues.iterator(); 75 while (itor.hasNext()) { 76 DAVStringValue val = (DAVStringValue) itor.next(); 77 Element arrayEl = xmlDoc.createElementNS(NamespaceType.XML_SCHEMA.getURI(), "string"); 78 Text txt = xmlDoc.createTextNode( val.getValue() ); 79 arrayEl.appendChild(txt); 80 propEl.appendChild(arrayEl); 81 } 82 } 83 } 84 85 92 public static void fromXML(PropertyInstance propInst, Element propEl) { 93 if(propEl.getChildNodes().getLength()==1) { 94 Node node = propEl.getFirstChild(); 95 if(node!=null && node.getNodeType()==Node.TEXT_NODE) { 96 Text txt = (Text ) propEl.getFirstChild(); 97 DAVStringValue val = (DAVStringValue) propInst.getNewValueInstance(); 98 val.setValue( txt.getData() ); 99 propInst.addValueWithoutFiringVirtualFileEvent(val); 100 } 101 } else if(propEl.getChildNodes().getLength()>1) { 102 NodeList nl = propEl.getChildNodes(); 103 for (int i = 0; i < nl.getLength(); i++) { 104 Node node = nl.item(i); 105 if(node.getNodeType()==Node.ELEMENT_NODE) { 106 Node node2 = node.getFirstChild(); 107 if(node2!=null && node2.getNodeType()==Node.TEXT_NODE) { 108 Text txt = (Text ) node.getFirstChild(); 109 DAVStringValue val = (DAVStringValue) propInst.getNewValueInstance(); 110 val.setValue( txt.getData() ); 111 propInst.addValueWithoutFiringVirtualFileEvent(val); 112 } 113 } 114 } 115 } 116 } 117 118 } 119 | Popular Tags |