Package org.htmlparser

Examples of org.htmlparser.StringNode


        try {
          do {
            node = reader.readElement();
            if (node != null) {
              if (node instanceof StringNode) {
                StringNode stringNode = (StringNode) node;
                if (xmlData.length() > 0)
                  xmlData += " ";
                xmlData += stringNode.getText();
              } else if (!(node instanceof org.htmlparser.tags.EndTag))
                xmlTagFound = false;
            }
          } while (node instanceof StringNode);
View Full Code Here


    }
  }

  private void assertStringNodeEquals(String displayMessage, Node expectedNode, Node actualNode) {
    if (expectedNode instanceof StringNode) {
      StringNode expectedString = (StringNode) expectedNode;
      StringNode actualString = (StringNode) actualNode;
      assertStringEquals(displayMessage, expectedString.getText(), actualString.getText());
    }
  }
View Full Code Here

    createParser("&nbsp;<![endif]>");
    parseAndAssertNodeCount(2);
    // The first node should be a HTMLRemarkNode
    assertTrue("First node should be a string node", node[0] instanceof StringNode);
    assertTrue("Second node should be a Tag", node[1] instanceof Tag);
    StringNode stringNode = (StringNode) node[0];
    Tag tag = (Tag) node[1];
    assertEquals("Text contents", "&nbsp;", stringNode.getText());
    assertEquals("Tag Contents", "![endif]", tag.getText());

  }
View Full Code Here

    StringBuffer buffer;
    PrintWriter out;
    boolean pass;
    NodeIterator enumeration;
    Node node;
    StringNode string;

    try {
      url = new URL("http://www.canadapost.ca/tools/pcl/bin/cp_search_response-e.asp");
      connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Referer", "http://www.canadapost.ca/tools/pcl/bin/default-e.asp");
      connection.setDoOutput(true);
      connection.setDoInput(true);
      connection.setUseCaches(false);
      buffer = new StringBuffer(1024);
      buffer.append("app_language=");
      buffer.append("english");
      buffer.append("&");
      buffer.append("app_response_start_row_number=");
      buffer.append("1");
      buffer.append("&");
      buffer.append("app_response_rows_max=");
      buffer.append("9");
      buffer.append("&");
      buffer.append("app_source=");
      buffer.append("quick");
      buffer.append("&");
      buffer.append("query_source=");
      buffer.append("q");
      buffer.append("&");
      buffer.append("name=");
      buffer.append("&");
      buffer.append("postal_code=");
      buffer.append("&");
      buffer.append("directory_area_name=");
      buffer.append("&");
      buffer.append("delivery_mode=");
      buffer.append("&");
      buffer.append("Suffix=");
      buffer.append("&");
      buffer.append("street_direction=");
      buffer.append("&");
      buffer.append("installation_type=");
      buffer.append("&");
      buffer.append("delivery_number=");
      buffer.append("&");
      buffer.append("installation_name=");
      buffer.append("&");
      buffer.append("unit_numbere=");
      buffer.append("&");
      buffer.append("app_state=");
      buffer.append("production");
      buffer.append("&");
      buffer.append("street_number=");
      buffer.append(number);
      buffer.append("&");
      buffer.append("street_name=");
      buffer.append(street);
      buffer.append("&");
      buffer.append("street_type=");
      buffer.append(type);
      buffer.append("&");
      buffer.append("test=");
      buffer.append("&");
      buffer.append("city=");
      buffer.append(city);
      buffer.append("&");
      buffer.append("prov=");
      buffer.append(province);
      buffer.append("&");
      buffer.append("Search=");
      out = new PrintWriter(connection.getOutputStream());
      out.print(buffer);
      out.close();
      parser = new Parser(connection);
    } catch (Exception e) {
      throw new ParserException("You must be offline! This test needs you to be connected to the internet.", e);
    }

    pass = false;
    for (enumeration = parser.elements(); enumeration.hasMoreNodes();) {
      node = enumeration.nextNode();
      if (node instanceof StringNode) {
        string = (StringNode) node;
        if (-1 != string.getText().indexOf(postal_code))
          pass = true;
      }
    }
    assertTrue("POST operation failed.", pass);
  }
