summaryrefslogtreecommitdiff
path: root/src/com/google/wireless/gdata/spreadsheets/serializer/xml/XmlListEntryGDataSerializer.java
blob: 55cc59c4054767a5818bbd43ad9099a8ee984459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
            }
        }
    }
}