KickJava   Java API By Example, From Geeks To Geeks.

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


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 date and time value implementation.
36  *
37  * @author Matthew Large
38  * @version $Revision: 1.1 $
39  *
40  */

41 public class DAVDateTimeValue extends DateTimeValue {
42
43     /**
44      * Constructs a new WebDAV date and time value.
45      *
46      * @param sValue Value
47      */

48     public DAVDateTimeValue(String JavaDoc sValue) {
49         super(sValue);
50     }
51
52     /**
53      *
54      */

55     public DAVDateTimeValue() {
56         super();
57     }
58     
59     /**
60      * Publishes WebDAV date and time values to a XML element.
61      *
62      * @param xmlDoc Owning XML document
63      * @param propEl Element to append to
64      * @param aValues List of {@link DAVDateTimeValue} objects
65      */

66     public static void toXML(Document JavaDoc xmlDoc, Element JavaDoc propEl, List JavaDoc aValues) {
67         if(aValues.size()==1) {
68             Text JavaDoc txt = xmlDoc.createTextNode( ((DAVDateTimeValue)aValues.get(0)).getValue() );
69             propEl.appendChild(txt);
70         } else if(aValues.size()>1) {
71             propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "type", "Array" );
72             propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "arraySize", Integer.toString(aValues.size()) );
73             propEl.setAttributeNS(NamespaceType.SOAP_ENCODING.getURI(), "itemType", NamespaceType.XML_SCHEMA.getPrefix()+":dateTime");
74             Iterator JavaDoc itor = aValues.iterator();
75             while (itor.hasNext()) {
76                 DAVDateTimeValue val = (DAVDateTimeValue) itor.next();
77                 Element JavaDoc arrayEl = xmlDoc.createElementNS(NamespaceType.XML_SCHEMA.getURI(), "dateTime");
78                 Text JavaDoc txt = xmlDoc.createTextNode( val.getValue() );
79                 arrayEl.appendChild(txt);
80                 propEl.appendChild(arrayEl);
81             }
82         }
83     }
84     
85     /**
86      * Populates a property instance with WebDAV date and time values from
87      * XML.
88      *
89      * @param propInst Property instance to populate
90      * @param propEl Root element of property instance
91      */

92     public static void fromXML(PropertyInstance propInst, Element JavaDoc propEl) {
93         if(propEl.getChildNodes().getLength()==1) {
94             Text JavaDoc txt = (Text JavaDoc) propEl.getFirstChild();
95             if(txt!=null) {
96                 DAVDateTimeValue val = (DAVDateTimeValue) propInst.getNewValueInstance();
97                 val.setValue( txt.getData() );
98                 propInst.addValueWithoutFiringVirtualFileEvent(val);
99             }
100         } else if(propEl.getChildNodes().getLength()>1) {
101             NodeList JavaDoc nl = propEl.getChildNodes();
102             for (int i = 0; i < nl.getLength(); i++) {
103                 Node JavaDoc node = nl.item(i);
104                 if(node.getNodeType()==Node.ELEMENT_NODE) {
105                     Text JavaDoc txt = (Text JavaDoc) node.getFirstChild();
106                     if(txt!=null) {
107                         DAVDateTimeValue val = (DAVDateTimeValue) propInst.getNewValueInstance();
108                         val.setValue( txt.getData() );
109                         propInst.addValueWithoutFiringVirtualFileEvent(val);
110                     }
111                 }
112             }
113         }
114     }
115
116 }
117
Popular Tags