summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-08-21 12:03:54 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-08-21 12:03:54 -0700
commit30201d6176bc5ac43f31b943f208d03d2f247e5a (patch)
treea8e6b982ed1a233f720b292401849f0471922dbf
parent2b1eeffed0eed39aca594481033e01c0bf669c2a (diff)
parent7bbd5148d3ccd92ac31b33013da8ce05b4f3b053 (diff)
downloadgdata-30201d6176bc5ac43f31b943f208d03d2f247e5a.tar.gz
Merge change 22070 into eclair
* changes: Cleanup of some GData functionallity. Changed parser.init() to parser.parseFeed(). Also added an overloadable method to the entry parsing code and changed parsing of content to take src and type into account. changed parseFeed to parseFeedEnvelope
-rw-r--r--src/com/google/wireless/gdata2/client/GDataClient.java2
-rw-r--r--src/com/google/wireless/gdata2/client/HttpException.java1
-rw-r--r--src/com/google/wireless/gdata2/client/QueryParams.java17
-rw-r--r--src/com/google/wireless/gdata2/data/Entry.java69
-rw-r--r--src/com/google/wireless/gdata2/data/Feed.java1
-rw-r--r--src/com/google/wireless/gdata2/parser/GDataParser.java3
-rw-r--r--src/com/google/wireless/gdata2/parser/xml/XmlGDataParser.java30
-rw-r--r--src/com/google/wireless/gdata2/parser/xml/XmlNametable.java1
8 files changed, 94 insertions, 30 deletions
diff --git a/src/com/google/wireless/gdata2/client/GDataClient.java b/src/com/google/wireless/gdata2/client/GDataClient.java
index 5de92d9..4f664c5 100644
--- a/src/com/google/wireless/gdata2/client/GDataClient.java
+++ b/src/com/google/wireless/gdata2/client/GDataClient.java
@@ -84,8 +84,6 @@ public interface GDataClient {
InputStream getMediaEntryAsStream(String mediaEntryUrl, String authToken, String eTag, String protocolVersion)
throws HttpException, IOException;
- // TODO: support batch update
-
/**
* Connects to a GData server (specified by the feedUrl) and creates a new
* entry. The response from the server is returned as an
diff --git a/src/com/google/wireless/gdata2/client/HttpException.java b/src/com/google/wireless/gdata2/client/HttpException.java
index cf1475f..4ca71b7 100644
--- a/src/com/google/wireless/gdata2/client/HttpException.java
+++ b/src/com/google/wireless/gdata2/client/HttpException.java
@@ -38,7 +38,6 @@ public class HttpException extends GDataException {
* Creates an HttpException with the given message, statusCode and
* responseStream.
*/
- //TODO: also record response headers?
public HttpException(String message, int statusCode,
InputStream responseStream) {
super(message);
diff --git a/src/com/google/wireless/gdata2/client/QueryParams.java b/src/com/google/wireless/gdata2/client/QueryParams.java
index c92d211..c3afb4a 100644
--- a/src/com/google/wireless/gdata2/client/QueryParams.java
+++ b/src/com/google/wireless/gdata2/client/QueryParams.java
@@ -147,16 +147,15 @@ public abstract class QueryParams {
/**
* @return the maxResults
*/
- public String getMaxResults() {
- return getParamValue(MAX_RESULTS_PARAM);
+ public int getMaxResults() {
+ return Integer.parseInt(getParamValue(MAX_RESULTS_PARAM));
}
- // TODO: use an int!
/**
* @param maxResults the maxResults to set
*/
- public void setMaxResults(String maxResults) {
- setParamValue(MAX_RESULTS_PARAM, maxResults);
+ public void setMaxResults(int maxResults) {
+ setParamValue(MAX_RESULTS_PARAM, String.valueOf(maxResults));
}
/**
@@ -204,15 +203,15 @@ public abstract class QueryParams {
/**
* @return the startIndex
*/
- public String getStartIndex() {
- return getParamValue(START_INDEX_PARAM);
+ public int getStartIndex() {
+ return Integer.parseInt(getParamValue(START_INDEX_PARAM));
}
/**
* @param startIndex the startIndex to set
*/
- public void setStartIndex(String startIndex) {
- setParamValue(START_INDEX_PARAM, startIndex);
+ public void setStartIndex(int startIndex) {
+ setParamValue(START_INDEX_PARAM, String.valueOf(startIndex));
}
/**
diff --git a/src/com/google/wireless/gdata2/data/Entry.java b/src/com/google/wireless/gdata2/data/Entry.java
index 5680e8b..266ff29 100644
--- a/src/com/google/wireless/gdata2/data/Entry.java
+++ b/src/com/google/wireless/gdata2/data/Entry.java
@@ -8,10 +8,8 @@ import com.google.wireless.gdata2.parser.ParseException;
/**
* Entry in a GData feed.
*/
-// TODO: make this an interface?
// allow for writing directly into data structures used by native PIM, etc.,
// APIs.
-// TODO: comment that setId(), etc., only used for parsing code.
public class Entry {
private String id = null;
private String title = null;
@@ -29,6 +27,8 @@ public class Entry {
private boolean deleted = false;
private BatchInfo batchInfo = null;
private String fields = null;
+ private String contentSource = null;
+ private String contentType = null;
/**
* Creates a new empty entry.
@@ -46,6 +46,8 @@ public class Entry {
htmlUri = null;
summary = null;
content = null;
+ contentType = null;
+ contentSource = null;
author = null;
email = null;
category = null;
@@ -102,7 +104,7 @@ public class Entry {
* @return the content
*/
public String getContent() {
- return content;
+ return this.content;
}
/**
@@ -113,13 +115,50 @@ public class Entry {
}
/**
+ * @return the contents type, either one of the default
+ * types (text, html, xhtml) or an atomMediaType
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * @param type the contentType to set
+ */
+ public void setContentType(String type) {
+ this.contentType = content;
+ }
+
+ /**
+ * If the content itself is empty, the src attribute
+ * points to the internet resource where the content
+ * can be loaded from
+ * @return the src attribute of the content element
+ */
+ public String getContentSource() {
+ return contentSource;
+ }
+
+ /**
+ * @param contentSource the url value to set
+ */
+ public void setContentSource(String contentSource) {
+ this.contentSource = contentSource;
+ }
+
+
+
+ /**
* @return the editUri
*/
public String getEditUri() {
return editUri;
}
- /**
+ /**
+ * Note that setting the editUri is only valid during parsing
+ * time, this is a server generated value and can not be changed
+ * by the client normally
* @param editUri the editUri to set
*/
public void setEditUri(String editUri) {
@@ -148,7 +187,10 @@ public class Entry {
return id;
}
- /**
+ /**
+ * Note that setting the ID is only valid during parsing time,
+ * an ID is a server generated value and can not be changed by
+ * the client normally
* @param id the id to set
*/
public void setId(String id) {
@@ -162,7 +204,10 @@ public class Entry {
return publicationDate;
}
- /**
+ /**
+ * Note that setting the publicationDate is only valid during
+ * parsing time, this is a server generated value and can not be
+ * changed by the client normally
* @param publicationDate the publicationDate to set
*/
public void setPublicationDate(String publicationDate) {
@@ -204,7 +249,10 @@ public class Entry {
return updateDate;
}
- /**
+ /**
+ * Note that setting the updateDate is only valid during parsing
+ * time, this is a server generated value and can not be changed
+ * by the client normally
* @param updateDate the updateDate to set
*/
public void setUpdateDate(String updateDate) {
@@ -232,8 +280,11 @@ public class Entry {
return eTagValue;
}
- /**
- * @param eTag the eTag on the entry, used during parsing
+ /**
+ * Note that setting the etag is only valid during parsing
+ * time, this is a server generated value and can not be changed
+ * by the client normally
+ * @param eTag the eTag on the entry
*/
public void setETag(String eTag) {
eTagValue = eTag;
diff --git a/src/com/google/wireless/gdata2/data/Feed.java b/src/com/google/wireless/gdata2/data/Feed.java
index dd9779c..92d719a 100644
--- a/src/com/google/wireless/gdata2/data/Feed.java
+++ b/src/com/google/wireless/gdata2/data/Feed.java
@@ -7,7 +7,6 @@ package com.google.wireless.gdata2.data;
* not contain any of the entries in that feed -- the entries are yielded
* separately from this Feed.
*/
-// TODO: add a createEntry method?
// TODO: comment that setters are only used for parsing code.
public class Feed {
private int totalResults;
diff --git a/src/com/google/wireless/gdata2/parser/GDataParser.java b/src/com/google/wireless/gdata2/parser/GDataParser.java
index 87c9ec3..ae3df73 100644
--- a/src/com/google/wireless/gdata2/parser/GDataParser.java
+++ b/src/com/google/wireless/gdata2/parser/GDataParser.java
@@ -22,8 +22,7 @@ public interface GDataParser {
* @return The {@link Feed} containing information about the parsed feed.
* @throws ParseException Thrown if the feed cannot be parsed.
*/
- // TODO: rename to parseFeed? need to make the API clear.
- Feed init() throws ParseException;
+ Feed parseFeedEnvelope() throws ParseException;
/**
* Parses a GData entry. You can either call {@link #init()} or
diff --git a/src/com/google/wireless/gdata2/parser/xml/XmlGDataParser.java b/src/com/google/wireless/gdata2/parser/xml/XmlGDataParser.java
index 25c22f3..92089b0 100644
--- a/src/com/google/wireless/gdata2/parser/xml/XmlGDataParser.java
+++ b/src/com/google/wireless/gdata2/parser/xml/XmlGDataParser.java
@@ -81,9 +81,9 @@ public class XmlGDataParser implements GDataParser {
/*
* (non-Javadoc)
- * @see com.google.wireless.gdata2.parser.GDataParser#init()
+ * @see com.google.wireless.gdata2.parser.GDataParser#parseFeedEnvelope()
*/
- public final Feed init() throws ParseException {
+ public final Feed parseFeedEnvelope() throws ParseException {
int eventType;
fields = null;
try {
@@ -258,7 +258,6 @@ public class XmlGDataParser implements GDataParser {
}
} else if (XmlNametable.ENTRY.equals(name)) {
// stop parsing here.
- // TODO: pay attention to depth?
return feed;
}
} else {
@@ -550,12 +549,18 @@ public class XmlGDataParser implements GDataParser {
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
- // TODO: make sure these elements are at the expected depth.
String name = parser.getName();
if (XmlNametable.ENTRY.equals(name)) {
// stop parsing here.
return;
- } else if (NAMESPACE_BATCH_URI.equals(parser.getNamespace())) {
+ }
+ // for each start tag, we call our subclasses first. Only do the default
+ // processing, if they have not done it.
+ if (handleDefaultEntryElements(entry)){
+ break;
+ }
+
+ if (NAMESPACE_BATCH_URI.equals(parser.getNamespace())) {
// We must check for the BATCH namespace first in case the tag name
// is reused in another namespace. e.g. "id".
handleBatchInfo(entry);
@@ -584,8 +589,9 @@ public class XmlGDataParser implements GDataParser {
} else if (XmlNametable.SUMMARY.equals(name)) {
entry.setSummary(XmlUtils.extractChildText(parser));
} else if (XmlNametable.CONTENT.equals(name)) {
- // TODO: parse the type
entry.setContent(XmlUtils.extractChildText(parser));
+ entry.setContentType(parser.getAttributeValue(null /* ns */, XmlNametable.TYPE));
+ entry.setContentSource(parser.getAttributeValue(null /* ns */, XmlNametable.SRC));
} else if (XmlNametable.AUTHOR.equals(name)) {
handleAuthor(entry);
} else if (XmlNametable.CATEGORY.equals(name)) {
@@ -720,6 +726,18 @@ public class XmlGDataParser implements GDataParser {
// no-op in this class.
}
+ /**
+ * Hook that allows a subclass to override default parsing
+ * behaviour. If the subclass returns true from this call,
+ * no default parsing will happen for the currently parsed tag
+ * @param entry The {@link Entry} being filled.
+ * @return true if the subclass handled the parsing.
+ */
+ protected boolean handleDefaultEntryElements(Entry entry)
+ throws XmlPullParserException, IOException {
+ // no-op in this class.
+ return false;
+ }
/**
* Hook that allows extra (service-specific) &lt;link&gt;s in an entry to be
* parsed.
diff --git a/src/com/google/wireless/gdata2/parser/xml/XmlNametable.java b/src/com/google/wireless/gdata2/parser/xml/XmlNametable.java
index 4952403..381a48c 100644
--- a/src/com/google/wireless/gdata2/parser/xml/XmlNametable.java
+++ b/src/com/google/wireless/gdata2/parser/xml/XmlNametable.java
@@ -22,6 +22,7 @@ public final class XmlNametable {
public static String HREF = "href";
public static String ETAG = "etag";
public static String TYPE = "type";
+ public static String SRC = "src";
public static String TEXT = "text";
public static String TEXTHTML = "text/html";
public static String ID = "id";