Example #1
0
 public string this[string name]
 {
     get
     {
         if (_collection != null)
         {
             object value = _collection.item(name);
             if (value != null)
             {
                 return(value.ToString());
             }
         }
         return(null);
     }
 }
Example #2
0
        private void BuildAttributeDictionary(IHTMLElement htmlElem)
        {
            IHTMLDOMNode             htmlNode       = (IHTMLDOMNode)htmlElem;
            IHTMLAttributeCollection attrCollection = (IHTMLAttributeCollection)htmlNode.attributes;

            for (int i = 0; i < attrCollection.length; ++i)
            {
                Object            crntIndex     = i;
                IHTMLDOMAttribute crntAttribute = (IHTMLDOMAttribute)attrCollection.item(ref crntIndex);

                String nodeName = ((String)(crntAttribute.nodeName)).ToLower();
                if (nodeName != CatStudioConstants.HOOKED_BY_REC_ATTR)
                {
                    if ((nodeName == "src") || (nodeName == "href") ||
                        (nodeName == "id") || (nodeName == "name") ||
                        (nodeName == "class") || (nodeName == "alt") ||
                        (nodeName == "title") || (nodeName == "action") ||
                        (nodeName == "for") || (nodeName == "value"))
                    {
                        String nodeValue = crntAttribute.nodeValue as String;
                        if (nodeValue != null)
                        {
                            this.attributeMap.Add(nodeName, nodeValue);
                        }
                    }
                }
            }

            // Add "uiName" pseudo-attribute to dictionary.
            IElement twbstElem = this.browser.core.AttachToNativeElement(htmlElem);
            String   textAttr  = twbstElem.uiName.Trim(); // Remove blanks from start/end of the text.

            // Skip too long texts or empty strings.
            if (!String.IsNullOrEmpty(textAttr) && (textAttr.Length <= CatStudioConstants.MAX_TEXT_ATTR_LEN_TO_RECORD))
            {
                this.attributeMap.Add("uiname", textAttr);
            }

            // Add innerText for Watir recorder.
            String innerText = htmlElem.innerText;

            if (!String.IsNullOrEmpty(innerText) && (innerText.Length <= CatStudioConstants.MAX_TEXT_ATTR_LEN_TO_RECORD))
            {
                this.attributeMap.Add("innertext", innerText);
            }
        }
Example #3
0
        /// <summary>
        /// Walk the supplied HTML DOM node (recursively) and add its contents into the
        /// supplied page using the supplied TextBlockBuilder.
        /// </summary>
        /// <remarks>When this routine is done there may be some residual text still in
        /// tbBuilder. The caller is resonsible for checking this and adding it to the
        /// page if present.</remarks>
        /// <param name="node">The HTML DOM node to recursively walk.</param>
        /// <param name="tbBuilder">The TextBlockBuilder to put the text into.</param>
        private TextBlockBuilder ParseDomNode(IHTMLDOMNode node, TextBlockBuilder tbBuilder)
        {
            TagType tagType = GetTagType(node.nodeName);

            switch (tagType)
            {
            case TagType.IMG:

                // Before we add the image, see if we need to write the text object first
                if (tbBuilder.HasText)
                {
                    // Yes it has
                    tbBuilder.Append(TagId.EOL);
                    FlushTextToBlock(m_CurrentPage, tbBuilder, m_MainBodyTextAttr);
                    tbBuilder = new TextBlockBuilder(GetNextObjId(), m_CharMapper);
                }

                IHTMLAttributeCollection attribs = (IHTMLAttributeCollection)node.attributes;
                object name = "src";
                string src  = ((IHTMLDOMAttribute)attribs.item(ref name)).nodeValue.ToString();
                name = "height";
                string height = ((IHTMLDOMAttribute)attribs.item(ref name)).nodeValue.ToString();
                name = "width";
                string width = ((IHTMLDOMAttribute)attribs.item(ref name)).nodeValue.ToString();

                addPageImage(m_CurrentPage, src, ushort.Parse(width), ushort.Parse(height));
                break;

            case TagType.text:
                AppendTextToBlock((string)node.nodeValue, tbBuilder);
                break;

            case TagType.I:
                tbBuilder.Append(TagId.ItalicBegin);
                break;

            case TagType.B:
                tbBuilder.Append(TagId.FontWeight, LegacyBBeB.k_BoldFontWeight);
                break;

            case TagType.SUP:
                tbBuilder.Append(TagId.BeginSup);
                break;

            case TagType.SUB:
                tbBuilder.Append(TagId.BeginSub);
                break;

            case TagType.H1:
            case TagType.H2:
            case TagType.H3:
            case TagType.H4:
            case TagType.H5:
            case TagType.H6:

                FlushTextToBlock(m_CurrentPage, tbBuilder, m_MainBodyTextAttr);
                tbBuilder = new TextBlockBuilder(GetNextObjId(), m_CharMapper);

                if (GetHeadingLevel(tagType) <= GetHeadingLevel(m_eNewPageHeadingFilter))
                {
                    if (m_CurrentPage.Children.Count > 0)                               // If current page not empty
                    {
                        // Start a new page
                        finalizePage(m_CurrentPage);

                        m_CurrentPage = createPage();

                        addBookPage(m_CurrentPage);
                    }
                }

                m_HeadingNodePageId[node] = m_CurrentPage.ID;
                m_TextObjectIdHeadingNode[tbBuilder.TextObjectId] = node;

                tbBuilder.Append(TagId.FontSize, GetHeadingFontSize(tagType));
                break;
            }

            if (node.hasChildNodes())
            {
                IHTMLDOMChildrenCollection childNodes = (IHTMLDOMChildrenCollection)node.childNodes;
                foreach (IHTMLDOMNode child in childNodes)
                {
                    tbBuilder = ParseDomNode(child, tbBuilder);
                }
            }

            switch (tagType)
            {
            case TagType.I:
                tbBuilder.Append(TagId.ItalicEnd);
                break;

            case TagType.B:
                tbBuilder.Append(TagId.FontWeight, LegacyBBeB.k_NormalFontWeight);
                break;

            case TagType.SUP:
                tbBuilder.Append(TagId.EndSup);
                break;

            case TagType.SUB:
                tbBuilder.Append(TagId.EndSub);
                break;

            case TagType.P:
                tbBuilder.Append(TagId.EOL);
                tbBuilder.Append(TagId.EOL);
                break;

            case TagType.H1:
            case TagType.H2:
            case TagType.H3:
            case TagType.H4:
            case TagType.H5:
            case TagType.H6:
                tbBuilder.Append(TagId.FontSize, LegacyBBeB.DefaultFontSize);
                FlushTextToBlock(m_CurrentPage, tbBuilder, m_MainBodyTextAttr);
                tbBuilder = new TextBlockBuilder(GetNextObjId(), m_CharMapper);
                break;

            case TagType.BR:
                tbBuilder.Append(TagId.EOL);
                break;
            }

            return(tbBuilder);
        }
Example #4
0
 public IHtmlAttribute Get( string name )
 {
   return ConvertExtensions.AsAttribute( _attributes.item( name ), _element );
 }