Skip to content

Commit c094b28

Browse files
author
pborissow
committed
- Added ability to create, update, and delete custom attributes (ExtendedProperty) for individual FolderItems.
- Added new constructors to the Contact and CalendarEvent classes to retrieve ExtendedProperty values. git-svn-id: svn://192.168.0.80/JavaXT/javaxt-exchange@367 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent c61460f commit c094b28

7 files changed

Lines changed: 543 additions & 55 deletions

File tree

src/javaxt/exchange/CalendarEvent.java

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,35 @@ public CalendarEvent(String title, String description, String location, Mailbox
8080
//**************************************************************************
8181
/** Creates a new instance of this class with an id
8282
*/
83-
public CalendarEvent(String exchangeID, Connection conn) throws ExchangeException{
84-
super(exchangeID, conn);
83+
public CalendarEvent(String exchangeID, Connection conn, ExtendedProperty[] AdditionalProperties) throws ExchangeException{
84+
super(exchangeID, conn, AdditionalProperties);
8585
parseCalendarItem();
8686
}
8787

88+
89+
//**************************************************************************
90+
//** Constructor
91+
//**************************************************************************
92+
/** Creates a new instance of this class with an id
93+
*/
94+
public CalendarEvent(String exchangeID, Connection conn) throws ExchangeException{
95+
this(exchangeID, conn, null);
96+
}
97+
98+
99+
//**************************************************************************
100+
//** Constructor
101+
//**************************************************************************
102+
/** Creates a new instance of this class using event information found in a
103+
* "*.ics" file (iCalendar Event).
104+
* http://en.wikipedia.org/wiki/ICalendar
105+
*/
106+
public CalendarEvent(String iCalendar) throws Exception{
107+
org.w3c.dom.Document xml = iCalToXML(iCalendar);
108+
throw new Exception("Not Implemented.");
109+
}
110+
111+
88112
//**************************************************************************
89113
//** Constructor
90114
//**************************************************************************
@@ -708,6 +732,16 @@ private String create(Connection conn) throws ExchangeException {
708732
msg.append("<t:ReminderMinutesBeforeStart>" + this.getReminder() + "</t:ReminderMinutesBeforeStart>");
709733
}
710734

735+
736+
//Add extended properties
737+
ExtendedProperty[] properties = this.getExtendedProperties();
738+
if (properties!=null){
739+
for (ExtendedProperty property : properties){
740+
msg.append(property.toXML("t", "create"));
741+
}
742+
}
743+
744+
711745
msg.append("<t:Start>" + formatDate(getStartTime()) + "</t:Start>");
712746
msg.append("<t:End>" + formatDate(getEndTime()) + "</t:End>");
713747

@@ -806,4 +840,65 @@ public void delete(Connection conn, boolean notify) throws ExchangeException {
806840
public String toString(){
807841
return this.getSubject();
808842
}
843+
844+
845+
//**************************************************************************
846+
//** iCalToXML
847+
//**************************************************************************
848+
/** Used to convert an iCalendar ICS File into an XML Document.
849+
*/
850+
private org.w3c.dom.Document iCalToXML(String iCalendar){
851+
StringBuffer str = new StringBuffer();
852+
java.util.ArrayList<String> nodes = new java.util.ArrayList<String>();
853+
String[] rows = iCalendar.split("\r\n");
854+
for (int i=0; i<rows.length; i++){
855+
String row = rows[i].trim();
856+
857+
//Special case for wrapped lines
858+
while (true){
859+
if (i+1>rows.length-1) break;
860+
String nextRow = rows[i+1];
861+
if (nextRow.trim().length()>0 && nextRow.startsWith(" ")){
862+
i++;
863+
row += nextRow.trim();
864+
}
865+
else{
866+
break;
867+
}
868+
}
869+
870+
if (row.contains(":")){
871+
String key = row.substring(0, row.indexOf(":")).trim();
872+
String value = row.substring(row.indexOf(":")+1).trim();
873+
String[] attr = new String[0];
874+
875+
if (key.contains(";")){
876+
attr = key.substring(key.indexOf(";")+1).split(";");
877+
key = key.substring(0, key.indexOf(";")).trim();
878+
}
879+
key = key.toLowerCase();
880+
881+
if (key.equals("begin")){
882+
nodes.add(key);
883+
str.append("<" + value.toLowerCase() + ">\r\n");
884+
}
885+
else if (key.equals("end")){
886+
nodes.remove(nodes.size()-1);
887+
str.append("</" + value.toLowerCase() + ">\r\n");
888+
}
889+
else{
890+
str.append("<" + key + ">");
891+
str.append(value);
892+
str.append("</" + key + ">\r\n");
893+
}
894+
895+
896+
}
897+
898+
899+
}
900+
901+
System.out.println(str);
902+
return null;
903+
}
809904
}

src/javaxt/exchange/Connection.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ public class Connection {
2222
/** Creates a new instance of Connection.
2323
* @param host URL to the Exchange Web Services (EWS) endpoint. The url
2424
* typically ends with "Exchange.asmx".
25-
* @param username
25+
* @param username Username. Typically this is an email address.
2626
* @param password
2727
*/
2828
public Connection(String host, String username, String password) {
2929
this.ews = host;
3030
this.username = username;
3131
this.password = password;
3232
}
33+
34+
public String getHost(){
35+
return ews;
36+
}
37+
38+
public String getUserName(){
39+
return username;
40+
}
3341

3442

3543
//**************************************************************************

src/javaxt/exchange/Contact.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,19 @@ public Contact(javaxt.exchange.Contact contact){
100100
//**************************************************************************
101101
/** Creates a new instance of this class
102102
*/
103-
public Contact(String exchangeID, Connection conn) throws ExchangeException{
104-
super(exchangeID, conn);
103+
public Contact(String exchangeID, Connection conn, ExtendedProperty[] AdditionalProperties) throws ExchangeException{
104+
super(exchangeID, conn, AdditionalProperties);
105105
parseContact();
106106
}
107107

108+
//**************************************************************************
109+
//** Constructor
110+
//**************************************************************************
111+
/** Creates a new instance of this class
112+
*/
113+
public Contact(String exchangeID, Connection conn) throws ExchangeException{
114+
this(exchangeID, conn, null);
115+
}
108116

109117
//**************************************************************************
110118
//** Constructor
@@ -1071,6 +1079,16 @@ private void create(Connection conn) throws ExchangeException {
10711079
msg.append("</t:Categories>");
10721080
}
10731081

1082+
1083+
//Add extended properties
1084+
ExtendedProperty[] properties = this.getExtendedProperties();
1085+
if (properties!=null){
1086+
for (ExtendedProperty property : properties){
1087+
msg.append(property.toXML("t", "create"));
1088+
}
1089+
}
1090+
1091+
10741092
msg.append("<t:FileAsMapping>LastCommaFirst</t:FileAsMapping>");
10751093
msg.append("<t:DisplayName>" + getFullName() + "</t:DisplayName>");
10761094
if (this.getFirstName()!=null) msg.append("<t:GivenName>" + firstName + "</t:GivenName>");
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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

Comments
 (0)