// Copyright (c) 2003-2011, Jodd Team (jodd.org). All Rights Reserved.

package madvoc.filter;

import jodd.lagarto.TagVisitor;
import jodd.lagarto.TagWriter;
import jodd.lagarto.adapter.StripHtmlTagAdapter;
import jodd.lagarto.adapter.htmlstapler.HtmlStaplerBundlesManager;
import jodd.lagarto.adapter.htmlstapler.HtmlStaplerTagAdapter;
import jodd.lagarto.filter.SimpleLagartoServletFilter;

import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

public class AppLagartoServletFilter extends SimpleLagartoServletFilter {

	protected HtmlStaplerBundlesManager bundlesManager;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		super.init(filterConfig);

		bundlesManager = new HtmlStaplerBundlesManager(filterConfig.getServletContext());
		bundlesManager.reset();
	}

	@Override
	protected TagVisitor createAdapters(TagWriter rootTagWriter, HttpServletRequest request) {
		StripHtmlTagAdapter stripHtmlTagAdapter = new StripHtmlTagAdapter(rootTagWriter);

		HtmlStaplerTagAdapter htmlStaplerTagAdapter = new HtmlStaplerTagAdapter(stripHtmlTagAdapter, request);

		return htmlStaplerTagAdapter;
	}
}

@@ -97,41 +97,8 @@
 %0D%0A%0D%0A
-import jodd.lagarto.TagVisitor;%0D%0A
 impo
@@ -490,16 +490,117 @@
 est;%0D%0A%0D%0A
+import static jodd.lagarto.adapter.htmlstapler.HtmlStaplerBundlesManager.Strategy.RESOURCES_ONLY;%0D%0A%0D%0A
 public c
@@ -920,16 +920,32 @@
 ontext()
+, RESOURCES_ONLY
 );%0D%0A%09%09bu
@@ -1000,33 +1000,141 @@
 ted 
-TagVisitor createAdapte
+LagartoParsingProcessor createParsingProcessor() %7B%0D%0A%09%09return new LagartoParsingProcessor() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09protected char%5B%5D pa
 rs
+e
 (Tag
@@ -1186,16 +1186,18 @@
 est) %7B%0D%0A
+%09%09
 %09%09StripH
@@ -1277,16 +1277,18 @@
 );%0D%0A%0D%0A%09%09
+%09%09
 HtmlStap
@@ -1391,42 +1391,141 @@
 %0D%0A%09%09
-return htmlStaplerTagAdapter
+%09%09char%5B%5D content = invokeLagarto(htmlStaplerTagAdapter);%0D%0A%0D%0A%09%09%09%09return htmlStaplerTagAdapter.postProcess(content);%0D%0A%09%09%09%7D%0D%0A%09%09%7D
 ;%0D%0A%09%7D%0D%0A
+%0D%0A
 %7D%0D%0A

apply changes to the example