Ejemplo n.º 1
0
 /// <summary>
 /// 初始化本类型,对外不公开
 /// </summary>
 /// <param name="page">类似XmlDocument,对本组件是XhtmlPage</param>
 /// <param name="localName">当前节点的本地名</param>
 /// <param name="attributes">当前节点的属性集合</param>
 internal virtual void InitializeComponent(XhtmlSection section, string localName, params XhtmlAttribute[] attributes)
 {
     this.InitializeComponent(section, localName);
     foreach (XhtmlAttribute item in attributes)
     {
         this.SetAttribute(item);
     }
 }
Ejemplo n.º 2
0
        private XhtmlComment(XhtmlSection section, string str1, bool isInclude)
        {
            string text;

            if (isInclude)
            {
                text = string.Format("#include virtual=\"{0}\"", str1);
            }
            else
            {
                text = str1;
            }
            this.InstanceSubMethod(section, text);
        }
Ejemplo n.º 3
0
            internal override void InitializeComponent(XhtmlSection section, string localName)
            {
                base.InitializeComponent(section, localName);

                this.MetaCollection.Inserted    += new EventHandler <EventArgs <XhtmlTags.Meta> >(MetaCollection_Inserted);
                this.MetaCollection.Removed     += new EventHandler <EventArgs <XhtmlTags.Meta> >(MetaCollection_Removed);
                this.MetaCollection.ItemChanged += new EventHandler <ChangedEventArgs <XhtmlTags.Meta> >(MetaCollection_ItemChanged);

                this.LinkCollection.Inserted    += new EventHandler <EventArgs <XhtmlTags.Link> >(LinkCollection_Inserted);
                this.LinkCollection.Removed     += new EventHandler <EventArgs <XhtmlTags.Link> >(LinkCollection_Removed);
                this.LinkCollection.ItemChanged += new EventHandler <ChangedEventArgs <XhtmlTags.Link> >(LinkCollection_ItemChanged);

                this.ScriptCollection.Inserted    += new EventHandler <EventArgs <XhtmlTags.Script> >(ScriptCollection_Inserted);
                this.ScriptCollection.Removed     += new EventHandler <EventArgs <XhtmlTags.Script> >(ScriptCollection_Removed);
                this.ScriptCollection.ItemChanged += new EventHandler <ChangedEventArgs <XhtmlTags.Script> >(ScriptCollection_ItemChanged);

                this.StyleCollection.Inserted    += new EventHandler <EventArgs <XhtmlTags.Style> >(StyleCollection_Inserted);
                this.StyleCollection.Removed     += new EventHandler <EventArgs <XhtmlTags.Style> >(StyleCollection_Removed);
                this.StyleCollection.ItemChanged += new EventHandler <ChangedEventArgs <XhtmlTags.Style> >(StyleCollection_ItemChanged);
            }
Ejemplo n.º 4
0
        /// <summary>
        /// 将一个片断(Jeelu.XhtmlSection)导入到引用节点(深度克隆)。
        /// 功能实现重点:是将一个文档的片断导入到另一个文档
        /// </summary>
        /// <param name="section">即将被导入的片断</param>
        /// <param name="refElement">引用的节点,片断将被导入这个节点的子节点列表的末尾</param>
        /// <returns>导入成功与否。true成功,false失败</returns>
        public virtual bool ImportSection(XhtmlSection section, XhtmlElement refElement)
        {
            if (section == null || refElement == null)
            {
                return(false);
            }
            XmlNode newNode = ((XmlDocument)this.AsXmlNode).ImportNode(((XmlDocument)section.AsXmlNode).DocumentElement, true);

            if (refElement.AsXmlNode is XmlDocument)
            {
                XmlDocument doc = (XmlDocument)refElement.AsXmlNode;
                doc.DocumentElement.AppendChild(newNode);
                return(true);
            }
            else
            {
                refElement.AsXmlNode.AppendChild(newNode);
                return(true);
            }
        }
