Example usage for javax.xml.crypto OctetStreamData getURI

List of usage examples for javax.xml.crypto OctetStreamData getURI

Introduction

In this page you can find the example usage for javax.xml.crypto OctetStreamData getURI.

Prototype

public String getURI() 

Source Link

Document

Returns the URI String identifying the data object represented by this OctetStreamData.

Usage

From source file:be.fedict.eid.applet.service.signer.ooxml.RelationshipTransformService.java

public Data transform(Data data, XMLCryptoContext context) throws TransformException {
    LOG.debug("transform(data,context)");
    LOG.debug("data java type: " + data.getClass().getName());
    OctetStreamData octetStreamData = (OctetStreamData) data;
    LOG.debug("URI: " + octetStreamData.getURI());
    InputStream octetStream = octetStreamData.getOctetStream();
    Document relationshipsDocument;
    try {/*from w  w  w. j ava 2s  .  c  o  m*/
        relationshipsDocument = loadDocument(octetStream);
    } catch (Exception e) {
        throw new TransformException(e.getMessage(), e);
    }
    try {
        LOG.debug("relationships document: " + toString(relationshipsDocument));
    } catch (TransformerException e) {
        throw new TransformException(e.getMessage(), e);
    }
    Element nsElement = relationshipsDocument.createElement("ns");
    nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns",
            "http://schemas.openxmlformats.org/package/2006/relationships");
    Element relationshipsElement = relationshipsDocument.getDocumentElement();
    NodeList childNodes = relationshipsElement.getChildNodes();
    for (int nodeIdx = 0; nodeIdx < childNodes.getLength(); nodeIdx++) {
        Node childNode = childNodes.item(nodeIdx);
        if (Node.ELEMENT_NODE != childNode.getNodeType()) {
            LOG.debug("removing node");
            relationshipsElement.removeChild(childNode);
            nodeIdx--;
            continue;
        }
        Element childElement = (Element) childNode;
        String idAttribute = childElement.getAttribute("Id");
        String typeAttribute = childElement.getAttribute("Type");
        LOG.debug("Relationship id attribute: " + idAttribute);
        LOG.debug("Relationship type attribute: " + typeAttribute);
        if (false == this.sourceIds.contains(idAttribute)
                && false == this.sourceTypes.contains(typeAttribute)) {
            LOG.debug("removing Relationship element: " + idAttribute);
            relationshipsElement.removeChild(childNode);
            nodeIdx--;
        }
        /*
         * See: ISO/IEC 29500-2:2008(E) - 13.2.4.24 Relationships Transform
         * Algorithm.
         */
        if (null == childElement.getAttributeNode("TargetMode")) {
            childElement.setAttribute("TargetMode", "Internal");
        }
    }
    LOG.debug("# Relationship elements: " + relationshipsElement.getElementsByTagName("*").getLength());
    sortRelationshipElements(relationshipsElement);
    try {
        return toOctetStreamData(relationshipsDocument);
    } catch (TransformerException e) {
        throw new TransformException(e.getMessage(), e);
    }
}