FileDocCategorySizeDatePackage
XmlEntryGDataSerializer.javaAPI DocAndroid 1.5 API8111Wed May 06 22:41:16 BST 2009com.google.wireless.gdata.serializer.xml

XmlEntryGDataSerializer

public class XmlEntryGDataSerializer extends Object implements com.google.wireless.gdata.serializer.GDataSerializer
Serializes GData entries to the Atom XML format.

Fields Summary
private final com.google.wireless.gdata.parser.xml.XmlParserFactory
factory
The XmlParserFactory that is used to create the XmlSerializer
private final com.google.wireless.gdata.data.Entry
entry
The entry being serialized.
Constructors Summary
public XmlEntryGDataSerializer(com.google.wireless.gdata.parser.xml.XmlParserFactory factory, com.google.wireless.gdata.data.Entry entry)
Creates a new XmlEntryGDataSerializer that will serialize the provided entry.

param
entry The entry that should be serialized.

    this.factory = factory;
    this.entry = entry;
  
Methods Summary
private final voiddeclareEntryNamespaces(org.xmlpull.v1.XmlSerializer serializer)

    serializer.setPrefix("" /* default ns */,
        XmlGDataParser.NAMESPACE_ATOM_URI);
    serializer.setPrefix(XmlGDataParser.NAMESPACE_GD,
        XmlGDataParser.NAMESPACE_GD_URI);
    declareExtraEntryNamespaces(serializer);
  
protected voiddeclareExtraEntryNamespaces(org.xmlpull.v1.XmlSerializer serializer)

    // no-op in this class
  
public java.lang.StringgetContentType()

    return "application/atom+xml";
  
protected com.google.wireless.gdata.data.EntrygetEntry()
Returns the entry being serialized.

return
The entry being serialized.

    return entry;
  
public voidserialize(java.io.OutputStream out, int format)

    XmlSerializer serializer = null;
    try {
      serializer = factory.createSerializer();
    } catch (XmlPullParserException e) {
      throw new ParseException("Unable to create XmlSerializer.", e);
    }
    // TODO: make the output compact

    serializer.setOutput(out, "UTF-8");
    serializer.startDocument("UTF-8", new Boolean(false));

    declareEntryNamespaces(serializer);
    serializer.startTag(XmlGDataParser.NAMESPACE_ATOM_URI, "entry");

    serializeEntryContents(serializer, format);

    serializer.endTag(XmlGDataParser.NAMESPACE_ATOM_URI, "entry");
    serializer.endDocument();
    serializer.flush();
  
private static voidserializeAuthor(org.xmlpull.v1.XmlSerializer serializer, java.lang.String author, java.lang.String email)

    if (StringUtils.isEmpty(author) || StringUtils.isEmpty(email)) {
      return;
    }
    serializer.startTag(null /* ns */, "author");
    serializer.startTag(null /* ns */, "name");
    serializer.text(author);
    serializer.endTag(null /* ns */, "name");
    serializer.startTag(null /* ns */, "email");
    serializer.text(email);
    serializer.endTag(null /* ns */, "email");
    serializer.endTag(null /* ns */, "author");
  
private static voidserializeCategory(org.xmlpull.v1.XmlSerializer serializer, java.lang.String category, java.lang.String categoryScheme)

    if (StringUtils.isEmpty(category) &&
        StringUtils.isEmpty(categoryScheme)) {
      return;
    }
    serializer.startTag(null /* ns */, "category");
    if (!StringUtils.isEmpty(category)) {
      serializer.attribute(null /* ns */, "term", category);
    }
    if (!StringUtils.isEmpty(categoryScheme)) {
      serializer.attribute(null /* ns */, "scheme", categoryScheme);
    }
    serializer.endTag(null /* ns */, "category");
  
