Package org.w3c.tidy

Examples of org.w3c.tidy.Tidy


        // HTML: can't do logical comparison

        if (comparator.equals("html-output")) {
            // TODO: Tidy gets upset by byte-order-marks. Use the strings constructed above as input.
            try {
                Tidy tidy = new Tidy();
                tidy.setXmlOut(true);
                tidy.setQuiet(true);
                tidy.setShowWarnings(false);
                tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
                InputStream in1 = new FileInputStream(outfile);
                File xml1 = new File(outfile + ".xml");
                xml1.createNewFile();
                OutputStream out1 = new FileOutputStream(xml1);
                tidy.parse(in1, out1);
                InputStream in2 = new FileInputStream(reffile);
                File xml2 = new File(reffile + ".xml");
                xml2.createNewFile();
                OutputStream out2 = new FileOutputStream(xml2);
                tidy.parse(in2, out2);
                return compare(xml1.toString(), xml2.toString(), "xml", silent);
            } catch (IOException e) {
                e.printStackTrace();
                return "false";
            }
View Full Code Here


        // HTML: can't do logical comparison

        if (comparator.equals("html-output")) {
            // TODO: Tidy gets upset by byte-order-marks. Use the strings constructed above as input.
            try {
                Tidy tidy = new Tidy();
                tidy.setXmlOut(true);
                tidy.setQuiet(true);
                tidy.setShowWarnings(false);
                tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
                InputStream in1 = new FileInputStream(outfile);
                File xml1 = new File(outfile + ".xml");
                xml1.createNewFile();
                OutputStream out1 = new FileOutputStream(xml1);
                tidy.parse(in1, out1);
                InputStream in2 = new FileInputStream(reffile);
                File xml2 = new File(reffile + ".xml");
                xml2.createNewFile();
                OutputStream out2 = new FileOutputStream(xml2);
                tidy.parse(in2, out2);
                return compare(xml1.toString(), xml2.toString(), "xml");
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
View Full Code Here

     */
    public void generate()
    throws IOException, SAXException, ProcessingException {
        try {
            // Setup an instance of Tidy.
            Tidy tidy = new Tidy();
            tidy.setXmlOut(true);

            if (this.properties == null) {
                tidy.setXHTML(true);
            } else {
                tidy.setConfigurationFromProps(this.properties);
            }

            //Set Jtidy warnings on-off
            tidy.setShowWarnings(getLogger().isWarnEnabled());
            //Set Jtidy final result summary on-off
            tidy.setQuiet(!getLogger().isInfoEnabled());
            //Set Jtidy infos to a String (will be logged) instead of System.out
            StringWriter stringWriter = new StringWriter();
            PrintWriter errorWriter = new PrintWriter(stringWriter);
            tidy.setErrout(errorWriter);

            // Extract the document using JTidy and stream it.

            if (inputSource != null)
                requestStream = this.inputSource.getInputStream();

            org.w3c.dom.Document doc = tidy.parseDOM(new BufferedInputStream(requestStream), null);

            // FIXME: Jtidy doesn't warn or strip duplicate attributes in same
            // tag; stripping.
            XMLUtils.stripDuplicateAttributes(doc, null);

View Full Code Here

     * @param text the string to be tidied
     */
    private void normalize(String text) throws ProcessingException {
        try {
            // Setup an instance of Tidy.
            Tidy tidy = new Tidy();
            tidy.setXmlOut(true);

            if (this.properties == null) {
                tidy.setXHTML(true);
            } else {
                tidy.setConfigurationFromProps(this.properties);
            }

            //Set Jtidy warnings on-off
            tidy.setShowWarnings(getLogger().isWarnEnabled());
            //Set Jtidy final result summary on-off
            tidy.setQuiet(!getLogger().isInfoEnabled());
            //Set Jtidy infos to a String (will be logged) instead of System.out
            StringWriter stringWriter = new StringWriter();
            PrintWriter errorWriter = new PrintWriter(stringWriter);
            tidy.setErrout(errorWriter);

            // Extract the document using JTidy and stream it.
            ByteArrayInputStream bais =
                new ByteArrayInputStream(text.getBytes());
            org.w3c.dom.Document doc =
                tidy.parseDOM(new BufferedInputStream(bais), null);

            // FIXME: Jtidy doesn't warn or strip duplicate attributes in same
            // tag; stripping.
            XMLUtils.stripDuplicateAttributes(doc, null);

View Full Code Here

        }
        catch (Exception e) {
            log.warn("Download failed. " + e.getMessage());
        }

        Tidy tidy = new Tidy();
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);

        if ( resultsFile == null || !resultsFile.exists() ) {
            log.info( resultsFileName + " could not be downloaded. Using the template to create anew");
            resultsFile = new File(project.getBasedir(), "src/main/resources/" + resultsFileName);
        }

        FileInputStream is = new FileInputStream( resultsFile );
        Document document = tidy.parseDOM(is, null);
        is.close();

        File reportsDir = new File(targetDirectory, "surefire-reports");
        if ( !reportsDir.exists() ) {
            log.warn("No surefire-reports directory here");
            return;
        }

        ArrayList files = (ArrayList) FileUtils.getFiles(reportsDir, "TEST-*.xml", null, true);
        if ( files.size() > 0 ) {
            document = insertNewColumn(document);
            if ( document == null ) {
                throw new MojoFailureException("Main table cannot be found in the " + resultsFileName + ". The file may be corrupted");
            }
        }

        for ( Iterator itr=files.iterator(); itr.hasNext(); ) {
            File file = (File) itr.next();
            log.debug("working on " + file.getAbsolutePath() );
            document = processFile(document, file);
        }

        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();

        // write the document back into a temporary file.
        File tempFile = new File(targetDirectory, "ResultsSummary-2.html");
        FileOutputStream os = new FileOutputStream( tempFile );
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);

        os.flush();
        os.close();

        // tidy the document and create/replace ResultsSummary.html in the target directory
        resultsFile = new File(targetDirectory, resultsFileName);
        is = new FileInputStream( tempFile );
        os = new FileOutputStream( resultsFile );
        tidy.parse(is, os);
        is.close();
        os.close();

        // delete the temp file.
        tempFile.delete();
View Full Code Here

    public static void convertHTMLToPDF (InputStream htmlInputStream,
                                         OutputStream outputStream)
    {
        try
        {
            Tidy tidy = new Tidy();
            tidy.setCharEncoding(Configuration.UTF8);
            tidy.setXHTML(true);
            tidy.setShowWarnings(false);

            File dir = SystemUtil.getLocalTempDirectory();
            File tempFile = File.createTempFile("pdf", "pdf", dir);
            FileOutputStream temp = new FileOutputStream(tempFile);
           
            tidy.parse(htmlInputStream, temp);
            temp.close();

            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocument(tempFile);
            renderer.layout();
View Full Code Here

     * @throws TidyException if a ParseError is detected and report_errors is true
     */
    private static Document tidyDoc(InputStream stream, boolean quiet, boolean showWarnings, boolean report_errors,
            boolean isXML, OutputStream out) throws TidyException {
        StringWriter sw = new StringWriter();
        Tidy tidy = makeTidyParser(quiet, showWarnings, isXML, sw);
        Document doc = tidy.parseDOM(stream, out);
        doc.normalize();
        if (tidy.getParseErrors() > 0) {
            if (report_errors) {
                log.error("TidyException: " + sw.toString());
                throw new TidyException(tidy.getParseErrors(),tidy.getParseWarnings());
            }
            log.warn("Tidy errors: " + sw.toString());
        }
        return doc;
    }
View Full Code Here

     * @param isXml - treat the content as XML?
     * @param stringWriter - if non-null, use this for Tidy errorOutput
     * @return the Tidy parser
     */
    public static Tidy makeTidyParser(boolean quiet, boolean showWarnings, boolean isXml, StringWriter stringWriter) {
        Tidy tidy = new Tidy();
        tidy.setInputEncoding("UTF8");
        tidy.setOutputEncoding("UTF8");
        tidy.setQuiet(quiet);
        tidy.setShowWarnings(showWarnings);
        tidy.setMakeClean(true);
        tidy.setXmlTags(isXml);
        if (stringWriter != null) {
            tidy.setErrout(new PrintWriter(stringWriter));
        }
        return tidy;
    }
View Full Code Here

                charEncoding = encodingConstantFromString(charset);
            }

            InputStream stream = connection.getInputStream();
            // Setup an instance of Tidy.
            Tidy tidy = new Tidy();
            tidy.setXmlOut(true);

            tidy.setCharEncoding(charEncoding);
            tidy.setXHTML(true);

            //Set Jtidy warnings on-off
            tidy.setShowWarnings(this.getLogger().isWarnEnabled());
            //Set Jtidy final result summary on-off
            tidy.setQuiet(!this.getLogger().isInfoEnabled());
            //Set Jtidy infos to a String (will be logged) instead of System.out
            StringWriter stringWriter = new StringWriter();
            //FIXME ??
            PrintWriter errorWriter = new PrintWriter(stringWriter);
            tidy.setErrout(errorWriter);
            // Extract the document using JTidy and stream it.
            Document doc = tidy.parseDOM(new BufferedInputStream(stream), null);
            errorWriter.flush();
            errorWriter.close();
            return doc;
        }
        catch (Exception ex) {
View Full Code Here

        catch ( Exception e )
        {
            log.warn("Download failed. " + e.getMessage());
        }

        Tidy tidy = new Tidy();
        tidy.setQuiet(true);
        tidy.setShowWarnings(false);



        if ( resultsFile == null || !resultsFile.exists() )
        {
            log.info( resultsFileName + " could not be downloaded. Using the template to create anew");
            resultsFile = new File(project.getBasedir(), "src/main/resources/" + resultsFileName);
        }

        FileInputStream is = new FileInputStream( resultsFile );
        Document document = tidy.parseDOM(is, null);
        is.close();

        File reportsDir = new File(targetDirectory, "surefire-reports");
        if ( !reportsDir.exists() )
        {
            log.warn("No surefire-reports directory here");
            return;
        }

        ArrayList files = (ArrayList) FileUtils.getFiles(reportsDir, "TEST-*.xml", null, true);
        if ( files.size() > 0 )
        {
            document = insertNewColumn(document);
            if ( document == null )
            {
                throw new MojoFailureException("Main table cannot be found in the " + resultsFileName + ". The file may be corrupted");
            }
        }

        for ( Iterator itr=files.iterator(); itr.hasNext(); )
        {
            File file = (File) itr.next();
            log.debug("working on " + file.getAbsolutePath() );
            document = processFile(document, file);
        }


        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();

        // write the document back into a temporary file.
        File tempFile = new File(targetDirectory, "ResultsSummary-2.html");
        FileOutputStream os = new FileOutputStream( tempFile );
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(os);
        transformer.transform(source, result);

        os.flush();
        os.close();

        // tidy the document and create/replace ResultsSummary.html in the target directory
        resultsFile = new File(targetDirectory, resultsFileName);
        is = new FileInputStream( tempFile );
        os = new FileOutputStream( resultsFile );
        tidy.parse(is, os);
        is.close();
        os.close();

        // delete the temp file.
        tempFile.delete();
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.