FileDocCategorySizeDatePackage
XmlEventEntryGDataSerializer.javaAPI DocAndroid 1.5 API15506Wed May 06 22:41:16 BST 2009com.google.wireless.gdata.calendar.serializer.xml

XmlEventEntryGDataSerializer

public class XmlEventEntryGDataSerializer extends com.google.wireless.gdata.serializer.xml.XmlEntryGDataSerializer
Serializes Google Calendar event entries into the Atom XML format.

Fields Summary
public static final String
NAMESPACE_GCAL
public static final String
NAMESPACE_GCAL_URI
Constructors Summary
public XmlEventEntryGDataSerializer(com.google.wireless.gdata.parser.xml.XmlParserFactory factory, com.google.wireless.gdata.calendar.data.EventEntry entry)


      
              
        super(factory, entry);
    
Methods Summary
protected voiddeclareExtraEntryNamespaces(org.xmlpull.v1.XmlSerializer serializer)

        serializer.setPrefix(NAMESPACE_GCAL, NAMESPACE_GCAL_URI);
    
protected com.google.wireless.gdata.calendar.data.EventEntrygetEventEntry()

        return (EventEntry) getEntry();
    
private static voidserializeCommentsUri(org.xmlpull.v1.XmlSerializer serializer, java.lang.String commentsUri)

        if (commentsUri == null) {
            return;
        }

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "feedLink");
        serializer.attribute(null /* ns */, "href", commentsUri);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "feedLink");
    
private static voidserializeEventStatus(org.xmlpull.v1.XmlSerializer serializer, byte status)


        String statusString;

        switch (status) {
            case EventEntry.STATUS_TENTATIVE:
                statusString = "http://schemas.google.com/g/2005#event.tentative";
                break;
            case EventEntry.STATUS_CANCELED:
                statusString = "http://schemas.google.com/g/2005#event.canceled";
                break;
            case EventEntry.STATUS_CONFIRMED:
                statusString = "http://schemas.google.com/g/2005#event.confirmed";
                break;
            default:
                // should not happen
                // TODO: log this
                statusString = "http://schemas.google.com/g/2005#event.tentative";
        }

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "eventStatus");
        serializer.attribute(null /* ns */, "value", statusString);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "eventStatus");
    
private static voidserializeExtendedProperty(org.xmlpull.v1.XmlSerializer serializer, java.lang.String name, java.lang.String value)

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "extendedProperty");
        serializer.attribute(null /* ns */, "name", name);
        serializer.attribute(null /* ns */, "value", value);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "extendedProperty");
    
protected voidserializeExtraEntryContents(org.xmlpull.v1.XmlSerializer serializer, int format)

        EventEntry entry = getEventEntry();

        serializeEventStatus(serializer, entry.getStatus());
        serializeTransparency(serializer, entry.getTransparency());
        serializeVisibility(serializer, entry.getVisibility());
        Enumeration attendees = entry.getAttendees().elements();
        while (attendees.hasMoreElements()) {
            Who attendee = (Who) attendees.nextElement();
            serializeWho(serializer, entry, attendee);
        }

        serializeRecurrence(serializer, entry.getRecurrence());
        // either serialize reminders directly under the entry, or serialize
        // whens (with reminders within the whens) -- should be just one.
        if (entry.getRecurrence() != null) {
            if (entry.getReminders() != null) {
                Enumeration reminders = entry.getReminders().elements();
                while (reminders.hasMoreElements()) {
                    Reminder reminder = (Reminder) reminders.nextElement();
                    serializeReminder(serializer, reminder);
                }
            }
        } else {
            Enumeration whens = entry.getWhens().elements();
            while (whens.hasMoreElements()) {
                When when = (When) whens.nextElement();
                serializeWhen(serializer, entry, when);
            }
        }
        serializeOriginalEvent(serializer,
                entry.getOriginalEventId(),
                entry.getOriginalEventStartTime());
        serializeWhere(serializer, entry.getWhere());

        serializeCommentsUri(serializer, entry.getCommentsUri());

        Hashtable extendedProperties = entry.getExtendedProperties();
        if (extendedProperties != null) {
            Enumeration propertyNames = extendedProperties.keys();
            while (propertyNames.hasMoreElements()) {
                String propertyName = (String) propertyNames.nextElement();
                String propertyValue = (String) extendedProperties.get(propertyName);
                serializeExtendedProperty(serializer, propertyName, propertyValue);
            }
        }
    
