1+ package javaxt .exchange ;
2+
3+ //******************************************************************************
4+ //** ExtendedProperty Class
5+ //******************************************************************************
6+ /**
7+ * Used to represent a custom, extended property associated with a folder
8+ * item.
9+ *
10+ ******************************************************************************/
11+
12+ public class ExtendedProperty {
13+
14+ private String id ;
15+ private String name ;
16+ private String type = "String" ;
17+ private String value ;
18+
19+
20+ //**************************************************************************
21+ //** Constructor
22+ //**************************************************************************
23+ /** Creates a new instance of this class.
24+ * @param id A unique id in the form of a Microsoft GUID
25+ */
26+ public ExtendedProperty (String id , String name , String value ){
27+ this .id = id ;
28+ this .name = name ;
29+ this .value = value ;
30+ }
31+
32+
33+
34+ //**************************************************************************
35+ //** Constructor
36+ //**************************************************************************
37+ /** Creates a new instance of this class.
38+ * @param node "ExtendedProperty" node
39+ */
40+ public ExtendedProperty (org .w3c .dom .Node node ){
41+
42+ org .w3c .dom .NodeList childNodes = node .getChildNodes ();
43+ for (int j =0 ; j <childNodes .getLength (); j ++){
44+ org .w3c .dom .Node childNode = childNodes .item (j );
45+ if (childNode .getNodeType ()==1 ){
46+
47+ String childNodeName = childNode .getNodeName ();
48+ if (childNodeName .contains (":" )) childNodeName = childNodeName .substring (childNodeName .indexOf (":" )+1 );
49+
50+ if (childNodeName .equalsIgnoreCase ("ExtendedFieldURI" )){
51+ name = javaxt .xml .DOM .getAttributeValue (childNode , "PropertyName" );
52+ type = javaxt .xml .DOM .getAttributeValue (childNode , "PropertyType" );
53+ id = javaxt .xml .DOM .getAttributeValue (childNode , "PropertySetId" );
54+
55+ String PropertyTag = javaxt .xml .DOM .getAttributeValue (childNode , "PropertyTag" );
56+ if (PropertyTag .length ()>0 ) name = PropertyTag ;
57+ }
58+ else if (childNodeName .equalsIgnoreCase ("Value" )){
59+ value = javaxt .xml .DOM .getNodeValue (childNode );
60+ }
61+ }
62+ }
63+ }
64+
65+ /** Returns the guid associated with this property. */
66+ public String getID (){
67+ return id ;
68+ }
69+
70+ public String getName (){
71+ return name ;
72+ }
73+
74+ public String getType (){
75+ return type ;
76+ }
77+
78+ public String getValue (){
79+ return value ;
80+ }
81+
82+ public void setValue (String value ){
83+ this .value = value ;
84+ }
85+
86+
87+ //**************************************************************************
88+ //** toXML
89+ //**************************************************************************
90+ /** Returns an xml fragment used to save or update an ExtendedProperty via
91+ * Exchange Web Services (EWS):<br/>
92+ * http://msdn.microsoft.com/en-us/library/exchange/dd633654%28v=exchg.80%29
93+ *
94+ * @param namespace The namespace assigned to the "type". Typically this is
95+ * "t" which corresponds to
96+ * "http://schemas.microsoft.com/exchange/services/2006/types".
97+ * Use a null value is you do not wish to append a namespace.
98+ *
99+ * @param operation String used to specify whether to return an xml
100+ * formatted for inserts, updates or deletes. Valid
101+ */
102+ protected String toXML (String namespace , String operation ){
103+
104+ //Update namespace prefix
105+ if (namespace !=null ){
106+ if (!namespace .endsWith (":" )) namespace +=":" ;
107+ }
108+ else {
109+ namespace = "" ;
110+ }
111+
112+ StringBuffer xml = new StringBuffer ();
113+ if (operation .equalsIgnoreCase ("create" )){
114+ xml .append ("<" + namespace + "ExtendedProperty>" );
115+ xml .append ("<" + namespace + "ExtendedFieldURI PropertySetId=\" " + id + "\" PropertyName=\" " + name + "\" PropertyType=\" " + type + "\" />" );
116+ xml .append ("<" + namespace + "Value>" + value + "</" + namespace + "Value>" );
117+ xml .append ("</" + namespace + "ExtendedProperty>" );
118+ }
119+ else if (operation .equalsIgnoreCase ("update" )){
120+ xml .append ("<" + namespace + "SetItemField>" );
121+ xml .append ("<" + namespace + "ExtendedFieldURI PropertySetId=\" " + id + "\" PropertyName=\" " + name + "\" PropertyType=\" " + type + "\" />" );
122+ xml .append ("<" + namespace + "Message>" );
123+ xml .append ("<" + namespace + "ExtendedProperty>" );
124+ xml .append ("<" + namespace + "ExtendedFieldURI PropertySetId=\" " + id + "\" PropertyName=\" " + name + "\" PropertyType=\" " + type + "\" />" );
125+ xml .append ("<" + namespace + "Value>" + value + "</" + namespace + "Value>" );
126+ xml .append ("</" + namespace + "ExtendedProperty>" );
127+ xml .append ("</" + namespace + "Message>" );
128+ xml .append ("</" + namespace + "SetItemField>" );
129+ }
130+ else if (operation .equalsIgnoreCase ("delete" )){
131+ xml .append ("<" + namespace + "DeleteItemField>" );
132+ xml .append ("<" + namespace + "ExtendedFieldURI PropertySetId=\" " + id + "\" PropertyName=\" " + name + "\" PropertyType=\" " + type + "\" />" );
133+ xml .append ("</" + namespace + "DeleteItemField>" );
134+ }
135+
136+ return xml .toString ();
137+ }
138+
139+
140+ public String toString (){
141+ return name + ": " + value ;
142+ }
143+
144+ public int hashCode (){
145+ return name .toUpperCase ().hashCode ();
146+ }
147+
148+ public boolean equals (Object obj ){
149+ if (obj instanceof ExtendedProperty ){
150+ ExtendedProperty property = (ExtendedProperty ) obj ;
151+ return (property .id .equalsIgnoreCase (this .id ) && property .value .equals (this .value ));
152+ }
153+ return false ;
154+ }
155+ }
0 commit comments