+ "<td>Cell 1</td><td>Cell 2</td>" + "<td>cell 3</td><td>Cell 4 </td>" + "</tr>" + "<tr>" + "<td>"
+ "<a href=\"/homepage.html\">HomePage</a>" + "</td>" + "<td>" + "<a href=\"/sitemap.html\">SiteMap</a>"
+ "</td>" + "</tr>" + "</tbody>" + "</table>" + "<!--This is a comment! -->"
+ "<img src=\"/images/home.gif\" alt=\"short desc\" usemap=\"#homePage.htm\" />" + "</body>" + "</html>";
HTMLDocument document = HTMLParser.createDocument(text);
assertNotNull(document);
assertEquals(5, document.getRoot().getChildrenNode().get(1).getChildrenNode().size());
//Note-Begin.
assertEquals(document.getRoot().getChildrenNode().get(1).getChildren().size(), document.getRoot()
.getChildrenNode().get(1).getChildrenNode().size());
//Note-End.
System.out.println("\n CHECK DOCUMENT:");
for (HTMLNode child : document.getRoot().getChildrenNode().get(1).getChildrenNode())
{
System.out.println(child.getName().toString() + " : " + new String(child.getValue()));
}
HyperLinkUtil hyperlinkUtil = new HyperLinkUtil();
List<String> linkList = new ArrayList<String>();
//SiteLink---------------------------------------------------------------------------------
linkList = hyperlinkUtil.getSiteLink(document.getRoot());
assertEquals(3, linkList.size());
assertEquals("http://www.exoplatform.com", linkList.get(0).toString());
System.out.println("\nSHOW ALL HYPERLINKs: ");
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();
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());
}
//CreateFullImageLink.-----------------------------------------------------------------------
hyperlinkUtil.createFullImageLink(document.getRoot(), new URL("http://www.myImageLink.net"));
System.out.println("\nNEW IMAGE_LINK1:" + hyperlinkUtil.getSingleImageLink(document.getRoot()));
hyperlinkUtil.createFullImageLink(document.getRoot(), new URL("http://www.exo.com"), new URLCreator());
System.out.println("\nNEW IMAGE_LINK2:" + hyperlinkUtil.getSingleImageLink(document.getRoot()));
}