Examples of HTMLNode


Examples of org.exoplatform.services.html.HTMLNode

      assertEquals(document.getRoot().getName(), Name.HTML);

      assertNull(document.getDoctype());

      //ROOT.
      HTMLNode root = document.getRoot();
      assertNotNull(root);
      assertEquals(root.getParent(), null);
      List<HTMLNode> children = root.getChildren();
      //ArrayList<HTMLNode> children = (ArrayList<HTMLNode>)root.getChildren();
      assertNotNull(children);
      assertEquals(children.size(), 2);
      assertEquals(children.get(0).getChildren().size(), 1);
      assertEquals(children.get(0).getChildren().get(0).getChildren().size(), 1);

      for (int i = 0; i < children.size(); i++)
      {
         if (i == 0)
         {
            assertEquals(children.get(i).getName(), Name.HEAD);
            assertEquals(children.get(i).getName().toString(), "HEAD");
         }
         if (i == 1)
         {
            assertEquals(children.get(i).getName(), Name.BODY);
            assertEquals(children.get(i).getName().toString(), "BODY");
         }
      }

      List<HTMLNode> children_ = root.getChildrenNode();
      assertEquals(children_.size(), 2);
      assertEquals(children.size(), children_.size());

      //BODY.
      NodePath path_ = NodePathParser.toPath(children.get(1));
      assertNotNull(path_);
      System.out.println("NODEPATH-CLASS: " + path_.getClass().getName());
      System.out.println("PATH OF BODY: " + path_.toString());
      HTMLNode bodyNode = NodePathUtil.lookFor(document.getRoot(), path_);
      assertEquals(bodyNode, children.get(1));

      String bodyPath = "html.body";
      HTMLNode bodyNode1 = NodePathUtil.lookFor(document.getRoot(), NodePathParser.toPath(bodyPath));
      assertNotNull(bodyNode1);
      assertEquals(bodyNode1, bodyNode);

      //Test Node.getChildren() and Node.getChildrenNode() methods.
      List<HTMLNode> bodyChildren = bodyNode.getChildren();
      List<HTMLNode> bodyChildren1 = bodyNode.getChildrenNode();
      assertEquals(bodyChildren.size(), bodyChildren1.size());
      assertEquals(bodyChildren.size(), 2);
      assertEquals(bodyChildren1.size(), 2);

      //TABLE
      String pathStr = "html.body.table[0]";
      NodePath path = NodePathParser.toPath(pathStr);
      assertNotNull(path);
      HTMLNode tableNode = NodePathUtil.lookFor(document.getRoot(), path);
      assertNotNull(tableNode);
      assertEquals(tableNode.getName(), Name.TABLE);
      assertEquals(tableNode.getName().toString(), "TABLE");
      assertEquals(tableNode.getChildren().size(), 1);
      assertEquals(true, tableNode.isNode(Name.TABLE));
      //assertNotSame(tableNode.isNode(Name.TABLE),tableNode.isNode(tableNode.getName().toString()));
      assertEquals(tableNode.isNode(Name.TABLE), tableNode.isNode(tableNode.getName().name()));
      assertEquals(tableNode.isNode(Name.TABLE), tableNode.isNode(tableNode.getName().toString()));

      assertEquals(new String(tableNode.getValue()), "table bgcolor='red' border='1' cellspacing='2' cellpadding='3'");
      System.out.println("\n\nTABLE-VALUE: " + new String(tableNode.getValue()));
      /*
      assertEquals(tableNode.getTextValue(),("<table bgcolor='red' border='1' cellspacing='2' cellpadding='3'>" +
                          "<tbody>" +
                          "<tr>" +
                            "<td><h1>Cell 1</h1></td><td><h2>Cell 2<h2></td>" +
                          "</tr>" +
                          "</tbody>" +
                        "</table>"));
       *///==>ERROR.
      //System.out.println("TABLE-TEXTVALUE: " + tableNode.getTextValue());

      List<HTMLNode> tableChildren = tableNode.getChildrenNode();
      assertEquals(tableChildren.size(), 1);
      assertEquals(tableChildren.get(0).getName(), Name.TBODY);
      assertEquals(tableChildren.get(0).getChildren().get(0).getName(), Name.TR);
      assertEquals(tableChildren.get(0).getChildren().get(0).getChildren().get(0).getName(), Name.TD);
      assertEquals(tableChildren.get(0).getChildren().get(0).getChildren().size(), 2);

      assertNotNull(HTML.getConfig(Name.TABLE));

      HTMLNode _node = NodePathUtil.lookFor(document.getRoot(), NodePathParser.toPath("html.body"));
      assertNotNull(_node);

      //There are two Ways for creating a Table.
      //1st Way.
      /* NodeImpl nodeImpl =new NodeImpl("table bgcolor='blue' border='0'".toCharArray(),HTML.getConfig("TABLE"),TypeToken.TAG);   
View Full Code Here

Examples of org.exoplatform.services.html.HTMLNode

         "<html>" + "<head>" + "</head>" + "<body>" + "<h1>This is a HTML file for testing!</h1>" + "</body>"
            + "</html>";
      HTMLDocument document = HTMLParser.createDocument(text);
      assertNotNull(document);
      NodePath path = NodePathParser.toPath("html.body.h1");
      HTMLNode node = NodePathUtil.lookFor(document.getRoot(), path);
      assertNotNull(node);
      assertEquals(node.getName(), Name.H1);
      assertEquals(node.getName().toString(), "H1");
      System.out.println("NAME: " + node.getName());
      System.out.println("VALUE: " + new String(node.getValue()));
      System.out.println("TEXTVALUE: " + node.getTextValue());
      // assertNull(node.getChildren());
      assertNotNull(node.getChildren());
      assertEquals(node.getChildren().size(), 1);
      assertEquals(!node.getChildren().isEmpty(), true);
      assertEquals(node.getChildren().get(0).getName(), Name.CONTENT);
      assertEquals(node.getChildren().get(0).getName().toString(), "CONTENT");

      HTMLNode child = node.getChildren().get(0);
      assertNotNull(child);
      assertNull(child.getChildren());
      assertEquals(child.getTextValue(), "This is a HTML file for testing!");
      // assertEquals(child.getValue(),"content");
      System.out.println("CONTENT-VALUE: " + new String(child.getValue()));
      assertEquals(child.getTextValue(), new String(child.getValue()));
   }
View Full Code Here

Examples of org.exoplatform.services.html.HTMLNode

      for (int i = 0; i < linkList.size(); i++)
      {
         System.out.println(linkList.get(i).toString());
      }

      HTMLNode tableNode = NodePathUtil.lookFor(document.getRoot(), NodePathParser.toPath("html.body.table"));
      linkList.clear();
      linkList = hyperlinkUtil.getSiteLink(tableNode);
      assertEquals(2, linkList.size());
      assertEquals("/homepage.html", linkList.get(0).toString());

      //ImageLink--------------------------------------------------------------------------------
      String imageLink = hyperlinkUtil.getSingleImageLink(document.getRoot());
      assertEquals("/images/home.gif", imageLink);
      System.out.println("\nIMAGE-LINK: " + imageLink);

      //CreateFullNormalLink.---------------------------------------------------------------------   
      HTMLNode bodyNode = document.getRoot().getChildrenNode().get(1);
      assertEquals(bodyNode.getName(), Name.BODY);
      /*
      URL url_ = new URL("http://www.exoplatform.com");   
      assertNotNull(url_);   
      hyperlinkUtil.createFullNormalLink(bodyNode, url_);
      */
      linkList.clear();
      linkList = hyperlinkUtil.getSiteLink(document.getRoot());
      System.out.println("\nSHOW ALL HYPERLINKs: ");
      for (int i = 0; i < linkList.size(); i++)
      {
         System.out.println(linkList.get(i).toString());
      }
      HTMLNode row2Node = tableNode.getChildren().get(0).getChildrenNode().get(1);
      assertNotNull(row2Node);
      assertEquals(row2Node.getName(), Name.TR);
      assertEquals("tr", new String(row2Node.getValue()));
      //System.out.println("ROW2: " + row2Node.getTextValue());
      HTMLNode row2Cell2 = row2Node.getChildrenNode().get(1);

      assertNotNull(new URL("http://www.mysite.net"));
      URLCreator urlCreator = new URLCreator();
      hyperlinkUtil.createFullNormalLink(row2Cell2, new URL("http://www.mysite.net"), urlCreator);
      linkList.clear();
View Full Code Here

Examples of org.vietspider.html.HTMLNode

    }
  }

  public void searchNodes(NodeIterator iterator, List<HTMLNode> nodes, Name name) {
    while(iterator.hasNext()) {
      HTMLNode n = iterator.next();
      if(n.isNode(name)) nodes.add(n);
    }
  } 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.