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 DAVResourceValue extends ResourceValue { 42 43 46 public DAVResourceValue() { 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( ((DAVResourceValue)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 DAVResourceValue val = (DAVResourceValue) 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 if(propEl.getChildNodes().getLength()==1) { 87 Element elHREF = (Element ) propEl.getFirstChild(); 88 Text txt = (Text ) elHREF.getFirstChild(); 89 if(txt!=null) { 90 DAVResourceValue val = (DAVResourceValue) propInst.getNewValueInstance(); 91 val.setValue( txt.getData() ); 92 propInst.addValueWithoutFiringVirtualFileEvent(val); 93 } 94 } else if(propEl.getChildNodes().getLength()>1) { 95 NodeList nl = propEl.getChildNodes(); 96 for (int i = 0; i < nl.getLength(); i++) { 97 Node node = nl.item(i); 98 if(node.getNodeType()==Node.ELEMENT_NODE) { 99 Text txt = (Text ) node.getFirstChild(); 100 if(txt!=null) { 101 DAVResourceValue val = (DAVResourceValue) propInst.getNewValueInstance(); 102 val.setValue( txt.getData() ); 103 propInst.addValueWithoutFiringVirtualFileEvent(val); 104 } 105 } 106 } 107 } 108 } 109 110 } 111 | Popular Tags |