use of org.apache.xml.security.test.dom.DSNamespaceContext in project santuario-java by apache.
the class Santuario273Test method testC14n11Base.
@org.junit.Test
public void testC14n11Base() throws Exception {
DocumentBuilder documentBuilder = XMLUtils.createDocumentBuilder(true);
documentBuilder.setErrorHandler(new org.apache.xml.security.utils.IgnoreAllErrorHandler());
Document doc = null;
try (InputStream is = new ByteArrayInputStream(input.getBytes())) {
doc = documentBuilder.parse(is);
}
Canonicalizer c14n = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS);
XPathFactory xpf = XPathFactory.newInstance();
XPath xPath = xpf.newXPath();
xPath.setNamespaceContext(new DSNamespaceContext());
Node signedInfo = (Node) xPath.evaluate("//ds:SignedInfo[1]", doc, XPathConstants.NODE);
byte[] output = c14n.canonicalizeSubtree(signedInfo);
assertEquals(new String(output, java.nio.charset.StandardCharsets.UTF_8), expectedResult);
}
use of org.apache.xml.security.test.dom.DSNamespaceContext in project santuario-java by apache.
the class BaltimoreEncTest method retrieveCCNumber.
/**
* Method retrieveCCNumber
*
* Retrieve the credit card number from the payment info document
*
* @param doc The document to retrieve the card number from
* @return The retrieved credit card number
* @throws XPathExpressionException
*/
private static String retrieveCCNumber(Document doc) throws javax.xml.transform.TransformerException, XPathExpressionException {
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
Map<String, String> namespace = new HashMap<>();
namespace.put("x", "urn:example:po");
DSNamespaceContext context = new DSNamespaceContext(namespace);
xpath.setNamespaceContext(context);
String expression = "//x:Number/text()";
Node ccnumElt = (Node) xpath.evaluate(expression, doc, XPathConstants.NODE);
if (ccnumElt != null) {
return ccnumElt.getNodeValue();
}
return null;
}
Aggregations