Wiki Markup |
---|
{composition-setup}
cloak.memory.duration = 3
{composition-setup} |
Adding a markup filter
In some very rare cases it might be necessary to add an additional markup filter to the default list. Lets say you want to log a warning or throw an exception in case of an empty src attribute like <img src="">. The Image component is not able to handle it because the wicket id is missing. A markup filter in contrast iterates over all xml tags and is able to detect the problem and to throw an exception.
Note: a markup filter is not able to detect an AttributeModifier changing the src attribute to an empty string.
Wicket 1.4:
Code Block |
---|
public class MyApplication extends Application
{
protected void init()
{
...
getMarkupSettings().setMarkupParserFactory(
new MyMarkupParserFactory());
...
}
}
public class MyMarkupParserFactory implements IMarkupParserFactory {
@Override
public MarkupParser newMarkupParser(MarkupResourceStream resource) {
MarkupParser parser = new MarkupParser(new XmlPullParser(), resource);
parser.appendMarkupFilter(new MyMarkupFilter());
return parser;
}
}
|
It's maybe a good idea to allow your MarkupParserFactory accept a list of filters which might get appended on creation of the parser in 'newMarkupParser'.
Wicket 1.2:
Code Block |
---|
public class MyApplication extends Application
{
protected void init()
{
IMarkupFilter filter = new HtmlProblemFinder(HtmlProblemFinder.ERR_THROW_EXCEPTION);
getMarkupSettings().setMarkupParserFactory(new MarkupParserFactory(this, filter));
}
}
|
Wicket 1.1
Code Block |
---|
public class MyApplication extends Application
{
public MarkupParser newMarkupParser()
{
final MarkupParser parser = new MarkupParser(container,
new XmlPullParser(settings.getDefaultMarkupEncoding())
{
public void initFilterChain()
{
appendMarkupFilter(new HtmlProblemFinder(HtmlProblemFinder.ERR_THROW_EXCEPTION));
}
}
);
parser.configure(getSettings());
return parser;
}
}
|