Package org.htmlparser.tags

Examples of org.htmlparser.tags.Tag


    String s = "input type=\"text\" value=\"<%=\"test\"%>\" name=\"text\"";
    String line = "<" + s + ">";
    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


  /**
   * Test parseParameter method 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);
      }

    } catch (ClassCastException ce) {
View Full Code Here

  /**
   * Test parseParameter method 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;
        assertEquals("paragraph contents", snode.getText(), "Paragraph");
View Full Code Here

  /**
   * Test parseParameter method 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;
        assertEquals("Verify the paragraph text", snode.getText(), "Paragraph");
View Full Code Here

   * Test parseParameter method Created by Kaarle Kaila (august 2002) 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

    parser.registerScanners();
    parseAndAssertNodeCount(1);
    // Check the tags
    assertType("node", Div.class, node[0]);
    Div div = (Div) node[0];
    Tag fontTag = (Tag) div.children().nextNode();
    assertEquals("Second tag should be corrected",
        "font face=\"Arial,helvetica,\" sans-serif=\"sans-serif\" size=\"2\" color=\"#FFFFFF\"", fontTag
            .getText());
    // Try to parse the parameters from this tag.
    Hashtable table = fontTag.getAttributes();
    assertNotNull("Parameters table", table);
    assertEquals("font sans-serif parameter", "sans-serif", table.get("SANS-SERIF"));
    assertEquals("font face parameter", "Arial,helvetica,", table.get("FACE"));
  }
View Full Code Here

        + "<A HREF=\"Hello.html\">Hey</A>");
    createParser(testHTML);
    parseAndAssertNodeCount(7);
    // The node should be an Tag
    assertTrue("1st Node should be a Tag", node[0] instanceof Tag);
    Tag tag = (Tag) node[0];
    assertStringEquals("toHTML()", "<MYTAG EFGH=\"\" ABCD=\"\" MNOP=\"\" IJKL=\"\">", tag.toHtml());
    assertTrue("2nd Node should be a Tag", node[1] instanceof Tag);
    assertTrue("5th Node should be a Tag", node[4] instanceof Tag);
    tag = (Tag) node[1];
    assertEquals("Raw String of the tag", "<TITLE>", tag.toHtml());
    tag = (Tag) node[4];
    assertEquals("Raw String of the tag", "<A HREF=\"Hello.html\">", tag.toHtml());
  }
View Full Code Here

  /**
   * Test parseParameter method Created by Kaarle Kaila (22 Oct 2001) This
   * test just wants the text in the element
   */
  public void testWithoutParseParameter() throws ParserException {
    Tag tag;
    EndTag etag;
    StringNode snode;
    Node node = null;
    String testHTML = "<A href=\"http://www.iki.fi/kaila\" myParameter yourParameter=\"Kaarle\">Kaarle's homepage</A><p>Paragraph</p>";
    createParser(testHTML);
View Full Code Here

  /**
   * Test parseParameter method Created by Kaarle Kaila (09 Jan 2003) This
   * test just wants the text in the element
   */
  public void testEmptyTagParseParameter() throws ParserException {
    Tag tag;
    EndTag etag;
    StringNode snode;
    Node node = null;
    String testHTML = "<INPUT name=\"foo\" value=\"foobar\" type=\"text\" />";

View Full Code Here

  public void testStyleSheetTag() throws ParserException {
    String testHTML1 = new String("<link rel src=\"af.css\"/>");
    createParser(testHTML1, "http://www.google.com/test/index.html");
    parseAndAssertNodeCount(1);
    assertTrue("Node should be a tag", node[0] instanceof Tag);
    Tag tag = (Tag) node[0];
    assertEquals("StyleSheet Source", "af.css", tag.getAttribute("src"));
  }
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.