Use UNIX line endings consistently
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / AdRotator.cs
index 876598b31d39147f383a3379323da288e218a108..ea504d18d0d657d29b2d3a3da587f156b39ca7dd 100644 (file)
@@ -30,6 +30,7 @@ using System.Xml;
 using System.Collections;
 using System.ComponentModel;
 using System.Security.Permissions;
+using System.Web.Util;
 
 namespace System.Web.UI.WebControls {
 
@@ -53,7 +54,6 @@ namespace System.Web.UI.WebControls {
 #endif 
        {
 #if NET_2_0
-               [MonoTODO]
                protected internal override void OnInit (EventArgs e)
                {
                        base.OnInit(e);
@@ -70,7 +70,13 @@ namespace System.Web.UI.WebControls {
                        Hashtable ht = null;
                        
                        if (ad_file != "" && ad_file != null) {
-                               ReadAdsFromFile (Page.MapPath (ad_file));
+                               ReadAdsFromFile (
+#if NET_2_0
+                                       GetPhysicalFilePath (ad_file)
+#else
+                                       Page.MapPath (ad_file)
+#endif
+                               );
                                ht = ChooseAd ();
                        }
 
@@ -81,13 +87,13 @@ namespace System.Web.UI.WebControls {
                }
 
 #if NET_2_0
-               [MonoTODO]
+               [MonoTODO ("Not implemented")]
                protected internal override void PerformDataBinding (IEnumerable data)
                {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
+               [MonoTODO ("Not implemented")]
                protected override void PerformSelect ()
                {
                        throw new NotImplementedException ();
@@ -106,23 +112,39 @@ namespace System.Web.UI.WebControls {
                        AdCreatedEventArgs e = createdargs;
 
                        base.AddAttributesToRender (w);
-                       
-                       if (e.NavigateUrl != null)
-                               w.AddAttribute (HtmlTextWriterAttribute.Href, ResolveUrl (e.NavigateUrl));
-                       w.AddAttribute (HtmlTextWriterAttribute.Target, Target);
+
+                       if (e.NavigateUrl != null && e.NavigateUrl.Length > 0)
+                               w.AddAttribute (HtmlTextWriterAttribute.Href, ResolveAdUrl (e.NavigateUrl));
+                       if (Target != null && Target.Length > 0)
+                               w.AddAttribute (HtmlTextWriterAttribute.Target, Target);
                        
                        w.RenderBeginTag (HtmlTextWriterTag.A);
 
-                       if (e.NavigateUrl != null)
-                               w.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (e.ImageUrl));
-                       
+                       if (e.ImageUrl != null && e.ImageUrl.Length > 0)
+                               w.AddAttribute (HtmlTextWriterAttribute.Src, ResolveAdUrl (e.ImageUrl));
+
                        w.AddAttribute (HtmlTextWriterAttribute.Alt, e.AlternateText == null ? "" : e.AlternateText);
-                       w.AddAttribute (HtmlTextWriterAttribute.Border, "0");
+                       w.AddAttribute (HtmlTextWriterAttribute.Border, "0", false);
                        w.RenderBeginTag (HtmlTextWriterTag.Img);
                        w.RenderEndTag (); // img
                        w.RenderEndTag (); // a
                }
 
+               string ResolveAdUrl (string url)
+               {
+                       string path = url;
+
+                       if (AdvertisementFile != null && AdvertisementFile.Length > 0 && path [0] != '/' && path [0] != '~')
+                               try {
+                                       new Uri (path);
+                               }
+                               catch {
+                                       return UrlUtils.Combine (UrlUtils.GetDirectory (ResolveUrl (AdvertisementFile)), path);
+                               }
+                       
+                       return ResolveUrl (path);
+               }
+
                //
                // We take all the ads in the ad file and add up their
                // impression weight. We then take a random number [0,
@@ -209,7 +231,7 @@ namespace System.Web.UI.WebControls {
                [DefaultValue ("AlternateText")]
                [WebSysDescriptionAttribute ("")]
                [WebCategoryAttribute ("Behavior")]
-               [MonoTODO]
+               [MonoTODO ("Not implemented")]
                public string AlternateTextField 
                {
                        get {
@@ -232,7 +254,7 @@ namespace System.Web.UI.WebControls {
 
 #if NET_2_0
                [DefaultValue ("ImageUrl")]
-               [MonoTODO]
+               [MonoTODO ("Not implemented")]
                [WebSysDescriptionAttribute ("")]
                [WebCategoryAttribute ("Behavior")]
                public string ImageUrlField 
@@ -263,7 +285,7 @@ namespace System.Web.UI.WebControls {
 
 #if NET_2_0
                [DefaultValue ("NavigateUrl")]
-               [MonoTODO]
+               [MonoTODO ("Not implemented")]
                [WebSysDescriptionAttribute ("")]
                [WebCategoryAttribute ("Behavior")]
                public string NavigateUrlField 
@@ -294,7 +316,6 @@ namespace System.Web.UI.WebControls {
 
 #if NET_2_0
                /* all these are listed in corcompare */
-               [MonoTODO]
                public override string UniqueID
                {
                        get {
@@ -302,7 +323,6 @@ namespace System.Web.UI.WebControls {
                        }
                }
 
-               [MonoTODO]
                protected override HtmlTextWriterTag TagKey 
                {
                        get {