Package org.htmlparser

Examples of org.htmlparser.Text


     */
    public void testPureText () throws ParserException
    {
        String reference;
        Lexer lexer;
        Text node;

        reference = "Hello world";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
    }
View Full Code Here


     */
    public void testUnixEOL () throws ParserException
    {
        String reference;
        Lexer lexer;
        Text node;

        reference = "Hello\nworld";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
    }
View Full Code Here

     */
    public void testDosEOL () throws ParserException
    {
        String reference;
        Lexer lexer;
        Text node;

        reference = "Hello\r\nworld";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
        reference = "Hello\rworld";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
    }
View Full Code Here

     */
    public void testEOF_EOL () throws ParserException
    {
        String reference;
        Lexer lexer;
        Text node;

        reference = "Hello world\n";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
        reference = "Hello world\r";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
        reference = "Hello world\r\n";
        lexer = new Lexer (reference);
        node = (Text)lexer.nextNode ();
        assertEquals ("Text contents wrong", reference, node.getText ());
    }
View Full Code Here

        String html =
            "<style type=\"text/css\" media=\"screen\">" +
            style +
            "</style>";
        StyleTag tag;
        Text string;

        createParser (html);
        parseAndAssertNodeCount (1);
        assertTrue ("Node should be a STYLE tag", node[0] instanceof StyleTag);
        tag = (StyleTag)node[0];
        assertTrue ("STYLE tag should have one child", 1 == tag.getChildCount ());
        assertTrue ("Child should be a StringNode", tag.getChild (0) instanceof Text);
        string = (Text)tag.getChild (0);
        assertStringEquals ("Style text incorrect", style, string.toHtml ());
    }
View Full Code Here

            "<%=head%>",
            "<?php ?>",
            "<!--head-->",
        };
        Lexer lexer;
        Text node;

        for (int i = 0; i < references.length; i++)
        {
            for (int j = 0; j < suffixes.length; j++)
            {
                lexer = new Lexer (references[i] + suffixes[j]);
                node = (Text)lexer.nextNode ();
                assertEquals ("Text contents wrong", references[i], node.getText ());
            }
        }
    }
View Full Code Here

        Node[] nodes = nodeList.toNodeArray();

        assertEquals("Number of nodes found",1,nodes.length);
        assertType("search result node",Text.class,nodes[0]);
        Text stringNode = (Text)nodes[0];
        assertEquals("Expected contents of string node","User Name",stringNode.getText());
    }
View Full Code Here

     * the tag name is here A (and should be eaten up by linkScanner)
     */
    public void testParseParameterA() throws ParserException {
        Tag tag;
        Tag etag;
        Text snode;
        Node node=null;
        String lin1 = "<A href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaarle Kaaila\">Kaarle's homepage</A><p>Paragraph</p>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        String a,href,myValue,nice;

        try {

            if (en.hasMoreNodes()) {
                node = en.nextNode();

                tag = (Tag)node;
                a = ((Attribute)(tag.getAttributesEx ().elementAt (0))).getName ();
                href = tag.getAttribute ("HREF");
                myValue = tag.getAttribute ("MYPARAMETER");
                nice = tag.getAttribute ("YOURPARAMETER");
                assertEquals ("Link tag (A)","A",a);
                assertEquals ("href value","http://www.iki.fi/kaila",href);
                assertEquals ("myparameter value",null,myValue);
                assertEquals ("yourparameter value","Kaarle Kaaila",nice);
            }
            if (!(node instanceof LinkTag)) {
                // linkscanner has eaten up this piece
                if ( en.hasMoreNodes()) {
                    node = en.nextNode();
                    snode = (Text)node;
                    assertEquals("Value of element","Kaarle's homepage",snode.getText());
                }

                if (en.hasMoreNodes()) {
                    node = en.nextNode();
                    etag = (Tag)node;
                    assertEquals("endtag of link","/A", etag.getText());
                }
            }
            // testing rest
            if (en.hasMoreNodes()) {
                node = en.nextNode();

                tag = (Tag)node;
                assertEquals("following paragraph begins",tag.getText(),"p");
            }
            if (en.hasMoreNodes()) {
                node = en.nextNode();
                snode = (Text)node;
                assertEquals("paragraph contents","Paragraph",snode.getText());
            }
            if (en.hasMoreNodes()) {
                node = en.nextNode();
                etag = (Tag)node;
                assertEquals("paragrapg endtag","/p",etag.getText());
View Full Code Here

     * the tag name is here G
     */
    public void testParseParameterG() throws ParserException{
        Tag tag;
        Tag etag;
        Text snode;
        Node node=null;
        String lin1 = "<G href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaila\">Kaarle's homepage</G><p>Paragraph</p>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        String a,href,myValue,nice;

        try {

            if (en.hasMoreNodes()) {
                node = en.nextNode();

                tag = (Tag)node;
                a = ((Attribute)(tag.getAttributesEx ().elementAt (0))).getName ();
                href = tag.getAttribute ("HREF");
                myValue = tag.getAttribute ("MYPARAMETER");
                nice = tag.getAttribute ("YOURPARAMETER");
                assertEquals ("The tagname should be G",a,"G");
                assertEquals ("Check the http address",href,"http://www.iki.fi/kaila");
                assertEquals ("myValue is not null",myValue,null);
                assertEquals ("The second parameter value",nice,"Kaila");
            }
            if (en.hasMoreNodes()) {
                node = en.nextNode();
                snode = (Text)node;
                assertEquals("The text of the element",snode.getText(),"Kaarle's homepage");
            }

            if (en.hasMoreNodes()) {
                node = en.nextNode();
                etag = (Tag)node;
                assertEquals("Endtag is G","/G", etag.getText());
            }
            // testing rest
            if (en.hasMoreNodes()) {
                node = en.nextNode();

                tag = (Tag)node;
                assertEquals("Follow up by p-tag","p", tag.getText());
            }
            if (en.hasMoreNodes()) {
                node = en.nextNode();
                snode = (Text)node;
                assertEquals("Verify the paragraph text","Paragraph", snode.getText());
            }
            if (en.hasMoreNodes()) {
                node = en.nextNode();
                etag = (Tag)node;
                assertEquals("Still patragraph endtag","/p", etag.getText());
View Full Code Here

    * Tests elements where = sign is surrounded by spaces
    */
    public void testParseParameterSpace() throws ParserException{
        Tag tag;
        Tag etag;
        Text snode;
        Node node=null;
        String lin1 = "<A yourParameter = \"Kaarle\">Kaarle's homepage</A>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        String a,nice;

        try {

            if (en.hasMoreNodes()) {
                node = en.nextNode();

                tag = (Tag)node;
                a = ((Attribute)(tag.getAttributesEx ().elementAt (0))).getName ();
                nice = tag.getAttribute ("YOURPARAMETER");
                assertEquals ("Link tag (A)",a,"A");
                assertEquals ("yourParameter value","Kaarle",nice);
            }
            if (!(node instanceof LinkTag)) {
                // linkscanner has eaten up this piece
                if ( en.hasMoreNodes()) {
                    node = en.nextNode();
                    snode = (Text)node;
                    assertEquals("Value of element","Kaarle's homepage",snode.getText());
                }

                if (en.hasMoreNodes()) {
                    node = en.nextNode();
                    etag = (Tag)node;
View Full Code Here

TOP

Related Classes of org.htmlparser.Text

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.