Package org.htmlparser.tags

Examples of org.htmlparser.tags.Tag


    {
        createParser("<BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000\nvLink=#551a8b>");
        parseAndAssertNodeCount(1);
        // The node should be an Tag
        assertTrue("Node should be a Tag", node[0] instanceof Tag);
        Tag tag = (Tag) node[0];
        assertEquals(
            "Contents of the tag",
            "BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000\r\nvLink=#551a8b",
            tag.getText());
    }
View Full Code Here


    {
        createParser("<MYTAG abcd\n" + "efgh\n" + "ijkl\n" + "mnop>");
        parseAndAssertNodeCount(1);
        // The node should be an Tag
        assertTrue("Node should be a Tag", node[0] instanceof Tag);
        Tag tag = (Tag) node[0];
        assertEquals(
            "Contents of the tag",
            "MYTAG abcd\r\nefgh\r\nijkl\r\nmnop",
            tag.getText());

    }
View Full Code Here

        createParser(line);
        parseAndAssertNodeCount(1);
        assertTrue(
            "The node found should have been an Tag",
            node[0] instanceof Tag);
        Tag tag = (Tag) node[0];
        assertEquals("Tag Contents", s, tag.getText());
    }
View Full Code Here

     * Created by Kaarle Kaila (august 2001)
     * the tag name is here G
     */
    public void testParseParameter3() throws ParserException
    {
        Tag tag;
        EndTag etag;
        StringNode snode;
        Node node = null;
        String lin1 =
            "<DIV class=\"userData\" id=\"oLayout\" name=\"oLayout\"></DIV>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

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

                tag = (Tag) node;
                h = tag.getAttributes();
                String classValue = (String) h.get("CLASS");
                assertEquals(
                    "The class value should be ",
                    "userData",
                    classValue);
View Full Code Here

     * Created by Kaarle Kaila (august 2001)
     * the tag name is here A (and should be eaten up by linkScanner)
     */
    public void testParseParameterA() throws ParserException
    {
        Tag tag;
        EndTag etag;
        StringNode 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();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

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

                tag = (Tag) node;
                h = tag.getAttributes();
                a = (String) h.get(Tag.TAGNAME);
                href = (String) h.get("HREF");
                myValue = (String) h.get("MYPARAMETER");
                nice = (String) h.get("YOURPARAMETER");
                assertEquals("Link tag (A)", "A", a);
                assertEquals("href value", "http://www.iki.fi/kaila", href);
                assertEquals("myparameter value", "", myValue);
                assertEquals("yourparameter value", "Kaarle Kaaila", nice);
            }
            if (!(node instanceof LinkTag))
            {
                // linkscanner has eaten up this piece
                if (en.hasMoreNodes())
                {
                    node = en.nextNode();
                    snode = (StringNode) node;
                    assertEquals(
                        "Value of element",
                        snode.getText(),
                        "Kaarle's homepage");
                }

                if (en.hasMoreNodes())
                {
                    node = en.nextNode();
                    etag = (EndTag) node;
                    assertEquals("endtag of link", etag.getText(), "A");
                }
            }
            // 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 = (StringNode) node;
View Full Code Here

     * Created by Kaarle Kaila (august 2001)
     * the tag name is here G
     */
    public void testParseParameterG() throws ParserException
    {
        Tag tag;
        EndTag etag;
        StringNode 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();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

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

                tag = (Tag) node;
                h = tag.getAttributes();
                a = (String) h.get(Tag.TAGNAME);
                href = (String) h.get("HREF");
                myValue = (String) h.get("MYPARAMETER");
                nice = (String) h.get("YOURPARAMETER");
                assertEquals("The tagname should be G", a, "G");
                assertEquals(
                    "Check the http address",
                    href,
                    "http://www.iki.fi/kaila");
                assertEquals("myValue is empty", myValue, "");
                assertEquals("The second parameter value", nice, "Kaila");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                snode = (StringNode) node;
                assertEquals(
                    "The text of the element",
                    snode.getText(),
                    "Kaarle's homepage");
            }

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

                tag = (Tag) node;
                assertEquals("Follow up by p-tag", tag.getText(), "p");
            }
            if (en.hasMoreNodes())
            {
                node = en.nextNode();
                snode = (StringNode) node;
View Full Code Here

     * the tag name is here A (and should be eaten up by linkScanner)
     * Tests elements where = sign is surrounded by spaces
     */
    public void testParseParameterSpace() throws ParserException
    {
        Tag tag;
        EndTag etag;
        StringNode snode;
        Node node = null;
        String lin1 = "<A yourParameter = \"Kaarle\">Kaarle's homepage</A>";
        createParser(lin1);
        NodeIterator en = parser.elements();
        Hashtable h;
        boolean testEnd = true; // test end of first part
        String a, href, myPara, myValue, nice;

        try
        {

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

                tag = (Tag) node;
                h = tag.getAttributes();
                a = (String) h.get(Tag.TAGNAME);
                nice = (String) h.get("YOURPARAMETER");
                assertEquals("Link tag (A)", a, "A");
                assertEquals("yourParameter value", "Kaarle", nice);
            }
View Full Code Here

        int state = TAG_BEFORE_PARSING_STATE;
        int i = position;
        char ch;
        char[] ignorechar = new char[1];
        // holds the character we're looking for when in TAG_IGNORE_DATA_STATE
        Tag tag =
            new Tag(
                new TagData(
                    position,
                    0,
                    reader.getLastLineNumber(),
                    0,
                    "",
                    input,
                    "",
                    false));

        Bool encounteredQuery = new Bool(false);
        while (i < tag.getTagLine().length()
            && state != TAG_FINISHED_PARSING_STATE
            && state != TAG_ILLEGAL_STATE)
        {
            ch = tag.getTagLine().charAt(i);
            state =
                automataInput(
                    encounteredQuery,
                    i,
                    state,
                    ch,
                    tag,
                    i,
                    ignorechar);
            i = incrementCounter(i, reader, state, tag);
        }
        if (state == TAG_FINISHED_PARSING_STATE)
        {
            String tagLine = tag.getTagLine();
            if (i > 1 && tagLine.charAt(i - 2) == '/')
            {
                tag.setEmptyXmlTag(true);
                String tagContents = tag.getText();
                tag.setText(tagContents.substring(0, tagContents.length() - 1));
            }
            return tag;
        }
        else
            return null;
View Full Code Here

    private void doEmptyXmlTagCheckOn(Node currentNode)
    {
        if (currentNode instanceof Tag)
        {
            Tag possibleEndTag = (Tag) currentNode;
            if (isXmlEndTag(tag))
            {
                endTag = possibleEndTag;
                endTagFound = true;
            }
View Full Code Here

    assertEquals("custom tag starting loc",0,customTag.elementBegin());
    assertEquals("custom tag ending loc",23,customTag.elementEnd());

    Node child = customTag.childAt(0);
    assertType("child",Tag.class,child);
    Tag tag = (Tag)child;
    assertStringEquals("child html","<HELLO>",child.toHtml());
  }
View Full Code Here

TOP

Related Classes of org.htmlparser.tags.Tag

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.