KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > webdav > client > value > DAVResourceValue


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.webdav.client.value;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
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 JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30 import org.w3c.dom.NodeList JavaDoc;
31 import org.w3c.dom.Text JavaDoc;
32
33
34 /**
35  * WebDAV resource relationship value implementation.
36  *
37  * @author Matthew Large
38  * @version $Revision: 1.1 $
39  *
40  */

41 public class DAVResourceValue extends ResourceValue {
42
43     /**
44      *
45      */

46     public DAVResourceValue() {
47         super();
48     }
49     
50     /**
51     * Publishes WebDAV resource relationship values to a XML element.
52     *
53     * @param xmlDoc Owning XML document
54     * @param propEl Element to append to
55     * @param aValues List of {@link DAVBooleanValue} objects
56     */

57     public static void toXML(Document JavaDoc xmlDoc, Element JavaDoc propEl, List JavaDoc aValues) {
58         if(aValues.size()==1) {
59             Element JavaDoc hrefEl = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "href");
60             propEl.appendChild(hrefEl);
61             Text JavaDoc 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 JavaDoc itor = aValues.iterator();
68             while (itor.hasNext()) {
69                 DAVResourceValue val = (DAVResourceValue) itor.next();
70                 Element JavaDoc arrayEl = xmlDoc.createElementNS(NamespaceType.DAV.getURI(), "href");
71                 Text JavaDoc txt = xmlDoc.createTextNode( val.getValue() );
72                 arrayEl.appendChild(txt);
73                 propEl.appendChild(arrayEl);
74             }
75         }
76     }
77     
78     /**
79      * Populates a property instance with WebDAV resource relationship values from
80      * XML.
81      *
82      * @param propInst Property instance to populate
83      * @param propEl Root element of property instance
84      */

85     public static void fromXML(PropertyInstance propInst, Element JavaDoc propEl) {
86         if(propEl.getChildNodes().getLength()==1) {
87             Element JavaDoc elHREF = (Element JavaDoc) propEl.getFirstChild();
88             Text JavaDoc txt = (Text JavaDoc) 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 JavaDoc nl = propEl.getChildNodes();
96             for (int i = 0; i < nl.getLength(); i++) {
97                 Node JavaDoc node = nl.item(i);
98                 if(node.getNodeType()==Node.ELEMENT_NODE) {
99                     Text JavaDoc txt = (Text JavaDoc) 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