Search in sources :

Example 1 with XPathTransform

use of xades4j.algorithms.XPathTransform in project xades4j by luisgoncalves.

the class XPathTransformParamsMarshallerTest method testMarshalXPathParametersWithNamespacePrefixes.

@Test
public void testMarshalXPathParametersWithNamespacePrefixes() throws Exception {
    XPathTransform xpath = new XPathTransform("foo:elem1/bar:elem2").withNamespace("foo", "http://test.xades4j/ns1").withNamespace("bar", "http://test.xades4j/ns2");
    List<Node> params = sut.marshalParameters(xpath, doc);
    assertEquals(1, params.size());
    Element paramNode = (Element) params.get(0);
    Map<String, String> namespaces = xpath.getNamespaces();
    for (Map.Entry<String, String> entry : namespaces.entrySet()) {
        String ns = paramNode.getAttributeNS(Constants.NamespaceSpecNS, entry.getKey());
        assertNotNull(ns);
        assertFalse(ns.isEmpty());
        assertEquals(entry.getValue(), ns);
    }
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) XPathTransform(xades4j.algorithms.XPathTransform) Map(java.util.Map) Test(org.junit.Test)

Example 2 with XPathTransform

use of xades4j.algorithms.XPathTransform in project xades4j by luisgoncalves.

the class DataObjectDescTest method testWithTransform.

@Test
public void testWithTransform() throws Exception {
    System.out.println("withTransform");
    Document doc = SignatureServicesTestBase.getNewDocument();
    DataObjectDesc instance = new DataObjectDescTestImpl().withTransform(new XPathTransform("xpath")).withTransform(XPath2Filter.subtract("xpath1").intersect("xpath2")).withTransform(new GenericAlgorithm("uri", doc.createElement("param1"), doc.createElement("param2")));
    Algorithm[] transforms = instance.getTransforms().toArray(new Algorithm[0]);
    assertEquals(3, transforms.length);
    assertEquals(XPathTransform.class, transforms[0].getClass());
    assertEquals(XPath2FilterTransform.class, transforms[1].getClass());
    assertEquals(GenericAlgorithm.class, transforms[2].getClass());
}
Also used : XPathTransform(xades4j.algorithms.XPathTransform) Document(org.w3c.dom.Document) Algorithm(xades4j.algorithms.Algorithm) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) Test(org.junit.Test)

Example 3 with XPathTransform

use of xades4j.algorithms.XPathTransform in project xades4j by luisgoncalves.

the class SignerBESTest method testSignBESDetachedWithXPathAndNamespaces.

@Test
public void testSignBESDetachedWithXPathAndNamespaces() throws Exception {
    System.out.println("signBESDetachedWithXPathAndNamespaces");
    Document doc = getNewDocument();
    XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).withBasicSignatureOptionsProvider(MyBasicSignatureOptionsProvider.class).newSigner();
    DataObjectDesc obj1 = new DataObjectReference("document.xml").withTransform(new XPathTransform("/collection/album/foo:tracks").withNamespace("foo", "http://test.xades4j/tracks")).withDataObjectFormat(new DataObjectFormatProperty("text/xml"));
    DataObjectDesc obj2 = new DataObjectReference("document.xml").withTransform(XPath2Filter.intersect("/collection/album/bar:tracks/bar:song[@tracknumber = 1]").withNamespace("bar", "http://test.xades4j/tracks"));
    SignedDataObjects objs = new SignedDataObjects(obj1, obj2).withBaseUri(new File("src/test/xml/").toURI().toString());
    signer.sign(objs, doc);
    outputDocument(doc, "detached.bes.xml");
}
Also used : DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) XPathTransform(xades4j.algorithms.XPathTransform) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 XPathTransform (xades4j.algorithms.XPathTransform)3 Document (org.w3c.dom.Document)2 File (java.io.File)1 Map (java.util.Map)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 Algorithm (xades4j.algorithms.Algorithm)1 GenericAlgorithm (xades4j.algorithms.GenericAlgorithm)1 DataObjectDesc (xades4j.properties.DataObjectDesc)1 DataObjectFormatProperty (xades4j.properties.DataObjectFormatProperty)1