Author: api.jfisher
Date: Thu Dec  6 10:32:55 2007
New Revision: 353

Modified:
   trunk/clients/cs/src/gdocuments/documententry.cs
   trunk/clients/cs/src/gdocuments/documentquery.cs
   trunk/clients/cs/src/gdocuments/documentservice.cs

Log:
Added support for uploading documents via the Documents List API. Also 
added the ability to query for starred items.

Modified: trunk/clients/cs/src/gdocuments/documententry.cs
==============================================================================
--- trunk/clients/cs/src/gdocuments/documententry.cs    (original)
+++ trunk/clients/cs/src/gdocuments/documententry.cs    Thu Dec  6 
10:32:55 2007
@@ -39,6 +39,7 @@
         static string PRESENTATION_KIND = 
"http://schemas.google.com/docs/2007#presentation";;
         static string DOCUMENT_KIND = 
"http://schemas.google.com/docs/2007#document";;
         static string SPREADSHEET_KIND = 
"http://schemas.google.com/docs/2007#spreadsheet";;
+        static string STARRED_KIND = 
"http://schemas.google.com/g/2005/labels#starred";;

         public static AtomCategory DOCUMENT_CATEGORY =
             new AtomCategory(DOCUMENT_KIND, new AtomUri(BaseNameTable.gKind));
@@ -46,6 +47,8 @@
             new AtomCategory(SPREADSHEET_KIND, new 
AtomUri(BaseNameTable.gKind));
         public static AtomCategory PRESENTATION_CATEGORY =
             new AtomCategory(PRESENTATION_KIND, new 
AtomUri(BaseNameTable.gKind));
+        public static AtomCategory STARRED_CATEGORY =
+            new AtomCategory(STARRED_KIND, new AtomUri(BaseNameTable.gLabels));


         /// <summary>
@@ -58,8 +61,17 @@
             Tracing.TraceMsg("Created DocumentEntry");
         }

+        public void toggleCategory(AtomCategory category, bool toggle) {
+            if(toggle) {
+                this.Categories.Add(category);
+            }
+            else {
+                this.Categories.Remove(category);
+            }
+        }
+
         /// <summary>
-        /// returns TRUE if this entry is a Document entry
+        /// Reflects if this entry is a word processor document
         /// </summary>
         public bool IsDocument
         {
@@ -69,18 +81,12 @@
             }
             set
             {
-                if (value == true)
-                {
-                    if (this.IsDocument == false)
-                    {
-                        this.Categories.Add(DocumentEntry.DOCUMENT_CATEGORY);
-                    }
-                }
+                this.toggleCategory(DocumentEntry.DOCUMENT_CATEGORY, value);
             }
         }

          /// <summary>
-        /// returns TRUE if this entry is a Document entry
+        /// Reflects if this entry is a spreadsheet document
         /// </summary>
         public bool IsSpreadsheet
         {
@@ -90,18 +96,12 @@
             }
             set
             {
-                if (value == true)
-                {
-                    if (this.IsSpreadsheet == false)
-                    {
-                        
this.Categories.Add(DocumentEntry.SPREADSHEET_CATEGORY);
-                    }
-                }
+                
this.toggleCategory(DocumentEntry.SPREADSHEET_CATEGORY, value);
             }
         }

-         /// <summary>
-        /// returns TRUE if this entry is a Document entry
+        /// <summary>
+        /// Reflects if this entry is a presentation document
         /// </summary>
         public bool IsPresentation
         {
@@ -111,15 +111,26 @@
             }
             set
             {
-                if (value == true)
-                {
-                    if (this.IsPresentation == false)
-                    {
-                        
this.Categories.Add(DocumentEntry.PRESENTATION_CATEGORY);
-                    }
-                }
+                
this.toggleCategory(DocumentEntry.PRESENTATION_CATEGORY, value);
             }
         }
+
+        /// <summary>
+        /// Reflects if this entry is starred
+        /// </summary>
+        public bool IsStarred
+        {
+            get
+            {
+                return 
this.Categories.Contains(DocumentEntry.STARRED_CATEGORY);
+            }
+            set
+            {
+                this.toggleCategory(DocumentEntry.STARRED_CATEGORY, value);
+            }
+        }
+
+
     }
 }


Modified: trunk/clients/cs/src/gdocuments/documentquery.cs
==============================================================================
--- trunk/clients/cs/src/gdocuments/documentquery.cs    (original)
+++ trunk/clients/cs/src/gdocuments/documentquery.cs    Thu Dec  6 
10:32:55 2007
@@ -75,6 +75,9 @@
         private static AtomCategory ATOMCATEGORY_PRESENTATIONS = new 
