Package org.htmlparser.tags

Examples of org.htmlparser.tags.ImageTag


        String html = "<img src=\"images/second\" alt=\"\">";

        createParser (html);
        parseAndAssertNodeCount (1);
        assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag);
        ImageTag img = (ImageTag)node[0];
        assertTrue ("bad source", "images/second".equals (img.getImageURL ()));
        assertTrue ("bad alt", "".equals (img.getAttribute ("alt")));
        assertStringEquals ("toHtml()", html, img.toHtml ());
    }
View Full Code Here


        String html = "<img alt=\"third\" src=\"images/third\">";

        createParser (html);
        parseAndAssertNodeCount (1);
        assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag);
        ImageTag img = (ImageTag)node[0];
        assertTrue ("bad source", "images/third".equals (img.getImageURL ()));
        assertTrue ("bad alt", "third".equals (img.getAttribute ("alt")));
        assertStringEquals ("toHtml()", html, img.toHtml ());
    }
View Full Code Here

        String html = "<img alt=\"\" src=\"images/third\">";

        createParser (html);
        parseAndAssertNodeCount (1);
        assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag);
        ImageTag img = (ImageTag)node[0];
        assertTrue ("bad source", "images/third".equals (img.getImageURL ()));
        assertTrue ("bad alt", "".equals (img.getAttribute ("alt")));
        assertStringEquals ("toHtml()", html, img.toHtml ());
    }
View Full Code Here

        for (int i = 0; i < htmls.length; i++)
        {
            createParser (htmls[i]);
            parseAndAssertNodeCount (1);
            assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag);
            ImageTag img = (ImageTag)node[0];
            Attribute src = img.getAttributeEx ("src");
            Attribute alt = img.getAttributeEx ("alt");
            Attribute readonly = img.getAttributeEx ("readonly");
            assertTrue ("src whitespace", !src.isWhitespace ());
            assertTrue ("src not valued", src.isValued ());
            assertTrue ("src empty", !src.isEmpty ());
            assertTrue ("src standalone", !src.isStandAlone ());
            assertTrue ("alt whitespace", !alt.isWhitespace ());
            assertTrue ("alt valued", !alt.isValued ());
            assertTrue ("alt empty", !alt.isEmpty ());
            assertTrue ("alt standalone", !alt.isStandAlone ());
            assertTrue ("readonly whitespace", !readonly.isWhitespace ());
            assertTrue ("readonly valued", !readonly.isValued ());
            assertTrue ("readonly empty", !readonly.isEmpty ());
            assertTrue ("readonly not standalone", readonly.isStandAlone ());
            // try assigning the name and checking again
            src.setName ("SRC");
            assertTrue ("setName() failed", "SRC=\"images/third\"".equals (src.toString ()));
            assertTrue ("src whitespace", !src.isWhitespace ());
            assertTrue ("src not valued", src.isValued ());
            assertTrue ("src empty", !src.isEmpty ());
            assertTrue ("src standalone", !src.isStandAlone ());
            alt.setName ("ALT");
            assertTrue ("setName() failed", "ALT=\"\"".equals (alt.toString ()));
            assertTrue ("alt whitespace", !alt.isWhitespace ());
            assertTrue ("alt valued", !alt.isValued ());
            assertTrue ("alt empty", !alt.isEmpty ());
            assertTrue ("alt standalone", !alt.isStandAlone ());
            readonly.setName ("READONLY");
            assertTrue ("setName() failed", "READONLY".equals (readonly.toString ()));
            assertTrue ("readonly whitespace", !readonly.isWhitespace ());
            assertTrue ("readonly valued", !readonly.isValued ());
            assertTrue ("readonly empty", !readonly.isEmpty ());
            assertTrue ("readonly not standalone", readonly.isStandAlone ());
            // try assigning the assignment and checking again
            src.setAssignment (" = ");
            assertTrue ("setAssignment() failed", "SRC = \"images/third\"".equals (src.toString ()));
            assertTrue ("src whitespace", !src.isWhitespace ());
            assertTrue ("src not valued", src.isValued ());
            assertTrue ("src empty", !src.isEmpty ());
            assertTrue ("src standalone", !src.isStandAlone ());
            alt.setAssignment (" = ");
            assertTrue ("setAssignment() failed", "ALT = \"\"".equals (alt.toString ()));
            assertTrue ("alt whitespace", !alt.isWhitespace ());
            assertTrue ("alt valued", !alt.isValued ());
            assertTrue ("alt empty", !alt.isEmpty ());
            assertTrue ("alt standalone", !alt.isStandAlone ());
            readonly.setAssignment ("=");
            assertTrue ("setAssignment() failed", "READONLY=".equals (readonly.toString ()));
            assertTrue ("readonly whitespace", !readonly.isWhitespace ());
            assertTrue ("readonly valued", !readonly.isValued ());
            assertTrue ("readonly not empty", readonly.isEmpty ());
            assertTrue ("readonly standalone", !readonly.isStandAlone ());
            // try assigning the value and checking again
            createParser (htmls[i]);
            parseAndAssertNodeCount (1);
            assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag);
            img = (ImageTag)node[0];
            src = img.getAttributeEx ("src");
            alt = img.getAttributeEx ("alt");
            readonly = img.getAttributeEx ("readonly");
            src.setValue ("cgi-bin/redirect");
            assertTrue ("setValue() failed", "src=\"cgi-bin/redirect\"".equals (src.toString ()));
            assertTrue ("src whitespace", !src.isWhitespace ());
            assertTrue ("src not valued", src.isValued ());
            assertTrue ("src empty", !src.isEmpty ());
