Пример #1
0
        public virtual void SvgCssResolverInvalidNameStylesheetTest()
        {
            iText.StyledXmlParser.Jsoup.Nodes.Element jsoupLink = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
                                                                                                                .ValueOf(SvgConstants.Tags.LINK), "");
            iText.StyledXmlParser.Jsoup.Nodes.Attributes linkAttributes = jsoupLink.Attributes();
            linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml"
                                                                               ));
            linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.REL, SvgConstants.Attributes
                                                                               .STYLESHEET));
            linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.HREF, "!invalid name!externalSheet.css"
                                                                               ));
            linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("type", "text/css"));
            JsoupElementNode       node = new JsoupElementNode(jsoupLink);
            SvgConverterProperties scp  = new SvgConverterProperties();

            scp.SetBaseUri(baseUri);
            SvgProcessorContext          processorContext = new SvgProcessorContext(scp);
            SvgStyleResolver             sr           = new SvgStyleResolver(node, processorContext);
            IDictionary <String, String> attr         = sr.ResolveStyles(node, new SvgCssContext());
            IDictionary <String, String> expectedAttr = new Dictionary <String, String>();

            expectedAttr.Put(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml");
            expectedAttr.Put(SvgConstants.Attributes.REL, SvgConstants.Attributes.STYLESHEET);
            expectedAttr.Put(SvgConstants.Attributes.HREF, "!invalid name!externalSheet.css");
            expectedAttr.Put("type", "text/css");
            NUnit.Framework.Assert.AreEqual(expectedAttr, attr);
        }
Пример #2
0
        public virtual void Html()
        {
            Attributes a = new Attributes();

            a.Put("Tot", "a&p");
            a.Put("Hello", "There");
            a.Put("data-name", "Jsoup");
            NUnit.Framework.Assert.AreEqual(3, a.Size());
            NUnit.Framework.Assert.IsTrue(a.HasKey("tot"));
            NUnit.Framework.Assert.IsTrue(a.HasKey("Hello"));
            NUnit.Framework.Assert.IsTrue(a.HasKey("data-name"));
            NUnit.Framework.Assert.AreEqual(1, a.Dataset().Count);
            NUnit.Framework.Assert.AreEqual("Jsoup", a.Dataset().Get("name"));
            NUnit.Framework.Assert.AreEqual("a&p", a.Get("tot"));
            NUnit.Framework.Assert.AreEqual(" tot=\"a&amp;p\" hello=\"There\" data-name=\"Jsoup\"", a.Html());
            NUnit.Framework.Assert.AreEqual(a.Html(), a.ToString());
        }
Пример #3
0
        public virtual void SvgCssResolveMalformedXlinkTest()
        {
            iText.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
                                                                                                                 .ValueOf("image"), "");
            iText.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
            imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "htt://are/"));
            JsoupElementNode             node = new JsoupElementNode(jsoupImage);
            SvgStyleResolver             sr   = new SvgStyleResolver();
            IDictionary <String, String> attr = sr.ResolveStyles(node, new SvgCssContext());

            NUnit.Framework.Assert.AreEqual("htt://are/", attr.Get("xlink:href"));
        }
Пример #4
0
        public virtual void HandlesBaseUri()
        {
            iText.StyledXmlParser.Jsoup.Parser.Tag tag = iText.StyledXmlParser.Jsoup.Parser.Tag.ValueOf("a");
            Attributes attribs = new Attributes();

            attribs.Put("relHref", "/foo");
            attribs.Put("absHref", "http://bar/qux");
            iText.StyledXmlParser.Jsoup.Nodes.Element noBase = new iText.StyledXmlParser.Jsoup.Nodes.Element(tag, "",
                                                                                                             attribs);
            NUnit.Framework.Assert.AreEqual("", noBase.AbsUrl("relHref"));
            // with no base, should NOT fallback to href attrib, whatever it is
            NUnit.Framework.Assert.AreEqual("http://bar/qux", noBase.AbsUrl("absHref"));
            // no base but valid attrib, return attrib
            iText.StyledXmlParser.Jsoup.Nodes.Element withBase = new iText.StyledXmlParser.Jsoup.Nodes.Element(tag, "http://foo/"
                                                                                                               , attribs);
            NUnit.Framework.Assert.AreEqual("http://foo/foo", withBase.AbsUrl("relHref"));
            // construct abs from base + rel
            NUnit.Framework.Assert.AreEqual("http://bar/qux", withBase.AbsUrl("absHref"));
            // href is abs, so returns that
            NUnit.Framework.Assert.AreEqual("", withBase.AbsUrl("noval"));
            iText.StyledXmlParser.Jsoup.Nodes.Element dodgyBase = new iText.StyledXmlParser.Jsoup.Nodes.Element(tag, "wtf://no-such-protocol/"
                                                                                                                , attribs);
            NUnit.Framework.Assert.AreEqual("http://bar/qux", dodgyBase.AbsUrl("absHref"));
        }
Пример #5
0
        public virtual void SvgCssResolveHashXlinkTest()
        {
            iText.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
                                                                                                                 .ValueOf("image"), "");
            iText.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
            imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "#testid"));
            JsoupElementNode       node = new JsoupElementNode(jsoupImage);
            SvgConverterProperties scp  = new SvgConverterProperties();

            scp.SetBaseUri(baseUri);
            SvgProcessorContext          processorContext = new SvgProcessorContext(scp);
            SvgStyleResolver             sr   = new SvgStyleResolver(node, processorContext);
            IDictionary <String, String> attr = sr.ResolveStyles(node, new SvgCssContext());

            NUnit.Framework.Assert.AreEqual("#testid", attr.Get("xlink:href"));
        }
Пример #6
0
        public virtual void SvgCssResolverXlinkTest()
        {
            iText.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
                                                                                                                 .ValueOf("image"), "");
            iText.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
            imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "itis.jpg"));
            JsoupElementNode       node = new JsoupElementNode(jsoupImage);
            SvgConverterProperties scp  = new SvgConverterProperties();

            scp.SetBaseUri(baseUri);
            SvgProcessorContext          processorContext = new SvgProcessorContext(scp);
            SvgStyleResolver             sr   = new SvgStyleResolver(node, processorContext);
            IDictionary <String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
            String fileName    = baseUri + "itis.jpg";
            String expectedURL = UrlUtil.ToNormalizedURI(fileName).ToString();

            NUnit.Framework.Assert.AreEqual(expectedURL, attr.Get("xlink:href"));
        }