Examples of HTMLDocument


Examples of org.exoplatform.services.html.HTMLDocument

      String text =
         "<html>" + "<head>" + "<title>Let me introduce to myself!</title>" + "</head>" + "<body>"
            + "<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>"
            + "<!--This is a comment! -->" + "</body>" + "</html>";
      HTMLDocument document = HTMLParser.createDocument(text);
      assertNotNull(document);
      System.out.println("DOCUMENT-TEXTVALUE: \n" + document.getTextValue());

      //assertEquals(HTMLParser.getCharset(),"ASCII");
      assertNull(HTMLParser.getCharset());
      System.out.println("CHARSET: " + HTMLParser.getCharset());

      //assertNull(document.getRoot());
      assertNotNull(document.getRoot());
      System.out.println("ROOT-NAME: " + document.getRoot().getName().toString());
      System.out.println("ROOT-VALUE: " + new String(document.getRoot().getValue()));
      System.out.println("ROOT_TEXTVALUE: \n" + document.getRoot().getTextValue());
      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.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

Examples of org.exoplatform.services.html.HTMLDocument

      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

Examples of org.exoplatform.services.html.HTMLDocument

   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

Examples of org.exoplatform.services.html.HTMLDocument

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

Examples of org.jacoco.report.html.HTMLDocument

  @Before
  public void setup() throws Exception {
    output = new MemoryMultiReportOutput();
    root = new ReportOutputFolder(output);
    resources = new Resources(root);
    doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
    doc.head().title();
    td = doc.body().table("somestyle").tr().td();
    support = new HTMLSupport();
    column = new BarColumn(CounterEntity.LINE, Locale.ENGLISH);
  }
View Full Code Here

Examples of org.jacoco.report.internal.html.HTMLDocument

  @Before
  public void setup() throws IOException {
    output = new MemoryMultiReportOutput();
    root = new ReportOutputFolder(output);
    resources = new Resources(root);
    doc = new HTMLDocument(root.createFile("Test.html"), "UTF-8");
    doc.head().title();
    body = doc.body();
    table = new Table();
  }
View Full Code Here

Examples of org.vietspider.html.HTMLDocument

    saveData(name);
  }

  public void saveData(String name) throws Exception {
    if(data == null || data.length < 1) return;
    HTMLDocument doc = new HTMLParser2().createDocument(data, "utf-8");
    if(this.addPaths == null) return;
    doc = htmlExtractor.extract(doc, this.addPaths);
    if(removePaths != null && removePaths.length > 0){
      htmlExtractor.remove(doc.getRoot(), removePaths);
    }
    data = doc.getTextValue().getBytes("utf-8");
    if(data.length < 1) return;
    File file = new File(name);
    FileOutputStream output = new FileOutputStream(file);
    output.write(data);
    output.flush();
View Full Code Here

Examples of org.w3c.dom.html.HTMLDocument

     * @return New HTML document
     */
    public final HTMLDocument createHTMLDocument( String title )
        throws DOMException
    {
  HTMLDocument doc;

  if ( title == null )
      throw new NullPointerException( "HTM014 Argument 'title' is null." );
  doc = new HTMLDocumentImpl();
  doc.setTitle( title );
  return doc;
    }
View Full Code Here

Examples of org.w3c.dom.html2.HTMLDocument

  public void processForms(IInjectionModuleContext ctx, HttpUriRequest request, IHttpResponse response) {
    final IHTMLParseResult html = response.getParsedHTML();
    if(html == null)
      return;

    final HTMLDocument document = html.getDOMDocument();
    final HTMLCollection forms = document.getForms();

    for(int i = 0; i < forms.getLength(); i++) {
      Node n = forms.item(i);
      if(n instanceof Element) {
        processFormElement(ctx, request, (Element) 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.