2007-07-24 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Literal.cs
index 61c0c3b1b4bb2900627583bdde3cd81eda1679a2..a578733ad99283c1c6357562cd489d3abff1c40c 100644 (file)
@@ -2,16 +2,9 @@
 // System.Web.UI.WebControls.Literal.cs
 //
 // Authors:
-//   Gaurav Vaish (gvaish@iitk.ac.in)
-//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
-//   Sanjay Gupta (gsanjay@novell.com)
+//     Jackson Harper (jackson@ximian.com)
 //
-// (C) Gaurav Vaish (2002)
-// (C) 2003 Andreas Nahr
-// (C) 2004, Novell, Inc. (http://www.novell.com)
-//
-//\r
-
+// (C) 2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-\r
-using System;\r
-using System.Web;\r
-using System.Web.UI;\r
-using System.ComponentModel;\r
-\r
-namespace System.Web.UI.WebControls\r
-{\r
-       [DefaultProperty("Text")]\r
-       [ControlBuilder(typeof(LiteralControlBuilder))]\r
-       [DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]\r
+
+using System.ComponentModel;
+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")]
 #if NET_2_0
-       [DesignerAttribute ("Value not found")]
-#endif
-       public class Literal : Control\r
+       [Designer ("System.Web.UI.Design.WebControls.LiteralDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+#endif         
+       public class Literal : Control
 #if NET_2_0
-       , IStaticTextControl
-#endif
-       {\r
-               public Literal () : base ()\r
-               {\r
-               }\r
+       , ITextControl
+#endif 
+       {
+
+               public Literal ()
+               {
+               }
 
-               [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
-               [WebSysDescription ("The text for the literal WebControl.")]\r
 #if NET_2_0
-               [Localizable (true)]
-#endif
-               public string Text\r
-               {\r
-                       get {\r
-                               object o = ViewState ["Text"];\r
-                               return (o == null) ? String.Empty : (string) o;\r
-                       }\r
-\r
-                       set { ViewState ["Text"] = value; }\r
-               }\r
-\r
-               protected override ControlCollection CreateControlCollection ()\r
-               {\r
-                       return new EmptyControlCollection (this);\r
-               }\r
-\r
-               protected override void AddParsedSubObject (object obj)\r
-               {\r
-                       if (!(obj is LiteralControl))\r
-                               throw new HttpException (HttpRuntime.FormatResourceString (\r
-                                                       "Cannot_Have_Children_Of_Type", "Literal",\r
-                                                       obj.GetType ().Name.ToString ()));\r
-\r
-                       Text = ((LiteralControl) obj).Text;\r
-               }\r
-\r
-               protected override void Render (HtmlTextWriter writer)\r
-               {\r
-                       if (Text.Length > 0)\r
-                               writer.Write (Text);\r
-               }\r
+               [DefaultValue (LiteralMode.Transform)]
+               [WebSysDescription ("")]
+               [WebCategory ("Behavior")]
+               public LiteralMode Mode 
+               {
+                       get {
+                               return ViewState ["Mode"] == null ? LiteralMode.Transform : (LiteralMode) ViewState ["Mode"];
+                       }
+                       set {
+                               if (((int) value) < 0 || ((int) value) > 2)
+                                       throw new ArgumentOutOfRangeException ();
+                               ViewState ["Mode"] = value;
+                       }
+               }
+#endif         
 
+               [Bindable(true)]
+               [DefaultValue("")]
+               [WebSysDescription ("")]
+               [WebCategory ("Appearance")]
 #if NET_2_0
-               private LiteralMode literalMode;
-               [DefaultValue (LiteralMode.Transform), WebCategory ("Behavior"), WebSysDescription ("Determines whether the text is transformed or encoded")]
-               public LiteralMode Mode {
-                       get { return literalMode; }
-                       set { literalMode = value; }
+               [Localizable (true)]
+#endif         
+               public string Text {
+                       get {
+                               return ViewState.GetString ("Text", String.Empty);
+                       }
+                       set {
+                               ViewState ["Text"] = value;
+                       }
                }
 
+#if NET_2_0
+               [EditorBrowsable (EditorBrowsableState.Never)]
                public override void Focus ()
                {
-                       throw new NotSupportedException ("The Literal control does not support the Focus operation"); 
+                       throw new NotSupportedException ();
+               }
+#endif         
+
+               protected override ControlCollection CreateControlCollection ()
+               {
+                       return new EmptyControlCollection (this);
+               }
+
+               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 ()));
                }
+
+#if NET_2_0
+               protected internal
+#else          
+               protected
+#endif         
+               override void Render (HtmlTextWriter output)
+               {
+#if NET_2_0
+                       if (Mode == LiteralMode.Encode)
+                               output.Write (HttpUtility.HtmlEncode (Text));
+                       else
 #endif
-       }\r
-}\r
-\r
+                       output.Write (Text);
+               }
+       }
+}
+