private static voidserializeOriginalEvent(org.xmlpull.v1.XmlSerializer serializer, java.lang.String originalEventId, java.lang.String originalEventTime)

        if (StringUtils.isEmpty(originalEventId) ||
                StringUtils.isEmpty(originalEventTime)) {
            return;
        }


        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "originalEvent");
        int index = originalEventId.lastIndexOf("/");
        if (index != -1) {
            String id = originalEventId.substring(index + 1);
            if (!StringUtils.isEmpty(id)) {
                serializer.attribute(null /* ns */, "id", id);
            }
        }
        serializer.attribute(null /* ns */, "href", originalEventId);
        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "when");
        serializer.attribute(null /* ns */, "startTime", originalEventTime);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "when");
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "originalEvent");
    
private static voidserializeRecurrence(org.xmlpull.v1.XmlSerializer serializer, java.lang.String recurrence)

        if (StringUtils.isEmpty(recurrence)) {
            return;
        }
        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "recurrence");
        serializer.text(recurrence);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "recurrence");
    
private static voidserializeReminder(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.calendar.data.Reminder reminder)


        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "reminder");
        byte method = reminder.getMethod();
        String methodStr = null;
        switch (method) {
            case Reminder.METHOD_ALERT:
                methodStr = "alert";
                break;
            case Reminder.METHOD_EMAIL:
                methodStr = "email";
                break;
            case Reminder.METHOD_SMS:
                methodStr = "sms";
                break;
        }
        if (methodStr != null) {
            serializer.attribute(null /* ns */, "method", methodStr);
        }

        int minutes = reminder.getMinutes();
        if (minutes != Reminder.MINUTES_DEFAULT) {
            serializer.attribute(null /* ns */, "minutes",
                    Integer.toString(minutes));
        }

        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "reminder");
    
private static voidserializeTransparency(org.xmlpull.v1.XmlSerializer serializer, byte transparency)


        String transparencyString;

        switch (transparency) {
            case EventEntry.TRANSPARENCY_OPAQUE:
                transparencyString =
                        "http://schemas.google.com/g/2005#event.opaque";
                break;
            case EventEntry.TRANSPARENCY_TRANSPARENT:
                transparencyString =
                        "http://schemas.google.com/g/2005#event.transparent";
                break;
            default:
                // should not happen
                // TODO: log this
                transparencyString =
                        "http://schemas.google.com/g/2005#event.transparent";
        }

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "transparency");
        serializer.attribute(null /* ns */, "value", transparencyString);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "transparency");
    
private static voidserializeVisibility(org.xmlpull.v1.XmlSerializer serializer, byte visibility)


        String visibilityString;

        switch (visibility) {
            case EventEntry.VISIBILITY_DEFAULT:
                visibilityString = "http://schemas.google.com/g/2005#event.default";
                break;
            case EventEntry.VISIBILITY_CONFIDENTIAL:
                visibilityString =
                        "http://schemas.google.com/g/2005#event.confidential";
                break;
            case EventEntry.VISIBILITY_PRIVATE:
                visibilityString = "http://schemas.google.com/g/2005#event.private";
                break;
            case EventEntry.VISIBILITY_PUBLIC:
                visibilityString = "http://schemas.google.com/g/2005#event.public";
                break;
            default:
                // should not happen
                // TODO: log this
                visibilityString = "http://schemas.google.com/g/2005#event.default";
        }

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "visibility");
        serializer.attribute(null /* ns */, "value", visibilityString);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "visibility");
    
