2007-07-24 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Literal.cs
index 9d81f5f91275d587fc572786d9711ab2ace81c94..a578733ad99283c1c6357562cd489d3abff1c40c 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.ComponentModel;
-using System.Web.UI;
+using System.Security.Permissions;
 
 namespace System.Web.UI.WebControls {
+
+       // CAS
+       [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       // attributes
        [ControlBuilder(typeof(LiteralControlBuilder))]
        [DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
        [DefaultProperty("Text")]
@@ -49,16 +53,17 @@ namespace System.Web.UI.WebControls {
 
 #if NET_2_0
                [DefaultValue (LiteralMode.Transform)]
-               [MonoTODO]
                [WebSysDescription ("")]
                [WebCategory ("Behavior")]
                public LiteralMode Mode 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState ["Mode"] == null ? LiteralMode.Transform : (LiteralMode) ViewState ["Mode"];
                        }
                        set {
-                               throw new NotImplementedException ();
+                               if (((int) value) < 0 || ((int) value) > 2)
+                                       throw new ArgumentOutOfRangeException ();
+                               ViewState ["Mode"] = value;
                        }
                }
 #endif         
@@ -69,11 +74,8 @@ namespace System.Web.UI.WebControls {
                [WebCategory ("Appearance")]
 #if NET_2_0
                [Localizable (true)]
-               public virtual
-#else          
-               public
 #endif         
-               string Text {
+               public string Text {
                        get {
                                return ViewState.GetString ("Text", String.Empty);
                        }
@@ -84,24 +86,25 @@ namespace System.Web.UI.WebControls {
 
 #if NET_2_0
                [EditorBrowsable (EditorBrowsableState.Never)]
-               [MonoTODO]
                public override void Focus ()
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 #endif         
 
-#if NET_2_0
-               [EditorBrowsable (EditorBrowsableState.Never)]
-#endif         
                protected override ControlCollection CreateControlCollection ()
                {
                        return new EmptyControlCollection (this);
                }
 
-               [MonoTODO ("I can't find a type that it can have children of")]
                protected override void AddParsedSubObject (object obj)
                {
+                       LiteralControl literal = obj as LiteralControl;
+                       if (literal != null) {
+                               Text = literal.Text;
+                               return;
+                       }
+
                        throw new HttpException (Locale.GetText (
                              "'Literal' cannot have children of type '{0}'",
                              obj.GetType ()));
@@ -114,6 +117,11 @@ namespace System.Web.UI.WebControls {
 #endif         
                override void Render (HtmlTextWriter output)
                {
+#if NET_2_0
+                       if (Mode == LiteralMode.Encode)
+                               output.Write (HttpUtility.HtmlEncode (Text));
+                       else
+#endif
                        output.Write (Text);
                }
        }