Package org.w3c.tidy

Examples of org.w3c.tidy.Tidy


     *
     * @param file the <code>File</code> containing the HTML to parse
     * @exception IOException if an I/O exception occurs
     */
    public HtmlDocument(File file) throws IOException {
        Tidy tidy = new Tidy();
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);

        org.w3c.dom.Document root = tidy.parseDOM(new FileInputStream(file), null);
        rawDoc = root.getDocumentElement();
    }
View Full Code Here


     *
     * @param is the <code>InputStream</code> containing the HTML
     * @exception IOException if I/O exception occurs
     */
    public HtmlDocument(InputStream is) throws IOException {
        Tidy tidy = new Tidy();
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);

        org.w3c.dom.Document root = tidy.parseDOM(is, null);
        rawDoc = root.getDocumentElement();
    }
View Full Code Here

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

     * @return   a <code>tidy</code> HTML parser
     */
    public static Tidy getParser()
    {
        log.debug("Start : getParser1");
        Tidy tidy = new Tidy();
        tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);

        if (log.isDebugEnabled())
        {
            log.debug("getParser1 : tidy parser created - " + tidy);
        }
View Full Code Here

    }

    result.setFailure(false);

    // create parser
    Tidy tidy = null;
    try {
      log.debug("HTMLAssertions.getResult(): Setup tidy ...");
      log.debug("doctype: " + getDoctype());
      log.debug("errors only: " + isErrorsOnly());
      log.debug("error threshold: " + getErrorThreshold());
      log.debug("warning threshold: " + getWarningThreshold());
      log.debug("html mode: " + isHTML());
      log.debug("xhtml mode: " + isXHTML());
      log.debug("xml mode: " + isXML());
      tidy = new Tidy();
      tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
      tidy.setQuiet(false);
      tidy.setShowWarnings(true);
      tidy.setOnlyErrors(isErrorsOnly());
      tidy.setDocType(getDoctype());
      if (isXHTML()) {
        tidy.setXHTML(true);
      } else if (isXML()) {
        tidy.setXmlTags(true);
      }
      log.debug("err file: " + getFilename());
      tidy.setErrfile(getFilename());

      if (log.isDebugEnabled()) {
        log.debug("getParser : tidy parser created - " + tidy);
      }
      log.debug("HTMLAssertions.getResult(): Tidy instance created!");

    } catch (Exception e) {
      log.error("Unable to instantiate tidy parser", e);
      result.setFailure(true);
      result.setFailureMessage("Unable to instantiate tidy parser");
      // return with an error
      return result;
    }

    /* Run tidy.
     */
    try {
      log.debug("HTMLAssertions.getResult(): start parsing with tidy ...");

      StringWriter errbuf = new StringWriter();
      tidy.setErrout(new PrintWriter(errbuf));
      //Node node = tidy.parseDOM(new ByteArrayInputStream(response.getResponseData()), null);
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      log.debug("Start : parse");
      Node node = tidy.parse(new ByteArrayInputStream(inResponse.getResponseData()), os);
      if (log.isDebugEnabled()) {
        log.debug("node : " + node);
      }
      log.debug("End   : parse");
      log.debug("HTMLAssertions.getResult(): parsing with tidy done!");
      log.debug("Output: " + os.toString());

      //write output to file
      writeOutput(errbuf.toString());

      //evaluate result
      if ((tidy.getParseErrors() > getErrorThreshold()) || (!isErrorsOnly() && (tidy.getParseWarnings() > getWarningThreshold()))) {
        log.debug("HTMLAssertions.getResult(): errors/warnings detected:");
        log.debug(errbuf.toString());
        result.setFailure(true);
        result.setFailureMessage(MessageFormat.format("Tidy Parser errors:   " + tidy.getParseErrors() + " (allowed " + getErrorThreshold() + ") " + "Tidy Parser warnings: " + tidy.getParseWarnings() + " (allowed " + getWarningThreshold() + ")", new Object[0]));
        //return with an error

      } else if ((tidy.getParseErrors() > 0) || (tidy.getParseWarnings() > 0)) {
        //return with no error
        log.debug("HTMLAssertions.getResult(): there were errors/warnings but threshold to high");
        result.setFailure(false);
      } else {
        //return with no error
View Full Code Here

    // noop
  }

  public static void prettyPrint(InputStream in, OutputStream writer)
      throws IOException {
    Tidy tidy = getDefaultTidy();

    tidy.parse( in, writer );

  }
View Full Code Here

    tidy.parse( in, writer );

  }

  static Tidy getDefaultTidy() throws IOException {
    Tidy tidy = new Tidy();

    // no output please!
    tidy.setErrout( new PrintWriter( new Writer() {
      public void close() throws IOException {
      }

      public void flush() throws IOException {
      }

      public void write(char[] cbuf, int off, int len) throws IOException {
       
      }
    } ) );

    Properties properties = new Properties();

    properties.load( XMLPrettyPrinter.class
        .getResourceAsStream( "jtidy.properties" ) );

    tidy.setConfigurationFromProps( properties );

    return tidy;
  }
View Full Code Here

      public boolean accept(File dir, String name) {
        return name.endsWith( prefix );
      }
    } );

    Tidy tidy = getDefaultTidy();
    prettyPrintFiles( tidy, files, files, silent );
  }
View Full Code Here

   protected Properties props;

   public TidyTransformerImpl()
   {
      super();
      tidy = new Tidy();
      initProps();
   }
View Full Code Here

   * Tidy a HTML Stream.
   * @param is
   */
  public static Reader tidy(InputStream is) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Tidy tidy = new Tidy();
    tidy.parse(is, out);
    return new InputStreamReader(new ByteArrayInputStream(out.toByteArray()));
  }
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.