diff options
Diffstat (limited to 'src/com/google/wireless/gdata/data')
-rw-r--r-- | src/com/google/wireless/gdata/data/Entry.java | 291 | ||||
-rw-r--r-- | src/com/google/wireless/gdata/data/ExtendedProperty.java | 53 | ||||
-rw-r--r-- | src/com/google/wireless/gdata/data/Feed.java | 122 | ||||
-rw-r--r-- | src/com/google/wireless/gdata/data/MediaEntry.java | 10 | ||||
-rw-r--r-- | src/com/google/wireless/gdata/data/StringUtils.java | 54 | ||||
-rw-r--r-- | src/com/google/wireless/gdata/data/XmlUtils.java | 133 | ||||
-rw-r--r-- | src/com/google/wireless/gdata/data/package.html | 5 |
7 files changed, 668 insertions, 0 deletions
diff --git a/src/com/google/wireless/gdata/data/Entry.java b/src/com/google/wireless/gdata/data/Entry.java new file mode 100644 index 0000000..3971f6b --- /dev/null +++ b/src/com/google/wireless/gdata/data/Entry.java @@ -0,0 +1,291 @@ +// Copyright 2007 The Android Open Source Project + +package com.google.wireless.gdata.data; + +import com.google.wireless.gdata.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; + private String editUri = null; + private String htmlUri = null; + private String summary = null; + private String content = null; + private String author = null; + private String email = null; + private String category = null; + private String categoryScheme = null; + private String publicationDate = null; + private String updateDate = null; + private boolean deleted = false; + + /** + * Creates a new empty entry. + */ + public Entry() { + } + + /** + * Clears all the values in this entry. + */ + public void clear() { + id = null; + title = null; + editUri = null; + htmlUri = null; + summary = null; + content = null; + author = null; + email = null; + category = null; + categoryScheme = null; + publicationDate = null; + updateDate = null; + deleted = false; + } + + /** + * @return the author + */ + public String getAuthor() { + return author; + } + + /** + * @param author the author to set + */ + public void setAuthor(String author) { + this.author = author; + } + + /** + * @return the category + */ + public String getCategory() { + return category; + } + + /** + * @param category the category to set + */ + public void setCategory(String category) { + this.category = category; + } + + /** + * @return the categoryScheme + */ + public String getCategoryScheme() { + return categoryScheme; + } + + /** + * @param categoryScheme the categoryScheme to set + */ + public void setCategoryScheme(String categoryScheme) { + this.categoryScheme = categoryScheme; + } + + /** + * @return the content + */ + public String getContent() { + return content; + } + + /** + * @param content the content to set + */ + public void setContent(String content) { + this.content = content; + } + + /** + * @return the editUri + */ + public String getEditUri() { + return editUri; + } + + /** + * @param editUri the editUri to set + */ + public void setEditUri(String editUri) { + this.editUri = editUri; + } + + /** + * @return The uri for the HTML version of this entry. + */ + public String getHtmlUri() { + return htmlUri; + } + + /** + * Set the uri for the HTML version of this entry. + * @param htmlUri The uri for the HTML version of this entry. + */ + public void setHtmlUri(String htmlUri) { + this.htmlUri = htmlUri; + } + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the publicationDate + */ + public String getPublicationDate() { + return publicationDate; + } + + /** + * @param publicationDate the publicationDate to set + */ + public void setPublicationDate(String publicationDate) { + this.publicationDate = publicationDate; + } + + /** + * @return the summary + */ + public String getSummary() { + return summary; + } + + /** + * @param summary the summary to set + */ + public void setSummary(String summary) { + this.summary = summary; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the updateDate + */ + public String getUpdateDate() { + return updateDate; + } + + /** + * @param updateDate the updateDate to set + */ + public void setUpdateDate(String updateDate) { + this.updateDate = updateDate; + } + + /** + * @return true if this entry represents a tombstone + */ + public boolean isDeleted() { + return deleted; + } + + /** + * @param isDeleted true if the entry is deleted + */ + public void setDeleted(boolean isDeleted) { + deleted = isDeleted; + } + + /** + * Appends the name and value to this StringBuffer, if value is not null. + * Uses the format: "<NAME>: <VALUE>\n" + * @param sb The StringBuffer in which the name and value should be + * appended. + * @param name The name that should be appended. + * @param value The value that should be appended. + */ + protected void appendIfNotNull(StringBuffer sb, + String name, String value) { + if (!StringUtils.isEmpty(value)) { + sb.append(name); + sb.append(": "); + sb.append(value); + sb.append("\n"); + } + } + + /** + * Helper method that creates the String representation of this Entry. + * Called by {@link #toString()}. + * Subclasses can add additional data to the StringBuffer. + * @param sb The StringBuffer that should be modified to add to the String + * representation of this Entry. + */ + protected void toString(StringBuffer sb) { + appendIfNotNull(sb, "ID", id); + appendIfNotNull(sb, "TITLE", title); + appendIfNotNull(sb, "EDIT URI", editUri); + appendIfNotNull(sb, "HTML URI", htmlUri); + appendIfNotNull(sb, "SUMMARY", summary); + appendIfNotNull(sb, "CONTENT", content); + appendIfNotNull(sb, "AUTHOR", author); + appendIfNotNull(sb, "CATEGORY", category); + appendIfNotNull(sb, "CATEGORY SCHEME", categoryScheme); + appendIfNotNull(sb, "PUBLICATION DATE", publicationDate); + appendIfNotNull(sb, "UPDATE DATE", updateDate); + appendIfNotNull(sb, "DELETED", String.valueOf(deleted)); + } + + /** + * Creates a StringBuffer and calls {@link #toString(StringBuffer)}. The + * return value for this method is simply the result of calling + * {@link StringBuffer#toString()} on this StringBuffer. Mainly used for + * debugging. + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + toString(sb); + return sb.toString(); + } + + /** + * @return the email + */ + public String getEmail() { + return email; + } + + /** + * @param email the email to set + */ + public void setEmail(String email) { + this.email = email; + } + + public void validate() throws ParseException { + } +} diff --git a/src/com/google/wireless/gdata/data/ExtendedProperty.java b/src/com/google/wireless/gdata/data/ExtendedProperty.java new file mode 100644 index 0000000..92e2c2b --- /dev/null +++ b/src/com/google/wireless/gdata/data/ExtendedProperty.java @@ -0,0 +1,53 @@ +package com.google.wireless.gdata.data; + +import com.google.wireless.gdata.parser.ParseException; + +/** + * The extendedProperty gdata type + */ +public class ExtendedProperty { + private String name; + private String value; + private String xmlBlob; + + public String getXmlBlob() { + return xmlBlob; + } + + public void setXmlBlob(String xmlBlob) { + this.xmlBlob = xmlBlob; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public void toString(StringBuffer sb) { + sb.append("ExtendedProperty"); + if (name != null) sb.append(" name:").append(name); + if (value != null) sb.append(" value:").append(value); + if (xmlBlob != null) sb.append(" xmlBlob:").append(xmlBlob); + } + + public void validate() throws ParseException { + if (name == null) { + throw new ParseException("name must not be null"); + } + + if ((value == null && xmlBlob == null) || (value != null && xmlBlob != null)) { + throw new ParseException("exactly one of value and xmlBlob must be present"); + } + } +} diff --git a/src/com/google/wireless/gdata/data/Feed.java b/src/com/google/wireless/gdata/data/Feed.java new file mode 100644 index 0000000..440e181 --- /dev/null +++ b/src/com/google/wireless/gdata/data/Feed.java @@ -0,0 +1,122 @@ +// Copyright 2007 The Android Open Source Project + +package com.google.wireless.gdata.data; + +/** + * Class containing information about a GData feed. Note that this feed does + * 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; + private int startIndex; + private int itemsPerPage; + private String title; + private String id; + private String lastUpdated; + private String category; + private String categoryScheme; + + /** + * Creates a new, empty feed. + */ + public Feed() { + } + + public int getTotalResults() { + return totalResults; + } + + public void setTotalResults(int totalResults) { + this.totalResults = totalResults; + } + + public int getStartIndex() { + return startIndex; + } + + public void setStartIndex(int startIndex) { + this.startIndex = startIndex; + } + + public int getItemsPerPage() { + return itemsPerPage; + } + + public void setItemsPerPage(int itemsPerPage) { + this.itemsPerPage = itemsPerPage; + } + + /** + * @return the category + */ + public String getCategory() { + return category; + } + + /** + * @param category the category to set + */ + public void setCategory(String category) { + this.category = category; + } + + /** + * @return the categoryScheme + */ + public String getCategoryScheme() { + return categoryScheme; + } + + /** + * @param categoryScheme the categoryScheme to set + */ + public void setCategoryScheme(String categoryScheme) { + this.categoryScheme = categoryScheme; + } + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the lastUpdated + */ + public String getLastUpdated() { + return lastUpdated; + } + + /** + * @param lastUpdated the lastUpdated to set + */ + public void setLastUpdated(String lastUpdated) { + this.lastUpdated = lastUpdated; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + +} diff --git a/src/com/google/wireless/gdata/data/MediaEntry.java b/src/com/google/wireless/gdata/data/MediaEntry.java new file mode 100644 index 0000000..873bd43 --- /dev/null +++ b/src/com/google/wireless/gdata/data/MediaEntry.java @@ -0,0 +1,10 @@ +package com.google.wireless.gdata.data; + +/** + * Entry containing information about media entries + */ +public class MediaEntry extends Entry { + public MediaEntry() { + super(); + } +} diff --git a/src/com/google/wireless/gdata/data/StringUtils.java b/src/com/google/wireless/gdata/data/StringUtils.java new file mode 100644 index 0000000..6036ab0 --- /dev/null +++ b/src/com/google/wireless/gdata/data/StringUtils.java @@ -0,0 +1,54 @@ +// Copyright 2007 The Android Open Source Project + +package com.google.wireless.gdata.data; + +/** + * Utility class for working with and manipulating Strings. + */ +public final class StringUtils { + // utility class + private StringUtils() { + } + + /** + * Returns whether or not the String is empty. A String is considered to + * be empty if it is null or if it has a length of 0. + * @param string The String that should be examined. + * @return Whether or not the String is empty. + */ + public static boolean isEmpty(String string) { + return ((string == null) || (string.length() == 0)); + } + + /** + * Returns {@code true} if the given string is null, empty, or comprises only + * whitespace characters, as defined by {@link Character#isWhitespace(char)}. + * + * @param string The String that should be examined. + * @return {@code true} if {@code string} is null, empty, or consists of + * whitespace characters only + */ + public static boolean isEmptyOrWhitespace(String string) { + if (string == null) { + return true; + } + int length = string.length(); + for (int i = 0; i < length; i++) { + if (!Character.isWhitespace(string.charAt(i))) { + return false; + } + } + return true; + } + + public static int parseInt(String string, int defaultValue) { + if (string != null) { + try { + return Integer.parseInt(string); + } catch (NumberFormatException nfe) { + // ignore + } + } + return defaultValue; + } +} diff --git a/src/com/google/wireless/gdata/data/XmlUtils.java b/src/com/google/wireless/gdata/data/XmlUtils.java new file mode 100644 index 0000000..1c067d3 --- /dev/null +++ b/src/com/google/wireless/gdata/data/XmlUtils.java @@ -0,0 +1,133 @@ +// Copyright 2007 The Android Open Source Project + +package com.google.wireless.gdata.data; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlSerializer; + +import java.io.IOException; + +/** + * Utility class for working with an XmlPullParser. + */ +public final class XmlUtils { + // utility class + private XmlUtils() { + } + + /** + * Extracts the child text for the current element in the pull parser. + * @param parser The XmlPullParser parsing an XML document. + * @return The child text for the current element. May be null, if there + * is no child text. + * @throws XmlPullParserException Thrown if the child text could not be + * parsed. + * @throws IOException Thrown if the InputStream behind the parser cannot + * be read. + */ + public static String extractChildText(XmlPullParser parser) + throws XmlPullParserException, IOException { + // TODO: check that the current node is an element? + int eventType = parser.next(); + if (eventType != XmlPullParser.TEXT) { + return null; + } + return parser.getText(); + } + + public static String extractFirstChildTextIgnoreRest(XmlPullParser parser) + throws XmlPullParserException, IOException { + int parentDepth = parser.getDepth(); + int eventType = parser.next(); + String child = null; + while (eventType != XmlPullParser.END_DOCUMENT) { + int depth = parser.getDepth(); + + if (eventType == XmlPullParser.TEXT) { + if (child == null) { + child = parser.getText(); + } + } else if (eventType == XmlPullParser.END_TAG && depth == parentDepth) { + return child; + } + eventType = parser.next(); + } + throw new XmlPullParserException("End of document reached; never saw expected end tag at " + + "depth " + parentDepth); + } + + public static String nextDirectChildTag(XmlPullParser parser, int parentDepth) + throws XmlPullParserException, IOException { + int targetDepth = parentDepth + 1; + int eventType = parser.next(); + while (eventType != XmlPullParser.END_DOCUMENT) { + int depth = parser.getDepth(); + + if (eventType == XmlPullParser.START_TAG && depth == targetDepth) { + return parser.getName(); + } + + if (eventType == XmlPullParser.END_TAG && depth == parentDepth) { + return null; + } + eventType = parser.next(); + } + throw new XmlPullParserException("End of document reached; never saw expected end tag at " + + "depth " + parentDepth); + } + +// public static void parseChildrenToSerializer(XmlPullParser parser, XmlSerializer serializer) +// throws XmlPullParserException, IOException { +// int parentDepth = parser.getDepth(); +// int eventType = parser.getEventType(); +// while (eventType != XmlPullParser.END_DOCUMENT) { +// // TODO: call parser.nextToken(), so we get all entities, comments, whitespace, etc.? +// // find out if this is necessary. +// eventType = parser.next(); +// int depth = parser.getDepth(); +// String name; +// String ns; +// switch (eventType) { +// case XmlPullParser.START_TAG: +// name = parser.getName(); +// ns = parser.getNamespace(); +// // grab all of the namespace definitions between the previous depth and the +// // current depth (e.g., what was just defined in the start tag). +// int nstackBegin = parser.getNamespaceCount(depth - 1); +// int nstackEnd = parser.getNamespaceCount(depth); +// for (int i = nstackBegin; i < nstackEnd; ++i) { +// serializer.setPrefix(parser.getNamespacePrefix(i), +// parser.getNamespaceUri(i)); +// } +// serializer.startTag(ns, name); +// +// int numAttrs = parser.getAttributeCount(); +// for (int i = 0; i < numAttrs; ++i) { +// String attrNs = parser.getAttributeNamespace(i); +// String attrName = parser.getAttributeName(i); +// String attrValue = parser.getAttributeValue(i); +// serializer.attribute(attrNs, attrName, attrValue); +// } +// break; +// case XmlPullParser.END_TAG: +// if (depth == parentDepth) { +// // we're done. +// return; +// } +// name = parser.getName(); +// ns = parser.getNamespace(); +// serializer.endTag(ns, name); +// break; +// case XmlPullParser.TEXT: +// serializer.text(parser.getText()); +// break; +// default: +// // ignore the rest. +// break; +// } +// } +// throw new XmlPullParserException("End of document reached; never saw expected end tag " +// + "at depth " + parentDepth); +// } +} diff --git a/src/com/google/wireless/gdata/data/package.html b/src/com/google/wireless/gdata/data/package.html new file mode 100644 index 0000000..1c9bf9d --- /dev/null +++ b/src/com/google/wireless/gdata/data/package.html @@ -0,0 +1,5 @@ +<html> +<body> + {@hide} +</body> +</html> |