AtomCategory("presentation");
         public static QueryCategory PRESENTATIONS = new 
QueryCategory(ATOMCATEGORY_PRESENTATIONS);

+        public static AtomCategory ATOMCATEGORY_STARRED = new 
AtomCategory("starred");
+        public static QueryCategory STARRED = new 
QueryCategory(ATOMCATEGORY_STARRED);
+
         /// <summary>
         /// base constructor
         /// </summary>
@@ -91,12 +94,34 @@
         : base(queryUri)
         {
         }
+
+        /// <summary>
+        /// Restricts the results to only starred documents
+        /// </summary>
+        public bool Starred
+        {
+            get
+            {
+                return this.Categories.Contains(DocumentsListQuery.STARRED);
+            }
+            set
+            {
+                if (value)
+                {
+                    this.Categories.Add(DocumentsListQuery.STARRED);
+                }
+                else
+                {
+                    this.Categories.Remove(DocumentsListQuery.STARRED);
+                }
+            }
+        }
     }



     /// <summary>
-    /// a subclass setup to just retrieve all documents
+    /// a subclass setup to just retrieve all word processor documents
     /// </summary>
     public class DocumentQuery : DocumentsListQuery
     {

Modified: trunk/clients/cs/src/gdocuments/documentservice.cs
==============================================================================
--- trunk/clients/cs/src/gdocuments/documentservice.cs  (original)
+++ trunk/clients/cs/src/gdocuments/documentservice.cs  Thu Dec  6 
10:32:55 2007
@@ -48,6 +48,33 @@
         public const string GDocumentsService = "writely";

         /// <summary>
+        /// A Hashtable that expresses the allowed content types.
+        /// </summary>
+        public static Hashtable GDocumentsAllowedTypes;
+
+        /// <summary>
+        /// Static constructor used to initialize GDocumentsAllowedTypes.
+        /// </summary>
+        static DocumentsService()
+        {
+            GDocumentsAllowedTypes = new Hashtable();
+            GDocumentsAllowedTypes.Add("CSV", "text/csv");
+            GDocumentsAllowedTypes.Add("TAB", "text/tab-separated-values");
+            GDocumentsAllowedTypes.Add("TSV", "text/tab-separated-values");
+            GDocumentsAllowedTypes.Add("TXT", "text/plain");
+            GDocumentsAllowedTypes.Add("HTML", "text/html");
+            GDocumentsAllowedTypes.Add("HTM", "text/html");
+            GDocumentsAllowedTypes.Add("DOC", "application/msword");
+            GDocumentsAllowedTypes.Add("ODS", 
"application/x-vnd.oasis.opendocument.spreadsheet");
+            GDocumentsAllowedTypes.Add("ODT", 
"application/vnd.oasis.opendocument.text");
+            GDocumentsAllowedTypes.Add("RTF", "application/rtf");
+            GDocumentsAllowedTypes.Add("SXW", 
"application/vnd.sun.xml.writer");
+            GDocumentsAllowedTypes.Add("XLS", "application/vnd.ms-excel");
+            GDocumentsAllowedTypes.Add("PPT", "application/vnd.ms-powerpoint");
+            GDocumentsAllowedTypes.Add("PPS", "application/vnd.ms-powerpoint");
+        }
+
+        /// <summary>
         ///  default constructor
         /// </summary>
         /// <param name="applicationName">the applicationname</param>
@@ -65,6 +92,35 @@
         {
             return base.Query(feedQuery) as DocumentsFeed;
         }
+
+
+        /// <summary>
+        /// Simple method to upload a document, presentation, or spreadsheet
+        /// based upon the file extension.
+        /// </summary>
+        /// <param name="fileName">The full path to the file.</param>
+        /// <param name="documentName">The desired name of the 
document on the server.</param>
+        /// <returns>A DocumentEntry describing the created document.</returns>
+        public DocumentEntry UploadDocument(string fileName, string 
documentName)
+        {
+            FileInfo fileInfo = new FileInfo(fileName);
+            FileStream stream = fileInfo.OpenRead();
+            Uri postUri = new Uri(DocumentsListQuery.documentsBaseUri);
+
+            //convert the extension to caps and strip the "." off the front
+            string ext = fileInfo.Extension.ToUpper().Substring(1);
+
+            String contentType = (String) GDocumentsAllowedTypes[ext];
+
+            if (contentType == null)
+            {
+                throw new ArgumentException("File extension '"+ext+"' 
is not recognized as valid.");
+            }
+
+            return this.Insert(postUri, stream, contentType, 
documentName) as DocumentEntry;
+        }
+
+

         //////////////////////////////////////////////////////////////////////
          /// <summary>eventchaining. We catch this by from the base 
service, which

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to