public Object exec(List arguments) throws TemplateModelException {
if (arguments == null || arguments.size() == 0)
throw new TemplateModelException("_type expects exactly one argument");
String arg = (String)arguments.get(0);
boolean invert = arg.indexOf('!") != -1;
// NOTE: true in each of these variables means 'remove', not 'keep'
// This is so we don't invert their values in the loop. So,
// a is true < -- > (a is not present in the string) xor invert.
boolean a = invert != (arg.indexOf('a") == -1);
boolean c = invert != (arg.indexOf('c") == -1);
boolean d = invert != (arg.indexOf('d") == -1);
boolean e = invert != (arg.indexOf('e") == -1);
boolean n = invert != (arg.indexOf('n") == -1);
boolean p = invert != (arg.indexOf('p") == -1);
boolean t = invert != (arg.indexOf('t") == -1);
boolean x = invert != (arg.indexOf('x") == -1);
LinkedList list = new LinkedList(nodes);
Iterator it = list.iterator();
while (it.hasNext()) {
Object node = it.next();
if ((node instanceof Element && e)
|| (node instanceof Attribute && a)
|| (node instanceof String && x)
|| (node instanceof Text && x)
|| (node instanceof ProcessingInstruction && p)
|| (node instanceof Comment && c)
|| (node instanceof EntityRef && n)
|| (node instanceof Document && d)
|| (node instanceof DocType && t))
it.remove();
}
return createNodeListModel(list, namespaces);
}
|