Examples of Tidy


Examples of org.w3c.tidy.Tidy

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

            // Extract the document using JTidy and stream it.
            org.w3c.dom.Document doc = tidy.parseDOM(new BufferedInputStream(this.inputSource.getInputStream()), null);
            if(xpath != null)
            {
                Transformer serializer = TransformerFactory.newInstance().newTransformer();
                serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
View Full Code Here

Examples of org.w3c.tidy.Tidy

        }
        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

Examples of org.w3c.tidy.Tidy

        status = STATUS_OK;
        message = "";

        try
        {
            Tidy tidy = new Tidy();
            Document doc = null;

            try
            {
                FileInputStream in = new FileInputStream(fileToCheck);
                tidy.setMakeClean(true);
                tidy.setXmlTags(true);
                tidy.setXmlOut(true);
                tidy.setQuiet(true);
                tidy.setShowWarnings(false);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintWriter errOut = new PrintWriter(baos);
                tidy.setErrout(errOut);
                LOG.debug("Processing:" + fileToCheck);
                tidy.setXHTML(true);
                org.w3c.dom.Document domDocument = tidy.parseDOM(in, null);

                // now read a dom4j document from
                // JTidy's W3C DOM object

                DOMReader domReader = new DOMReader();
View Full Code Here

Examples of org.w3c.tidy.Tidy

        }
        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

Examples of org.w3c.tidy.Tidy

     * @throws TransferFailedException if there was a problem fetching the raw html.
     */
    public static List parseFileList( String baseurl, InputStream is )
        throws TransferFailedException
    {
        Tidy tidy = new Tidy();
        tidy.setXHTML( true );
        // Don't care about the warning messages.
        tidy.setErrout( new PrintWriter( new NullOutputStream() ) );
        // Don't care about the cleaned up version of the HTML.
        Document doc = tidy.parseDOM( is, new NullOutputStream() );

        List links = new ArrayList();
        links = findAnchorLinks( links, baseurl, doc );

        return links;
View Full Code Here

Examples of org.w3c.tidy.Tidy

     */
    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

Examples of org.w3c.tidy.Tidy

        }

        result.setFailure(false);

        // create parser
        Tidy tidy = null;
        try {
            if (log.isDebugEnabled()){
                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.setInputEncoding("UTF8");
            tidy.setOutputEncoding("UTF8");
            tidy.setQuiet(false);
            tidy.setShowWarnings(true);
            tidy.setOnlyErrors(isErrorsOnly());
            tidy.setDocType(getDoctype());
            if (isXHTML()) {
                tidy.setXHTML(true);
            } else if (isXML()) {
                tidy.setXmlTags(true);
            }
            tidy.setErrfile(getFilename());

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

        } catch (Exception e) {//TODO replace with proper Exception
            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()))) {
                if (log.isDebugEnabled()) {
                    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

Examples of org.w3c.tidy.Tidy

     *
     * @return a <code>tidy</code> HTML parser
     */
    private static Tidy getTidyParser(String encoding) {
        log.debug("Start : getParser");
        Tidy tidy = new Tidy();
        tidy.setInputEncoding(encoding);
        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

Examples of org.w3c.tidy.Tidy

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

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

View Full Code Here

Examples of org.w3c.tidy.Tidy

        // 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
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.