FileDocCategorySizeDatePackage
SpreadsheetsClient.javaAPI DocAndroid 1.5 API10128Wed May 06 22:41:16 BST 2009com.google.wireless.gdata.spreadsheets.client

SpreadsheetsClient

public class SpreadsheetsClient extends com.google.wireless.gdata.client.GDataServiceClient
GDataServiceClient for accessing Google Spreadsheets. This client can access and parse all of the Spreadsheets feed types: Spreadsheets feed, Worksheets feed, List feed, and Cells feed. Read operations are supported on all feed types, but only the List and Cells feeds support write operations. (This is a limitation of the protocol, not this API. Such write access may be added to the protocol in the future, requiring changes to this implementation.) Only 'private' visibility and 'full' projections are currently supported.

Fields Summary
private static final String
SERVICE
The name of the service, dictated to be 'wise' by the protocol.
public static final String
SPREADSHEETS_BASE_FEED_URL
Standard base feed url for spreadsheets.
private final String
baseFeedUrl
Base feed url for spreadsheets.
Constructors Summary
public SpreadsheetsClient(com.google.wireless.gdata.client.GDataClient client, com.google.wireless.gdata.client.GDataParserFactory spreadsheetFactory, String baseFeedUrl)
Create a new SpreadsheetsClient.

param
client The GDataClient that should be used to authenticate requests, retrieve feeds, etc.
param
spreadsheetFactory The GDataParserFactory that should be used to obtain GDataParsers used by this client.
param
baseFeedUrl The base URL for spreadsheets feeds.


                                                         
      
             
              
        super(client, spreadsheetFactory);
        this.baseFeedUrl = baseFeedUrl;
    
public SpreadsheetsClient(com.google.wireless.gdata.client.GDataClient client, com.google.wireless.gdata.client.GDataParserFactory spreadsheetFactory)
Create a new SpreadsheetsClient. Uses the standard base URL for spreadsheets feeds.

param
client The GDataClient that should be used to authenticate requests, retrieve feeds, etc.

        this(client, spreadsheetFactory, SPREADSHEETS_BASE_FEED_URL);
    
Methods Summary
public com.google.wireless.gdata.data.EntrycreateEntry(java.lang.String feedUri, java.lang.String authToken, com.google.wireless.gdata.data.Entry entry)


        GDataParserFactory factory = getGDataParserFactory();
        GDataSerializer serializer = factory.createSerializer(entry);

        InputStream is = getGDataClient().createEntry(feedUri, authToken, serializer);
        GDataParser parser = factory.createParser(entry.getClass(), is);
        try {
            return parser.parseStandaloneEntry();
        } finally {
            parser.close();
        }
    
public java.lang.StringgetBaseFeedUrl()

        return baseFeedUrl;
    
public com.google.wireless.gdata.parser.GDataParsergetParserForCellsFeed(java.lang.String feedUri, java.lang.String authToken)
Returns a parser for a Cells-based feed.

param
feedUri the URI of the feed to be fetched and parsed
param
authToken the current authToken to use for the request
return
a parser for the indicated feed
throws
HttpException if an http error is encountered
throws
ParseException if the response from the server could not be parsed

        return getParserForTypedFeed(CellEntry.class, feedUri, authToken);
    
public com.google.wireless.gdata.parser.GDataParsergetParserForFeed(java.lang.Class feedEntryClass, java.lang.String feedUri, java.lang.String authToken)
Fetches a GDataParser for the indicated feed. The parser can be used to access the contents of URI. WARNING: because we cannot reliably infer the feed type from the URI alone, this method assumes the default feed type! This is probably NOT what you want. Please use the getParserFor[Type]Feed methods.

