AppendLiteralString() public method

public AppendLiteralString ( string s ) : void
s string
return void
Example #1
0
        public virtual void AppendLiteralString(string s)
        {
            if (s == null || s.Length == 0)
            {
                return;
            }

            if (childrenAsProperties || !isIParserAccessor)
            {
                if (defaultPropertyBuilder != null)
                {
                    defaultPropertyBuilder.AppendLiteralString(s);
                }
                else if (s.Trim().Length != 0)
                {
                    throw new HttpException(String.Format("Literal content not allowed for '{0}' {1} \"{2}\"",
                                                          tagName, GetType(), s));
                }

                return;
            }

            if (!AllowWhitespaceLiterals() && s.Trim().Length == 0)
            {
                return;
            }

            if (HtmlDecodeLiterals())
            {
                s = HttpUtility.HtmlDecode(s);
            }

            AddChild(s);
        }
        /// <include file='doc\ControlBuilder.uex' path='docs/doc[@for="ControlBuilder.AppendLiteralString"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual void AppendLiteralString(string s)
        {
            // Ignore null strings
            if (s == null)
            {
                return;
            }

            // If we are not building a control, or if our children define
            // properties, we should not get literal strings.  Ignore whitespace
            // ones, and fail for others
            if (FIsNonParserAccessor || FChildrenAsProperties)
            {
                // If there is a default property, delegate to its builder
                if (_defaultPropBuilder != null)
                {
                    _defaultPropBuilder.AppendLiteralString(s);
                    return;
                }

                if (!Util.IsWhiteSpaceString(s))
                {
                    throw new HttpException(HttpRuntime.FormatResourceString(
                                                SR.Literal_content_not_allowed, _ctrlType.FullName, s.Trim()));
                }
                return;
            }

            // Ignore literals that are just whitespace if the control does not want them
            if ((AllowWhitespaceLiterals() == false) && Util.IsWhiteSpaceString(s))
            {
                return;
            }

            // A builder can specify its strings need to be html decoded
            if (HtmlDecodeLiterals())
            {
                s = HttpUtility.HtmlDecode(s);
            }

            // If the last builder is a DataBoundLiteralControlBuilder, add the string
            // to it instead of to our list of sub-builders
            object lastBuilder = GetLastBuilder();
            DataBoundLiteralControlBuilder dataBoundBuilder = lastBuilder as DataBoundLiteralControlBuilder;

            if (dataBoundBuilder != null)
            {
                Debug.Assert(!InDesigner, "!InDesigner");
                dataBoundBuilder.AddLiteralString(s);
            }
            else
            {
                AddSubBuilder(s);
            }
        }
Example #3
0
		public void Deny_Unrestricted ()
		{
			ControlBuilder cb = new ControlBuilder ();
			Assert.IsNull (cb.ControlType, "ControlType");
			Assert.IsFalse (cb.HasAspCode, "HasAspCode");
			cb.ID = "mono";
			Assert.AreEqual ("mono", cb.ID, "ID");
			Assert.AreEqual (typeof (Control), cb.NamingContainerType, "NamingContainerType");
			Assert.IsNull (cb.TagName, "TagName");
			Assert.IsTrue (cb.AllowWhitespaceLiterals (), "AllowWhitespaceLiterals");
			cb.AppendLiteralString ("mono");
			cb.AppendSubBuilder (cb);
			cb.CloseControl ();
			Assert.IsNull (cb.GetChildControlType (null, null), "GetChildControlType");
			Assert.IsTrue (cb.HasBody (), "HasBody");
			Assert.IsFalse (cb.HtmlDecodeLiterals (), "HtmlDecodeLiterals");
			cb.Init (null, cb, typeof (TemplateBuilder), "span", "mono", null);
			Assert.IsFalse (cb.NeedsTagInnerText (), "NeedsTagInnerText");
			//cb.OnAppendToParentBuilder (null);
			cb.SetTagInnerText ("mono");

			cb = ControlBuilder.CreateBuilderFromType (null, cb, typeof (TemplateBuilder), "span", "mono", null, 0, String.Empty);
			Assert.IsNotNull (cb, "CreateBuilderFromType");
		}
 private void AddTagInnerTextElements(ControlBuilder builder)
 {
     if (_tagInnerTextElements != null)
     {
         foreach(Object o in _tagInnerTextElements)
         {
             if (o is String)
             {
                 builder.AppendLiteralString((String)o);
             }
             else
             {
                 builder.AppendSubBuilder((ControlBuilder)o);
             }
         }
         _tagInnerTextElements = null;
     }
 }