Ejemplo n.º 5
0
        private XhtmlCData(XhtmlSection section, int placeFlag)
        {
            string text = string.Empty;

            switch (placeFlag)
            {
            case 0:    //0表示在Html文件头部包含头部与正文相关信息
                text = "<? include($_GET['content_id'].'_h.inc') ?>";
                break;

            case 1:    //1表示包含Content正文的页面片文件
                text = "<? include($_GET['content_id'].'_c.inc') ?>";
                break;

            default:
                Debug.Fail("仅支持数字0和1,\r\n0表示在Html文件头部包含头部与正文相关信息;\r\n1表示包含Content正文的页面片文件");
                break;
            }
            this.InstanceSubMethod(section, text);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 初始化本类型,对外不公开
 /// </summary>
 /// <param name="page">类似XmlDocument,对本组件是XhtmlPage</param>
 /// <param name="localName">当前节点的本地名</param>
 internal virtual void InitializeComponent(XhtmlSection section, string localName)
 {
     this.AsXmlNode  = ((XmlDocument)section.AsXmlNode).CreateElement(localName);
     this.Attributes = new XhtmlAttributeCollection(this);
     this.OwnerPage  = section;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// This will parse a string containing HTML and will produce a domain tree.
        /// </summary>
        /// <param name="html">The HTML to be parsed</param>
        /// <param name="isRemoveEmptyElementText">The default mechanism will extract a pure DOM tree, which will contain many text nodes containing just whitespace (carriage returns etc.) However, with normal parsing, these are useless and only serve to complicate matters. Therefore, this option exists to automatically remove those empty text nodes.</param>
        /// <returns>A tree representing the elements</returns>
        public static XhtmlTCollection <XhtmlElement> Parse(string html, bool isRemoveEmptyElementText)
        {
            XhtmlTCollection <XhtmlElement> nodes = new XhtmlTCollection <XhtmlElement>();

            html = PreprocessScript(html, "script");
            html = PreprocessScript(html, "style");

            html = RemoveComments(html);
            html = RemoveSGMLComments(html);
            StringCollection tokens = GetTokens(html);

            int          index   = 0;
            XhtmlSection element = null;

            while (index < tokens.Count)
            {
                if ("<".Equals(tokens[index]))
                {
                    // Read open tag

                    index++;
                    if (index >= tokens.Count)
                    {
                        break;
                    }
                    string tag_name = tokens[index];
                    index++;
                    element = new XhtmlSection(tag_name);
                    // read the attributes and values

                    while (index < tokens.Count && !">".Equals(tokens[index]) && !"/>".Equals(tokens[index]))
                    {
                        string attribute_name = tokens[index];
                        index++;
                        if (index < tokens.Count && "=".Equals(tokens[index]))
                        {
                            index++;
                            string attribute_value;
                            if (index < tokens.Count)
                            {
                                attribute_value = tokens[index];
                            }
                            else
                            {
                                attribute_value = null;
                            }
                            index++;
                            XhtmlAttribute attribute = new XhtmlAttribute(attribute_name, XhtmlEncoder.Decode(attribute_value));
                            element.Attributes.Add(attribute);
                        }
                        else if (index < tokens.Count)
                        {
                            // Null-value attribute
                            XhtmlAttribute attribute = new XhtmlAttribute(attribute_name, null);
                            element.Attributes.Add(attribute);
                        }
                    }
                    nodes.Add(element);
                    if (index < tokens.Count && "/>".Equals(tokens[index]))
                    {
                        element.IsTerminated = true;
                        index++;
                        element = null;
                    }
                    else if (index < tokens.Count && ">".Equals(tokens[index]))
                    {
                        index++;
                    }
                }
                else if (">".Equals(tokens[index]))
                {
                    index++;
                }
                else if ("</".Equals(tokens[index]))
                {
                    // Read close tag
                    index++;
                    if (index >= tokens.Count)
                    {
                        break;
                    }
                    string tag_name = tokens[index];
                    index++;

                    int open_index = FindTagOpenNodeIndex(nodes, tag_name);
                    if (open_index != -1)
                    {
                        MoveNodesDown(ref nodes, open_index + 1, (XhtmlElement)nodes[open_index]);
                    }
                    else
                    {
                        // Er, there is a close tag without an opening tag!!
                    }

                    // Skip to the end of this tag
                    while (index < tokens.Count && !">".Equals(tokens[index]))
                    {
                        index++;
                    }
                    if (index < tokens.Count && ">".Equals(tokens[index]))
                    {
                        index++;
                    }

                    element = null;
                }
                else
                {
                    // Read text
                    string value = tokens[index];
                    if (isRemoveEmptyElementText)
                    {
                        value = RemoveWhitespace(value);
                    }
                    value = DecodeScript(value);

                    if (isRemoveEmptyElementText && value.Length == 0)
                    {
                        // We do nothing
                    }
                    else
                    {
                        if (!(element != null && element.NoEscaping))
                        {
                            value = XhtmlEncoder.Decode(value);
                        }
                        XhtmlText textNode = new XhtmlText(element, value);
                        nodes.Add(textNode);

                        //HtmlText node = new HtmlText(value);
                        //nodes.Add(node);
                    }
                    index++;
                }
            }
            return(nodes);
        }
Ejemplo n.º 8
0
 private void InstanceSubMethod(XhtmlSection section, string text)
 {
     this._xhtmlSection = section;
     this.AsXmlNode     = ((XmlDocument)section.AsXmlNode).CreateTextNode(text);
     this.Attributes    = new XhtmlAttributeCollection(this);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 构造函数,实例化一个Xhtml的文本节点
 /// </summary>
 /// <param name="section">一个Xhtml文本的上下文文档,可以是Page,也可以是Section</param>
 /// <param name="xhtmlText">Xhtml文本</param>
 internal XhtmlText(XhtmlSection section, string text)
 {
     this.InstanceSubMethod(section, text);
 }
Ejemplo n.º 10
0
 internal ShtmlInclude(XhtmlSection section, string fullFile)
     : base(section, fullFile, true)
 {
 }
Ejemplo n.º 11
0
 internal ShtmlInclude(XhtmlSection section, string path, string file)
     : base(section, path, file)
 {
 }
Ejemplo n.º 12
0
        private XhtmlComment(XhtmlSection section, string str1, string str2)
        {
            string text = string.Format("#include virtual=\"{0}{1}\"", str1, str2);

            this.InstanceSubMethod(section, text);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// 构造函数,实例化一个Xhtml的注释文本节点
 /// </summary>
 /// <param name="section">一个Xhtml文本的上下文文档,可以是Page,也可以是Section</param>
 /// <param name="xhtmlText">注释文本</param>
 internal XhtmlComment(XhtmlSection section, string commentText)
 {
     this.InstanceSubMethod(section, commentText);
 }
Ejemplo n.º 14
0
 internal PHPInclude(XhtmlSection section, int placeFlag)
     : base(section, placeFlag)
 {
 }