XmlContactEntryGDataSerializerpublic class XmlContactEntryGDataSerializer extends com.google.wireless.gdata.serializer.xml.XmlEntryGDataSerializer Serializes Google Contact entries into the Atom XML format. |
Methods Summary |
---|
protected void | declareExtraEntryNamespaces(org.xmlpull.v1.XmlSerializer serializer)
super.declareExtraEntryNamespaces(serializer);
serializer.setPrefix(XmlContactsGDataParser.NAMESPACE_CONTACTS,
XmlContactsGDataParser.NAMESPACE_CONTACTS_URI);
| protected com.google.wireless.gdata.contacts.data.ContactEntry | getContactEntry()
return (ContactEntry) getEntry();
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.GroupMembershipInfo groupMembershipInfo)
final String group = groupMembershipInfo.getGroup();
final boolean isDeleted = groupMembershipInfo.isDeleted();
if (StringUtils.isEmptyOrWhitespace(group)) {
throw new ParseException("the group must not be empty");
}
serializer.startTag(XmlContactsGDataParser.NAMESPACE_CONTACTS_URI, "groupMembershipInfo");
serializer.attribute(null /* ns */, "href", group);
serializer.attribute(null /* ns */, "deleted", isDeleted ? "true" : "false");
serializer.endTag(XmlContactsGDataParser.NAMESPACE_CONTACTS_URI, "groupMembershipInfo");
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.data.ExtendedProperty extendedProperty)
final String name = extendedProperty.getName();
final String value = extendedProperty.getValue();
final String xmlBlob = extendedProperty.getXmlBlob();
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "extendedProperty");
if (!StringUtils.isEmpty(name)) {
serializer.attribute(null /* ns */, "name", name);
}
if (!StringUtils.isEmpty(value)) {
serializer.attribute(null /* ns */, "value", value);
}
if (!StringUtils.isEmpty(xmlBlob)) {
serializeBlob(serializer, xmlBlob);
}
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "extendedProperty");
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.EmailAddress email)
if (StringUtils.isEmptyOrWhitespace(email.getAddress())) return;
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "email");
serializeContactsElement(serializer, email, XmlContactsGDataParser.TYPE_TO_REL_EMAIL);
serializer.attribute(null /* ns */, "address", email.getAddress());
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "email");
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.ImAddress im)
if (StringUtils.isEmptyOrWhitespace(im.getAddress())) return;
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "im");
serializeContactsElement(serializer, im, XmlContactsGDataParser.TYPE_TO_REL_IM);
serializer.attribute(null /* ns */, "address", im.getAddress());
String protocolString;
switch (im.getProtocolPredefined()) {
case ImAddress.PROTOCOL_NONE:
// don't include the attribute if no protocol was specified
break;
case ImAddress.PROTOCOL_CUSTOM:
protocolString = im.getProtocolCustom();
if (protocolString == null) {
throw new IllegalArgumentException(
"the protocol is custom, but the custom string is null");
}
serializer.attribute(null /* ns */, "protocol", protocolString);
break;
default:
protocolString = (String)XmlContactsGDataParser.IM_PROTOCOL_TYPE_TO_STRING_MAP.get(
new Byte(im.getProtocolPredefined()));
serializer.attribute(null /* ns */, "protocol", protocolString);
break;
}
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "im");
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.PhoneNumber phone)
if (StringUtils.isEmptyOrWhitespace(phone.getPhoneNumber())) return;
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "phoneNumber");
serializeContactsElement(serializer, phone, XmlContactsGDataParser.TYPE_TO_REL_PHONE);
serializer.text(phone.getPhoneNumber());
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "phoneNumber");
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.Organization organization)
final String name = organization.getName();
final String title = organization.getTitle();
if (StringUtils.isEmptyOrWhitespace(name) && StringUtils.isEmptyOrWhitespace(title)) return;
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "organization");
serializeContactsElement(serializer,
organization, XmlContactsGDataParser.TYPE_TO_REL_ORGANIZATION);
if (!StringUtils.isEmpty(name)) {
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "orgName");
serializer.text(name);
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "orgName");
}
if (!StringUtils.isEmpty(title)) {
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "orgTitle");
serializer.text(title);
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "orgTitle");
}
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "organization");
| private static void | serialize(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.PostalAddress addr)
if (StringUtils.isEmptyOrWhitespace(addr.getValue())) return;
serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "postalAddress");
serializeContactsElement(serializer, addr, XmlContactsGDataParser.TYPE_TO_REL_POSTAL);
final String addressValue = addr.getValue();
if (addressValue != null) serializer.text(addressValue);
serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "postalAddress");
| private static void | serializeBlob(org.xmlpull.v1.XmlSerializer serializer, java.lang.String blob)
serializer.text(blob);
| private static void | serializeContactsElement(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.contacts.data.ContactsElement element, java.util.Hashtable typeToRelMap)
final String label = element.getLabel();
boolean hasType = element.getType() != ContactsElement.TYPE_NONE;
if (((label == null) && !hasType) || ((label != null) && hasType)) {
throw new ParseException("exactly one of label or rel must be set");
}
if (label != null) {
serializer.attribute(null /* ns */, "label", label);
}
if (hasType) {
serializer.attribute(null /* ns */, "rel",
(String)typeToRelMap.get(new Byte(element.getType())));
}
if (element.isPrimary()) {
serializer.attribute(null /* ns */, "primary", "true");
}
| protected void | serializeExtraEntryContents(org.xmlpull.v1.XmlSerializer serializer, int format)
ContactEntry entry = getContactEntry();
entry.validate();
serializeLink(serializer, XmlContactsGDataParser.LINK_REL_EDIT_PHOTO,
entry.getLinkEditPhotoHref(), entry.getLinkEditPhotoType());
serializeLink(serializer, XmlContactsGDataParser.LINK_REL_PHOTO,
entry.getLinkPhotoHref(), entry.getLinkPhotoType());
// Serialize the contact specific parts of this entry. Note that
// gd:ContactSection and gd:geoPt are likely to be deprecated, and
// are not currently serialized.
Enumeration eachEmail = entry.getEmailAddresses().elements();
while (eachEmail.hasMoreElements()) {
serialize(serializer, (EmailAddress) eachEmail.nextElement());
}
Enumeration eachIm = entry.getImAddresses().elements();
while (eachIm.hasMoreElements()) {
serialize(serializer, (ImAddress) eachIm.nextElement());
}
Enumeration eachPhone = entry.getPhoneNumbers().elements();
while (eachPhone.hasMoreElements()) {
serialize(serializer, (PhoneNumber) eachPhone.nextElement());
}
Enumeration eachAddress = entry.getPostalAddresses().elements();
while (eachAddress.hasMoreElements()) {
serialize(serializer, (PostalAddress) eachAddress.nextElement());
}
Enumeration eachOrganization = entry.getOrganizations().elements();
while (eachOrganization.hasMoreElements()) {
serialize(serializer, (Organization) eachOrganization.nextElement());
}
Enumeration eachExtendedProperty = entry.getExtendedProperties().elements();
while (eachExtendedProperty.hasMoreElements()) {
serialize(serializer, (ExtendedProperty) eachExtendedProperty.nextElement());
}
Enumeration eachGroup = entry.getGroups().elements();
while (eachGroup.hasMoreElements()) {
serialize(serializer, (GroupMembershipInfo) eachGroup.nextElement());
}
serializeYomiName(serializer, entry.getYomiName());
| private static void | serializeYomiName(org.xmlpull.v1.XmlSerializer serializer, java.lang.String yomiName)
if (StringUtils.isEmpty(yomiName)) {
return;
}
serializer.startTag(XmlContactsGDataParser.NAMESPACE_CONTACTS_URI, "yomiName");
serializer.text(yomiName);
serializer.endTag(XmlContactsGDataParser.NAMESPACE_CONTACTS_URI, "yomiName");
|
|