use of xades4j.algorithms.XPath2FilterTransform.XPath2Filter in project xades4j by luisgoncalves.
the class XPath2FilterTransformParamsMarshaller method marshalParameters.
@Override
public List<Node> marshalParameters(XPath2FilterTransform alg, Document doc) {
List<XPath2Filter> filters = alg.getFilters();
List<Node> params = new ArrayList<Node>(filters.size());
Set<Map.Entry<String, String>> namespaces = alg.getNamespaces().entrySet();
for (XPath2Filter filter : filters) {
XPath2FilterContainer c = null;
String filterType = filter.getFilterType();
if (XPath2FilterContainer.INTERSECT.equals(filterType)) {
c = XPath2FilterContainer.newInstanceIntersect(doc, filter.getXPath());
} else if (XPath2FilterContainer.SUBTRACT.equals(filterType)) {
c = XPath2FilterContainer.newInstanceSubtract(doc, filter.getXPath());
} else if (XPath2FilterContainer.UNION.equals(filterType)) {
c = XPath2FilterContainer.newInstanceUnion(doc, filter.getXPath());
} else {
throw new IllegalArgumentException(filterType);
}
// different filters.
for (Map.Entry<String, String> ns : namespaces) {
try {
c.setXPathNamespaceContext(ns.getKey(), ns.getValue());
} catch (XMLSecurityException ex) {
throw new IllegalArgumentException("Invalid namespaces for XPath query", ex);
}
}
params.add(c.getElement());
}
return params;
}
use of xades4j.algorithms.XPath2FilterTransform.XPath2Filter in project xades4j by luisgoncalves.
the class XPath2FilterTransformTest method testCreation.
@Test
public void testCreation() {
XPath2FilterTransform t1 = XPath2Filter.intersect("1");
XPath2FilterTransform t2 = t1.union("2");
XPath2FilterTransform t3 = t2.subtract("3");
assertSame(t1, t2);
assertSame(t2, t3);
List<XPath2Filter> filters = t3.getFilters();
assertEquals(3, filters.size());
XPath2Filter f = filters.get(0);
assertEquals("1", f.getXPath());
assertEquals("intersect", f.getFilterType());
f = filters.get(1);
assertEquals("2", f.getXPath());
assertEquals("union", f.getFilterType());
f = filters.get(2);
assertEquals("3", f.getXPath());
assertEquals("subtract", f.getFilterType());
}
Aggregations