1 19 package org.openharmonise.webdav.client.value; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.openharmonise.commons.xml.namespace.*; 26 import org.openharmonise.vfs.*; 27 import org.openharmonise.vfs.metadata.*; 28 import org.openharmonise.vfs.metadata.value.*; 29 import org.openharmonise.webdav.client.*; 30 import org.openharmonise.webdav.client.methods.*; 31 import org.w3c.dom.Document ; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 import org.w3c.dom.NodeList ; 35 36 37 44 public class DAVPropertyValue extends PropertyValue { 45 46 49 public DAVPropertyValue() { 50 super(); 51 } 52 53 58 public DAVPropertyValue(ArrayList aPropertyInstances) { 59 super(aPropertyInstances); 60 } 61 62 69 public static void toXML(Document xmlDoc, Element propEl, List aValues) { 70 if(aValues.size()==1) { 71 72 Element innerPropEl = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "prop"); 73 propEl.appendChild(innerPropEl); 74 75 Iterator itor = ((DAVPropertyValue)aValues.get(0)).getValue().iterator(); 76 while (itor.hasNext()) { 77 PropertyInstance propInst = (PropertyInstance) itor.next(); 78 PropPatch.publishPropertyInstanceToXML(xmlDoc, propInst, innerPropEl); 79 } 80 } else if(aValues.size()>1) { 81 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" ); 82 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) ); 83 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.DAV.getPrefix()+":prop"); 84 Iterator itor = aValues.iterator(); 85 while (itor.hasNext()) { 86 Element innerPropEl = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "prop"); 87 propEl.appendChild(innerPropEl); 88 89 Iterator itor2 = ((DAVPropertyValue)itor.next()).getValue().iterator(); 90 while (itor2.hasNext()) { 91 PropertyInstance propInst = (PropertyInstance) itor2.next(); 92 PropPatch.publishPropertyInstanceToXML(xmlDoc, propInst, innerPropEl); 93 } 94 propEl.appendChild(innerPropEl); 95 } 96 } 97 } 98 99 107 public static void fromXML(VirtualFile vfFile, PropertyInstance propInst, Element propEl) { 108 if(propEl.getChildNodes().getLength()==1) { 109 Element containerEl = (Element ) propEl.getFirstChild(); 110 if(containerEl!=null) { 111 DAVPropertyValue valInst = (DAVPropertyValue) propInst.getNewValueInstance(); 112 ArrayList aPropertyInstances = new ArrayList (); 113 NodeList nl = containerEl.getChildNodes(); 114 for(int i=0; i<nl.getLength(); i++) { 115 Node node = nl.item(i); 116 if(node.getNodeType()==Node.ELEMENT_NODE) { 117 Element subPropEl = (Element )node; 118 PropertyInstance subProp = new PropertyInstance(); 119 aPropertyInstances.add(subProp); 120 ((WebDAVFileSystem)vfFile.getVFS()).populatePropertyInstance(vfFile, subPropEl, subProp, false); 121 } 123 } 124 valInst.setValue(aPropertyInstances); 125 propInst.addValueWithoutFiringVirtualFileEvent(valInst); 126 } 127 } else if(propEl.getChildNodes().getLength()>1) { 128 NodeList nl = propEl.getChildNodes(); 129 for (int i = 0; i < nl.getLength(); i++) { 130 Node node = nl.item(i); 131 if(node.getNodeType()==Node.ELEMENT_NODE) { 132 Element containerEl = (Element ) node; 133 if(containerEl!=null) { 134 DAVPropertyValue valInst = (DAVPropertyValue) propInst.getNewValueInstance(); 135 ArrayList aPropertyInstances = new ArrayList (); 136 NodeList nl2 = containerEl.getChildNodes(); 137 for(int j=0; j<nl2.getLength(); j++) { 138 Node node2 = nl2.item(j); 139 if(node.getNodeType()==Node.ELEMENT_NODE) { 140 Element subPropEl = (Element )node2; 141 PropertyInstance subProp = new PropertyInstance(); 142 aPropertyInstances.add(subProp); 143 ((WebDAVFileSystem)vfFile.getVFS()).populatePropertyInstance(vfFile, subPropEl, subProp, false); 144 } 145 } 146 valInst.setValue(aPropertyInstances); 147 propInst.addValueWithoutFiringVirtualFileEvent(valInst); 148 } 149 } 150 } 151 } 152 } 153 154 } 155 | Popular Tags |