blob: b64f76ad42f47d542d9e1ca830135c63988ef32a (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// 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.data.StringUtils;
import com.google.wireless.gdata.data.XmlUtils;
import com.google.wireless.gdata.parser.ParseException;
import com.google.wireless.gdata.parser.xml.XmlGDataParser;
import com.google.wireless.gdata.spreadsheets.data.CellEntry;
import com.google.wireless.gdata.spreadsheets.data.CellFeed;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.InputStream;
/**
* Parser for non-Atom data in a GData Spreadsheets Cell-based feed.
*/
public class XmlCellsGDataParser extends XmlGDataParser {
/**
* The rel ID used by the server to identify the URLs for Cell POSTs
* (updates)
*/
private static final String CELL_FEED_POST_REL =
"http://schemas.google.com/g/2005#post";
/**
* Creates a new XmlCellsGDataParser.
*
* @param is the stream from which to read the data
* @param xmlParser the XMLPullParser to use for parsing the raw XML
* @throws ParseException if the super-class throws one
*/
public XmlCellsGDataParser(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 CellEntry();
}
/* (non-JavaDoc)
* Creates a new Feed that can handle the data parsed by this class.
*/
protected Feed createFeed() {
return new CellFeed();
}
/* (non-JavaDoc)
* Callback to handle non-Atom data present in an Atom entry tag.
*/
protected void handleExtraElementInEntry(Entry entry)
throws XmlPullParserException, IOException {
XmlPullParser parser = getParser();
if (!(entry instanceof CellEntry)) {
throw new IllegalArgumentException("Expected CellEntry!");
}
CellEntry row = (CellEntry) entry;
String name = parser.getName();
// cells can only have row, col, inputValue, & numericValue attrs
if ("cell".equals(name)) {
int count = parser.getAttributeCount();
String attrName = null;
for (int i = 0; i < count; ++i) {
attrName = parser.getAttributeName(i);
if ("row".equals(attrName)) {
row.setRow(StringUtils.parseInt(parser
.getAttributeValue(i), 0));
} else if ("col".equals(attrName)) {
row.setCol(StringUtils.parseInt(parser
.getAttributeValue(i), 0));
} else if ("numericValue".equals(attrName)) {
row.setNumericValue(parser.getAttributeValue(i));
} else if ("inputValue".equals(attrName)) {
row.setInputValue(parser.getAttributeValue(i));
}
}
// also need the data stored in the child text node
row.setValue(XmlUtils.extractChildText(parser));
}
}
/* (non-JavaDoc)
* Callback to handle non-Atom data in the feed.
*/
protected void handleExtraElementInFeed(Feed feed)
throws XmlPullParserException, IOException {
XmlPullParser parser = getParser();
if (!(feed instanceof CellFeed)) {
throw new IllegalArgumentException("Expected CellFeed!");
}
CellFeed cellFeed = (CellFeed) feed;
String name = parser.getName();
if (!"link".equals(name)) {
return;
}
int numAttrs = parser.getAttributeCount();
String rel = null;
String href = null;
String attrName = null;
for (int i = 0; i < numAttrs; ++i) {
attrName = parser.getAttributeName(i);
if ("rel".equals(attrName)) {
rel = parser.getAttributeValue(i);
} else if ("href".equals(attrName)) {
href = parser.getAttributeValue(i);
}
}
if (!(StringUtils.isEmpty(rel) || StringUtils.isEmpty(href))) {
if (CELL_FEED_POST_REL.equals(rel)) {
cellFeed.setEditUri(href);
}
}
}
}
|