Example #1
0
 protected ParsingObject(string tagid, ParsingObject parent)
 {
     if (parent == null && ! (this is RootParsingObject) )
         throw new ArgumentNullException ("parent", "All ParsingObjects except RootParsingObjects must have parents");
     this.tagid = tagid;
     this.parent = parent;
 }
Example #2
0
 protected ParsingObject(string tagid, ParsingObject parent)
 {
     if (parent == null && !(this is RootParsingObject))
     {
         throw new ArgumentNullException("parent", "All ParsingObjects except RootParsingObjects must have parents");
     }
     this.tagid  = tagid;
     this.parent = parent;
 }
Example #3
0
        /// <summary>
        /// Parses a document fragment. Processes all controls and directives and adds them to host.
        /// </summary>
        /// <param name="fragment">The document fragment to parse</param>
        /// <returns>The document with all controls, directives and script blocks replaced by placeholders</returns>
        public void ProcessFragment(string fragment, out Control[] controls, out string substText)
        {
            AspParser parser = InitialiseParser(fragment);

            rootParsingObject = new RootParsingObject(host);
            openObject        = rootParsingObject;

            parser.Parse();

            if (openObject != rootParsingObject)
            {
                throw new Exception("The tag " + openObject.TagID + " was left unclosed");
            }

            rootParsingObject.GetParsedContent(out controls, out substText);
        }
Example #4
0
		/// <summary>
		/// Parses a document fragment. Processes all controls and directives and adds them to host. 
		/// </summary>
		/// <param name="fragment">The document fragment to parse</param>
		/// <returns>The document with all controls, directives and script blocks replaced by placeholders</returns>
		public void ProcessFragment (string fragment, out Control[] controls, out string substText)
		{
			
			AspParser parser = InitialiseParser (fragment);
			
			rootParsingObject = new RootParsingObject(host);
			openObject = rootParsingObject;
			
			parser.Parse ();
			
			if (openObject != rootParsingObject) {
				throw new Exception ("The tag " +  openObject.TagID + " was left unclosed");
			}
			
			rootParsingObject.GetParsedContent (out controls, out substText);
		}
Example #5
0
        /// <summary>
        /// Parses a document fragment. Processes all controls and directives and adds them to host. 
        /// </summary>
        /// <param name="fragment">The document fragment to parse</param>
        /// <returns>The document with all controls, directives and script blocks replaced by placeholders</returns>
        public void ParseDocument(string fragment, out Control[] controls, out string designDocument)
        {
            AspParser parser = InitialiseParser (fragment);

            rootParsingObject = new RootParsingObject(host);
            openObject = rootParsingObject;

            parser.Parse ();

            if (openObject != rootParsingObject) {
                throw new Exception ("The tag " +  openObject.TagID + " was left unclosed");
            }

            object[] objects;
            rootParsingObject.BuildObject(out objects, out designDocument);
            controls = new Control[objects.Length];
            objects.CopyTo (controls, 0);
        }
Example #6
0
        /// <summary>
        /// Parses a document fragment. Processes all controls and directives and adds them to host.
        /// </summary>
        /// <param name="fragment">The document fragment to parse</param>
        /// <returns>The document with all controls, directives and script blocks replaced by placeholders</returns>
        public void ParseDocument(string fragment, out Control[] controls, out string designDocument)
        {
            AspParser parser = InitialiseParser(fragment);

            rootParsingObject = new RootParsingObject(host);
            openObject        = rootParsingObject;

            parser.Parse();

            if (openObject != rootParsingObject)
            {
                throw new Exception("The tag " + openObject.TagID + " was left unclosed");
            }

            object[] objects;
            rootParsingObject.BuildObject(out objects, out designDocument);
            controls = new Control[objects.Length];
            objects.CopyTo(controls, 0);
        }
