package wicket.markup;

import wicket.Application;
import wicket.markup.parser.IMarkupFilter;
import wicket.markup.parser.XmlPullParser;

/**
 * Default implementation of IMarkupParserFactory
 * 
 * @author Igor Vaynberg (ivaynberg)
 */
public class MarkupParserFactory implements IMarkupParserFactory
{
	private IMarkupFilter[] filters;
	private Application application;

	/**
	 * Construct.
	 * 
	 * @param application
	 *            Application settings necessary to configure the parser
	 */
	public MarkupParserFactory(final Application application)
	{
		this.application = application;
	}

	/**
	 * Construct.
	 * 
	 * @param application
	 *            Application settings necessary to configure the parser
	 * @param filters
	 *            additional markup filters
	 */
	public MarkupParserFactory(final Application application, IMarkupFilter[] filters)
	{
		this(application);
		this.filters = filters;
	}

	/**
	 * Construct.
	 * 
	 * @param application
	 *            Application settings necessary to configure the parser
	 * @param filter
	 *            additional markup filter
	 */
	public MarkupParserFactory(final Application application, IMarkupFilter filter)
	{
		this(application);
		this.filters = new IMarkupFilter[] { filter };
	}

	/**
	 * @see wicket.markup.IMarkupParserFactory#newMarkupParser()
	 */
	public MarkupParser newMarkupParser()
	{
		final MarkupParser parser = new MarkupParser(application, new XmlPullParser())
		{
			public void initFilterChain()
			{
				if (filters != null)
				{
					for (int i = 0; i < filters.length; i++)
					{
						appendMarkupFilter(filters[i]);
					}
				}
			}
		};
		return parser;
	}
}

@@ -129,16 +129,78 @@
 lParser;
+%0Aimport wicket.markup.parser.filter.PrependContextPathHandler;
 %0A%0A/**%0A *
@@ -647,16 +647,101 @@
 cation;%0A
+%09%09this.filters = new IMarkupFilter%5B%5D %7B new PrependContextPathHandler(application) %7D;%0A
 %09%7D%0A%0A%09/**
@@ -1004,33 +1004,33 @@
 lters)%0A%09%7B%0A%09%09this
-(
+.
 application);%0A%09%09
@@ -1016,33 +1016,46 @@
 this.application
-)
+ = application
 ;%0A%09%09this.filters
@@ -1057,23 +1057,193 @@
 lters = 
-filters
+new IMarkupFilter%5Bfilters.length+1%5D;%0A%09%09System.arraycopy(filters, 0, this.filters, 0, filters.length);%0A%09%09this.filters%5Bfilters.length%5D = new PrependContextPathHandler(application)
 ;%0A%09%7D%0A%0A%09/
@@ -1511,17 +1511,31 @@
 %7B%0A%09%09this
-(
+.application = 
 applicat
@@ -1537,17 +1537,16 @@
 lication
-)
 ;%0A%09%09this
@@ -1584,16 +1584,60 @@
 %7B filter
+, new PrependContextPathHandler(application)
  %7D;%0A%09%7D%0A%0A

add always a prependcontextpath handler as a filter. Users shouldn't do this themselfs..