Search in sources :

Example 1 with XPath2Filter

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;
}
Also used : Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) XPath2Filter(xades4j.algorithms.XPath2FilterTransform.XPath2Filter) XPath2FilterContainer(org.apache.xml.security.transforms.params.XPath2FilterContainer) Map(java.util.Map)

Example 2 with XPath2Filter

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());
}
Also used : XPath2Filter(xades4j.algorithms.XPath2FilterTransform.XPath2Filter) Test(org.junit.Test)

Aggregations

XPath2Filter (xades4j.algorithms.XPath2FilterTransform.XPath2Filter)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 XPath2FilterContainer (org.apache.xml.security.transforms.params.XPath2FilterContainer)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1