View Full Code Here

  public void testStringNodeBug1() throws ParserException {
    createParser("<HTML><HEAD><TITLE>Google</TITLE>");
    parseAndAssertNodeCount(5);
    // The fourth node should be a HTMLStringNode- with the text - Google
    assertTrue("Fourth node should be a HTMLStringNode", node[3] instanceof StringNode);
    StringNode stringNode = (StringNode) node[3];
    assertEquals("Text of the StringNode", "Google", stringNode.getText());
  }
View Full Code Here

    parser.addScanner(new LinkScanner("-l"));
    parseAndAssertNodeCount(3);
    // The first node should be a HTMLStringNode- with the text - view these
    // documents, you must have
    assertTrue("First node should be a HTMLStringNode", node[0] instanceof StringNode);
    StringNode stringNode = (StringNode) node[0];
    assertEquals("Text of the StringNode", "view these documents, you must have ", stringNode.getText());
    assertTrue("Second node should be a link node", node[1] instanceof LinkTag);
    LinkTag linkNode = (LinkTag) node[1];
    assertEquals("Link is", "http://www.adobe.com", linkNode.getLink());
    assertEquals("Link text is", "Adobe \r\nAcrobat Reader", linkNode.getLinkText());

    assertTrue("Third node should be a string node", node[2] instanceof StringNode);
    StringNode stringNode2 = (StringNode) node[2];
    assertEquals("Contents of third node", " installed on your computer.", stringNode2.getText());
  }
View Full Code Here

  public void testToPlainTextString() throws ParserException {
    createParser("<HTML><HEAD><TITLE>This is the Title</TITLE></HEAD><BODY>Hello World, this is the HTML Parser</BODY></HTML>");
    parseAndAssertNodeCount(10);
    assertTrue("Fourth Node identified must be a string node", node[3] instanceof StringNode);
    StringNode stringNode = (StringNode) node[3];
    assertEquals("First String Node", "This is the Title", stringNode.toPlainTextString());
    assertTrue("Eighth Node identified must be a string node", node[7] instanceof StringNode);
    stringNode = (StringNode) node[7];
    assertEquals("Second string node", "Hello World, this is the HTML Parser", stringNode.toPlainTextString());
  }
View Full Code Here

  public void testToHTML() throws ParserException {
    createParser("<HTML><HEAD><TITLE>This is the Title</TITLE></HEAD><BODY>Hello World, this is the HTML Parser</BODY></HTML>");
    parseAndAssertNodeCount(10);
    assertTrue("Fourth Node identified must be a string node", node[3] instanceof StringNode);
    StringNode stringNode = (StringNode) node[3];
    assertEquals("First String Node", "This is the Title", stringNode.toHtml());
    assertTrue("Eighth Node identified must be a string node", node[7] instanceof StringNode);
    stringNode = (StringNode) node[7];
    assertEquals("Second string node", "Hello World, this is the HTML Parser", stringNode.toHtml());
  }
View Full Code Here

    createParser("Before Comment <!-- Comment --> After Comment");
    parseAndAssertNodeCount(3);
    assertTrue("First node should be HTMLStringNode", node[0] instanceof StringNode);
    assertTrue("Second node should be HTMLRemarkNode", node[1] instanceof RemarkNode);
    assertTrue("Third node should be HTMLStringNode", node[2] instanceof StringNode);
    StringNode stringNode = (StringNode) node[0];
    assertEquals("First String node contents", "Before Comment ", stringNode.getText());
    StringNode stringNode2 = (StringNode) node[2];
    assertEquals("Second String node contents", " After Comment", stringNode2.getText());
    RemarkNode remarkNode = (RemarkNode) node[1];
    assertEquals("Remark Node contents", " Comment ", remarkNode.getText());

  }
View Full Code Here

   */
  public void testLastLineWithOneChar() throws ParserException {
    createParser("a");
    parseAndAssertNodeCount(1);
    assertTrue("First node should be HTMLStringNode", node[0] instanceof StringNode);
    StringNode stringNode = (StringNode) node[0];
    assertEquals("First String node contents", "a", stringNode.getText());
  }
View Full Code Here

TOP

Related Classes of org.htmlparser.StringNode

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.