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.him.harmonise.*; 26 import org.openharmonise.vfs.metadata.*; 27 import org.openharmonise.vfs.metadata.value.*; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 import org.w3c.dom.Text ; 33 34 35 42 public class DAVDomainValue extends DomainValue { 43 44 47 public DAVDomainValue() { 48 super(); 49 } 50 51 56 public DAVDomainValue(String sPath) { 57 super(sPath); 58 } 59 60 69 public DAVDomainValue( 70 String sPath, 71 int nMinOccurs, 72 int nMaxOccurs, 73 List aContentTypes, 74 String sResourceType) { 75 super(sPath, nMinOccurs, nMaxOccurs, aContentTypes, sResourceType); 76 } 77 78 85 public static void toXML(Document xmlDoc, Element propEl, List aValues) { 86 if(aValues.size()==1) { 87 DAVDomainValue.toXMLDomainData(xmlDoc, propEl, (DAVDomainValue) aValues.get(0)); 88 } else if(aValues.size()>1) { 89 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" ); 90 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) ); 91 propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.DAV.getPrefix()+":domainData"); 92 Iterator itor = aValues.iterator(); 93 while (itor.hasNext()) { 94 DAVDomainValue value = (DAVDomainValue) itor.next(); 95 Element elDomainData = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "domainData"); 96 propEl.appendChild(elDomainData); 97 DAVDomainValue.toXMLDomainData(xmlDoc, elDomainData, value); 98 } 99 } 100 } 101 102 109 private static void toXMLDomainData(Document xmlDoc, Element parentEl, DAVDomainValue value) { 110 Element elResourceType = null; 111 112 elResourceType = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "resourcetype"); 113 parentEl.appendChild(elResourceType); 114 115 if(value.getResourceType()==DomainValue.RESOURCE) { 116 if(value.getPath().startsWith(HarmonisePaths.PATH_PROPERTIES)) { 117 Element elType = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), DAVDomainValue.PROPERTY); 118 elResourceType.appendChild(elType); 119 } else if(value.getPath().startsWith(HarmonisePaths.PATH_VALUES)) { 120 Element elType = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), DAVDomainValue.VALUE); 121 elResourceType.appendChild(elType); 122 } else { 123 Element elType = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), value.getResourceType()); 124 elResourceType.appendChild(elType); 125 } 126 } else { 127 Element elType = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), value.getResourceType()); 128 elResourceType.appendChild(elType); 129 } 130 131 132 if(value.getContentTypes().size()>0) { 133 Iterator itorCT = value.getContentTypes().iterator(); 134 while (itorCT.hasNext()) { 135 String sContentType = (String ) itorCT.next(); 136 Element elContentType = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "contenttype"); 137 parentEl.appendChild(elContentType); 138 139 Text txt = xmlDoc.createTextNode(sContentType); 140 elContentType.appendChild(txt); 141 } 142 } 143 144 if(value.getPath()!=null && !value.getPath().equals("")) { 145 Element elHREF = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "href"); 146 parentEl.appendChild(elHREF); 147 Text txtHREF = xmlDoc.createTextNode(value.getPath()); 148 elHREF.appendChild(txtHREF); 149 } 150 151 Element elMaxOccurs = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "maxOccurs"); 152 parentEl.appendChild(elMaxOccurs); 153 Text txtMax = xmlDoc.createTextNode(Integer.toString(value.getMaxOccurs())); 154 elMaxOccurs.appendChild(txtMax); 155 156 Element elMinOccurs = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "minOccurs"); 157 parentEl.appendChild(elMinOccurs); 158 Text txtMin = xmlDoc.createTextNode(Integer.toString(value.getMinOccurs())); 159 elMinOccurs.appendChild(txtMin); 160 } 161 162 169 public static void fromXML(PropertyInstance propInst, Element propEl) { 170 boolean bMultiple = false; 171 if(propEl.getChildNodes().getLength()>1) { 172 NodeList nl = propEl.getChildNodes(); 173 for (int i = 0; i < nl.getLength(); i++) { 174 Node node = nl.item(i); 175 if(node.getNodeType()==Node.ELEMENT_NODE) { 176 if( ((Element )node).getLocalName().equalsIgnoreCase("domainData")) { 177 bMultiple=true; 178 } 179 } 180 } 181 } 182 183 if(!bMultiple) { 184 DAVDomainValue val = (DAVDomainValue) propInst.getNewValueInstance(); 185 DAVDomainValue.fromXMLDomainData(propInst, propEl, val); 186 if(val.getPath()!=null && !val.getPath().equals("")) { 187 propInst.addValueWithoutFiringVirtualFileEvent(val); 188 } 189 } else if(propEl.getChildNodes().getLength()>1) { 190 NodeList nl = propEl.getChildNodes(); 191 for (int i = 0; i < nl.getLength(); i++) { 192 Node node = nl.item(i); 193 if(node.getNodeType()==Node.ELEMENT_NODE) { 194 DAVDomainValue val = (DAVDomainValue) propInst.getNewValueInstance(); 195 DAVDomainValue.fromXMLDomainData(propInst, (Element ) node, val); 196 if(val.getPath()!=null && !val.getPath().equals("")) { 197 propInst.addValueWithoutFiringVirtualFileEvent(val); 198 } 199 } 200 } 201 } 202 } 203 204 212 public static void fromXMLDomainData(PropertyInstance propInst, Element parentEl, DAVDomainValue value) { 213 NodeList nl = parentEl.getChildNodes(); 214 for (int i = 0; i < nl.getLength(); i++) { 215 Node node = nl.item(i); 216 if(node.getNodeType()==Node.ELEMENT_NODE) { 217 Element elTemp = (Element ) node; 218 if(elTemp.getLocalName().equals("resourcetype")) { 219 if(elTemp.getChildNodes().getLength()>0 && elTemp.getFirstChild().getNodeType()==Node.ELEMENT_NODE) { 220 Element elType = (Element ) elTemp.getFirstChild(); 221 if(elType.getLocalName().equals("collection")) { 222 value.setResourceType(DAVDomainValue.COLLECTION); 223 } else if(elType.getLocalName().equals("property-resource")) { 224 value.setResourceType(DAVDomainValue.RESOURCE); 225 } else if(elType.getLocalName().equals("value")) { 226 value.setResourceType(DAVDomainValue.RESOURCE); 227 }else { 228 value.setResourceType(DAVDomainValue.RESOURCE); 229 } 230 } else { 231 value.setResourceType(DAVDomainValue.RESOURCE); 232 } 233 } else if(elTemp.getLocalName().equals("contentype")) { 234 if(elTemp.getChildNodes().getLength()>0 && elTemp.getFirstChild().getNodeType()==Node.TEXT_NODE) { 235 String sContentType = elTemp.getFirstChild().getNodeValue(); 236 value.addContentType(sContentType); 237 } 238 } else if(elTemp.getLocalName().equals("href")) { 239 if(elTemp.getChildNodes().getLength()>0 && elTemp.getFirstChild().getNodeType()==Node.TEXT_NODE) { 240 String sHREF = elTemp.getFirstChild().getNodeValue(); 241 value.setPath(sHREF); 242 } 243 } else if(elTemp.getLocalName().equals("maxOccurs")) { 244 if(elTemp.getChildNodes().getLength()>0 && elTemp.getFirstChild().getNodeType()==Node.TEXT_NODE) { 245 String sMaxOccurs = elTemp.getFirstChild().getNodeValue(); 246 value.setMaxOccurs( Integer.parseInt(sMaxOccurs) ); 247 } 248 } else if(elTemp.getLocalName().equals("minOccurs")) { 249 if(elTemp.getChildNodes().getLength()>0 && elTemp.getFirstChild().getNodeType()==Node.TEXT_NODE) { 250 String sMinOccurs = elTemp.getFirstChild().getNodeValue(); 251 value.setMinOccurs( Integer.parseInt(sMinOccurs) ); 252 } 253 } 254 } 255 256 } 257 } 258 259 } 260 | Popular Tags |