1
/* Copyright (c) 2006 Google Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
19
using System.Collections;
22
using Google.GData.Client;
23
using Google.GData.Extensions;
26
namespace Google.GData.Documents {
28
//////////////////////////////////////////////////////////////////////
30
/// The Google Documents List data API allows client applications to upload
31
/// documents to Google Documents and list them in the form of Google data
32
/// API ("GData") feeds. Your client application can request a list of a user's
33
/// documents, and query the content in an existing document.
34
/// Here are some of the things you can do with the Documents List data API:
35
/// Upload the word processing documents and spreadsheets on
36
/// your computer to allow you to back them up or
37
/// collaborate online when editing.
38
/// Find all of your documents that contain specific keywords.
39
/// Get a list of spreadsheets which can be accessed through the Google Spreadsheets data API.
41
//////////////////////////////////////////////////////////////////////
42
public class DocumentsService : Service
45
/// <summary>The Calendar service's name</summary>
46
public const string GDocumentsService = "writely";
49
/// A Hashtable that expresses the allowed content types.
51
public static Hashtable GDocumentsAllowedTypes;
54
/// Static constructor used to initialize GDocumentsAllowedTypes.
56
static DocumentsService()
58
GDocumentsAllowedTypes = new Hashtable();
59
GDocumentsAllowedTypes.Add("CSV", "text/csv");
60
GDocumentsAllowedTypes.Add("TAB", "text/tab-separated-values");
61
GDocumentsAllowedTypes.Add("TSV", "text/tab-separated-values");
62
GDocumentsAllowedTypes.Add("TXT", "text/plain");
63
GDocumentsAllowedTypes.Add("HTML", "text/html");
64
GDocumentsAllowedTypes.Add("HTM", "text/html");
65
GDocumentsAllowedTypes.Add("DOC", "application/msword");
66
GDocumentsAllowedTypes.Add("ODS", "application/x-vnd.oasis.opendocument.spreadsheet");
67
GDocumentsAllowedTypes.Add("ODT", "application/vnd.oasis.opendocument.text");
68
GDocumentsAllowedTypes.Add("RTF", "application/rtf");
69
GDocumentsAllowedTypes.Add("SXW", "application/vnd.sun.xml.writer");
70
GDocumentsAllowedTypes.Add("XLS", "application/vnd.ms-excel");
71
GDocumentsAllowedTypes.Add("PPT", "application/vnd.ms-powerpoint");
72
GDocumentsAllowedTypes.Add("PPS", "application/vnd.ms-powerpoint");
73
GDocumentsAllowedTypes.Add("PDF", "application/pdf");
77
/// default constructor
79
/// <param name="applicationName">the applicationname</param>
80
public DocumentsService(string applicationName) : base(GDocumentsService, applicationName)
82
this.NewFeed += new ServiceEventHandler(this.OnNewFeed);
86
/// overloaded to create typed version of Query
88
/// <param name="feedQuery"></param>
89
/// <returns>EventFeed</returns>
90
public DocumentsFeed Query(DocumentsListQuery feedQuery)
92
return base.Query(feedQuery) as DocumentsFeed;
97
/// Simple method to upload a document, presentation, or spreadsheet
98
/// based upon the file extension.
100
/// <param name="fileName">The full path to the file.</param>
101
/// <param name="documentName">The desired name of the document on the server.</param>
102
/// <returns>A DocumentEntry describing the created document.</returns>
103
public DocumentEntry UploadDocument(string fileName, string documentName)
106
FileInfo fileInfo = new FileInfo(fileName);
107
FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
108
Uri postUri = new Uri(DocumentsListQuery.documentsBaseUri);
110
if (documentName == null)
112
documentName = fileInfo.Name;
115
//convert the extension to caps and strip the "." off the front
116
string ext = fileInfo.Extension.ToUpper().Substring(1);
118
String contentType = (String) GDocumentsAllowedTypes[ext];
120
if (contentType == null)
122
throw new ArgumentException("File extension '"+ext+"' is not recognized as valid.");
125
DocumentEntry entry = this.Insert(postUri, stream, contentType, documentName) as DocumentEntry;
134
/// by default all services now use version 1 for the protocol.
135
/// this needs to be overridden by a service to specify otherwise.
136
/// YouTube uses version 2
138
/// <returns></returns>
139
protected override void InitVersionInformation()
141
this.ProtocolMajor = VersionDefaults.VersionTwo;
147
//////////////////////////////////////////////////////////////////////
148
/// <summary>eventchaining. We catch this by from the base service, which
149
/// would not by default create an atomFeed</summary>
150
/// <param name="sender"> the object which send the event</param>
151
/// <param name="e">FeedParserEventArguments, holds the feedentry</param>
152
/// <returns> </returns>
153
//////////////////////////////////////////////////////////////////////
154
protected void OnNewFeed(object sender, ServiceEventArgs e)
156
Tracing.TraceMsg("Created new Documents Feed");
159
throw new ArgumentNullException("e");
161
e.Feed = new DocumentsFeed(e.Uri, e.Service);
163
/////////////////////////////////////////////////////////////////////////////