diff options
Diffstat (limited to 'src/com/google/wireless/gdata/spreadsheets/serializer/xml')
3 files changed, 155 insertions, 0 deletions
diff --git a/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlCellEntryGDataSerializer.java b/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlCellEntryGDataSerializer.java new file mode 100755 index 0000000..995af2c --- /dev/null +++ b/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlCellEntryGDataSerializer.java @@ -0,0 +1,83 @@ +package com.google.wireless.gdata.spreadsheets.serializer.xml; + +import com.google.wireless.gdata.data.Entry; +import com.google.wireless.gdata.data.StringUtils; +import com.google.wireless.gdata.parser.ParseException; +import com.google.wireless.gdata.parser.xml.XmlParserFactory; +import com.google.wireless.gdata.serializer.xml.XmlEntryGDataSerializer; +import com.google.wireless.gdata.spreadsheets.data.CellEntry; + +import org.xmlpull.v1.XmlSerializer; + +import java.io.IOException; + +/** + * A serializer for handling GData Spreadsheets Cell entries. + */ +public class XmlCellEntryGDataSerializer extends XmlEntryGDataSerializer { + /** The namespace to use for the GData Cell attributes */ + public static final String NAMESPACE_GS = "gs"; + + /** The URI of the GData Cell namespace */ + public static final String NAMESPACE_GS_URI = + "http://schemas.google.com/spreadsheets/2006"; + + /** + * Creates a new XmlCellEntryGDataSerializer. + * + * @param entry the entry to be serialized + */ + public XmlCellEntryGDataSerializer(XmlParserFactory xmlFactory, + Entry entry) { + super(xmlFactory, entry); + } + + /** + * Sets up the GData Cell namespace. + * + * @param serializer the serializer to use + */ + protected void declareExtraEntryNamespaces(XmlSerializer serializer) + throws IOException { + serializer.setPrefix(NAMESPACE_GS, NAMESPACE_GS_URI); + } + + /* + * Handles the non-Atom data belonging to the GData Spreadsheets Cell + * namespace. + * + * @param serializer the XML serializer to use + * @param format unused + * @throws ParseException if the data could not be serialized + * @throws IOException on network error + */ + protected void serializeExtraEntryContents(XmlSerializer serializer, + int format) throws ParseException, IOException { + CellEntry entry = (CellEntry) getEntry(); + int row = entry.getRow(); + int col = entry.getCol(); + String value = entry.getValue(); + String inputValue = entry.getInputValue(); + if (row < 0 || col < 0) { + throw new ParseException("Negative row or column value"); + } + + // cells require row & col attrs, and allow inputValue and + // numericValue + serializer.startTag(NAMESPACE_GS_URI, "cell"); + serializer.attribute(null /* ns */, "row", "" + row); + serializer.attribute(null /* ns */, "col", "" + col); + if (inputValue != null) { + serializer.attribute(null /* ns */, "inputValue", inputValue); + } + if (entry.hasNumericValue()) { + serializer.attribute(null /* ns */, "numericValue", entry + .getNumericValue()); + } + + // set the child text... + value = StringUtils.isEmpty(value) ? "" : value; + serializer.text(value); + serializer.endTag(NAMESPACE_GS_URI, "cell"); + } +} diff --git a/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlListEntryGDataSerializer.java b/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlListEntryGDataSerializer.java new file mode 100755 index 0000000..55cc59c --- /dev/null +++ b/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlListEntryGDataSerializer.java @@ -0,0 +1,67 @@ +package com.google.wireless.gdata.spreadsheets.serializer.xml; + +import com.google.wireless.gdata.data.Entry; +import com.google.wireless.gdata.parser.ParseException; +import com.google.wireless.gdata.parser.xml.XmlParserFactory; +import com.google.wireless.gdata.serializer.xml.XmlEntryGDataSerializer; +import com.google.wireless.gdata.spreadsheets.data.ListEntry; + +import org.xmlpull.v1.XmlSerializer; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Vector; + +/** + * A serializer for handling GData Spreadsheets List entries. + */ +public class XmlListEntryGDataSerializer extends XmlEntryGDataSerializer { + /** The prefix to use for the GData Spreadsheets list namespace */ + public static final String NAMESPACE_GSX = "gsx"; + + /** The URI of the GData Spreadsheets list namespace */ + public static final String NAMESPACE_GSX_URI = + "http://schemas.google.com/spreadsheets/2006/extended"; + + /** + * Creates a new XmlListEntryGDataSerializer. + * + * @param entry the entry to be serialized + */ + public XmlListEntryGDataSerializer(XmlParserFactory xmlFactory, Entry entry) { + super(xmlFactory, entry); + } + + /** + * Sets up the GData Spreadsheets list namespace. + * + * @param serializer the XML serializer to use + * @throws IOException on stream errors. + */ + protected void declareExtraEntryNamespaces(XmlSerializer serializer) + throws IOException { + serializer.setPrefix(NAMESPACE_GSX, NAMESPACE_GSX_URI); + } + + /* (non-JavaDoc) + * Handles the non-Atom data belonging to the GData Spreadsheets Cell + * namespace. + */ + protected void serializeExtraEntryContents(XmlSerializer serializer, + int format) throws ParseException, IOException { + ListEntry entry = (ListEntry) getEntry(); + Vector names = entry.getNames(); + String name = null; + String value = null; + Iterator it = names.iterator(); + while (it.hasNext()) { + name = (String) it.next(); + value = entry.getValue(name); + if (value != null) { + serializer.startTag(NAMESPACE_GSX_URI, name); + serializer.text(value); + serializer.endTag(NAMESPACE_GSX_URI, name); + } + } + } +} diff --git a/src/com/google/wireless/gdata/spreadsheets/serializer/xml/package.html b/src/com/google/wireless/gdata/spreadsheets/serializer/xml/package.html new file mode 100644 index 0000000..1c9bf9d --- /dev/null +++ b/src/com/google/wireless/gdata/spreadsheets/serializer/xml/package.html @@ -0,0 +1,5 @@ +<html> +<body> + {@hide} +</body> +</html> |