diff options
author | fmantek <fmantek@google.com> | 2009-07-10 16:03:16 +0200 |
---|---|---|
committer | fmantek <fmantek@google.com> | 2009-07-15 19:37:02 +0200 |
commit | be301ed85eb8d8c36bfb75cc3478583dd69bb338 (patch) | |
tree | 2adbe7a83e3fc38c048c3b83985361181f943989 | |
parent | 8f1cdc5e7f74b4eb73e485e60b76b87cc2782e51 (diff) | |
download | gdata-be301ed85eb8d8c36bfb75cc3478583dd69bb338.tar.gz |
Squashed commit of the following:
Parser for contacts v3. Added XmlNametable....
Changed minor details per feedback
fixed a compile issue for j2me
commit 5ac7e9105a5ba27e54d0d1388d4fab21eae29240
Author: fmantek <fmantek@google.com>
Date: Thu Jul 9 15:58:31 2009 +0200
Modified parsing code
Added nametables etc
commit 15a906c834a34bf4f13621ee3287d39404df798a
Author: fmantek <fmantek@google.com>
Date: Thu Jul 9 15:57:29 2009 +0200
changed jot.java to Jot.java
commit 0c704e0e4e5958889e3e98d29d000d7030db5e87
Author: fmantek <fmantek@google.com>
Date: Thu Jul 9 15:55:35 2009 +0200
Parser changes.
11 files changed, 653 insertions, 324 deletions
diff --git a/src/com/google/wireless/gdata2/contacts/data/ContactEntry.java b/src/com/google/wireless/gdata2/contacts/data/ContactEntry.java index 8edc878..27e2bcc 100644 --- a/src/com/google/wireless/gdata2/contacts/data/ContactEntry.java +++ b/src/com/google/wireless/gdata2/contacts/data/ContactEntry.java @@ -2,14 +2,14 @@ package com.google.wireless.gdata2.contacts.data; +import java.util.Enumeration; +import java.util.Vector; + import com.google.wireless.gdata2.data.Entry; import com.google.wireless.gdata2.data.ExtendedProperty; import com.google.wireless.gdata2.data.StringUtils; import com.google.wireless.gdata2.parser.ParseException; -import java.util.Vector; -import java.util.Enumeration; - /** * Entry containing information about a contact. */ @@ -44,10 +44,22 @@ public class ContactEntry extends Entry { private String mileage; private String nickname; private String occupation; - private String priority; - private String sensitivity; private String shortName; private String subject; + private String birthday; + private String billingInformation; + + public static final byte TYPE_PRIORITY_HIGH = 1; + public static final byte TYPE_PRIORITY_NORMAL = 2; + public static final byte TYPE_PRIORITY_LOW = 3; + private Byte priority; + + public static final byte TYPE_SENSITIVITY_CONFIDENTIAL = 1; + public static final byte TYPE_SENSITIVITY_NORMAL = 2; + public static final byte TYPE_SENSITIVITY_PERSONAL = 3; + public static final byte TYPE_SENSITIVITY_PRIVATE = 4; + private Byte sensitivity; + private Name name; /** @@ -199,7 +211,7 @@ public class ContactEntry extends Entry { /** * Adds a new member to the Jot collection */ - public void addJot(String jot) { + public void addJot(Jot jot) { jots.addElement(jot); } @@ -360,22 +372,22 @@ public class ContactEntry extends Entry { /** * Priority associated with this Contact */ - public String getPriority() { + public Byte getPriority() { return this.priority; } /** * Priority associated with this Contact */ - public void setPriority(String prority) { - this.priority = prority; + public void setPriority(Byte type) { + this.priority = priority; } /** * Specifies contact's sensitivity. Can be either confidential, * normal, personal or private. */ - public String getSensitivity() { + public Byte getSensitivity() { return this.sensitivity; } @@ -383,7 +395,7 @@ public class ContactEntry extends Entry { * Specifies contact's sensitivity. Can be either confidential, * normal, personal or private. */ - public void setSensitivity(String sensitiviy) { + public void setSensitivity(Byte sensitiviy) { this.sensitivity = sensitiviy; } @@ -428,6 +440,34 @@ public class ContactEntry extends Entry { public void setName(Name name) { this.name = name; } + + /** + * Birthday associated with this Contact + */ + public String getBirthday() { + return this.birthday; + } + + /** + * Birthday associated with this Contact + */ + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + /** + * BillingInformation associated with this Contact + */ + public String getBillingInformation() { + return this.billingInformation; + } + + /** + * BillingInformation associated with this Contact + */ + public void setBillingInformation(String billingInformation) { + this.billingInformation = billingInformation; + } /* * (non-Javadoc) @@ -503,12 +543,10 @@ public class ContactEntry extends Entry { if (!StringUtils.isEmpty(occupation)) { sb.append(" occupaton:").append(occupation); } - if (!StringUtils.isEmpty(priority)) { - sb.append(" priority:").append(priority); - } - if (!StringUtils.isEmpty(sensitivity)) { - sb.append(" sensitivity:").append(sensitivity); - } + sb.append(" priority:").append(priority); + + sb.append(" sensitivity:").append(sensitivity); + if (!StringUtils.isEmpty(shortName)) { sb.append(" shortName:").append(shortName); } diff --git a/src/com/google/wireless/gdata2/contacts/data/ContactsElement.java b/src/com/google/wireless/gdata2/contacts/data/ContactsElement.java index 0897822..26e8410 100644 --- a/src/com/google/wireless/gdata2/contacts/data/ContactsElement.java +++ b/src/com/google/wireless/gdata2/contacts/data/ContactsElement.java @@ -9,12 +9,7 @@ import com.google.wireless.gdata2.parser.ParseException; /** * Contains attributes that are common to all elements in a ContactEntry. */ -public abstract class ContactsElement { - public static final byte TYPE_NONE = -1; - private byte type = TYPE_NONE; - - private String label; - +public abstract class ContactsElement extends TypedElement { private boolean isPrimary; public boolean isPrimary() { @@ -25,37 +20,8 @@ public abstract class ContactsElement { isPrimary = primary; } - public byte getType() { - return type; - } - - public void setType(byte rel) { - this.type = rel; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - public void toString(StringBuffer sb) { - sb.append(" type:").append(type); + super.toString(sb); sb.append(" isPrimary:").append(isPrimary); - if (label != null) sb.append(" label:").append(label); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - toString(sb); - return sb.toString(); - } - - public void validate() throws ParseException { - if ((label == null && type == TYPE_NONE) || (label != null && type != TYPE_NONE)) { - throw new ParseException("exactly one of label or type must be set"); - } } } diff --git a/src/com/google/wireless/gdata2/contacts/data/Event.java b/src/com/google/wireless/gdata2/contacts/data/Event.java index fae86f7..fc0df68 100644 --- a/src/com/google/wireless/gdata2/contacts/data/Event.java +++ b/src/com/google/wireless/gdata2/contacts/data/Event.java @@ -14,10 +14,10 @@ import com.google.wireless.gdata2.parser.ParseException; * These elements describe events associated with a contact. * They may be repeated. */ -public class Event { - - private String label; - private String type; +public class Event extends TypedElement { + public static final byte TYPE_ANNIVERSARY = 1; + public static final byte TYPE_OTHER = 2; + private String startDate; /** @@ -25,78 +25,23 @@ public class Event { */ public Event() {} - - /** - * A simple string value used to name this event. It allows UIs to - * display a label such as "Start Date". May not be empty or all - * whitespace. - */ - public String getLabel() { - return this.label; - } - - /** - * A simple string value used to name this event. It allows UIs to - * display a label such as "Start Date". May not be empty or all - * whitespace. - */ - public void setLabel(String label) { - this.label = label; - } - - /** - * A programmatic value that identifies the type of event. - */ - public String getType() { - return this.type; - } - - /** - * A programmatic value that identifies the type of event. - */ - public void setType(String type) { - this.type = type; - } - /** - * Contacts supports an xs:date value here - * Describes when the event starts. + * StartDate associated with this event */ public String getStartDate() { return this.startDate; } /** - * Contacts supports an xs:date value here - * Describes when the event starts. + * StartDate associated with this event */ public void setStartDate(String startDate) { this.startDate = startDate; } - public String toString() { - StringBuffer sb = new StringBuffer(); - toString(sb); - return sb.toString(); - } - - public void toString(StringBuffer sb) { - sb.append("ExternalId"); + super.toString(sb); sb.append(" date:").append(startDate.toString()); - if (!StringUtils.isEmpty(label)) { - sb.append(" label:").append(label); - } - if (!StringUtils.isEmpty(type)) { - sb.append(" type:").append(type); - } - } - - /** - * Currently empty, will be filled when the parser is done - * - */ - public void validate() throws ParseException { } } diff --git a/src/com/google/wireless/gdata2/contacts/data/ExternalId.java b/src/com/google/wireless/gdata2/contacts/data/ExternalId.java index 4840b04..25c124a 100644 --- a/src/com/google/wireless/gdata2/contacts/data/ExternalId.java +++ b/src/com/google/wireless/gdata2/contacts/data/ExternalId.java @@ -11,11 +11,14 @@ import com.google.wireless.gdata2.data.StringUtils; * Describes an ID of the contact in an external system of some * kind. This element may be repeated.. */ -public class ExternalId { - - private String label; +public class ExternalId extends TypedElement { + public static final byte TYPE_ACCOUNT = 1; + public static final byte TYPE_CUSTOMER = 2; + public static final byte TYPE_NETWORK = 3; + public static final byte TYPE_ORGANIZATION = 4; + + private String value; - private String type; /** * default empty constructor @@ -23,34 +26,6 @@ public class ExternalId { public ExternalId() {} /** - * A simple string value used to name this ID. - */ - public String getLabel() { - return this.label; - } - - /** - * A simple string value used to name this ID. - */ - public void setLabel(String label) { - this.label = label; - } - - /** - * A programmatic value that identifies the type of external ID - */ - public String getType() { - return this.type; - } - - /** - * A programmatic value that identifies the type of external ID - */ - public void setRel(String type) { - this.type = type; - } - - /** * The value of this external ID. */ public String getValue() { @@ -64,31 +39,11 @@ public class ExternalId { this.value = value; } - public String toString() { - StringBuffer sb = new StringBuffer(); - toString(sb); - return sb.toString(); - } - - public void toString(StringBuffer sb) { - sb.append("ExternalId"); - if (!StringUtils.isEmpty(type)) { - sb.append(" type:").append(type); - } + super.toString(sb); if (!StringUtils.isEmpty(value)) { sb.append(" value:").append(value); - } - if (!StringUtils.isEmpty(label)) { - sb.append(" label:").append(label); - } } - - /** - * Currently empty, will be filled when the parser is done - * - */ - public void validate() throws ParseException { } } diff --git a/src/com/google/wireless/gdata2/contacts/data/Jot.java b/src/com/google/wireless/gdata2/contacts/data/Jot.java new file mode 100644 index 0000000..619e2e4 --- /dev/null +++ b/src/com/google/wireless/gdata2/contacts/data/Jot.java @@ -0,0 +1,25 @@ +/** + * Copyright (C) 2009 The Android Open Source Project + */ +package com.google.wireless.gdata2.contacts.data; + +import com.google.wireless.gdata2.parser.ParseException; + + +/** + * Storage for arbitrary pieces of information about the + * contact. Each jot has a type specified by the rel attribute + * and a text value. The element can be repeated. + */ +public class Jot extends TypedElement { + public static final byte TYPE_HOME = 1; + public static final byte TYPE_WORK = 2; + public static final byte TYPE_KEYWORDS = 3; + public static final byte TYPE_USER = 4; + public static final byte TYPE_OTHER = 5; + + /** + * default empty constructor + */ + public Jot() {} +} diff --git a/src/com/google/wireless/gdata2/contacts/data/Name.java b/src/com/google/wireless/gdata2/contacts/data/Name.java index f7c0419..37ece2a 100644 --- a/src/com/google/wireless/gdata2/contacts/data/Name.java +++ b/src/com/google/wireless/gdata2/contacts/data/Name.java @@ -27,14 +27,14 @@ public class Name { /** * Getter for givenName, Person's given name. */ - public String getGiveName() { + public String getGivenName() { return this.givenName; } /** * Setter for givenName, Person's given name. */ - public void setGiveName(String givenName) { + public void setGivenName(String givenName) { this.givenName = givenName; } @@ -42,7 +42,7 @@ public class Name { * Getter for addtionalName, Additional name of the person, eg. * middle name. */ - public String getAddtionalName() { + public String getAdditionalName() { return this.additionalName; } @@ -50,7 +50,7 @@ public class Name { * Setter for addtionalName, Additional name of the person, eg. * middle name. */ - public void setAddtionalName(String addtionalName) { + public void setAdditionalName(String addtionalName) { this.additionalName = addtionalName; } @@ -113,14 +113,14 @@ public class Name { /** * Getter for addtionalNameYomi, Phonetic representation */ - public String getAdditonalNameYomi() { + public String getAdditionalNameYomi() { return this.additionalNameYomi; } /** * Setter for addtionalNameYomi, Phonetic representation */ - public void setAdditonalNameYomi(String addtionalNameYomi) { + public void setAdditionalNameYomi(String addtionalNameYomi) { this.additionalNameYomi = addtionalNameYomi; } diff --git a/src/com/google/wireless/gdata2/contacts/data/Relation.java b/src/com/google/wireless/gdata2/contacts/data/Relation.java index dd444c1..10ab8e5 100644 --- a/src/com/google/wireless/gdata2/contacts/data/Relation.java +++ b/src/com/google/wireless/gdata2/contacts/data/Relation.java @@ -9,18 +9,25 @@ import com.google.wireless.gdata2.data.StringUtils; /** - * Specifies the preferred languages of the contact. The element - * can be repeated.* The language must be specified using one of - * two mutually exclusive methods: using the freeform label - * attribute, or using the code attribute, whose value must - * conform to the IETF BCP 47 specification. Describes an ID of - * the contact in an external system of some kind. This element - * may be repeated.. + * This element describe another entity (usually a person) + * that is in a relation of some kind with the contact */ -public class Relation { - - private String label; - private String type; +public class Relation extends TypedElement { + public static final byte TYPE_ASSISTANT = 1; + public static final byte TYPE_BROTHER = 2; + public static final byte TYPE_CHILD = 3; + public static final byte TYPE_DOMESTICPARTNER = 4; + public static final byte TYPE_FATHER = 5; + public static final byte TYPE_FRIEND = 6; + public static final byte TYPE_MANAGER = 7; + public static final byte TYPE_MOTHER = 8; + public static final byte TYPE_PARENT = 9; + public static final byte TYPE_PARTNER = 10; + public static final byte TYPE_REFERREDBY = 11; + public static final byte TYPE_RELATIVE = 12; + public static final byte TYPE_SISTER = 13; + public static final byte TYPE_SPOUSE = 14; + private String text; /** @@ -28,37 +35,9 @@ public class Relation { */ public Relation() {} - /** - * A simple string value used to name this relation. - * The value must not be empty or all whitespace - */ - public String getLabel() { - return this.label; - } - - /** - * A simple string value used to name this relation. - * The value must not be empty or all whitespace - */ - public void setLabel(String label) { - this.label = label; - } - - /** - * A programmatic value that identifies the type of relation. - */ - public String getType() { - return this.type; - } + /** - * A programmatic value that identifies the type of relation. - */ - public void setType(String type) { - this.type = type; - } - - /** * The entity in relation with the contact. */ public String getText() { @@ -73,31 +52,11 @@ public class Relation { } - public String toString() { - StringBuffer sb = new StringBuffer(); - toString(sb); - return sb.toString(); - } - - - public void toString(StringBuffer sb) { - sb.append("ExternalId"); + public void toString(StringBuffer sb) { + super.toString(sb); if (!StringUtils.isEmpty(text)) { sb.append(" text:").append(text); } - if (!StringUtils.isEmpty(label)) { - sb.append(" label:").append(label); - } - if (!StringUtils.isEmpty(type)) { - sb.append(" type:").append(type); - } - } - - /** - * Currently empty, will be filled when the parser is done - * - */ - public void validate() throws ParseException { } } diff --git a/src/com/google/wireless/gdata2/contacts/data/TypedElement.java b/src/com/google/wireless/gdata2/contacts/data/TypedElement.java new file mode 100644 index 0000000..bb37e93 --- /dev/null +++ b/src/com/google/wireless/gdata2/contacts/data/TypedElement.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2009 The Android Open Source Project + */ +package com.google.wireless.gdata2.contacts.data; + +import com.google.wireless.gdata2.parser.ParseException; + + +/** + * Contains attributes that are common to all elements in a ContactEntry. + */ +public abstract class TypedElement { + public static final byte TYPE_NONE = -1; + private byte type = TYPE_NONE; + + private String label; + + public byte getType() { + return type; + } + + public void setType(byte rel) { + this.type = rel; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public void toString(StringBuffer sb) { + sb.append(" type:").append(type); + if (label != null) sb.append(" label:").append(label); + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + toString(sb); + return sb.toString(); + } + + public void validate() throws ParseException { + if ((label == null && type == TYPE_NONE) || (label != null && type != TYPE_NONE)) { + throw new ParseException("exactly one of label or type must be set"); + } + } +} diff --git a/src/com/google/wireless/gdata2/contacts/data/WebSite.java b/src/com/google/wireless/gdata2/contacts/data/WebSite.java index 3fef9de..35800f0 100644 --- a/src/com/google/wireless/gdata2/contacts/data/WebSite.java +++ b/src/com/google/wireless/gdata2/contacts/data/WebSite.java @@ -10,7 +10,7 @@ import com.google.wireless.gdata2.data.StringUtils; */ public class WebSite extends ContactsElement { /** The phone number type. */ - public static final byte TYPE_HOME_PAGE = 1; + public static final byte TYPE_HOMEPAGE = 1; public static final byte TYPE_BLOG = 2; public static final byte TYPE_PROFILE = 3; public static final byte TYPE_HOME = 4; diff --git a/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java b/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java index c6901f9..62e8259 100644 --- a/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java +++ b/src/com/google/wireless/gdata2/contacts/parser/xml/XmlContactsGDataParser.java @@ -1,31 +1,23 @@ -// Copyright 2007 The Android Open Source Project +// Copyright 2009 The Android Open Source Project package com.google.wireless.gdata2.contacts.parser.xml; -import com.google.wireless.gdata2.contacts.data.ContactEntry; -import com.google.wireless.gdata2.contacts.data.ContactsElement; -import com.google.wireless.gdata2.contacts.data.ContactsFeed; -import com.google.wireless.gdata2.contacts.data.EmailAddress; -import com.google.wireless.gdata2.contacts.data.ImAddress; -import com.google.wireless.gdata2.contacts.data.Organization; -import com.google.wireless.gdata2.contacts.data.PhoneNumber; -import com.google.wireless.gdata2.contacts.data.StructuredPostalAddress; -import com.google.wireless.gdata2.contacts.data.GroupMembershipInfo; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Hashtable; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import com.google.wireless.gdata2.contacts.data.*; import com.google.wireless.gdata2.data.Entry; +import com.google.wireless.gdata2.data.ExtendedProperty; import com.google.wireless.gdata2.data.Feed; import com.google.wireless.gdata2.data.XmlUtils; -import com.google.wireless.gdata2.data.ExtendedProperty; import com.google.wireless.gdata2.parser.ParseException; import com.google.wireless.gdata2.parser.xml.XmlGDataParser; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Hashtable; -import java.util.Enumeration; - /** * GDataParser for a contacts feed. */ @@ -74,6 +66,55 @@ public class XmlContactsGDataParser extends XmlGDataParser { public static final String IM_PROTOCOL_JABBER = GD_NAMESPACE + "JABBER"; public static final String IM_PROTOCOL_NETMEETING = GD_NAMESPACE + "netmeeting"; + public static final String TYPESTRING_CALENDARLINK_HOME = "home"; + public static final String TYPESTRING_CALENDARLINK_WORK = "work"; + public static final String TYPESTRING_CALENDARLINK_FREEBUSY = "free-busy"; + + public static final String TYPESTRING_EVENT_ANNIVERARY = "anniversary"; + public static final String TYPESTRING_EVENT_OTHER = "other"; + + public static final String TYPESTRING_EXTERNALID_ACCOUNT = "account"; + public static final String TYPESTRING_EXTERNALID_CUSTOMER = "customer"; + public static final String TYPESTRING_EXTERNALID_NETWORK = "network"; + public static final String TYPESTRING_EXTERNALID_ORGANIZATION = "organization"; + + public static final String TYPESTRING_JOT_HOME = TYPESTRING_CALENDARLINK_HOME; + public static final String TYPESTRING_JOT_WORK = TYPESTRING_CALENDARLINK_WORK; + public static final String TYPESTRING_JOT_OTHER = TYPESTRING_EVENT_OTHER; + public static final String TYPESTRING_JOT_KEYWORDS = "keywords"; + public static final String TYPESTRING_JOT_USER = "user"; + + public static final String TYPESTRING_PRIORITY_HIGH = "high"; + public static final String TYPESTRING_PRIORITY_LOW = "low"; + public static final String TYPESTRING_PRIORITY_NORMAL = "normal"; + + public static final String TYPESTRING_RELATION_ASSISTANT = "assistant"; + public static final String TYPESTRING_RELATION_BROTHER = "brother"; + public static final String TYPESTRING_RELATION_CHILD = "child"; + public static final String TYPESTRING_RELATION_DOMESTICPARTNER = "domestic-partner"; + public static final String TYPESTRING_RELATION_FATHER = "father"; + public static final String TYPESTRING_RELATION_FRIEND = "friend"; + public static final String TYPESTRING_RELATION_MANAGER = "manager"; + public static final String TYPESTRING_RELATION_MOTHER = "mother"; + public static final String TYPESTRING_RELATION_PARENT = "parent"; + public static final String TYPESTRING_RELATION_PARTNER = "partner"; + public static final String TYPESTRING_RELATION_REFERREDBY = "referred-by"; + public static final String TYPESTRING_RELATION_RELATIVE = "relative"; + public static final String TYPESTRING_RELATION_SISTER = "sister"; + public static final String TYPESTRING_RELATION_SPOUSE = "spouse"; + + public static final String TYPESTRING_SENSITIVITY_CONFIDENTIAL = "confidential"; + public static final String TYPESTRING_SENSITIVITY_NORMAL = "normal"; + public static final String TYPESTRING_SENSITIVITY_PERSONAL = "personal"; + public static final String TYPESTRING_SENSITIVITY_PRIVATE = "private"; + + public static final String TYPESTRING_WEBSITE_HOMEPAGE = "home-page"; + public static final String TYPESTRING_WEBSITE_BLOG = "blog"; + public static final String TYPESTRING_WEBSITE_PROFILE = "profile"; + public static final String TYPESTRING_WEBSITE_HOME = TYPESTRING_CALENDARLINK_HOME; + public static final String TYPESTRING_WEBSITE_WORK = TYPESTRING_CALENDARLINK_WORK; + public static final String TYPESTRING_WEBSITE_OTHER = TYPESTRING_EVENT_OTHER; + public static final String TYPESTRING_WEBSITE_FTP = "ftp"; private static final Hashtable REL_TO_TYPE_EMAIL; private static final Hashtable REL_TO_TYPE_PHONE; @@ -81,6 +122,14 @@ public class XmlContactsGDataParser extends XmlGDataParser { private static final Hashtable REL_TO_TYPE_IM; private static final Hashtable REL_TO_TYPE_ORGANIZATION; private static final Hashtable IM_PROTOCOL_STRING_TO_TYPE_MAP; + private static final Hashtable REL_TO_TYPE_CALENDARLINK; + private static final Hashtable REL_TO_TYPE_EVENT; + private static final Hashtable REL_TO_TYPE_EXTERNALID; + private static final Hashtable REL_TO_TYPE_JOT; + private static final Hashtable REL_TO_TYPE_PRIORITY; + private static final Hashtable REL_TO_TYPE_RELATION; + private static final Hashtable REL_TO_TYPE_SENSITIVITY; + private static final Hashtable REL_TO_TYPE_WEBSITE; public static final Hashtable TYPE_TO_REL_EMAIL; public static final Hashtable TYPE_TO_REL_PHONE; @@ -88,6 +137,14 @@ public class XmlContactsGDataParser extends XmlGDataParser { public static final Hashtable TYPE_TO_REL_IM; public static final Hashtable TYPE_TO_REL_ORGANIZATION; public static final Hashtable IM_PROTOCOL_TYPE_TO_STRING_MAP; + public static final Hashtable TYPE_TO_REL_CALENDARLINK; + public static final Hashtable TYPE_TO_REL_EVENT; + public static final Hashtable TYPE_TO_REL_EXTERNALID; + public static final Hashtable TYPE_TO_REL_JOT; + public static final Hashtable TYPE_TO_REL_PRIORITY; + public static final Hashtable TYPE_TO_REL_RELATION; + public static final Hashtable TYPE_TO_REL_SENSITIVITY; + public static final Hashtable TYPE_TO_REL_WEBSITE; static { Hashtable map; @@ -96,8 +153,6 @@ public class XmlContactsGDataParser extends XmlGDataParser { map.put(TYPESTRING_HOME, new Byte(EmailAddress.TYPE_HOME)); map.put(TYPESTRING_WORK, new Byte(EmailAddress.TYPE_WORK)); map.put(TYPESTRING_OTHER, new Byte(EmailAddress.TYPE_OTHER)); - // TODO: this is a hack to support the old feed - map.put(GD_NAMESPACE + "primary", new Byte((byte) 4)); REL_TO_TYPE_EMAIL = map; TYPE_TO_REL_EMAIL = swapMap(map); @@ -156,6 +211,86 @@ public class XmlContactsGDataParser extends XmlGDataParser { IM_PROTOCOL_STRING_TO_TYPE_MAP = map; IM_PROTOCOL_TYPE_TO_STRING_MAP = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_CALENDARLINK_HOME, new Byte(CalendarLink.TYPE_HOME)); + map.put(TYPESTRING_CALENDARLINK_WORK, new Byte(CalendarLink.TYPE_WORK)); + map.put(TYPESTRING_CALENDARLINK_FREEBUSY, new Byte(CalendarLink.TYPE_FREE_BUSY)); + REL_TO_TYPE_CALENDARLINK = map; + TYPE_TO_REL_CALENDARLINK = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_EVENT_ANNIVERARY, new Byte(Event.TYPE_ANNIVERSARY)); + map.put(TYPESTRING_EVENT_OTHER, new Byte(Event.TYPE_OTHER)); + REL_TO_TYPE_EVENT = map; + TYPE_TO_REL_EVENT = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_EXTERNALID_ACCOUNT, new Byte(ExternalId.TYPE_ACCOUNT)); + map.put(TYPESTRING_EXTERNALID_CUSTOMER, new Byte(ExternalId.TYPE_CUSTOMER)); + map.put(TYPESTRING_EXTERNALID_NETWORK, new Byte(ExternalId.TYPE_NETWORK)); + map.put(TYPESTRING_EXTERNALID_ORGANIZATION, new Byte(ExternalId.TYPE_ORGANIZATION)); + REL_TO_TYPE_EXTERNALID = map; + TYPE_TO_REL_EXTERNALID = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_JOT_HOME, new Byte(Jot.TYPE_HOME)); + map.put(TYPESTRING_JOT_KEYWORDS, new Byte(Jot.TYPE_KEYWORDS)); + map.put(TYPESTRING_JOT_OTHER, new Byte(Jot.TYPE_OTHER)); + map.put(TYPESTRING_JOT_USER, new Byte(Jot.TYPE_USER)); + map.put(TYPESTRING_JOT_WORK, new Byte(Jot.TYPE_WORK)); + REL_TO_TYPE_JOT = map; + TYPE_TO_REL_JOT = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_PRIORITY_HIGH, new Byte(ContactEntry.TYPE_PRIORITY_HIGH)); + map.put(TYPESTRING_PRIORITY_NORMAL, new Byte(ContactEntry.TYPE_PRIORITY_NORMAL)); + map.put(TYPESTRING_PRIORITY_LOW, new Byte(ContactEntry.TYPE_PRIORITY_LOW)); + REL_TO_TYPE_PRIORITY = map; + TYPE_TO_REL_PRIORITY = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_RELATION_ASSISTANT, new Byte(Relation.TYPE_ASSISTANT)); + map.put(TYPESTRING_RELATION_BROTHER, new Byte(Relation.TYPE_BROTHER)); + map.put(TYPESTRING_RELATION_CHILD, new Byte(Relation.TYPE_CHILD)); + map.put(TYPESTRING_RELATION_DOMESTICPARTNER, new Byte(Relation.TYPE_DOMESTICPARTNER)); + map.put(TYPESTRING_RELATION_FATHER, new Byte(Relation.TYPE_FATHER)); + map.put(TYPESTRING_RELATION_FRIEND, new Byte(Relation.TYPE_FRIEND)); + map.put(TYPESTRING_RELATION_MANAGER, new Byte(Relation.TYPE_MANAGER)); + map.put(TYPESTRING_RELATION_MOTHER, new Byte(Relation.TYPE_MOTHER)); + map.put(TYPESTRING_RELATION_PARENT, new Byte(Relation.TYPE_PARENT)); + map.put(TYPESTRING_RELATION_PARTNER, new Byte(Relation.TYPE_PARTNER)); + map.put(TYPESTRING_RELATION_REFERREDBY, new Byte(Relation.TYPE_REFERREDBY)); + map.put(TYPESTRING_RELATION_RELATIVE, new Byte(Relation.TYPE_RELATIVE)); + map.put(TYPESTRING_RELATION_SISTER, new Byte(Relation.TYPE_SISTER)); + map.put(TYPESTRING_RELATION_SPOUSE, new Byte(Relation.TYPE_SPOUSE)); + REL_TO_TYPE_RELATION = map; + TYPE_TO_REL_RELATION = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_SENSITIVITY_CONFIDENTIAL, + new Byte(ContactEntry.TYPE_SENSITIVITY_CONFIDENTIAL)); + map.put(TYPESTRING_SENSITIVITY_NORMAL, + new Byte(ContactEntry.TYPE_SENSITIVITY_NORMAL)); + map.put(TYPESTRING_SENSITIVITY_PERSONAL, + new Byte(ContactEntry.TYPE_SENSITIVITY_PERSONAL)); + map.put(TYPESTRING_SENSITIVITY_PRIVATE, + new Byte(ContactEntry.TYPE_SENSITIVITY_PRIVATE)); + REL_TO_TYPE_SENSITIVITY= map; + TYPE_TO_REL_SENSITIVITY = swapMap(map); + + map = new Hashtable(); + map.put(TYPESTRING_WEBSITE_BLOG, new Byte(WebSite.TYPE_BLOG)); + map.put(TYPESTRING_WEBSITE_HOMEPAGE, new Byte(WebSite.TYPE_HOMEPAGE)); + map.put(TYPESTRING_WEBSITE_PROFILE, new Byte(WebSite.TYPE_PROFILE)); + map.put(TYPESTRING_WEBSITE_HOME, new Byte(WebSite.TYPE_HOME)); + map.put(TYPESTRING_WEBSITE_WORK, new Byte(WebSite.TYPE_WORK)); + map.put(TYPESTRING_WEBSITE_OTHER, new Byte(WebSite.TYPE_OTHER)); + map.put(TYPESTRING_WEBSITE_FTP, new Byte(WebSite.TYPE_FTP)); + + REL_TO_TYPE_WEBSITE = map; + TYPE_TO_REL_WEBSITE = swapMap(map); + } private static Hashtable swapMap(Hashtable originalMap) { @@ -207,65 +342,149 @@ public class XmlContactsGDataParser extends XmlGDataParser { } ContactEntry contactEntry = (ContactEntry) entry; String name = parser.getName(); - if ("email".equals(name)) { - EmailAddress emailAddress = new EmailAddress(); - parseContactsElement(emailAddress, parser, REL_TO_TYPE_EMAIL); - // TODO: remove this when the feed is upgraded - if (emailAddress.getType() == 4) { - emailAddress.setType(EmailAddress.TYPE_OTHER); - emailAddress.setIsPrimary(true); - emailAddress.setLabel(null); - } - emailAddress.setAddress(parser.getAttributeValue(null /* ns */, "address")); - contactEntry.addEmailAddress(emailAddress); - } else if ("deleted".equals(name)) { - contactEntry.setDeleted(true); - } else if ("im".equals(name)) { - ImAddress imAddress = new ImAddress(); - parseContactsElement(imAddress, parser, REL_TO_TYPE_IM); - imAddress.setAddress(parser.getAttributeValue(null /* ns */, "address")); - imAddress.setLabel(parser.getAttributeValue(null /* ns */, "label")); - String protocolString = parser.getAttributeValue(null /* ns */, "protocol"); - if (protocolString == null) { - imAddress.setProtocolPredefined(ImAddress.PROTOCOL_NONE); - imAddress.setProtocolCustom(null); - } else { - Byte predefinedProtocol = (Byte) IM_PROTOCOL_STRING_TO_TYPE_MAP.get(protocolString); - if (predefinedProtocol == null) { - imAddress.setProtocolPredefined(ImAddress.PROTOCOL_CUSTOM); - imAddress.setProtocolCustom(protocolString); - } else { - imAddress.setProtocolPredefined(predefinedProtocol.byteValue()); + String ns = parser.getNamespace(); + + if (XmlGDataParser.NAMESPACE_GD_URI.equals(ns)) { + if (XmlNametable.GD_EMAIL.equals(name)) { + EmailAddress emailAddress = new EmailAddress(); + parseContactsElement(emailAddress, parser, REL_TO_TYPE_EMAIL); + emailAddress.setDisplayName(parser.getAttributeValue(null /* ns */, + XmlNametable.GD_EMAIL_DISPLAYNAME)); + emailAddress.setAddress(parser.getAttributeValue(null /* ns */, + XmlNametable.GD_ADDRESS)); + contactEntry.addEmailAddress(emailAddress); + } else if (XmlNametable.GD_DELETED.equals(name)) { + contactEntry.setDeleted(true); + } else if (XmlNametable.GD_IM.equals(name)) { + ImAddress imAddress = new ImAddress(); + parseContactsElement(imAddress, parser, REL_TO_TYPE_IM); + imAddress.setAddress(parser.getAttributeValue(null /* ns */, + XmlNametable.GD_ADDRESS)); + imAddress.setLabel(parser.getAttributeValue(null /* ns */, + XmlNametable.LABEL)); + String protocolString = parser.getAttributeValue(null /* ns */, + XmlNametable.GD_PROTOCOL); + if (protocolString == null) { + imAddress.setProtocolPredefined(ImAddress.PROTOCOL_NONE); imAddress.setProtocolCustom(null); + } else { + Byte predefinedProtocol = (Byte) IM_PROTOCOL_STRING_TO_TYPE_MAP.get(protocolString); + if (predefinedProtocol == null) { + imAddress.setProtocolPredefined(ImAddress.PROTOCOL_CUSTOM); + imAddress.setProtocolCustom(protocolString); + } else { + imAddress.setProtocolPredefined(predefinedProtocol.byteValue()); + imAddress.setProtocolCustom(null); + } } + contactEntry.addImAddress(imAddress); + } else if (XmlNametable.GD_SPA.equals(name)) { + StructuredPostalAddress postalAddress = new StructuredPostalAddress(); + parseContactsElement(postalAddress, parser, REL_TO_TYPE_POSTAL); + handleStructuredPostalAddressSubElement(postalAddress, parser); + contactEntry.addPostalAddress(postalAddress); + } else if (XmlNametable.GD_PHONENUMBER.equals(name)) { + PhoneNumber phoneNumber = new PhoneNumber(); + parseContactsElement(phoneNumber, parser, REL_TO_TYPE_PHONE); + phoneNumber.setPhoneNumber(XmlUtils.extractChildText(parser)); + contactEntry.addPhoneNumber(phoneNumber); + } else if (XmlNametable.GD_ORGANIZATION.equals(name)) { + Organization organization = new Organization(); + parseContactsElement(organization, parser, REL_TO_TYPE_ORGANIZATION); + handleOrganizationSubElement(organization, parser); + contactEntry.addOrganization(organization); + } else if (XmlNametable.GD_EXTENDEDPROPERTY.equals(name)) { + ExtendedProperty extendedProperty = new ExtendedProperty(); + parseExtendedProperty(extendedProperty); + contactEntry.addExtendedProperty(extendedProperty); + } else if (XmlNametable.GD_NAME.equals(name)) { + Name n = new Name(); + handleNameSubElement(n, parser); + contactEntry.setName(n); } - contactEntry.addImAddress(imAddress); - } else if ("postalAddress".equals(name)) { - StructuredPostalAddress postalAddress = new StructuredPostalAddress(); - parseContactsElement(postalAddress, parser, REL_TO_TYPE_POSTAL); - // TODO: write the parsing code - // postalAddress.setValue(XmlUtils.extractChildText(parser)); - contactEntry.addPostalAddress(postalAddress); - } else if ("phoneNumber".equals(name)) { - PhoneNumber phoneNumber = new PhoneNumber(); - parseContactsElement(phoneNumber, parser, REL_TO_TYPE_PHONE); - phoneNumber.setPhoneNumber(XmlUtils.extractChildText(parser)); - contactEntry.addPhoneNumber(phoneNumber); - } else if ("organization".equals(name)) { - Organization organization = new Organization(); - parseContactsElement(organization, parser, REL_TO_TYPE_ORGANIZATION); - handleOrganizationSubElement(organization, parser); - contactEntry.addOrganization(organization); - } else if ("extendedProperty".equals(name)) { - ExtendedProperty extendedProperty = new ExtendedProperty(); - parseExtendedProperty(extendedProperty); - contactEntry.addExtendedProperty(extendedProperty); - } else if ("groupMembershipInfo".equals(name)) { - GroupMembershipInfo group = new GroupMembershipInfo(); - group.setGroup(parser.getAttributeValue(null /* ns */, "href")); - group.setDeleted("true".equals(parser.getAttributeValue(null /* ns */, "deleted"))); - contactEntry.addGroup(group); - } + } else if (XmlContactsGDataParser.NAMESPACE_CONTACTS_URI.equals(ns)) { + if (XmlNametable.GC_GMI.equals(name)) { + GroupMembershipInfo group = new GroupMembershipInfo(); + group.setGroup(parser.getAttributeValue(null /* ns */, + XmlNametable.HREF)); + group.setDeleted("true".equals(parser.getAttributeValue(null /* ns */, + XmlNametable.GD_DELETED))); + contactEntry.addGroup(group); + } else if (XmlNametable.GC_BIRTHDAY.equals(name)) { + contactEntry.setBirthday(parser.getAttributeValue(null /* ns */, + XmlNametable.GD_WHEN)); + } else if (XmlNametable.GC_BILLINGINFO.equals(name)) { + contactEntry.setBillingInformation(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_CALENDARLINK.equals(name)) { + CalendarLink cl = new CalendarLink(); + parseContactsElement(cl, parser, REL_TO_TYPE_CALENDARLINK); + cl.setHRef(parser.getAttributeValue(null /* ns */, XmlNametable.HREF)); + contactEntry.addCalendarLink(cl); + } else if (XmlNametable.GC_DIRECTORYSERVER.equals(name)) { + contactEntry.setDirectoryServer(XmlUtils.extractChildText(parser)); + } else if ("event".equals(name)) { + Event event = new Event(); + parseTypedElement(event, parser, REL_TO_TYPE_EVENT); + handleEventSubElement(event, parser); + contactEntry.addEvent(event); + } else if (XmlNametable.GC_EXTERNALID.equals(name)) { + ExternalId externalId = new ExternalId(); + parseTypedElement(externalId, parser, REL_TO_TYPE_EXTERNALID); + externalId.setValue(parser.getAttributeValue(null /* ns */, XmlNametable.VALUE)); + contactEntry.addExternalId(externalId); + } else if (XmlNametable.GC_GENDER.equals(name)) { + contactEntry.setGender(parser.getAttributeValue(null /* ns */, XmlNametable.VALUE)); + } else if (XmlNametable.GC_HOBBY.equals(name)) { + contactEntry.addHobby(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_INITIALS.equals(name)) { + contactEntry.setInitials(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_JOT.equals(name)) { + Jot jot = new Jot(); + parseTypedElement(jot, parser, REL_TO_TYPE_JOT); + jot.setLabel(XmlUtils.extractChildText(parser)); + contactEntry.addJot(jot); + } else if (XmlNametable.GC_LANGUAGE.equals(name)) { + Language language = new Language(); + language.setCode(parser.getAttributeValue(null /* ns */, XmlNametable.CODE)); + language.setLabel(parser.getAttributeValue(null /* */, XmlNametable.VALUE)); + contactEntry.addLanguage(language); + } else if (XmlNametable.GC_MAIDENNAME.equals(name)) { + contactEntry.setMaidenName(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_MILEAGE.equals(name)) { + contactEntry.setMileage(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_NICKNAME.equals(name)) { + contactEntry.setNickname(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_OCCUPATION.equals(name)) { + contactEntry.setOccupation(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_PRIORITY.equals(name)) { + contactEntry.setPriority(relToType( + parser.getAttributeValue(null /* ns */, XmlNametable.REL), + REL_TO_TYPE_PRIORITY)); + } else if (XmlNametable.GC_RELATION.equals(name)) { + Relation relation = new Relation(); + parseTypedElement(relation, parser, REL_TO_TYPE_RELATION); + relation.setText(XmlUtils.extractChildText(parser)); + contactEntry.addRelation(relation); + } else if (XmlNametable.GC_SENSITIVITY.equals(name)) { + contactEntry.setSensitivity(relToType( + parser.getAttributeValue(null /* ns */, XmlNametable.REL), + REL_TO_TYPE_SENSITIVITY)); + } else if (XmlNametable.GC_SHORTNAME.equals(name)) { + contactEntry.setShortName(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_SUBJECT.equals(name)) { + contactEntry.setSubject(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GC_UDF.equals(name)) { + UserDefinedField udf = new UserDefinedField(); + udf.setKey(parser.getAttributeValue(null /* ns */, XmlNametable.KEY)); + udf.setValue(parser.getAttributeValue(null /* ns */, XmlNametable.VALUE)); + contactEntry.addUserDefinedField(udf); + } else if (XmlNametable.GC_WEBSITE.equals(name)) { + WebSite ws = new WebSite(); + parseContactsElement(ws, parser, REL_TO_TYPE_WEBSITE); + ws.setHRef(parser.getAttributeValue(null /* ns */, XmlNametable.HREF)); + contactEntry.addWebSite(ws); + } + } } protected void handleExtraLinkInEntry(String rel, String type, String href, Entry entry) @@ -273,15 +492,21 @@ public class XmlContactsGDataParser extends XmlGDataParser { if (LINK_REL_PHOTO.equals(rel)) { ContactEntry contactEntry = (ContactEntry) entry; XmlPullParser parser = getParser(); - String etag = parser.getAttributeValue(null /* ns */, "etag"); + String etag = parser.getAttributeValue(null /* ns */, XmlNametable.ETAG); contactEntry.setLinkPhoto(href, type, etag); } } private static void parseContactsElement(ContactsElement element, XmlPullParser parser, Hashtable relToTypeMap) throws XmlPullParserException { - String rel = parser.getAttributeValue(null /* ns */, "rel"); - String label = parser.getAttributeValue(null /* ns */, "label"); + parseTypedElement(element, parser, relToTypeMap); + element.setIsPrimary("true".equals(parser.getAttributeValue(null /* ns */, "primary"))); + } + + private static void parseTypedElement(TypedElement element, XmlPullParser parser, + Hashtable relToTypeMap) throws XmlPullParserException { + String rel = parser.getAttributeValue(null /* ns */, XmlNametable.REL); + String label = parser.getAttributeValue(null /* ns */, XmlNametable.LABEL); if ((label == null && rel == null) || (label != null && rel != null)) { // TODO: remove this once the focus feed is fixed to not send this case @@ -289,14 +514,21 @@ public class XmlContactsGDataParser extends XmlGDataParser { } if (rel != null) { + element.setType(relToType(rel, relToTypeMap)); + } + element.setLabel(label); + } + + private static byte relToType(String rel, Hashtable relToTypeMap) + throws XmlPullParserException { + if (rel != null) { final Object type = relToTypeMap.get(rel.toLowerCase()); if (type == null) { throw new XmlPullParserException("unknown rel, " + rel); } - element.setType(((Byte) type).byteValue()); + return ((Byte) type).byteValue(); } - element.setLabel(label); - element.setIsPrimary("true".equals(parser.getAttributeValue(null /* ns */, "primary"))); + return TypedElement.TYPE_NONE; } private static void handleOrganizationSubElement(Organization element, XmlPullParser parser) @@ -305,14 +537,92 @@ public class XmlContactsGDataParser extends XmlGDataParser { while (true) { String tag = XmlUtils.nextDirectChildTag(parser, depth); if (tag == null) break; - if ("orgName".equals(tag)) { + if (XmlNametable.GD_ORG_NAME.equals(tag)) { element.setName(XmlUtils.extractChildText(parser)); - } else if ("orgTitle".equals(tag)) { + } else if (XmlNametable.GD_ORG_TITLE.equals(tag)) { element.setTitle(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_ORG_DEPARTMENT.equals(tag)) { + element.setOrgDepartment(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_ORG_JOBDESC.equals(tag)) { + element.setOrgJobDescription(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_ORG_SYMBOL.equals(tag)) { + element.setOrgSymbol(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_WHERE.equals(tag)) { + String where = parser.getAttributeValue(null /* ns */, + XmlNametable.VALUESTRING); + element.setWhere(where); + } + } + } + + + private static void handleEventSubElement(Event element, XmlPullParser parser) + throws XmlPullParserException, IOException { + int depth = parser.getDepth(); + while (true) { + String tag = XmlUtils.nextDirectChildTag(parser, depth); + if (tag == null) break; + if (XmlNametable.GD_WHEN.equals(tag)) { + String startDate = parser.getAttributeValue(null /* ns */, + XmlNametable.STARTTIME); + element.setStartDate(startDate); } } } + + private static void handleNameSubElement(Name element, XmlPullParser parser) + throws XmlPullParserException, IOException { + int depth = parser.getDepth(); + while (true) { + String tag = XmlUtils.nextDirectChildTag(parser, depth); + if (tag == null) break; + if (XmlNametable.GD_NAME.equals(tag)) { + element.setGivenName(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_NAME_ADDITIONALNAME.equals(tag)) { + element.setAdditionalNameYomi( + parser.getAttributeValue(null /* ns */, XmlNametable.GD_NAME_YOMI)); + element.setAdditionalName(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_NAME_FAMILYNAME.equals(tag)) { + element.setFamilyNameYomi( + parser.getAttributeValue(null /* ns */, XmlNametable.GD_NAME_YOMI)); + element.setFamilyName(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_NAME_PREFIX.equals(tag)) { + element.setNamePrefix(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_NAME_SUFFIX.equals(tag)) { + element.setNameSuffix(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_NAME_FULLNAME.equals(tag)) { + element.setFullName(XmlUtils.extractChildText(parser)); + } + } + } + + private static void handleStructuredPostalAddressSubElement( + StructuredPostalAddress element, XmlPullParser parser) + throws XmlPullParserException, IOException { + int depth = parser.getDepth(); + while (true) { + String tag = XmlUtils.nextDirectChildTag(parser, depth); + if (tag == null) break; + if (XmlNametable.GD_SPA_STREET.equals(tag)) { + element.setStreet(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_SPA_POBOX.equals(tag)) { + element.setPobox(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_SPA_NEIGHBORHOOD.equals(tag)) { + element.setNeighborhood(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_SPA_REGION.equals(tag)) { + element.setRegion(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_SPA_POSTCODE.equals(tag)) { + element.setPostcode(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_SPA_COUNTRY.equals(tag)) { + element.setCountry(XmlUtils.extractChildText(parser)); + } else if (XmlNametable.GD_SPA_FORMATTEDADDRESS.equals(tag)) { + element.setFormatedAddress(XmlUtils.extractChildText(parser)); + } + } + } + + /** * Parse the ExtendedProperty. The parser is assumed to be at the beginning of the tag * for the ExtendedProperty. @@ -321,8 +631,8 @@ public class XmlContactsGDataParser extends XmlGDataParser { private void parseExtendedProperty(ExtendedProperty extendedProperty) throws IOException, XmlPullParserException { XmlPullParser parser = getParser(); - extendedProperty.setName(parser.getAttributeValue(null /* ns */, "name")); - extendedProperty.setValue(parser.getAttributeValue(null /* ns */, "value")); + extendedProperty.setName(parser.getAttributeValue(null /* ns */, XmlNametable.GD_NAME)); + extendedProperty.setValue(parser.getAttributeValue(null /* ns */, XmlNametable.VALUE)); extendedProperty.setXmlBlob(XmlUtils.extractFirstChildTextIgnoreRest(parser)); } } diff --git a/src/com/google/wireless/gdata2/contacts/parser/xml/XmlNametable.java b/src/com/google/wireless/gdata2/contacts/parser/xml/XmlNametable.java new file mode 100644 index 0000000..e9e5a66 --- /dev/null +++ b/src/com/google/wireless/gdata2/contacts/parser/xml/XmlNametable.java @@ -0,0 +1,81 @@ +// Copyright 2009 The Android Open Source Project + +package com.google.wireless.gdata2.contacts.parser.xml; + +/** + * Class to hold static strings that are used to parse and + * serialize the xml elements in the contacts feed + */ +public final class XmlNametable { + private XmlNametable() {} + + // generic strings for attributes + public static String HREF = "href"; + public static String LABEL = "label"; + public static String VALUE = "value"; + public static String CODE = "code"; + public static String REL = "rel"; + public static String KEY = "key"; + public static String ETAG = "etag"; + public static String VALUESTRING = "valueString"; + public static String STARTTIME = "startTime"; + + // GD namespace + public static String GD_EMAIL = "email"; + public static String GD_EMAIL_DISPLAYNAME = "displayName"; + public static String GD_ADDRESS = "adress"; + public static String GD_PROTOCOL = "protocol"; + public static String GD_IM = "im"; + public static String GD_DELETED = "deleted"; + public static String GD_NAME = "name"; + public static String GD_NAME_ADDITIONALNAME = "additionalName"; + public static String GD_NAME_YOMI = "yomi"; + public static String GD_NAME_FAMILYNAME = "familyName"; + public static String GD_NAME_PREFIX = "namePrefix"; + public static String GD_NAME_SUFFIX = "nameSuffix"; + public static String GD_NAME_FULLNAME = "fullName"; + public static String GD_SPA = "structuredPostalAddress"; + public static String GD_SPA_STREET = "street"; + public static String GD_SPA_POBOX = "pobox"; + public static String GD_SPA_NEIGHBORHOOD = "neighborhood"; + public static String GD_SPA_CITY = "city"; + public static String GD_SPA_REGION = "region"; + public static String GD_SPA_POSTCODE = "postcode"; + public static String GD_SPA_COUNTRY = "country"; + public static String GD_SPA_FORMATTEDADDRESS = "formattedAddress"; + public static String GD_PHONENUMBER = "phonenumber"; + public static String GD_ORGANIZATION = "organization"; + public static String GD_EXTENDEDPROPERTY = "extendedProperty"; + public static String GD_WHEN = "when"; + public static String GD_WHERE = "where"; + public static String GD_ORG_NAME = "orgName"; + public static String GD_ORG_TITLE = "orgTitle"; + public static String GD_ORG_DEPARTMENT = "orgDepartment"; + public static String GD_ORG_JOBDESC = "orgJobDescription"; + public static String GD_ORG_SYMBOL = "orgSymbol"; + + // Contacts namespace + public static String GC_GMI = "groupMembershipInfo"; + public static String GC_BIRTHDAY = "birthday"; + public static String GC_BILLINGINFO = "billingInformation"; + public static String GC_CALENDARLINK = "calendarLink"; + public static String GC_DIRECTORYSERVER = "directoryServer"; + public static String GC_EVENT = "event"; + public static String GC_EXTERNALID = "externalId"; + public static String GC_GENDER = "gender"; + public static String GC_HOBBY = "hobby"; + public static String GC_INITIALS = "initials"; + public static String GC_JOT = "jot"; + public static String GC_LANGUAGE = "language"; + public static String GC_MAIDENNAME = "maidenName"; + public static String GC_MILEAGE = "mileage"; + public static String GC_NICKNAME = "nickname"; + public static String GC_OCCUPATION = "occupation"; + public static String GC_PRIORITY = "priority"; + public static String GC_RELATION = "relation"; + public static String GC_SENSITIVITY = "sensitivity"; + public static String GC_SHORTNAME = "shortName"; + public static String GC_SUBJECT = "subject"; + public static String GC_UDF = "userDefefinedField"; + public static String GC_WEBSITE ="website"; +}
\ No newline at end of file |