private static voidserializeWhen(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.calendar.data.EventEntry entry, com.google.wireless.gdata.calendar.data.When when)

        // TODO: throw exn if startTime is empty but endTime is not?
        String startTime = when.getStartTime();
        String endTime = when.getEndTime();
        if (StringUtils.isEmpty(when.getStartTime())) {
            return;
        }

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "when");
        serializer.attribute(null /* ns */, "startTime", startTime);
        if (!StringUtils.isEmpty(endTime)) {
            serializer.attribute(null /* ns */, "endTime", endTime);
        }
        if (entry.getReminders() != null) {
            Enumeration reminders = entry.getReminders().elements();
            while (reminders.hasMoreElements()) {
                Reminder reminder = (Reminder) reminders.nextElement();
                serializeReminder(serializer, reminder);
            }
        }
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "when");
    
private static voidserializeWhere(org.xmlpull.v1.XmlSerializer serializer, java.lang.String where)

        if (StringUtils.isEmpty(where)) {
            return;
        }

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "where");
        serializer.attribute(null /* ns */, "valueString", where);
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "where");
    
private static voidserializeWho(org.xmlpull.v1.XmlSerializer serializer, com.google.wireless.gdata.calendar.data.EventEntry entry, com.google.wireless.gdata.calendar.data.Who who)

        serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI, "who");
        String email = who.getEmail();
        if (!StringUtils.isEmpty(email)) {
            serializer.attribute(null /* ns */, "email", email);
        }

        String value = who.getValue();
        if (!StringUtils.isEmpty(value)) {
            serializer.attribute(null /* ns */, "valueString", value);
        }

        String rel = null;
        switch (who.getRelationship()) {
            case Who.RELATIONSHIP_NONE:
                break;
            case Who.RELATIONSHIP_ATTENDEE:
                rel = "http://schemas.google.com/g/2005#event.attendee";
                break;
            case Who.RELATIONSHIP_ORGANIZER:
                rel = "http://schemas.google.com/g/2005#event.organizer";
                break;
            case Who.RELATIONSHIP_PERFORMER:
                rel = "http://schemas.google.com/g/2005#event.performer";
                break;
            case Who.RELATIONSHIP_SPEAKER:
                rel = "http://schemas.google.com/g/2005#event.speaker";
                break;
            default:
                throw new ParseException("Unexpected rel: " + who.getRelationship());
        }
        if (!StringUtils.isEmpty(rel)) {
            serializer.attribute(null /* ns */, "rel", rel);
        }

        String status = null;
        switch (who.getStatus()) {
            case Who.STATUS_NONE:
                break;
            case Who.STATUS_ACCEPTED:
                status = "http://schemas.google.com/g/2005#event.accepted";
                break;
            case Who.STATUS_DECLINED:
                status = "http://schemas.google.com/g/2005#event.declined";
                break;
            case Who.STATUS_INVITED:
                status = "http://schemas.google.com/g/2005#event.invited";
                break;
            case Who.STATUS_TENTATIVE:
                status = "http://schemas.google.com/g/2005#event.tentative";
                break;
            default:
                throw new ParseException("Unexpected status: " + who.getStatus());
        }
        if (!StringUtils.isEmpty(status)) {
            serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI,
                    "attendeeStatus");
            serializer.attribute(null /* ns */, "value", status);
            serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI,
                    "attendeeStatus");
        }

        String type = null;
        switch (who.getType()) {
            case Who.TYPE_NONE:
                break;
            case Who.TYPE_REQUIRED:
                type = "http://schemas.google.com/g/2005#event.required";
                break;
            case Who.TYPE_OPTIONAL:
                type = "http://schemas.google.com/g/2005#event.optional";
                break;
            default:
                throw new ParseException("Unexpected type: " + who.getType());
        }
        if (!StringUtils.isEmpty(type)) {
            serializer.startTag(XmlGDataParser.NAMESPACE_GD_URI,
                    "attendeeType");
            serializer.attribute(null /* ns */, "value", type);
            serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "attendeeType");
        }
        serializer.endTag(XmlGDataParser.NAMESPACE_GD_URI, "who");