Package org.jsoup.nodes

Examples of org.jsoup.nodes.Document


        // dumpResponse( response );

        List<String> expectedLinks = Arrays.asList( ".indexer/", "commons-lang/", "net/", "org/" );

        Document document = Jsoup.parse( response.getContentAsString() );
        Elements elements = document.getElementsByTag( "a" );

        assertLinks( expectedLinks, elements );
    }
View Full Code Here


        WebResponse response = getServletUnitClient().getResponse( request );
        assertEquals( "Response", HttpServletResponse.SC_OK, response.getStatusCode() );

        List<String> expectedLinks = Arrays.asList( "../", "apache/", "codehaus/" );

        Document document = Jsoup.parse( response.getContentAsString() );
        Elements elements = document.getElementsByTag( "a" );

        assertLinks( expectedLinks, elements );
    }
View Full Code Here

        }

        String startPath = StringUtils.substringBefore( path, "/" );

        // replace all links !!
        Document document = Jsoup.parse( is, "UTF-8", "" );

        Element body = document.body().child( 0 );

        Elements links = body.select( "a[href]" );

        for ( Element link : links ) {
            link.attr( "href", "#" + startPath + "/" + link.attr( "href" ) );
        }

        Elements codes = body.select( "code" );

        for ( Element code : codes ) {
            code.attr( "class", code.attr( "class" ) + " nice-code" );
        }

        //default generated enunciate use h1/h2/h3 which is quite big so transform to h3/h4/h5

        Elements headers = body.select( "h1" );

        for ( Element header : headers ) {
            header.tagName( "h3" );
        }

        headers = body.select( "h2" );

        for ( Element header : headers ) {
            header.tagName( "h4" );
        }

        headers = body.select( "h3" );

        for ( Element header : headers ) {
            header.tagName( "h5" );
        }

        Document res = new Document( "" );
        res.appendChild( body.select( "div[id=main]" ).first() );

        resp.getOutputStream().write( res.outerHtml().getBytes() );

    }
View Full Code Here

                while((text = input.readLine()) != null
                    buffer.append(text +"\n");
                code = buffer.toString();
               
//              将html中table提取出来,html头部等信息都不要
                Document doc = Jsoup.parse(code);
            StringBuffer sb = new StringBuffer();
            Elements elements = doc.select("table");
            for(int i=0;i<elements.size();i++){
              Element element = elements.get(i);
              sb.append(element.toString());
            }
           
View Full Code Here

 
  public OperResult renderXLSV2(String id,String html,String time,String title,String mode,Map parameterMap){
//    System.out.println(html);
    OperResult result = new OperResult();
    if(html!=null){
      Document doc = Jsoup.parseBodyFragment(html);
      Elements tables = doc.select("table");
      Workbook book = HTMLAdjustMent4J.convertHTML2Excel(tables);
      if(book!=null){
        result.setSucceed();
        result.setData(book);
//        result.setInfoMSG("报表");
View Full Code Here

  }
 
  public OperResult renderXLS(String id,String html,Map parameterMap) {
    OperResult result = new OperResult();
    if(html!=null){
      Document doc = Jsoup.parseBodyFragment(html);
      Elements tables = doc.select("table");
      List<Workbook> books = new ArrayList<Workbook>();
      for(int i=0;i<tables.size();i++){
        Element table = tables.get(i);
        Workbook book = HTMLAdjustMent4J.convertHTML2Excel(table.toString());
        if(book!=null){
View Full Code Here

        System.out.println(t.toStringTree());

    }
   
    private static void testHTMLExcelBridge(String content) throws Exception, ExcelException{
      Document doc = Jsoup.parseBodyFragment(content);
      Elements sheets = doc.select("table");
      HTMLExcelBridge heb = new HTMLExcelBridge(sheets);
      heb.reEvaluateAll();
      System.out.println(sheets.toString());
    }
View Full Code Here

    return null;
  }
 
  public HTMLTableManipulator(String code){
    if(code!=null){
      Document document = Jsoup.parseBodyFragment(code);
      tables = document.select("table");
     
    }
  }
View Full Code Here

    OperResult result = new OperResult();
    InputStream in = null;
    try {
      in = new FileInputStream(file1);
      Workbook book = WorkbookFactory.create(in);
      Document doc = Jsoup.parse("");
      Element body = doc.body();
      for(int i=0;i<book.getNumberOfSheets();i++){
        Sheet sheet = book.getSheetAt(i);
        if(!ExcelUtility.isEmptySheet(sheet)){
          Element table = body.appendElement("table");
          table.attr("title",sheet.getSheetName());
          ExcelUtility.convertSheet2HTMLTable(sheet, table);
        }
      }
      result.setSucceed();
      result.setData(doc.select("table").toString());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      result.setFailed(e.getMessage());
    } finally{
View Full Code Here

    
  }
 
  public static Workbook convertHTML2Excel(String tables){
    if(tables!=null){
      Document doc = Jsoup.parse(tables);
      doc.head().append("<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=utf-8\">");
      try {
//        byte[] html = doc.toString().getBytes("utf-8");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
//        DocumentConverter.convert(doc.toString().getBytes("utf-8"), "html", bos, "xls");
        Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bos.toByteArray()));
        Elements tableElements = doc.select("table");
        for(int i=0;i<tableElements.size();i++){
          Element table = tableElements.get(i);
          if(table.hasAttr("title")){
            if(wb.getNumberOfSheets()>i){
              wb.setSheetName(i, table.attr("title"));
View Full Code Here

TOP

Related Classes of org.jsoup.nodes.Document

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.