View Full Code Here

        String html = "<img alt=\"\" src=\"images/third\" toast>";

        createParser (html);
        parseAndAssertNodeCount (1);
        assertTrue ("Node should be an ImageTag", node[0] instanceof ImageTag);
        ImageTag img = (ImageTag)node[0];
        Attribute src = img.getAttributeEx ("src");
        src.setQuote ('\0');
        assertTrue ("setQuote('\\0') failed", "src=images/third".equals (src.toString ()));
        src.setQuote ('\'');
        assertTrue ("setQuote('\\'') failed", "src='images/third'".equals (src.toString ()));
    }
View Full Code Here

        createParser("<A HREF=\"mytest.html\"><IMG SRC=\"abcd.jpg\">Hello World</A>","http://www.yahoo.com");
        parser.setNodeFactory (
            new PrototypicalNodeFactory (
                new Tag[] {
                    new LinkTag (),
                    new ImageTag (),
                }));
        parseAndAssertNodeCount(1);
        assertTrue("Node should be a link node",node[0] instanceof LinkTag);

        LinkTag linkTag = (LinkTag)node[0];
        // Get the link data and cross-check
        Node [] dataNode= new Node[10];
        int i = 0;
        for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();)
        {
            dataNode[i++] = e.nextNode();
        }
        assertEquals("Number of data nodes",new Integer(2),new Integer(i));
        assertTrue("First data node should be an Image Node",dataNode[0] instanceof ImageTag);
        assertTrue("Second data node shouls be a String Node",dataNode[1] instanceof Text);

        // Check the contents of each data node
        ImageTag imageTag = (ImageTag)dataNode[0];
        assertEquals("Image URL","http://www.yahoo.com/abcd.jpg",imageTag.getImageURL());
        Text stringNode = (Text)dataNode[1];
        assertEquals("String Contents","Hello World",stringNode.getText());
    }
