summaryrefslogtreecommitdiff
path: root/src/com/google/wireless/gdata/spreadsheets/parser/xml/XmlSpreadsheetsGDataParser.java
blob: cb1094d575a468f410c62f7ffd2af25d25698c17 (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
68
// Copyright 2007 The Android Open Source Project
package com.google.wireless.gdata.spreadsheets.parser.xml;

import com.google.wireless.gdata.data.Entry;
import com.google.wireless.gdata.data.Feed;
import com.google.wireless.gdata.parser.ParseException;
import com.google.wireless.gdata.parser.xml.XmlGDataParser;
import com.google.wireless.gdata.spreadsheets.data.SpreadsheetEntry;
import com.google.wireless.gdata.spreadsheets.data.SpreadsheetFeed;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;

/**
 * Parser helper for non-Atom data in a GData Spreadsheets meta-feed.
 */
public class XmlSpreadsheetsGDataParser extends XmlGDataParser {
    /**
     * The rel ID used by the server to identify the URLs for the worksheets
     * feed
     */
    protected static final String WORKSHEET_FEED_REL =
            "http://schemas.google.com/spreadsheets/2006#worksheetsfeed";

    /**
     * Creates a new XmlSpreadsheetsGDataParser.
     * 
     * @param is the stream from which to read the data
     * @param xmlParser the XmlPullParser to use to parse the raw XML
     * @throws ParseException if the super-class throws one
     */
    public XmlSpreadsheetsGDataParser(InputStream is, XmlPullParser xmlParser)
            throws ParseException {
        super(is, xmlParser);
    }

    /* (non-JavaDoc)
     * Creates a new Entry that can handle the data parsed by this class.
     */
    protected Entry createEntry() {
        return new SpreadsheetEntry();
    }

    /* (non-JavaDoc)
     * Creates a new Feed that can handle the data parsed by this class.
     */
    protected Feed createFeed() {
        return new SpreadsheetFeed();
    }

    /* (non-JavaDoc)
     * Callback to handle link elements that are not recognized as Atom links.
     * Used to pick out the link tag in a Spreadsheet's entry that corresponds
     * to that spreadsheet's worksheets meta-feed.
     */
    protected void handleExtraLinkInEntry(String rel, String type, String href,
            Entry entry) throws XmlPullParserException, IOException {
        super.handleExtraLinkInEntry(rel, type, href, entry);
        if (WORKSHEET_FEED_REL.equals(rel)
                && "application/atom+xml".equals(type)) {
            SpreadsheetEntry sheet = (SpreadsheetEntry) entry;
            sheet.setWorksheetFeedUri(href);
        }
    }
}