Search in sources :

Example 1 with HtmlParser

use of org.eclipse.mylyn.wikitext.parser.HtmlParser in project mylyn.docs by eclipse.

the class HtmlParserTest method testCanParseSomething.

@Test
public void testCanParseSomething() throws Exception {
    HtmlParser parser = new HtmlParser();
    assertCanParseSomething(parser);
}
Also used : HtmlParser(org.eclipse.mylyn.wikitext.parser.HtmlParser) Test(org.junit.Test)

Example 2 with HtmlParser

use of org.eclipse.mylyn.wikitext.parser.HtmlParser in project mylyn.docs by eclipse.

the class HtmlParserTest method parseHtmlToHtml.

private String parseHtmlToHtml(String input, boolean asDocument) throws IOException, SAXException {
    HtmlParser parser = new HtmlParser();
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    parser.parse(new InputSource(new StringReader(input)), builder, asDocument);
    return out.toString();
}
Also used : HtmlParser(org.eclipse.mylyn.wikitext.parser.HtmlParser) InputSource(org.xml.sax.InputSource) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)

Example 3 with HtmlParser

use of org.eclipse.mylyn.wikitext.parser.HtmlParser in project mylyn.docs by eclipse.

the class HtmlParserTest method parsePreservesAsDocumentSetting.

@Test
public void parsePreservesAsDocumentSetting() throws IOException, SAXException {
    HtmlParser parser = new HtmlParser();
    StringWriter out = new StringWriter();
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(out);
    builder.setEmitAsDocument(false);
    parser.parse(new InputSource(new StringReader("before <em>emphasis</em> after")), builder);
    assertEquals("before <em>emphasis</em> after", out.toString());
}
Also used : HtmlParser(org.eclipse.mylyn.wikitext.parser.HtmlParser) InputSource(org.xml.sax.InputSource) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) Test(org.junit.Test)

Example 4 with HtmlParser

use of org.eclipse.mylyn.wikitext.parser.HtmlParser in project mylyn.docs by eclipse.

the class HtmlLanguage method processContent.

@Override
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
    HtmlParser htmlParser = createHtmlParser();
    InputSource source = new InputSource(new StringReader(markupContent));
    try {
        htmlParser.parse(source, parser.getBuilder(), asDocument);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } catch (SAXException e) {
        throw Throwables.propagate(e);
    }
}
Also used : HtmlParser(org.eclipse.mylyn.wikitext.parser.HtmlParser) InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 5 with HtmlParser

use of org.eclipse.mylyn.wikitext.parser.HtmlParser in project mylyn.docs by eclipse.

the class HtmlToMarkupTask method processFile.

private void processFile(MarkupLanguage markupLanguage, File folder, File source) {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToHtmlTask.14"), source), Project.MSG_VERBOSE);
    if (isValidate()) {
        // $NON-NLS-1$
        log(MessageFormat.format(Messages.getString("HtmlToMarkupTask.1"), source), Project.MSG_WARN);
    }
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File outputFile = computeTargetFile(markupLanguage, source, name);
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.16"), outputFile, e.getMessage()), // $NON-NLS-1$
            e);
        }
        try {
            DocumentBuilder builder = markupLanguage.createDocumentBuilder(writer);
            Reader input;
            InputStream in;
            try {
                in = new BufferedInputStream(new FileInputStream(source));
                input = getSourceEncoding() == null ? new InputStreamReader(in) : new InputStreamReader(in, getSourceEncoding());
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(Messages.getString("MarkupTask.cannotReadSource"), source, e.getMessage()), // $NON-NLS-1$
                e);
            }
            try {
                new HtmlParser().parse(new InputSource(input), builder);
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(Messages.getString("HtmlToMarkupTask.failedToProcessContent"), source, e.getMessage()), // $NON-NLS-1$
                e);
            } finally {
                try {
                    in.close();
                } catch (Exception e) {
                    throw new BuildException(MessageFormat.format(Messages.getString("MarkupTask.cannotReadSource"), source, e.getMessage()), // $NON-NLS-1$
                    e);
                }
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToHtmlTask.17"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BuildException(org.apache.tools.ant.BuildException) FileInputStream(java.io.FileInputStream) HtmlParser(org.eclipse.mylyn.wikitext.parser.HtmlParser) DocumentBuilder(org.eclipse.mylyn.wikitext.parser.DocumentBuilder) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

HtmlParser (org.eclipse.mylyn.wikitext.parser.HtmlParser)8 Test (org.junit.Test)5 InputSource (org.xml.sax.InputSource)4 StringReader (java.io.StringReader)3 StringWriter (java.io.StringWriter)2 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 BuildException (org.apache.tools.ant.BuildException)1 DocumentBuilder (org.eclipse.mylyn.wikitext.parser.DocumentBuilder)1 SAXException (org.xml.sax.SAXException)1