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 DAVValueValue extends ValueValue { 42 43 46 public DAVValueValue() { 47 super(); 48 } 49 50 57 public static void toXML(Document xmlDoc, Element propEl, List aValues) { 58 if(aValues.size()==1) { 59 Element hrefEl = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "href"); 60 propEl.appendChild(hrefEl); 61 Text txt = xmlDoc.createTextNode( ((DAVValueValue)aValues.get(0)).getValue() ); 62 hrefEl.appendChild(txt); 63 } else if(aValues.size()>1) { 64 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" ); 65 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) ); 66 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.DAV.getPrefix()+":href"); 67 Iterator itor = aValues.iterator(); 68 while (itor.hasNext()) { 69 DAVValueValue val = (DAVValueValue) itor.next(); 70 Element arrayEl = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "href"); 71 Text txt = xmlDoc.createTextNode( val.getValue() ); 72 arrayEl.appendChild(txt); 73 propEl.appendChild(arrayEl); 74 } 75 } 76 } 77 78 85 public static void fromXML(PropertyInstance propInst, Element propEl) { 86 try { 87 if(propEl.getChildNodes().getLength()==1) { 88 Element elHREF = (Element ) propEl.getFirstChild(); 89 Text txt = (Text ) elHREF.getFirstChild(); 90 if(txt!=null) { 91 DAVValueValue val = (DAVValueValue) propInst.getNewValueInstance(); 92 val.setValue( txt.getData() ); 93 propInst.addValueWithoutFiringVirtualFileEvent(val); 94 } 95 } else if(propEl.getChildNodes().getLength()>1) { 96 NodeList nl = propEl.getChildNodes(); 97 for (int i = 0; i < nl.getLength(); i++) { 98 Node node = nl.item(i); 99 if(node.getNodeType()==Node.ELEMENT_NODE) { 100 Text txt = (Text ) node.getFirstChild(); 101 if(txt!=null) { 102 DAVValueValue val = (DAVValueValue) propInst.getNewValueInstance(); 103 val.setValue( txt.getData() ); 104 propInst.addValueWithoutFiringVirtualFileEvent(val); 105 } 106 } 107 } 108 } 109 } catch(Exception e) { 110 e.printStackTrace(System.err); 111 } 112 } 113 114 } 115 | Popular Tags |