param
feedEntryClass
param
feedUri the URI of the feed to be fetched and parsed
param
authToken the current authToken to use for the request
return
a parser for the indicated feed
throws
HttpException if an http error is encountered
throws
ParseException if the response from the server could not be parsed

        GDataClient gDataClient = getGDataClient();
        GDataParserFactory gDataParserFactory = getGDataParserFactory();
        InputStream is = gDataClient.getFeedAsStream(feedUri, authToken);
        return gDataParserFactory.createParser(feedEntryClass, is);
    
public com.google.wireless.gdata.parser.GDataParsergetParserForListFeed(java.lang.String feedUri, java.lang.String authToken)
Returns a parser for a List (row-based) feed.

param
feedUri the URI of the feed to be fetched and parsed
param
authToken the current authToken to use for the request
return
a parser for the indicated feed
throws
HttpException if an http error is encountered
throws
ParseException if the response from the server could not be parsed

        return getParserForTypedFeed(ListEntry.class, feedUri, authToken);
    
public com.google.wireless.gdata.parser.GDataParsergetParserForSpreadsheetsFeed(java.lang.String feedUri, java.lang.String authToken)
Returns a parser for a Spreadsheets meta-feed.

param
feedUri the URI of the feed to be fetched and parsed
param
authToken the current authToken to use for the request
return
a parser for the indicated feed
throws
HttpException if an http error is encountered
throws
ParseException if the response from the server could not be parsed

        return getParserForTypedFeed(SpreadsheetEntry.class, feedUri, authToken);
    
private com.google.wireless.gdata.parser.GDataParsergetParserForTypedFeed(java.lang.Class feedEntryClass, java.lang.String feedUri, java.lang.String authToken)
Returns a parser for the specified feed type.

param
feedEntryClass the Class of entry type that will be parsed. This lets this method figure out which parser to create.
param
feedUri the URI of the feed to be fetched and parsed
param
authToken the current authToken to use for the request @return a parser for the indicated feed
throws
HttpException if an http error is encountered
throws
ParseException if the response from the server could not be parsed

        GDataClient gDataClient = getGDataClient();
        GDataParserFactory gDataParserFactory = getGDataParserFactory();

        InputStream is = gDataClient.getFeedAsStream(feedUri, authToken);
        return gDataParserFactory.createParser(feedEntryClass, is);
    
public com.google.wireless.gdata.parser.GDataParsergetParserForWorksheetsFeed(java.lang.String feedUri, java.lang.String authToken)
Returns a parser for a Worksheets meta-feed.

param
feedUri the URI of the feed to be fetched and parsed
param
authToken the current authToken to use for the request
return
a parser for the indicated feed
throws
HttpException if an http error is encountered
throws
ParseException if the response from the server could not be parsed

        return getParserForTypedFeed(WorksheetEntry.class, feedUri, authToken);
    
public java.lang.StringgetServiceName()

        return SERVICE;
    
public com.google.wireless.gdata.data.EntryupdateEntry(com.google.wireless.gdata.data.Entry entry, java.lang.String authToken)
Updates an entry. The URI to be updated is taken from entry. Note that only entries in List and Cells feeds can be updated, so entry must be of the corresponding type; other types will result in an exception.

param
entry the entry to be updated; must include its URI
param
authToken the current authToken to be used for the operation
return
An Entry containing the re-parsed version of the entry returned by the server in response to the update.
throws
HttpException if an http error is encountered
throws
ParseException if the server returned an error, if the server's response was unparseable (unlikely), or if entry is of a read-only type
throws
IOException on network error

        GDataParserFactory factory = getGDataParserFactory();
        GDataSerializer serializer = factory.createSerializer(entry);

        String editUri = entry.getEditUri();
        if (StringUtils.isEmpty(editUri)) {
            throw new ParseException("No edit URI -- cannot update.");
        }

        InputStream is = getGDataClient().updateEntry(editUri, authToken, serializer);
        GDataParser parser = factory.createParser(entry.getClass(), is);
        try {
            return parser.parseStandaloneEntry();
        } finally {
            parser.close();
        }