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.Globalization;
20
using System.Diagnostics;
21
using Google.GData.Client;
23
namespace Google.GData.Documents {
25
//////////////////////////////////////////////////////////////////////
27
/// A subclass of FeedQuery, to create an Documents query URI.
28
/// Provides public properties that describe the different
29
/// aspects of the URI, as well as a composite URI.
31
/// Documents List supports the following standard GData query parameters:
32
/// alt, author, q, start-index, max-results, updated-min, updated-max, /category
33
/// For more information about the standard parameters, see the GData protocol reference document.
34
/// In addition to the standard GData query parameters, the Documents List data API uses the following parameters.
36
/// title Specifies the search terms for the title of a document.
37
/// This parameter used without title-exact will only submit partial queries, not exact queries.
39
/// title-exact Specifies whether the title query should be taken as an exact string.
40
/// Meaningless without title. Possible values are true and false.
42
/// The Documents List data API supports the following categories.
43
/// Category: Document Type
44
/// Scheme: http://schemas.google.com/g/2005#kind
45
/// Term: http://schemas.google.com/docs/2007#type
47
/// All documents of the corresponding type in the requesting users document list.
48
/// Type is currently one of (document|spreadsheet|presentation)
49
/// Category: Starred Status
50
/// Scheme: http://schemas.google.com/g/2005/labels
53
/// All documents that have been starred by the requesting user
54
/// Category: Containing Folders
55
/// Scheme: http://schemas.google.com/docs/2007/folders/user-email
57
/// Label: folder-name
58
/// All documents inside the given folder for the requesting user
60
//////////////////////////////////////////////////////////////////////
61
public class DocumentsListQuery : FeedQuery
66
/// document feed base URI
68
public static string documentsBaseUri = "http://docs.google.com/feeds/documents/private/full";
73
/// <returns></returns>
74
public static string folderBaseUri = "http://docs.google.com/feeds/folders/private/full/folder%3A";
76
private static AtomCategory ATOMCATEGORY_DOCUMENTS = new AtomCategory("document");
78
/// predefined query category for documents
80
public static QueryCategory DOCUMENTS = new QueryCategory(ATOMCATEGORY_DOCUMENTS);
82
private static AtomCategory ATOMCATEGORY_SPREADSHEETS = new AtomCategory("spreadsheet");
84
/// predefined query category for spreadsheets
86
public static QueryCategory SPREADSHEETS = new QueryCategory(ATOMCATEGORY_SPREADSHEETS);
88
private static AtomCategory ATOMCATEGORY_PRESENTATIONS = new AtomCategory("presentation");
90
/// predefined query category for presentations
92
public static QueryCategory PRESENTATIONS = new QueryCategory(ATOMCATEGORY_PRESENTATIONS);
94
private static AtomCategory ATOMCATEGORY_PDFS = new AtomCategory("pdf");
96
/// predefined query category for presentations
98
public static QueryCategory PDFS = new QueryCategory(ATOMCATEGORY_PDFS);
102
/// predefined query category for starred documents
104
public static AtomCategory ATOMCATEGORY_STARRED = new AtomCategory("starred");
106
/// predefined query category for starred documents
108
public static QueryCategory STARRED = new QueryCategory(ATOMCATEGORY_STARRED);
112
/// predefined query category for starred documents
114
public static AtomCategory ATOMCATEGORY_FOLDER = new AtomCategory("folder");
116
/// predefined query category for starred documents
118
public static QueryCategory FOLDER = new QueryCategory(ATOMCATEGORY_FOLDER);
120
//Local variable to hold the contents of a title query
121
private string title;
122
//Local variable to hold if the title query we are doing should be exact.
123
private bool titleExact;
128
public DocumentsListQuery()
129
: base(documentsBaseUri)
131
this.CategoryQueriesAsParameter = true;
135
/// base constructor, with initial queryUri
137
/// <param name="queryUri">the query to use</param>
138
public DocumentsListQuery(string queryUri)
141
this.CategoryQueriesAsParameter = true;
145
/// Restricts the results to only starred documents
147
[CLSCompliant(false)]
152
return this.Categories.Contains(DocumentsListQuery.STARRED);
158
this.Categories.Add(DocumentsListQuery.STARRED);
162
this.Categories.Remove(DocumentsListQuery.STARRED);
167
private bool showFolders;
169
/// shows folders if true in the result
171
[CLSCompliant(false)]
172
public bool ShowFolders
176
return this.showFolders;
180
this.showFolders = value;
185
/// Restricts the results to only documents with titles matching a string.
200
/// Restricts the results to only documents matching a string provided
201
/// by the Title property exactly. (No partial matches.)
203
public bool TitleExact
207
return this.titleExact;
211
this.titleExact = value;
217
/// tries to parse a document id iri and return just the
220
/// <param name="documentUri">the document id link as a string</param>
221
/// <returns>the document id or null if failed</returns>
222
public static string DocumentId(string documentUri)
224
const string token="%3A";
225
if (documentUri == null)
228
throw new ArgumentNullException("documentUri");
230
int pos = documentUri.LastIndexOf(token);
234
if (pos < documentUri.Length)
236
return documentUri.Substring(pos);
242
#if WindowsCE || PocketPC
244
//////////////////////////////////////////////////////////////////////
245
/// <summary>Parses custom properties out of the incoming URI</summary>
246
/// <param name="targetUri">A URI representing a query on a feed</param>
247
/// <returns>returns the base uri</returns>
248
//////////////////////////////////////////////////////////////////////
249
protected override Uri ParseUri(Uri targetUri)
251
base.ParseUri(targetUri);
252
if (targetUri != null)
254
char[] deli = { '?', '&' };
256
TokenCollection tokens = new TokenCollection(targetUri.Query, deli);
257
foreach (String token in tokens)
259
if (token.Length > 0)
261
char[] otherDeli = { '=' };
262
String[] parameters = token.Split(otherDeli, 2);
263
switch (parameters[0])
266
this.TitleExact = bool.Parse(parameters[1]);
269
this.Title = parameters[1];
272
this.ShowFolders = bool.Parse(parameters[1]);
281
//////////////////////////////////////////////////////////////////////
282
/// <summary>Creates the partial URI query string based on all
283
/// set properties.</summary>
284
/// <returns> A string representing the query part of the URI.</returns>
285
//////////////////////////////////////////////////////////////////////
286
protected override string CalculateQuery(string basePath)
288
string path = base.CalculateQuery(basePath);
289
StringBuilder newPath = new StringBuilder(path, 2048);
290
char paramInsertion = InsertionParameter(path);
292
paramInsertion = AppendQueryPart(this.Title, "title", paramInsertion, newPath);
294
if (this.TitleExact == true)
296
paramInsertion = AppendQueryPart("true", "title-exact", paramInsertion, newPath);
298
if (this.ShowFolders == true)
300
paramInsertion = AppendQueryPart("true", "showfolders", paramInsertion, newPath);
302
return newPath.ToString();
309
/// a subclass setup to just retrieve all word processor documents
311
public class TextDocumentQuery : DocumentsListQuery
317
public TextDocumentQuery()
320
this.Categories.Add(DocumentsListQuery.DOCUMENTS);
326
/// a subclass setup to just retrieve all spreadsheets
328
public class SpreadsheetQuery : DocumentsListQuery
334
public SpreadsheetQuery()
337
this.Categories.Add(DocumentsListQuery.SPREADSHEETS);
342
/// a subclass setup to just retrieve all presentations
344
public class PresentationsQuery : DocumentsListQuery
350
public PresentationsQuery()
353
this.Categories.Add(DocumentsListQuery.PRESENTATIONS);
358
/// a subclass setup to just retrieve all PDFs
360
public class PDFsQuery : DocumentsListQuery
369
this.Categories.Add(DocumentsListQuery.PDFS);
375
/// a subclass setup to just retrieve all Folders
377
public class FolderQuery : DocumentsListQuery
386
this.Categories.Add(DocumentsListQuery.FOLDER);
387
this.ShowFolders = true;