View Full Code Here

        createParser("<a href=\"http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689\" target=\"_new\"><img src=\"http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif\" width=468 height=60 border=\"0\" alt=\"See Signs in Theaters 8-2 - Starring Mel Gibson\" align=><font face=\"verdana,arial,helvetica\" SIZE=\"1\"><b></b></font></a>","http://transfer.go.com");
        parser.setNodeFactory (
            new PrototypicalNodeFactory (
                new Tag[] {
                    new LinkTag (),
                    new ImageTag (),
                }));
        parseAndAssertNodeCount(1);
        assertTrue("Node 0 should be a link tag",node[0] instanceof LinkTag);
        LinkTag linkTag = (LinkTag)node[0];
        assertEquals("Link URL","http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689",linkTag.getLink());
        assertEquals("Link Text","",linkTag.getLinkText());
        Node [] containedNodes = new Node[10];
        int i=0;
        for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) {
            containedNodes[i++] = e.nextNode();
        }
        assertEquals("There should be 5 contained nodes in the link tag",5,i);
        assertTrue("First contained node should be an image tag",containedNodes[0] instanceof ImageTag);
        ImageTag imageTag = (ImageTag)containedNodes[0];
        assertEquals("Image Location","http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif",imageTag.getImageURL());
        assertEquals("Image Height","60",imageTag.getAttribute("HEIGHT"));
        assertEquals("Image Width","468",imageTag.getAttribute("WIDTH"));
        assertEquals("Image Border","0",imageTag.getAttribute("BORDER"));
        assertEquals("Image Alt","See Signs in Theaters 8-2 - Starring Mel Gibson",imageTag.getAttribute("ALT"));
        assertTrue("Second contained node should be Tag",containedNodes[1] instanceof Tag);
        Tag tag1 = (Tag)containedNodes[1];
        assertEquals("Tag Contents","font face=\"verdana,arial,helvetica\" SIZE=\"1\"",tag1.getText());
        assertTrue("Third contained node should be Tag",containedNodes[2] instanceof Tag);
        Tag tag2 = (Tag)containedNodes[2];
View Full Code Here

        for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) {
            insideNodes[j++]= e.nextNode();
        }
        assertEquals("Number of contained internal nodes",1,j);
        assertTrue(insideNodes[0] instanceof ImageTag);
        ImageTag imageTag = (ImageTag)insideNodes[0];
        assertEquals("Image Tag Location","http://www.fedpage.com/images\\register.gif",imageTag.getImageURL());
    }
View Full Code Here

    assertEquals("Number of data nodes", new Integer(2), new Integer(i));
    assertTrue("First data node should be an Image Node", dataNode[0] instanceof ImageTag);
    assertTrue("Second data node shouls be a String Node", dataNode[1] instanceof StringNode);

    // Check the contents of each data node
    ImageTag imageTag = (ImageTag) dataNode[0];
    assertEquals("Image URL", "http://www.yahoo.com/abcd.jpg", imageTag.getImageURL());
    StringNode stringNode = (StringNode) dataNode[1];
    assertEquals("String Contents", "Hello World", stringNode.getText());
  }
View Full Code Here

    for (SimpleNodeIterator e = linkTag.children(); e.hasMoreNodes();) {
      containedNodes[i++] = e.nextNode();
    }
    assertEquals("There should be 5 contained nodes in the link tag", 5, i);
    assertTrue("First contained node should be an image tag", containedNodes[0] instanceof ImageTag);
    ImageTag imageTag = (ImageTag) containedNodes[0];
    assertEquals("Image Location", "http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif",
        imageTag.getImageURL());
    assertEquals("Image Height", "60", imageTag.getAttribute("HEIGHT"));
    assertEquals("Image Width", "468", imageTag.getAttribute("WIDTH"));
    assertEquals("Image Border", "0", imageTag.getAttribute("BORDER"));
    assertEquals("Image Alt", "See Signs in Theaters 8-2 - Starring Mel Gibson", imageTag.getAttribute("ALT"));
    assertTrue("Second contained node should be Tag", containedNodes[1] instanceof Tag);
    Tag tag1 = (Tag) containedNodes[1];
    assertEquals("Tag Contents", "font face=\"verdana,arial,helvetica\" SIZE=\"1\"", tag1.getText());
    assertTrue("Third contained node should be Tag", containedNodes[2] instanceof Tag);
    Tag tag2 = (Tag) containedNodes[2];
View Full Code Here

TOP

Related Classes of org.htmlparser.tags.ImageTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.