use of javax.xml.crypto.NodeSetData in project syndesis by syndesisio.
the class BaseSwaggerGeneratorExampleTest method c14Xml.
private static String c14Xml(final String xml) {
if (xml == null) {
return null;
}
try {
final DocumentBuilder documentBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
final Document document = documentBuilder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
final TransformService transformation = TransformService.getInstance(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, "DOM");
transformation.init(null);
final NodeList allElements = document.getElementsByTagName("*");
final List<Node> elements = new ArrayList<>();
for (int i = 0; i < allElements.getLength(); i++) {
elements.add(allElements.item(i));
}
final OctetStreamData data = (OctetStreamData) transformation.transform((NodeSetData) elements::iterator, null);
try (final InputStream stream = data.getOctetStream()) {
final byte[] buffy = new byte[stream.available()];
stream.read(buffy);
return new String(buffy, StandardCharsets.UTF_8);
}
} catch (GeneralSecurityException | TransformException | SAXException | IOException | ParserConfigurationException e) {
throw new AssertionError(e);
}
}
use of javax.xml.crypto.NodeSetData in project santuario-java by apache.
the class DOMRetrievalMethod method dereference.
@Override
public Data dereference(XMLCryptoContext context) throws URIReferenceException {
if (context == null) {
throw new NullPointerException("context cannot be null");
}
/*
* If URIDereferencer is specified in context; use it, otherwise use
* built-in.
*/
URIDereferencer deref = context.getURIDereferencer();
if (deref == null) {
deref = DOMURIDereferencer.INSTANCE;
}
Data data = deref.dereference(this, context);
// pass dereferenced data through Transforms
try {
for (Transform transform : transforms) {
data = transform.transform(data, context);
}
} catch (Exception e) {
throw new URIReferenceException(e);
}
// guard against RetrievalMethod loops
if (data instanceof NodeSetData && Utils.secureValidation(context)) {
NodeSetData nsd = (NodeSetData) data;
Iterator<?> i = nsd.iterator();
if (i.hasNext()) {
Node root = (Node) i.next();
if ("RetrievalMethod".equals(root.getLocalName())) {
throw new URIReferenceException("It is forbidden to have one RetrievalMethod point " + "to another when secure validation is enabled");
}
}
}
return data;
}
Aggregations