/////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="count"></param>
        public void RemoveRange(int index, int count)
        {
            System.Diagnostics.Debug.Assert(index >= 0 && index < m_attributeList.Count);
            System.Diagnostics.Debug.Assert(count > 0);
            System.Diagnostics.Debug.Assert(index + count <= m_attributeList.Count);

            for (int scanIndex = index; scanIndex < index + count; ++scanIndex)
            {
                CHtmlAttribute attribute = m_attributeList[scanIndex];

                // 속성 소유자
                if (m_ownerNode != null)
                {
                    System.Diagnostics.Debug.Assert(m_ownerNode == attribute.OwnerNode);
                    attribute.OwnerNode = null;
                }

                // Update m_attributeHash
                if (m_attributeHash[attribute.Name] == attribute)
                {
                    m_attributeHash.Remove(attribute.Name);
                    for (int listIndex = index + count, listCount = m_attributeList.Count; listIndex < listCount; ++listIndex)
                    {
                        CHtmlAttribute temp = m_attributeList[listIndex];
                        if (attribute.Name.Equals(temp.Name))
                        {
                            m_attributeHash[attribute.Name] = temp;
                            break;
                        }
                    }
                }
            }

            m_attributeList.RemoveRange(index, count);
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        /// <param name="name"></param>
        /// <param name="attributeName"></param>
        /// <param name="attributeValue"></param>
        /// <param name="searchChildren"></param>
        public void FindByNameAttributeValue(CHtmlNodeCollection result, string name, string attributeName, string attributeValue, bool searchChildren)
        {
            System.Diagnostics.Debug.Assert(result != null);
            System.Diagnostics.Debug.Assert(attributeName != null);

            attributeName = attributeName.Trim().ToLower();

            for (int index = 0, count = m_nodeList.Count; index < count; ++index)
            {
                CHtmlNode node = m_nodeList[index];

                if (node.NodeName.Equals(name) && node is IHtmlNodeHasAttribute)
                {
                    CHtmlAttribute attribute = ((IHtmlNodeHasAttribute)node).Attributes[attributeName];
                    if (attribute != null && attribute.Value == attributeValue)
                    {
                        result.Add(node);
                    }
                }

                if (searchChildren && node is CHtmlElement)
                {
                    ((CHtmlElement)node).Nodes.FindByNameAttributeValue(result, name, attributeName, attributeValue, searchChildren);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 집합의 지정위치에 속성 추가
        /// </summary>
        /// <param name="index">추가할 인덱스 위치</param>
        /// <param name="node">추가한 속성</param>
        public void Insert(int index, CHtmlAttribute attribute)
        {
            System.Diagnostics.Debug.Assert(index >= 0 && index <= m_attributeList.Count);
            System.Diagnostics.Debug.Assert(attribute != null);

            // 속성 소유자
            if (m_ownerNode != null)
            {
                if (attribute.OwnerNode != null)
                {
                    attribute.OwnerNode.Attributes.RemoveAt(attribute.OwnerNode.Attributes.IndexOf(attribute));
                }

                attribute.OwnerNode = m_ownerNode;
            }

            // Update m_attributeHash
            if (m_attributeHash.ContainsKey(attribute.Name) == false)
            {
                m_attributeHash[attribute.Name] = attribute;
            }
            else
            {
                CHtmlAttribute temp      = (CHtmlAttribute)m_attributeHash[attribute.Name];
                int            tempIndex = m_attributeList.IndexOf(temp);
                if (index < tempIndex)
                {
                    m_attributeHash[attribute.Name] = attribute;
                }
            }

            m_attributeList.Insert(index, attribute);
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        public void RemoveAt(int index)
        {
            System.Diagnostics.Debug.Assert(index >= 0 && index < m_attributeList.Count);

            CHtmlAttribute attribute = m_attributeList[index];

            // 속성 소유자
            if (m_ownerNode != null)
            {
                System.Diagnostics.Debug.Assert(m_ownerNode == attribute.OwnerNode);
                attribute.OwnerNode = null;
            }

            m_attributeList.RemoveAt(index);

            // Update m_attributeHash
            if (m_attributeHash[attribute.Name] == attribute)
            {
                m_attributeHash.Remove(attribute.Name);
                for (int count = m_attributeList.Count; index < count; ++index)
                {
                    CHtmlAttribute temp = m_attributeList[index];
                    if (attribute.Name.Equals(temp.Name))
                    {
                        m_attributeHash[attribute.Name] = temp;
                        break;
                    }
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// »ý¼ºÀÚ
        /// </summary>
        public CHtmlAttribute(CHtmlAttribute obj)
        {
            System.Diagnostics.Debug.Assert(obj != null);

            obj.AssertValid();
            m_attributeName  = obj.m_attributeName;
            m_attributeValue = obj.m_attributeValue;
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="result"></param>
        public void FindByNameValue(string name, string value, CHtmlAttributeCollection result)
        {
            System.Diagnostics.Debug.Assert(name != null);
            System.Diagnostics.Debug.Assert(result != null);

            name = name.ToLower();
            for (int index = 0, count = m_attributeList.Count; index < count; ++index)
            {
                CHtmlAttribute attribute = m_attributeList[index];
                if (attribute.Name.Equals(name) && attribute.Value.Equals(value))
                {
                    result.Add(attribute);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        public void Clear()
        {
            // 속성 소유지
            if (m_ownerNode != null)
            {
                for (int index = 0, count = m_attributeList.Count; index < count; ++index)
                {
                    CHtmlAttribute attribute = m_attributeList[index];
                    System.Diagnostics.Debug.Assert(m_ownerNode == attribute.OwnerNode);
                    attribute.OwnerNode = null;
                }
            }

            m_attributeList.Clear();
            m_attributeHash.Clear();
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 속성의 인덱스 위치
        /// </summary>
        /// <param name="name">속성명.</param>
        /// <returns>속성 인덱스 위치</returns>
        public int IndexOf(string name)
        {
            System.Diagnostics.Debug.Assert(name != null);

            name = name.ToLower();

            int result = -1;

            for (int index = 0, count = m_attributeList.Count; index < count; ++index)
            {
                CHtmlAttribute attribute = m_attributeList[index];
                if (attribute.Name.Equals(name))
                {
                    result = index;
                    break;
                }
            }

            return(result);
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 속성 추가 메소드
        /// </summary>
        /// <param name="attribute">속성.</param>
        /// <returns>추가된 인덱스.</returns>
        public void Add(CHtmlAttribute attribute)
        {
            System.Diagnostics.Debug.Assert(attribute != null);

            if (m_ownerNode != null)
            {
                if (attribute.OwnerNode != null)
                {
                    attribute.OwnerNode.Attributes.RemoveAt(attribute.OwnerNode.Attributes.IndexOf(attribute));
                }

                attribute.OwnerNode = m_ownerNode;
            }

            // Update m_attributeHash
            if (m_attributeHash.ContainsKey(attribute.Name) == false)
            {
                m_attributeHash[attribute.Name] = attribute;
            }

            m_attributeList.Add(attribute);
        }
Exemplo n.º 10
0
        ///////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// ������
        /// </summary>
        public CHtmlAttribute(CHtmlAttribute obj)
        {
            System.Diagnostics.Debug.Assert(obj != null);

            obj.AssertValid();
            m_attributeName = obj.m_attributeName;
            m_attributeValue = obj.m_attributeValue;
        }
Exemplo n.º 11
0
        /////////////////////////////////////////////////////////////////////////////////
        #region

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="htmlStream"></param>
        /// <returns></returns>
        private Encoding DetectCharset(CHtmlNodeCollection nodes)
        {
            Encoding result = null;

            string charset = "";

            CHtmlNodeCollection metaNodes = new CHtmlNodeCollection();
            CHtmlElement        node      = nodes["html"] as CHtmlElement;

            if (node != null)
            {
                node = node.Nodes["head"] as CHtmlElement;
            }
            if (node != null)
            {
                node.Nodes.FindByNameAttribute(metaNodes, "meta", "content", false);
            }

            for (int nodeIndex = 0, count = metaNodes.Count; nodeIndex < count; ++nodeIndex)
            {
                CHtmlElement metaElement = metaNodes[nodeIndex] as CHtmlElement;
                if (metaElement != null)
                {
                    int index = -1;
                    CHtmlAttributeCollection attributes = metaElement.Attributes.FindByName("content");
                    for (int attributeIndex = 0, attributeCount = attributes.Count; attributeIndex < attributeCount; ++attributeIndex)
                    {
                        CHtmlAttribute attribute = attributes[attributeIndex];
                        if ((index = attribute.Value.IndexOf("charset")) != -1)
                        {
                            string value      = attribute.Value;
                            int    startIndex = index + 7;
                            while (startIndex < value.Length && CHtmlUtil.EqualesOfAnyChar(value[startIndex], " ="))
                            {
                                ++startIndex;
                            }
                            int endIndex = startIndex + 1;
                            while (endIndex < value.Length && !CHtmlUtil.EqualesOfAnyChar(value[endIndex], " "))
                            {
                                ++endIndex;
                            }

                            if (startIndex < value.Length && endIndex - startIndex > 0)
                            {
                                charset = value.Substring(startIndex, endIndex - startIndex);
                                try
                                {
                                    result = Encoding.GetEncoding(charset);
                                    break;
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 12
0
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="token"></param>
        /// <param name="attributeCollection"></param>
        private void ResolveAttribute(ref int visitor, CHtmlAttributeCollection attributeCollection)
        {
            Token token = m_tokens[visitor];

            // read the attributes and values
            while(token.Type != Token.TokenType.TagEnd && token.Type != Token.TokenType.TagCloseEnd)
            {
                System.Diagnostics.Debug.Assert(token.Type == Token.TokenType.AttributeName);
                string attribute_name = token.Content;
                ++visitor;
                token = m_tokens[visitor];
                if(token.Type == Token.TokenType.AttributeValue)
                {
                    string attribute_value = CHtmlUtil.TranHtmlTextToStr(token.Content);
                    CHtmlAttribute attribute = new CHtmlAttribute(attribute_name, attribute_value);
                    attributeCollection.Add(attribute);
                    ++visitor;
                }
                else
                {
                    // Null-value attribute
                    CHtmlAttribute attribute = new CHtmlAttribute(attribute_name);
                    attributeCollection.Add(attribute);
                }

                token = m_tokens[visitor];
            }
        }
 /////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// 속성의 인뎃스 위치
 /// </summary>
 /// <param name="node">속성노드</param>
 /// <returns>인덱스 위치</returns>
 public int IndexOf(CHtmlAttribute attribute)
 {
     System.Diagnostics.Debug.Assert(attribute != null);
     return(m_attributeList.IndexOf(attribute));
 }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// ������ ������ġ�� �Ӽ� �߰�
        /// </summary>
        /// <param name="index">�߰��� �ε��� ��ġ</param>
        /// <param name="node">�߰��� �Ӽ�</param>
        public void Insert(int index, CHtmlAttribute attribute)
        {
            System.Diagnostics.Debug.Assert(index >= 0 && index <= m_attributeList.Count);
            System.Diagnostics.Debug.Assert(attribute != null);

            // �Ӽ� ������
            if(m_ownerNode != null)
            {
                if(attribute.OwnerNode != null)
                    attribute.OwnerNode.Attributes.RemoveAt(attribute.OwnerNode.Attributes.IndexOf(attribute));

                attribute.OwnerNode = m_ownerNode;
            }

            // Update m_attributeHash
            if(m_attributeHash.ContainsKey(attribute.Name) == false)
                m_attributeHash[attribute.Name] = attribute;
            else
            {
                CHtmlAttribute temp = (CHtmlAttribute)m_attributeHash[attribute.Name];
                int tempIndex = m_attributeList.IndexOf(temp);
                if(index < tempIndex)
                    m_attributeHash[attribute.Name] = attribute;
            }

            m_attributeList.Insert(index, attribute);
        }
 /////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// �Ӽ��� �ε��� ��ġ
 /// </summary>
 /// <param name="node">�Ӽ����</param>
 /// <returns>�ε��� ��ġ</returns>
 public int IndexOf(CHtmlAttribute attribute)
 {
     System.Diagnostics.Debug.Assert(attribute != null);
     return m_attributeList.IndexOf(attribute);
 }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// �Ӽ� �߰� �޼ҵ�
        /// </summary>
        /// <param name="attribute">�Ӽ�.</param>
        /// <returns>�߰��� �ε���.</returns>
        public void Add(CHtmlAttribute attribute)
        {
            System.Diagnostics.Debug.Assert(attribute != null);

            if(m_ownerNode != null)
            {
                if(attribute.OwnerNode != null)
                    attribute.OwnerNode.Attributes.RemoveAt(attribute.OwnerNode.Attributes.IndexOf(attribute));

                attribute.OwnerNode = m_ownerNode;
            }

            // Update m_attributeHash
            if(m_attributeHash.ContainsKey(attribute.Name) == false)
                m_attributeHash[attribute.Name] = attribute;

            m_attributeList.Add(attribute);
        }