Author: fmantek
Date: Tue Sep 4 08:13:35 2007
New Revision: 228
Modified:
trunk/clients/cs/RELEASE_NOTES.txt
trunk/clients/cs/src/core/basenametable.cs
trunk/clients/cs/src/extensions/gdatanametable.cs
trunk/clients/cs/src/extensions/simpleelement.cs
trunk/clients/cs/src/gcalendar/eventfeed.cs
trunk/clients/cs/src/gcalendar/webcontent.cs
trunk/clients/cs/src/unittests/caltest.cs
Log:
Support for Calendar Gadgets
Modified: trunk/clients/cs/RELEASE_NOTES.txt
==============================================================================
--- trunk/clients/cs/RELEASE_NOTES.txt (original)
+++ trunk/clients/cs/RELEASE_NOTES.txt Tue Sep 4 08:13:35 2007
@@ -20,6 +20,8 @@
works on the first Reminder in the list. Setting the old property will
delete all addtional reminders.The Reminders
property is of type ArrayList (this is an artifact of being .NET 1.1
compatible, once we move to .NET 2.0 or later, if
that ever happens, this could/should be typed).
+- Support for Google Calendar WebContent Gadgets is included. A WebContent
element has a SortedList property to set and retrieve
+ those preferences. See caltest.cs for an example.
== 1.0.9.9 ==
- added GBase support for m:adjusted_name and gm:adjusted_value inside
attributes
Modified: trunk/clients/cs/src/core/basenametable.cs
==============================================================================
--- trunk/clients/cs/src/core/basenametable.cs (original)
+++ trunk/clients/cs/src/core/basenametable.cs Tue Sep 4 08:13:35 2007
@@ -71,6 +71,7 @@
private object type;
private object value;
+ private object name;
/// <summary>static namespace string declaration</summary>
@@ -163,6 +164,8 @@
public const string XmlAttributeBatchUnprocessed = "unprocessed";
/// <summary>XmlAttribute for value in enums</summary>
public const string XmlAttributeValue = "value";
+ /// <summary>XmlAttribute for name in enums</summary>
+ public const string XmlAttributeName = "name";
/// <summary>XmlAttribute for value in enums</summary>
public const string XmlAttributeType = "type";
@@ -200,7 +203,8 @@
this.type =
this.atomNameTable.Add(BaseNameTable.XmlAttributeType);
this.value =
this.atomNameTable.Add(BaseNameTable.XmlAttributeValue);
-
+ this.name =
this.atomNameTable.Add(BaseNameTable.XmlAttributeValue);
+
@@ -417,6 +421,15 @@
public object Type
{
get {return this.type;}
+ }
+
/////////////////////////////////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>Read only accessor for name</summary>
+ //////////////////////////////////////////////////////////////////////
+ public object Name
+ {
+ get {return this.name;}
}
/////////////////////////////////////////////////////////////////////////////
Modified: trunk/clients/cs/src/extensions/gdatanametable.cs
==============================================================================
--- trunk/clients/cs/src/extensions/gdatanametable.cs (original)
+++ trunk/clients/cs/src/extensions/gdatanametable.cs Tue Sep 4 08:13:35 2007
@@ -118,6 +118,8 @@
#region Calendar specific (consider moving to seperate table)
/// <summary>static string for parsing a webcontent element</summary>
public const string XmlWebContentElement = "webContent";
+ /// <summary>static string for parsing a webcontent element</summary>
+ public const string XmlWebContentGadgetElement =
"webContentGadgetPref";
/// <summary>static string for parsing the extendedProperty
element</summary>
public const string XmlExtendedPropertyElement = "extendedProperty";
/// <summary>static string for the url attribute</summary>
Modified: trunk/clients/cs/src/extensions/simpleelement.cs
==============================================================================
--- trunk/clients/cs/src/extensions/simpleelement.cs (original)
+++ trunk/clients/cs/src/extensions/simpleelement.cs Tue Sep 4 08:13:35 2007
@@ -116,7 +116,7 @@
get { return this.xmlPrefix; }
}
-
//////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////
/// <summary>Parses an xml node to create a Who object.</summary>
/// <param name="node">georsswhere node</param>
/// <param name="parser">AtomFeedParser to use</param>
Modified: trunk/clients/cs/src/gcalendar/eventfeed.cs
==============================================================================
--- trunk/clients/cs/src/gcalendar/eventfeed.cs (original)
+++ trunk/clients/cs/src/gcalendar/eventfeed.cs Tue Sep 4 08:13:35 2007
@@ -118,6 +118,7 @@
/// <param name="iService">the Service to use</param>
public EventFeed(Uri uriBase, IService iService) : base(uriBase,
iService)
{
+ AddExtension(new WebContent());
}
@@ -228,7 +229,9 @@
/// <param name="e"></param>
/// <param name="parser">the atom feed parser used</param>
protected override void
HandleExtensionElements(ExtensionElementEventArgs e, AtomFeedParser parser)
{
- Tracing.TraceMsg("\t HandleExtensionElements for CalendarFeed
called");
+ Tracing.TraceMsg("\t HandleExtensionElements for CalendarFeed
called");
+ // the base implementation handles all things registered with
AddExtension
+ base.HandleExtensionElements(e, parser);
if (String.Compare(e.ExtensionElement.NamespaceURI,
BaseNameTable.gNamespace, true) == 0)
{
@@ -261,12 +264,6 @@
eventFeed.TimeZone =
TimeZone.ParseTimeZone(e.ExtensionElement);
e.DiscardEntry = true;
}
- }
- else if (e.ExtensionElement.LocalName ==
GDataParserNameTable.XmlWebContentElement)
- {
- WebContent content =
WebContent.ParseWebContent(e.ExtensionElement);
- e.Base.ExtensionElements.Add(content);
- e.DiscardEntry = true;
}
}
}
Modified: trunk/clients/cs/src/gcalendar/webcontent.cs
==============================================================================
--- trunk/clients/cs/src/gcalendar/webcontent.cs (original)
+++ trunk/clients/cs/src/gcalendar/webcontent.cs Tue Sep 4 08:13:35 2007
@@ -26,11 +26,12 @@
/// <summary>
/// GData schema extension describing a webcontent for the calendar
/// </summary>
- public class WebContent : IExtensionElement
+ public class WebContent : IExtensionElement, IExtensionElementFactory
{
private string url;
private uint width;
private uint height;
+ private SortedList gadgetPrefs;
//////////////////////////////////////////////////////////////////////
@@ -63,25 +64,46 @@
set { this.height = value; }
}
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>accessor method public SortedList
GadgetPreferences</summary>
+ /// <returns> </returns>
+ //////////////////////////////////////////////////////////////////////
+ public SortedList GadgetPreferences
+ {
+ get
+ {
+ if (this.gadgetPrefs == null)
+ {
+ this.gadgetPrefs = new SortedList();
+ }
+ return this.gadgetPrefs;
+ }
+ set {this.gadgetPrefs = value;}
+ }
+ // end of accessor public SortedList GadgetPreferences
+
#region WebContent Parser
+
//////////////////////////////////////////////////////////////////////
- /// <summary>Parses an xml node to create an WebContent
object.</summary>
- /// <param name="node">WebContent node</param>
- /// <returns>the created WebContent object</returns>
+ /// <summary>Parses an xml node to create a Who object.</summary>
+ /// <param name="node">georsswhere node</param>
+ /// <param name="parser">AtomFeedParser to use</param>
+ /// <returns>the created SimpleElement object</returns>
//////////////////////////////////////////////////////////////////////
- public static WebContent ParseWebContent(XmlNode node)
+ public IExtensionElement CreateInstance(XmlNode node, AtomFeedParser
parser)
{
Tracing.TraceCall();
- WebContent webContent = null;
Tracing.Assert(node != null, "node should not be null");
if (node == null)
{
throw new ArgumentNullException("node");
}
+ WebContent webContent = null;
+
object localname = node.LocalName;
- if (localname.Equals(GDataParserNameTable.XmlWebContentElement))
+ if (localname.Equals(XmlName))
{
webContent = new WebContent();
if (node.Attributes != null)
@@ -108,7 +130,35 @@
{
webContent.Height = uint.Parse(value,
System.Globalization.NumberStyles.Integer, CultureInfo.InvariantCulture);
}
-
+ }
+ // single event, g:reminder is inside g:when
+ if (node.HasChildNodes)
+ {
+ XmlNode gadgetPrefs = node.FirstChild;
+ IExtensionElementFactory f = new Reminder() as
IExtensionElementFactory;
+ while (gadgetPrefs != null && gadgetPrefs is XmlElement)
+ {
+ if (String.Compare(gadgetPrefs.NamespaceURI,
XmlNameSpace, true) == 0)
+ {
+ if (String.Compare(gadgetPrefs.LocalName,
GDataParserNameTable.XmlWebContentGadgetElement) == 0)
+ {
+ if (gadgetPrefs.Attributes != null)
+ {
+ string value =
gadgetPrefs.Attributes[BaseNameTable.XmlAttributeValue] != null ?
+
gadgetPrefs.Attributes[BaseNameTable.XmlAttributeValue].Value : null;
+
+ string name =
gadgetPrefs.Attributes[BaseNameTable.XmlAttributeName] != null ?
+
gadgetPrefs.Attributes[BaseNameTable.XmlAttributeName].Value : null;
+
+ if (name != null)
+ {
+ webContent.GadgetPreferences.Add(name,
value);
+ }
+ }
+ }
+ }
+ gadgetPrefs = gadgetPrefs.NextSibling;
+ }
}
}
@@ -127,6 +177,21 @@
get { return GDataParserNameTable.XmlWebContentElement; }
}
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>Returns the constant representing this XML
element.</summary>
+ //////////////////////////////////////////////////////////////////////
+ public string XmlNameSpace
+ {
+ get { return GDataParserNameTable.NSGCal; }
+ }
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>Returns the constant representing this XML
element.</summary>
+ //////////////////////////////////////////////////////////////////////
+ public string XmlPrefix
+ {
+ get { return GDataParserNameTable.gCalPrefix; }
+ }
+
/// <summary>
/// Persistence method for the When object
/// </summary>
@@ -135,10 +200,30 @@
{
if (Utilities.IsPersistable(this.Url))
{
- writer.WriteStartElement(GDataParserNameTable.gCalPrefix,
XmlName, GDataParserNameTable.NSGCal);
+ writer.WriteStartElement(XmlPrefix, XmlName, XmlNameSpace);
writer.WriteAttributeString(GDataParserNameTable.XmlAttributeUrl, this.Url);
writer.WriteAttributeString(GDataParserNameTable.XmlAttributeHeight,
this.Height.ToString());
writer.WriteAttributeString(GDataParserNameTable.XmlAttributeWidth,
this.Width.ToString());
+ if (this.gadgetPrefs != null && this.gadgetPrefs.Count > 0)
+ {
+ for (int i=0; i < this.gadgetPrefs.Count; i++)
+ {
+ string name = this.gadgetPrefs.GetKey(i) as string;
+ string value = this.gadgetPrefs.GetByIndex(i) as
string;
+ if (name != null)
+ {
+ writer.WriteStartElement(XmlPrefix,
+
GDataParserNameTable.XmlWebContentGadgetElement,
+ XmlNameSpace);
+
writer.WriteAttributeString(BaseNameTable.XmlAttributeName, name);
+ if (value != null)
+ {
+
writer.WriteAttributeString(BaseNameTable.XmlAttributeValue, value);
+ }
+ writer.WriteEndElement();
+ }
+ }
+ }
writer.WriteEndElement();
}
}
Modified: trunk/clients/cs/src/unittests/caltest.cs
==============================================================================
--- trunk/clients/cs/src/unittests/caltest.cs (original)
+++ trunk/clients/cs/src/unittests/caltest.cs Tue Sep 4 08:13:35 2007
@@ -657,6 +657,9 @@
content.Url = "http://www.google.com/logos/july4th06.gif";
content.Width = 270;
content.Height = 130;
+ content.GadgetPreferences.Add("color", "blue");
+ content.GadgetPreferences.Add("taste", "sweet");
+ content.GadgetPreferences.Add("smell", "fresh");
link.ExtensionElements.Add(content);
entry.Links.Add(link);
@@ -667,6 +670,19 @@
link =
newEntry.Links.FindService("http://schemas.google.com/gCal/2005/webContent",
"image/gif");
Assert.IsTrue(link != null, "the link did not come back
for the webContent");
Tracing.TraceMsg("Created calendar entry");
+
+ WebContent returnedContent =
link.FindExtension(GDataParserNameTable.XmlWebContentElement,
+
GDataParserNameTable.NSGCal) as WebContent;
+
+ Assert.IsTrue(returnedContent != null, "The returned
WebContent element was not found");
+
+ Assert.AreEqual(3,
returnedContent.GadgetPreferences.Count, "The gadget preferences should be
there");
+ Assert.AreEqual("blue",
returnedContent.GadgetPreferences["color"], "Color should be blue");
+ Assert.AreEqual("sweet",
returnedContent.GadgetPreferences["taste"], "Taste should be sweet");
+ Assert.AreEqual("fresh",
returnedContent.GadgetPreferences["smell"], "smell should be fresh");
+
+
+
newEntry.Content.Content = "Updated..";
newEntry.Update();
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---