* @param node
*/
public void visitFilter(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
{
String name = node.getString("filter-name", false, true);
FilterHolder holder = _filterHolderMap.get(name);
if (holder == null)
{
holder = context.getServletHandler().newFilterHolder(Source.DESCRIPTOR);
holder.setName(name);
_filterHolderMap.put(name,holder);
_filterHolders.add(holder);
}
String filter_class = node.getString("filter-class", false, true);
if (filter_class != null)
{
((WebDescriptor)descriptor).addClassName(filter_class);
switch (context.getMetaData().getOrigin(name+".filter.filter-class"))
{
case NotSet:
{
//no class set yet
holder.setClassName(filter_class);
context.getMetaData().setOrigin(name+".filter.filter-class", descriptor);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//filter class was set in web.xml, only allow other web xml descriptors (override/default) to change it
if (!(descriptor instanceof FragmentDescriptor))
{
holder.setClassName(filter_class);
context.getMetaData().setOrigin(name+".filter.filter-class", descriptor);
}
break;
}
case WebFragment:
{
//the filter class was set up by a web fragment, all fragments must be the same
if (!holder.getClassName().equals(filter_class))
throw new IllegalStateException("Conflicting filter-class for filter "+name+" in "+descriptor.getResource());
break;
}
default:
LOG.warn(new Throwable()); // TODO throw ISE?
}
}
Iterator<XmlParser.Node> iter = node.iterator("init-param");
while (iter.hasNext())
{
XmlParser.Node paramNode = iter.next();
String pname = paramNode.getString("param-name", false, true);
String pvalue = paramNode.getString("param-value", false, true);
switch (context.getMetaData().getOrigin(name+".filter.init-param."+pname))
{
case NotSet:
{
//init-param not already set, so set it
holder.setInitParameter(pname, pvalue);
context.getMetaData().setOrigin(name+".filter.init-param."+pname, descriptor);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//previously set by a web xml descriptor, if we're parsing another web xml descriptor allow override
//otherwise just ignore it
if (!(descriptor instanceof FragmentDescriptor))
{
holder.setInitParameter(pname, pvalue);
context.getMetaData().setOrigin(name+".filter.init-param."+pname, descriptor);
}
break;
}
case WebFragment:
{
//previously set by a web-fragment, make sure that the value matches, otherwise its an error
if (!holder.getInitParameter(pname).equals(pvalue))
throw new IllegalStateException("Mismatching init-param "+pname+"="+pvalue+" in "+descriptor.getResource());
break;
}
default:
LOG.warn(new Throwable()); // TODO throw ISE?
}
}
String async=node.getString("async-supported",false,true);
if (async!=null)
holder.setAsyncSupported(async.length()==0||Boolean.valueOf(async));
if (async!=null)
{
boolean val = async.length()==0||Boolean.valueOf(async);
switch (context.getMetaData().getOrigin(name+".filter.async-supported"))
{
case NotSet:
{
//set it
holder.setAsyncSupported(val);
context.getMetaData().setOrigin(name+".filter.async-supported", descriptor);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//async-supported set by previous web xml descriptor, only allow override if we're parsing another web descriptor(web.xml/web-override.xml/web-default.xml)
if (!(descriptor instanceof FragmentDescriptor))
{
holder.setAsyncSupported(val);
context.getMetaData().setOrigin(name+".filter.async-supported", descriptor);
}
break;
}
case WebFragment:
{
//async-supported set by another fragment, this fragment's value must match
if (holder.isAsyncSupported() != val)
throw new IllegalStateException("Conflicting async-supported="+async+" for filter "+name+" in "+descriptor.getResource());
break;
}
default:
LOG.warn(new Throwable()); // TODO throw ISE?