private static voidserializeContent(org.xmlpull.v1.XmlSerializer serializer, java.lang.String content)

    if (content == null) {
      return;
    }
    serializer.startTag(null /* ns */, "content");
    serializer.attribute(null /* ns */, "type", "text");
    serializer.text(content);
    serializer.endTag(null /* ns */, "content");
  
private final voidserializeEntryContents(org.xmlpull.v1.XmlSerializer serializer, int format)

param
serializer
throws
IOException


    if (format != FORMAT_CREATE) {
      serializeId(serializer, entry.getId());
    }

    serializeTitle(serializer, entry.getTitle());

    if (format != FORMAT_CREATE) {
      serializeLink(serializer, "edit" /* rel */, entry.getEditUri(), null /* type */);
      serializeLink(serializer, "alternate" /* rel */, entry.getHtmlUri(), "text/html" /* type */);
    }

    serializeSummary(serializer, entry.getSummary());

    serializeContent(serializer, entry.getContent());

    serializeAuthor(serializer, entry.getAuthor(), entry.getEmail());

    serializeCategory(serializer,
        entry.getCategory(), entry.getCategoryScheme());

    if (format == FORMAT_FULL) {
      serializePublicationDate(serializer,
          entry.getPublicationDate());
    }

    if (format != FORMAT_CREATE) {
      serializeUpdateDate(serializer,
          entry.getUpdateDate());
    }

    serializeExtraEntryContents(serializer, format);
  
protected voidserializeExtraEntryContents(org.xmlpull.v1.XmlSerializer serializer, int format)
Hook for subclasses to serialize extra fields within the entry.

param
serializer The XmlSerializer being used to serialize the entry.
param
format The serialization format for the entry.
throws
ParseException Thrown if the entry cannot be serialized.
throws
IOException Thrown if the entry cannot be written to the underlying {@link OutputStream}.

    // no-op in this class.
  
private static voidserializeId(org.xmlpull.v1.XmlSerializer serializer, java.lang.String id)

    if (StringUtils.isEmpty(id)) {
      return;
    }
    serializer.startTag(null /* ns */, "id");
    serializer.text(id);
    serializer.endTag(null /* ns */, "id");
  
public static voidserializeLink(org.xmlpull.v1.XmlSerializer serializer, java.lang.String rel, java.lang.String href, java.lang.String type)

    if (StringUtils.isEmpty(href)) {
      return;
    }
    serializer.startTag(null /* ns */, "link");
    serializer.attribute(null /* ns */, "rel", rel);
    serializer.attribute(null /* ns */, "href", href);
    if (!StringUtils.isEmpty(type)) serializer.attribute(null /* ns */, "type", type);
    serializer.endTag(null /* ns */, "link");
  
private static voidserializePublicationDate(org.xmlpull.v1.XmlSerializer serializer, java.lang.String publicationDate)

    if (StringUtils.isEmpty(publicationDate)) {
      return;
    }
    serializer.startTag(null /* ns */, "published");
    serializer.text(publicationDate);
    serializer.endTag(null /* ns */, "published");
  
private static voidserializeSummary(org.xmlpull.v1.XmlSerializer serializer, java.lang.String summary)

    if (StringUtils.isEmpty(summary)) {
      return;
    }
    serializer.startTag(null /* ns */, "summary");
    serializer.text(summary);
    serializer.endTag(null /* ns */, "summary");
  
private static voidserializeTitle(org.xmlpull.v1.XmlSerializer serializer, java.lang.String title)

    if (StringUtils.isEmpty(title)) {
      return;
    }
    serializer.startTag(null /* ns */, "title");
    serializer.text(title);
    serializer.endTag(null /* ns */, "title");
  
private static voidserializeUpdateDate(org.xmlpull.v1.XmlSerializer serializer, java.lang.String updateDate)

    if (StringUtils.isEmpty(updateDate)) {
      return;
    }
    serializer.startTag(null /* ns */, "updated");
    serializer.text(updateDate);
    serializer.endTag(null /* ns */, "updated");