Example #7
0
        public ServerObjectParsingObject(Type type, Hashtable attributes, string tagid, ParsingObject parent)
            : base(tagid, parent)
        {
            //create the object
            if (type.GetInterface("System.ComponentModel.IComponent") != null)
            {
                //note: this automatically adds to parent's container, as some controls
                //need to be sited e.g. if they use site dictionaries
                //TODO: should this action be passed up the tree so controls can intercept?
                obj = ((AspNetEdit.Editor.ComponentModel.DesignerHost)base.DesignerHost).CreateComponent(type, attributes["ID"] as string, false);
            }
            else
            {
                obj = Activator.CreateInstance(type);
            }

            //and populate it from the attributes
            pdc = TypeDescriptor.GetProperties(obj);
            foreach (DictionaryEntry de in attributes)
            {
                if (0 == string.Compare((string)de.Key, "runat"))
                {
                    continue;
                }
                if (0 == string.Compare((string)de.Key, "ID"))
                {
                    continue;
                }
                //use the dash subproperty syntax
                string[]           str = ((string)de.Key).Split('-');
                PropertyDescriptor pd  = pdc.Find(str[0], true);

                //if property not found, try events
                if (str.Length == 1 && pd == null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(str[0].ToLower(), "on"))
                {
                    IEventBindingService iebs = (IEventBindingService)DesignerHost.GetService(typeof(IEventBindingService));
                    if (iebs == null)
                    {
                        throw new Exception("Could not obtain IEventBindingService from host");
                    }

                    EventDescriptorCollection edc = TypeDescriptor.GetEvents(obj);
                    EventDescriptor           e   = edc.Find(str[0].Remove(0, 2), true);
                    if (e != null)
                    {
                        pd = iebs.GetEventProperty(e);
                    }
                    else
                    {
                        throw new Exception("Could not find event " + str[0].Remove(0, 2));
                    }
                }

                object loopObj = obj;

                for (int i = 0; i < str.Length; i++)
                {
                    if (pd == null)
                    {
                        throw new Exception("Could not find property " + (string)de.Key);
                    }

                    if (i == str.Length - 1)
                    {
                        pd.SetValue(obj, pd.Converter.ConvertFromString((string)de.Value));
                        break;
                    }

                    loopObj = pd.GetValue(loopObj);
                    pd      = TypeDescriptor.GetProperties(loopObj).Find(str[0], true);
                }
            }

            parseAtt = TypeDescriptor.GetAttributes(obj)[typeof(ParseChildrenAttribute)] as ParseChildrenAttribute;
            //FIXME: fix this in MCS classlib
            if (parseAtt.DefaultProperty.Length == 0)
            {
                parseAtt = null;
            }

            //work out how we're trying to parse the children
            if (parseAtt != null)
            {
                if (parseAtt.DefaultProperty != null)
                {
                    PropertyDescriptor pd = pdc[parseAtt.DefaultProperty];
                    if (pd == null)
                    {
                        throw new Exception("Default property does not exist");
                    }
                    if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList)))
                    {
                        mode = ParseChildrenMode.DefaultCollectionProperty;
                    }
                    else
                    {
                        mode = ParseChildrenMode.DefaultProperty;
                    }
                }
                else if (parseAtt.ChildrenAsProperties)
                {
                    mode = ParseChildrenMode.Properties;
                }
                else
                {
                    mode = ParseChildrenMode.Controls;
                }
            }
            else
            {
                //FIXME: these are actually persistence hints, but ParseChildrenAttribute doesn't always exist.
                //FIXME: logic would be dodgy with bad input
                parseAtt = ParseChildrenAttribute.Default;
                mode     = ParseChildrenMode.Controls;
                foreach (PropertyDescriptor pd in pdc)
                {
                    PersistenceModeAttribute modeAttrib = pd.Attributes[typeof(PersistenceModeAttribute)] as PersistenceModeAttribute;
                    if (modeAttrib == null)
                    {
                        return;
                    }

                    switch (modeAttrib.Mode)
                    {
                    case PersistenceMode.Attribute:
                        continue;

                    case PersistenceMode.EncodedInnerDefaultProperty:
                        parseAtt.DefaultProperty = pd.Name;
                        mode = ParseChildrenMode.DefaultEncodedProperty;
                        break;

                    case PersistenceMode.InnerDefaultProperty:
                        parseAtt.DefaultProperty = pd.Name;
                        if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList)))
                        {
                            mode = ParseChildrenMode.DefaultCollectionProperty;
                        }
                        else
                        {
                            mode = ParseChildrenMode.DefaultProperty;
                        }
                        break;

                    case PersistenceMode.InnerProperty:
                        mode = ParseChildrenMode.Properties;
                        break;
                    }
                }
            }
        }
