XmlEntryGDataSerializerpublic class XmlEntryGDataSerializer extends Object implements com.google.wireless.gdata.serializer.GDataSerializerSerializes GData entries to the Atom XML format. |
Fields Summary |
---|
private final com.google.wireless.gdata.parser.xml.XmlParserFactory | factoryThe XmlParserFactory that is used to create the XmlSerializer | private final com.google.wireless.gdata.data.Entry | entryThe entry being serialized. |
Methods Summary |
---|
private final void | declareEntryNamespaces(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 void | declareExtraEntryNamespaces(org.xmlpull.v1.XmlSerializer serializer)
// no-op in this class
| public java.lang.String | getContentType()
return "application/atom+xml";
| protected com.google.wireless.gdata.data.Entry | getEntry()Returns the entry being serialized.
return entry;
| public void | serialize(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 void | serializeAuthor(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 void | serializeCategory(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 void | serializeContent(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 void | serializeEntryContents(org.xmlpull.v1.XmlSerializer serializer, int format)
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 void | serializeExtraEntryContents(org.xmlpull.v1.XmlSerializer serializer, int format)Hook for subclasses to serialize extra fields within the entry.
// no-op in this class.
| private static void | serializeId(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 void | serializeLink(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 void | serializePublicationDate(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 void | serializeSummary(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 void | serializeTitle(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 void | serializeUpdateDate(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");
|
|