예제 #1
0
        public virtual void MatchesRootSelectorItemTest()
        {
            CssPseudoClassRootSelectorItem item = CssPseudoClassRootSelectorItem.GetInstance();
            IXmlParser    htmlParser            = new JsoupHtmlParser();
            IDocumentNode documentNode          = htmlParser.Parse("<div><p>Alexander</p><p>Alexander</p></div>");
            INode         headNode = documentNode.ChildNodes()[0];

            NUnit.Framework.Assert.IsTrue(item.Matches(headNode));
        }
예제 #2
0
        public virtual void MatchesRootSelectorItemTestNotTaggedText()
        {
            CssPseudoClassRootSelectorItem item = CssPseudoClassRootSelectorItem.GetInstance();
            IXmlParser    htmlParser            = new JsoupHtmlParser();
            IDocumentNode documentNode          = htmlParser.Parse("SomeText!");
            INode         bodyNode = documentNode.ChildNodes()[0].ChildNodes()[1];
            INode         divNode  = bodyNode.ChildNodes()[0];

            NUnit.Framework.Assert.IsFalse(item.Matches(divNode));
        }
        public static iText.StyledXmlParser.Css.Selector.Item.CssPseudoClassSelectorItem Create(String pseudoClass
                                                                                                , String arguments)
        {
            switch (pseudoClass)
            {
            case CommonCssConstants.EMPTY: {
                return(CssPseudoClassEmptySelectorItem.GetInstance());
            }

            case CommonCssConstants.FIRST_CHILD: {
                return(CssPseudoClassFirstChildSelectorItem.GetInstance());
            }

            case CommonCssConstants.FIRST_OF_TYPE: {
                return(CssPseudoClassFirstOfTypeSelectorItem.GetInstance());
            }

            case CommonCssConstants.LAST_CHILD: {
                return(CssPseudoClassLastChildSelectorItem.GetInstance());
            }

            case CommonCssConstants.LAST_OF_TYPE: {
                return(CssPseudoClassLastOfTypeSelectorItem.GetInstance());
            }

            case CommonCssConstants.NTH_CHILD: {
                return(new CssPseudoClassNthChildSelectorItem(arguments));
            }

            case CommonCssConstants.NTH_OF_TYPE: {
                return(new CssPseudoClassNthOfTypeSelectorItem(arguments));
            }

            case CommonCssConstants.NOT: {
                CssSelector selector = new CssSelector(arguments);
                foreach (ICssSelectorItem item in selector.GetSelectorItems())
                {
                    if (item is CssPseudoClassNotSelectorItem || item is CssPseudoElementSelectorItem)
                    {
                        return(null);
                    }
                }
                return(new CssPseudoClassNotSelectorItem(selector));
            }

            case CommonCssConstants.ROOT: {
                return(CssPseudoClassRootSelectorItem.GetInstance());
            }

            case CommonCssConstants.LINK: {
                return(new CssPseudoClassSelectorItem.AlwaysApplySelectorItem(pseudoClass, arguments));
            }

            case CommonCssConstants.ACTIVE:
            case CommonCssConstants.FOCUS:
            case CommonCssConstants.HOVER:
            case CommonCssConstants.TARGET:
            case CommonCssConstants.VISITED: {
                return(new CssPseudoClassSelectorItem.AlwaysNotApplySelectorItem(pseudoClass, arguments));
            }

            default: {
                //Still unsupported, should be addressed in DEVSIX-1440
                //case CommonCssConstants.CHECKED:
                //case CommonCssConstants.DISABLED:
                //case CommonCssConstants.ENABLED:
                //case CommonCssConstants.IN_RANGE:
                //case CommonCssConstants.INVALID:
                //case CommonCssConstants.LANG:
                //case CommonCssConstants.NTH_LAST_CHILD:
                //case CommonCssConstants.NTH_LAST_OF_TYPE:
                //case CommonCssConstants.ONLY_OF_TYPE:
                //case CommonCssConstants.ONLY_CHILD:
                //case CommonCssConstants.OPTIONAL:
                //case CommonCssConstants.OUT_OF_RANGE:
                //case CommonCssConstants.READ_ONLY:
                //case CommonCssConstants.READ_WRITE:
                //case CommonCssConstants.REQUIRED:
                //case CommonCssConstants.VALID:
                return(null);
            }
            }
        }