Search in sources :

Example 1 with NekoContent

use of org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent in project OpenOLAT by OpenOLAT.

the class XmlDocument method readContent.

// fxdiff FXOLAT-97: index run in infinite loop
protected FileContent readContent(VFSLeaf leaf) throws IOException {
    InputStream is = leaf.getInputStream();
    // Remove all HTML and   Tags
    NekoContent output;
    try {
        output = new NekoHTMLFilter().filter(is);
        if (log.isDebug())
            log.debug("HTML content without tags :" + output);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        FileUtils.closeSafely(is);
    }
    return new FileContent(output.getTitle(), output.getContent());
}
Also used : NekoHTMLFilter(org.olat.core.util.filter.impl.NekoHTMLFilter) InputStream(java.io.InputStream) NekoContent(org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with NekoContent

use of org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent in project OpenOLAT by OpenOLAT.

the class NekoHTMLFilterTest method testHtmlTextAndTitle.

@Test
public void testHtmlTextAndTitle() {
    String htmlText = "<html><head><title>Hello Neko</title><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test&nbsp;Text" + // Text = 'Dies ist der Test Text'
    "</body></html>";
    // must include '\u00A0' !!! 19.5.2010/cg
    String text = "Hello Neko Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
    NekoContent content = filter.filter(new ByteArrayInputStream(htmlText.getBytes()));
    Assert.assertNotNull(content);
    Assert.assertEquals("Hello Neko", content.getTitle());
    Assert.assertEquals(text, content.getContent());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NekoContent(org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent) Test(org.junit.Test)

Example 3 with NekoContent

use of org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent in project openolat by klemens.

the class XmlDocument method readContent.

// fxdiff FXOLAT-97: index run in infinite loop
protected FileContent readContent(VFSLeaf leaf) throws IOException {
    InputStream is = leaf.getInputStream();
    // Remove all HTML and &nbsp; Tags
    NekoContent output;
    try {
        output = new NekoHTMLFilter().filter(is);
        if (log.isDebug())
            log.debug("HTML content without tags :" + output);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        FileUtils.closeSafely(is);
    }
    return new FileContent(output.getTitle(), output.getContent());
}
Also used : NekoHTMLFilter(org.olat.core.util.filter.impl.NekoHTMLFilter) InputStream(java.io.InputStream) NekoContent(org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent) IOException(java.io.IOException) IOException(java.io.IOException)

Example 4 with NekoContent

use of org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent in project openolat by klemens.

the class NekoHTMLFilterTest method testHtmlTextAndTitle.

@Test
public void testHtmlTextAndTitle() {
    String htmlText = "<html><head><title>Hello Neko</title><meta name=\"generator\" content=\"olat-tinymce-1\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + "<H1>Test HTML Seite fuer JUnit Test</H1>" + "Dies ist<br />der Test&nbsp;Text" + // Text = 'Dies ist der Test Text'
    "</body></html>";
    // must include '\u00A0' !!! 19.5.2010/cg
    String text = "Hello Neko Test HTML Seite fuer JUnit Test Dies ist der Test\u00A0Text";
    NekoContent content = filter.filter(new ByteArrayInputStream(htmlText.getBytes()));
    Assert.assertNotNull(content);
    Assert.assertEquals("Hello Neko", content.getTitle());
    Assert.assertEquals(text, content.getContent());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NekoContent(org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent) Test(org.junit.Test)

Aggregations

NekoContent (org.olat.core.util.filter.impl.NekoHTMLFilter.NekoContent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 NekoHTMLFilter (org.olat.core.util.filter.impl.NekoHTMLFilter)2