Search in sources :

Example 1 with StripHtmlTagAdapter

use of jodd.lagarto.adapter.StripHtmlTagAdapter in project jodd by oblac.

the class TagAdapterTest method testCleanHtml.

@Test
public void testCleanHtml() throws IOException {
    File ff = new File(testAdapterRoot, "clean.html");
    LagartoParser lagartoParser = new LagartoParser(FileUtil.readString(ff), false);
    StringBuilder out = new StringBuilder();
    TagWriter tagWriter = new TagWriter(out);
    StripHtmlTagAdapter stripHtmlTagAdapter = new StripHtmlTagAdapter(tagWriter);
    lagartoParser.parse(stripHtmlTagAdapter);
    ff = new File(testAdapterRoot, "clean-out.html");
    assertEquals(FileUtil.readString(ff), out.toString());
}
Also used : StripHtmlTagAdapter(jodd.lagarto.adapter.StripHtmlTagAdapter) File(java.io.File) Test(org.junit.Test)

Example 2 with StripHtmlTagAdapter

use of jodd.lagarto.adapter.StripHtmlTagAdapter in project jodd by oblac.

the class HtmlStaplerFilter method createParsingProcessor.

@Override
protected LagartoParsingProcessor createParsingProcessor() {
    if (!enabled) {
        return null;
    }
    return new LagartoParsingProcessor(true) {

        @Override
        protected char[] parse(TagWriter rootTagWriter, HttpServletRequest request) {
            TagVisitor visitor = rootTagWriter;
            if (stripHtml) {
                visitor = new StripHtmlTagAdapter(rootTagWriter) {

                    @Override
                    public void end() {
                        super.end();
                        if (log.isDebugEnabled()) {
                            log.debug("Stripped: " + getStrippedCharsCount() + " chars");
                        }
                    }
                };
            }
            String servletPath = DispatcherUtil.getServletPath(request);
            HtmlStaplerTagAdapter htmlStaplerTagAdapter = new HtmlStaplerTagAdapter(bundlesManager, servletPath, visitor);
            // todo add more adapters
            char[] content = invokeLagarto(htmlStaplerTagAdapter);
            return htmlStaplerTagAdapter.postProcess(content);
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TagWriter(jodd.lagarto.TagWriter) StripHtmlTagAdapter(jodd.lagarto.adapter.StripHtmlTagAdapter) TagVisitor(jodd.lagarto.TagVisitor)

Aggregations

StripHtmlTagAdapter (jodd.lagarto.adapter.StripHtmlTagAdapter)2 File (java.io.File)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 TagVisitor (jodd.lagarto.TagVisitor)1 TagWriter (jodd.lagarto.TagWriter)1 Test (org.junit.Test)1