Package org.w3c.tidy

Examples of org.w3c.tidy.Tidy


   */
  private void parseToDOM() {
    ByteArrayInputStream is = new ByteArrayInputStream(content);
   
    // set tidy parameters
    Tidy tidy = new Tidy();
    tidy.setUpperCaseTags(false);
    tidy.setUpperCaseAttrs(false);
    tidy.setErrout(new PrintWriter(System.err));
   
    domDoc = tidy.parseDOM(is,null);
  }
View Full Code Here


      return input;
    }

    // okay, parse the HTML code
    ByteArrayInputStream bis = new ByteArrayInputStream(input.getContent());
    Tidy tidy = new Tidy();
    tidy.setUpperCaseTags(false);
    tidy.setUpperCaseAttrs(false);
    tidy.setErrout(new PrintWriter(new NullWriter()));

    Document doc = tidy.parseDOM(bis,null);

    rewriteDOM(doc,input.getURL());

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    tidy.pprint(doc,bos);

    input.setContent(bos.toByteArray());
   
    return input;
  }
View Full Code Here

  public ByteArrayOutputStream transformHTML(String sHTML)
    throws IOException,FOPException,TransformerException,TransformerConfigurationException {
    ByteArrayOutputStream oXml = new ByteArrayOutputStream();
    StringBufferInputStream oHtm = new StringBufferInputStream(sHTML);
    Tidy oTdy = new Tidy();
    oTdy.setXmlOut(true);
    oTdy.setTidyMark(false);
    oTdy.setNumEntities(true);
  oTdy.parseDOM(oHtm, oXml);
  return transformXHTML(oXml.toString(Charset.defaultCharset().name()));
  }
View Full Code Here

      throw new NullPointerException("Input HTML code string is NULL");
    }
    StringReader stringReader = new StringReader(htmlCode);
    StringWriter tidyHtmlWriter = new StringWriter();
    try{
      Tidy tidy = new Tidy();
      tidy.setPrintBodyOnly(bodyOnly);
      tidy.setJoinClasses(true);
      tidy.setJoinStyles(true);
      tidy.setQuoteAmpersand(true);
      tidy.setHideComments(true);
      tidy.setInputEncoding(encoding);
      tidy.setOutputEncoding(encoding);   
      tidy.parse(stringReader,tidyHtmlWriter);
      return tidyHtmlWriter.getBuffer().toString();
    }catch(Exception e){
      logger.error("FormatUtil: tidyHTML error: " + e);
    }finally{   
      if(stringReader != null){
View Full Code Here

        }
        return false;
    }
   
    public InputStream tidy(InputStream is) {
        Tidy tidy = new Tidy();
        tidy.setXHTML(false);
        tidy.setPrintBodyOnly(true);
        tidy.setDocType("loose");
        tidy.setXHTML(true);
        tidy.setForceOutput(true);
        java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(1024);
        tidy.parse(is,out);
        return new ByteArrayInputStream(out.toByteArray());
    }
View Full Code Here

    }
    public void testPageRender() throws IOException {
        HtmlCanvas html = new HtmlCanvas();
        html.render(new PersonalPage());
       
        Tidy tidy = new Tidy();
        tidy.setMessageListener(new TidyMessageCheck());
        tidy.setXHTML(true);
        tidy.setDocType("loose");
        tidy.parse(new ByteArrayInputStream(html.toHtml().getBytes()), System.out);       
    }
View Full Code Here

    public void testPageRenderWithError() throws IOException {
        HtmlCanvas html = new HtmlCanvas();
        html.tag("bogus");
        html.render(new PersonalPage());
       
        Tidy tidy = new Tidy();
        tidy.setMessageListener(new TidyMessageCheck());
        tidy.setXHTML(true);
        tidy.setDocType("loose");
        try {
            tidy.parse(new ByteArrayInputStream(html.toHtml().getBytes()), System.out);       
        } catch (AssertionFailedError err) {
            System.out.println(err);
            // good thing
        }
    }
View Full Code Here

      buf.append("<body>");
      buf.append(htmlContent);
      buf.append("</body>");
      buf.append("</html>");
     
      Tidy tidy = new Tidy();
    tidy.setXHTML(true);
    tidy.setQuiet(true);
    tidy.setShowWarnings(false);
     
      return tidy.parseDOM(new ByteArrayInputStream(buf.toString().getBytes()), null);
  }
View Full Code Here

        // there is also a javax.swing.text.Document class.
        org.w3c.dom.Document document = null;

        StringWriter sw = new StringWriter();
        Tidy tidy = XPathUtil.makeTidyParser(true, true, true, sw);
        document = tidy.parseDOM(baIS, null);
        document.normalize();
        if (tidy.getParseErrors() > 0) {
            showErrorMessageDialog(sw.toString(),
                    "Tidy: " + tidy.getParseErrors() + " errors, " + tidy.getParseWarnings() + " warnings",
                    JOptionPane.WARNING_MESSAGE);
        }

        JPanel domTreePanel = new DOMTreePanel(document);
        resultsScrollPane.setViewportView(domTreePanel);
View Full Code Here

     *
     * @return a <code>tidy</code> HTML parser
     */
    private static Tidy getTidyParser() {
        log.debug("Start : getParser");
        Tidy tidy = new Tidy();
        tidy.setInputEncoding("UTF8");
        tidy.setOutputEncoding("UTF8");
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);
        if (log.isDebugEnabled()) {
            log.debug("getParser : tidy parser created - " + tidy);
        }
        log.debug("End   : getParser");
        return tidy;
View Full Code Here

TOP

Related Classes of org.w3c.tidy.Tidy

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.