Package org.exoplatform.services.html

Examples of org.exoplatform.services.html.HTMLDocument


      System.out.println("FILE PATH: " + this.file_.getCanonicalPath());
   }

   public void testCharsetWithFile() throws Exception
   {
      HTMLDocument document = HTMLParser.createDocument(this.file_, null);
      assertNotNull(document);
      assertEquals("ASCII", HTMLParser.getCharset());
      assertNotSame("UTF-8", HTMLParser.getCharset());
      System.out.println("CHARSET: " + HTMLParser.getCharset());

      System.out.println("DOCUMENT-TEXTVALUE: " + document.getTextValue());
      System.out.println("DOCUMENT-ROOT: " + document.getRoot().getName().toString());
      System.out.println("CLASS: " + document.getClass().getName() + "\n");

      System.out.println("DOCUMENT-DOCTYPE-TEXTVALUE: " + document.getDoctype().getTextValue());
      System.out.println("DOCUMENT-DOCTYPE-VALUE: " + new String(document.getDoctype().getValue()));
      System.out.println("DOCUMENT-DOCTYPE-NAME: " + document.getDoctype().getName().toString());
   }
View Full Code Here


      System.out.println("DOCUMENT-DOCTYPE-NAME: " + document.getDoctype().getName().toString());
   }

   public void testCharsetWithURL() throws Exception
   {
      HTMLDocument document;
      try
      {
         URL url_ = new URL("http://www.24h.com.vn");
         document = HTMLParser.createDocument(url_.openConnection().getInputStream(), null);
         document = HTMLParser.createDocument(url_.openStream(), null);
      }
      catch (java.net.UnknownHostException e)
      {
         return;
      }
      catch (java.net.ConnectException e)
      {
         return;
      }

      assertNotNull(document);
      assertNotNull(document.getRoot());
   }
View Full Code Here

   public void testCharsetWithTEXT() throws Exception
   {
      String text =
         "<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()));
View Full Code Here

            + "<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()));
   }
View Full Code Here

      {
         HTMLNode element = lookFor(root, path);
         if (element != null)
            html.addChild(element);
      }
      HTMLDocument document = new HTMLDocument();
      document.setRoot(html);
      return document;
   }
View Full Code Here

      return newNode;
   }

   public static synchronized HTMLDocument createDocument(char[] data) throws Exception
   {
      HTMLDocument document = new HTMLDocument();
      CharsToken tokens = new CharsToken();
      tokens.setDocument(document);
      ParserService.getTokenParser().createBeans(tokens, data);
      ParserService.parse(tokens, document);
      return document;
View Full Code Here

TOP

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

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.