Example #8
0
        void TagParsed(ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
        {
            switch (tagtype)
            {
            case TagType.Close:
                if (openObject == null)
                {
                    throw new ParseException(location, "There are more closing tags than opening tags");
                }

                if (0 != string.Compare(openObject.TagID, tagid))
                {
                    throw new ParseException(location, "Closing tag " + tagid + " does not match opening tag " + openObject.TagID);
                }
                openObject = openObject.CloseObject(location.PlainText);
                break;

            case TagType.CodeRender:
                throw new NotImplementedException("Code render expressions have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.CodeRenderExpression:
                throw new NotImplementedException("Code render expressions have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.DataBinding:
                throw new NotImplementedException("Data binding expressions have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.Directive:
                ProcessDirective(tagid, attributes);
                break;

            case TagType.Include:
                throw new NotImplementedException("Server-side includes have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.ServerComment:
                throw new NotImplementedException("Server comments have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.Tag:
                //TODO: don't do this for XHTML
                if ((string.Compare(tagid, "br", true) == 0) ||
                    (string.Compare(tagid, "hr", true) == 0))
                {
                    goto case TagType.SelfClosing;
                }

                openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
                break;

            case TagType.SelfClosing:
                if (openObject == null)
                {
                    throw new Exception("Root tag cannot be self-closing");
                }

                openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
                openObject = openObject.CloseObject(string.Empty);
                break;

            case TagType.Text:
                throw new NotImplementedException("Text tagtypes have not yet been implemented: " + location.PlainText);
                //break;
            }
        }
Example #9
0
		public ServerFormParsingObject (string tagText, string tagid, ParsingObject parent)
			: base (tagText, tagid, parent)
		{
		}
Example #10
0
		public HtmlParsingObject (string tagText, string tagid, ParsingObject parent)
			: base (tagid, parent)
		{
			AddText (tagText);
		}
Example #11
0
		void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
		{
			switch (tagtype)
			{
				case TagType.Close:
					if (openObject == null)
						throw new ParseException (location, "There are more closing tags than opening tags");

					if (0 != string.Compare (openObject.TagID, tagid))
						throw new ParseException (location, "Closing tag " + tagid + " does not match opening tag " + openObject.TagID);
					openObject = openObject.CloseObject (location.PlainText);
					break;
				case TagType.CodeRender:
					throw new NotImplementedException ("Code render expressions have not yet been implemented: " + location.PlainText);
					//break;
				case TagType.CodeRenderExpression:
					throw new NotImplementedException ("Code render expressions have not yet been implemented: " + location.PlainText);
					//break;
				case TagType.DataBinding:
					throw new NotImplementedException("Data binding expressions have not yet been implemented: " + location.PlainText);
					//break;
				case TagType.Directive:
					ProcessDirective (tagid, attributes);
					break;
				case TagType.Include:
					throw new NotImplementedException ("Server-side includes have not yet been implemented: " + location.PlainText);
					//break;
				case TagType.ServerComment:
					throw new NotImplementedException ("Server comments have not yet been implemented: " + location.PlainText);
					//break;
				case TagType.Tag:
					//TODO: don't do this for XHTML
					if ((string.Compare (tagid, "br", true) == 0)
						|| (string.Compare (tagid, "hr", true) == 0))
						goto case TagType.SelfClosing;
					
					openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
					break;
				case TagType.SelfClosing:
					if (openObject == null)
						throw new Exception ("Root tag cannot be self-closing");
				
					openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
					openObject = openObject.CloseObject(string.Empty);
					break;
				case TagType.Text:
					throw new NotImplementedException("Text tagtypes have not yet been implemented: " + location.PlainText);
					//break;
			}
		}
 public ServerFormParsingObject(string tagText, string tagid, ParsingObject parent)
     : base(tagText, tagid, parent)
 {
 }
 public HtmlParsingObject(string tagText, string tagid, ParsingObject parent)
     : base(tagid, parent)
 {
     AddText(tagText);
 }
		public ServerObjectParsingObject(Type type, Hashtable attributes, string tagid, ParsingObject parent)
			: base (tagid, parent)
		{
			//create the object
			if (type.GetInterface ("System.ComponentModel.IComponent") != null)
				//note: this automatically adds to parent's container, as some controls
				//need to be sited e.g. if they use site dictionaries
				//TODO: should this action be passed up the tree so controls can intercept?
				obj = ((AspNetEdit.Editor.ComponentModel.DesignerHost) base.DesignerHost).CreateComponent (type, attributes["ID"] as string, false);
			else
				obj = Activator.CreateInstance (type);
				
			//and populate it from the attributes
			pdc = TypeDescriptor.GetProperties (obj);
			foreach (DictionaryEntry de in attributes) {
				if (0 == string.Compare((string)de.Key, "runat"))
					continue;
				if (0 == string.Compare((string)de.Key, "ID"))
					continue;
				//use the dash subproperty syntax
				string[] str = ((string)de.Key).Split ('-');
				PropertyDescriptor pd = pdc.Find (str[0], true);

				//if property not found, try events
				if (str.Length == 1 && pd == null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix (str[0].ToLower(), "on")) {
					IEventBindingService iebs = (IEventBindingService) DesignerHost.GetService (typeof (IEventBindingService));
					if (iebs == null)
						throw new Exception ("Could not obtain IEventBindingService from host");

					EventDescriptorCollection edc = TypeDescriptor.GetEvents (obj);
					EventDescriptor e = edc.Find (str[0].Remove(0,2), true);
					if (e != null)
						pd = iebs.GetEventProperty(e);
					else
						throw new Exception ("Could not find event " + str[0].Remove(0,2));
				}
				
				object loopObj = obj;
				
				for (int i = 0; i < str.Length; i++ )
				{
					if (pd == null)
						throw new Exception ("Could not find property " + (string)de.Key);
					
					if (i == str.Length - 1) {
						pd.SetValue (obj, pd.Converter.ConvertFromString ((string) de.Value));
						break;
					}
					
					loopObj = pd.GetValue (loopObj);
					pd = TypeDescriptor.GetProperties (loopObj).Find (str[0], true);
					
				}
			}

			parseAtt = TypeDescriptor.GetAttributes (obj)[typeof(ParseChildrenAttribute )] as ParseChildrenAttribute;
			//FIXME: fix this in MCS classlib
			if (parseAtt.DefaultProperty.Length == 0)
				parseAtt = null;
			
			//work out how we're trying to parse the children
			if (parseAtt != null) {
				if (parseAtt.DefaultProperty != null) {
					PropertyDescriptor pd = pdc[parseAtt.DefaultProperty];
					if (pd == null)
						throw new Exception ("Default property does not exist");
					if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList)))
						mode = ParseChildrenMode.DefaultCollectionProperty;
					else
						mode = ParseChildrenMode.DefaultProperty;
				}
				else if (parseAtt.ChildrenAsProperties)
					mode = ParseChildrenMode.Properties;
				else
					mode = ParseChildrenMode.Controls;
			}
			else {
				//FIXME: these are actually persistence hints, but ParseChildrenAttribute doesn't always exist.
				//FIXME: logic would be dodgy with bad input
				parseAtt = ParseChildrenAttribute.Default;
				mode = ParseChildrenMode.Controls;
				foreach (PropertyDescriptor pd in pdc) {
					PersistenceModeAttribute modeAttrib = pd.Attributes[typeof(PersistenceModeAttribute)] as PersistenceModeAttribute;
					if (modeAttrib == null) return;
					
					switch (modeAttrib.Mode) {
						case PersistenceMode.Attribute:
							continue;
						case PersistenceMode.EncodedInnerDefaultProperty:
							parseAtt.DefaultProperty = pd.Name;
							mode = ParseChildrenMode.DefaultEncodedProperty;
							break;				
						case PersistenceMode.InnerDefaultProperty:
							parseAtt.DefaultProperty = pd.Name;
							if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList)))
								mode = ParseChildrenMode.DefaultCollectionProperty;
							else
								mode = ParseChildrenMode.DefaultProperty;
							break;
						case PersistenceMode.InnerProperty:
							mode = ParseChildrenMode.Properties;
							break;
					}
				}
			}
		
		}