Package org.exoplatform.services.html

Examples of org.exoplatform.services.html.HTMLNode


         System.out.print(text + " " + node);
   }

   public void testParser() throws Exception
   {
      HTMLNode node =
         HTMLParser.createDocument(new File("C:\\Documents and Settings\\exo\\Desktop\\130033.htm"), "utf-8").getRoot();
      //System.out.println(node.getTextValue());
      //print("", node);
      assertEquals(node.getTextValue(), node.getTextValue());
   }
View Full Code Here


      //Gets the NodePath object locating the path of a TAG in the HTML file.
      NodePath path = NodePathParser.toPath("html.body.h2");

      //Looks for the Node coresponding to the NodePath object of the HTML document.
      //and checks the existing of this TAG.
      HTMLNode node = NodePathUtil.lookFor(document.getRoot(), path);
      assertEquals(node.getName(), Name.H2);
      assertEquals(node.getName().toString(), "H2");

      //Similar as above.
      path = NodePathParser.toPath("html.body.font[1]");
      node = NodePathUtil.lookFor(document.getRoot(), path);
      assertNotNull(node);

      //Gets all the attributes of the Node object in the HTML document.
      //simultaneously checks the existing of an Attribute of this Node.
      Attributes attributes = AttributeParser.getAttributes(node);
      assertEquals(attributes.get("size").getValue(), "4");

      //Removes an Attribute of a Node.
      //and then checks the existing of this Attribute in the attribute collection of the Node.
      attributes.remove("size");
      System.out.println(node.getTextValue());
      //assertNotNull(attributes.get("size"));  
   }
View Full Code Here

   public void testRoot() throws Exception
   {
      HTMLDocument document = HTMLParser.createDocument(this.file_, null);
      assertNotNull(document);
      //HTMLNode root = NodePathUtil.lookFor(document.getRoot(),NodePathParser.toPath("html"));
      HTMLNode root = document.getRoot();
      assertNotNull(root);
      System.out.println("ROOT-NAME: " + root.getName());
      System.out.println("ROOT-VALUE: " + root.getValue().toString());
      System.out.println("ROOT-TEXTVALUE: " + root.getTextValue());
   }
View Full Code Here

   public void testHead() throws Exception
   {
      HTMLDocument document = HTMLParser.createDocument(this.file_, null);
      String pathStr = "html.head";
      NodePath path = NodePathParser.toPath(pathStr);
      HTMLNode node = NodePathUtil.lookFor(document.getRoot(), path);
      assertNotNull(node);
      assertEquals(node.getName(), Name.HEAD);
      assertEquals(node.getName().toString(), "HEAD");
      List<HTMLNode> children = node.getChildrenNode();
      assertNotNull(children);
      int i = 0;
      for (HTMLNode child : children)
      {
         assertNotNull(child);
View Full Code Here

   public void testBody() throws Exception
   {
      HTMLDocument document = HTMLParser.createDocument(this.file_, null);
      String pathStr = "html.body";
      NodePath path = NodePathParser.toPath(pathStr);
      HTMLNode node = NodePathUtil.lookFor(document.getRoot(), path);
      assertNotNull(node);
      assertEquals(node.getName(), Name.BODY);
      assertEquals(node.getName().toString(), "BODY");
   }
View Full Code Here

      NodePath tablePath = NodePathParser.toPath("html.body.table[1]");
      assertNotNull(tablePath);
      System.out.println(tablePath.toString());

      //HTMLNode.
      HTMLNode node = NodePathUtil.lookFor(htmlDocument.getRoot(), tablePath);
      assertNotNull(node);
      assertEquals(node.getName(), Name.TABLE);
      assertEquals(node.getName().toString(), "TABLE");
      System.out.println("NODE-NAME: " + node.getName());
      System.out.println("NODE-VALUE: " + new String(node.getValue()));
      System.out.println("NODE-TEXT VALUE: " + node.getTextValue());

      //Attributes.
      Attributes attrs = AttributeParser.getAttributes(node);
      for (Attribute attr : attrs)
      {
View Full Code Here

      NodePath path = NodePathParser.toPath(pathStr);
      assertNotNull(path);
      assertEquals(path.toString(), "HTML[0].HEAD[0].TITLE[0]");
      System.out.println("PATH: " + path.toString());

      HTMLNode node = NodePathUtil.lookFor(document.getRoot(), path);
      assertNotNull(node);
      assertEquals(node.getName(), Name.TITLE);

      //Add a Tag to HTMLDocument.
      NodeImpl impl = new NodeImpl("h2 id = \"dds\"".toCharArray(), Name.H2);
      node.addChild(impl);
      assertNotNull(node.getChildrenNode().get(1));
      assertEquals(node.getChildren().get(1).getName(), Name.H2);
      System.out.println("THE NEW NODE-NAME: " + node.getChildrenNode().get(1).getName().toString());
      System.out.println("THE NEW NODE-VALUE: " + new String(node.getChildren().get(1).getValue()));

      //Add a Table to HTMLDocument.
      HTMLDocument doc = HTMLParser.createDocument("<table border='1'><tr></tr></table>");
      HTMLNode table = NodePathUtil.lookFor(doc.getRoot(), NodePathParser.toPath("html.body.table"));
      node.addChild(table);

      //Remove a Node which is text in format from HTMLDocument.
      System.out.println("\n\nRemove:");
      HTMLNode contentNode = NodePathUtil.lookFor(document.getRoot(), NodePathParser.toPath("html.head.title.content"));
      assertNotNull(contentNode);
      assertEquals(Name.CONTENT, contentNode.getName());
      assertEquals("CONTENT", contentNode.getName().toString());
      assertEquals(new String(contentNode.getValue()), contentNode.getTextValue());

      System.out.println("NODE-VALUE: " + new String(contentNode.getValue()));
      System.out.println("NODE-TEXTVALUE: " + contentNode.getTextValue());

      assertEquals(true, node.getChildren().remove(contentNode));

      //Pass the Node which has removed from HTMLDocument into the <h2> TAG.
      HTMLNode h2Node = NodePathUtil.lookFor(document.getRoot(), NodePathParser.toPath("html.head.title.h2"));
      assertNotNull(h2Node);
      assertEquals(Name.H2, h2Node.getName());
      assertEquals("H2", h2Node.getName().toString());
      h2Node.addChild(contentNode);

      //Show all.
      System.out.println("\n\nShow all the content of HTML file:");
      System.out.println(node.getTextValue());
   }
View Full Code Here

      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

         "<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

      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

TOP

Related Classes of org.exoplatform.services.html.HTMLNode

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.