Example usage for javax.xml.crypto.dsig TransformException TransformException

List of usage examples for javax.xml.crypto.dsig TransformException TransformException

Introduction

In this page you can find the example usage for javax.xml.crypto.dsig TransformException TransformException.

Prototype

public TransformException(Throwable cause) 

Source Link

Document

Constructs a new TransformException with the specified cause and a detail message of (cause==null ?

Usage

From source file:org.apache.jcp.xml.dsig.internal.dom.ApacheCanonicalizer.java

public Data transform(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException {
    if (data == null) {
        throw new NullPointerException("data must not be null");
    }//from  w  w w .  jav a2 s . co  m
    if (os == null) {
        throw new NullPointerException("output stream must not be null");
    }

    if (ownerDoc == null) {
        throw new TransformException("transform must be marshalled");
    }

    if (apacheTransform == null) {
        try {
            apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
            apacheTransform.setElement(transformElem, xc.getBaseURI());
            if (log.isDebugEnabled()) {
                log.debug("Created transform for algorithm: " + getAlgorithm());
            }
        } catch (Exception ex) {
            throw new TransformException("Couldn't find Transform for: " + getAlgorithm(), ex);
        }
    }

    XMLSignatureInput in;
    if (data instanceof ApacheData) {
        if (log.isDebugEnabled()) {
            log.debug("ApacheData = true");
        }
        in = ((ApacheData) data).getXMLSignatureInput();
    } else if (data instanceof NodeSetData) {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = true");
        }
        if (data instanceof DOMSubTreeData) {
            DOMSubTreeData subTree = (DOMSubTreeData) data;
            in = new XMLSignatureInput(subTree.getRoot());
            in.setExcludeComments(subTree.excludeComments());
        } else {
            @SuppressWarnings("unchecked")
            Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData) data).iterator());
            in = new XMLSignatureInput(nodeSet);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = false");
        }
        try {
            in = new XMLSignatureInput(((OctetStreamData) data).getOctetStream());
        } catch (Exception ex) {
            throw new TransformException(ex);
        }
    }

    try {
        in = apacheTransform.performTransform(in, os);
        if (!in.isNodeSet() && !in.isElement()) {
            return null;
        }
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception ex) {
        throw new TransformException(ex);
    }
}

From source file:org.apache.jcp.xml.dsig.internal.dom.ApacheTransform.java

private Data transformIt(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException {
    if (ownerDoc == null) {
        throw new TransformException("transform must be marshalled");
    }/*from  w ww .  j  a va 2 s .c om*/

    if (apacheTransform == null) {
        try {
            apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
            apacheTransform.setElement(transformElem, xc.getBaseURI());
            if (log.isDebugEnabled()) {
                log.debug("Created transform for algorithm: " + getAlgorithm());
            }
        } catch (Exception ex) {
            throw new TransformException("Couldn't find Transform for: " + getAlgorithm(), ex);
        }
    }

    Boolean secureValidation = (Boolean) xc.getProperty("org.apache.jcp.xml.dsig.secureValidation");
    if (secureValidation != null && secureValidation.booleanValue()) {
        String algorithm = getAlgorithm();
        if (Transforms.TRANSFORM_XSLT.equals(algorithm)) {
            throw new TransformException(
                    "Transform " + algorithm + " is forbidden when secure validation is enabled");
        }
    }

    XMLSignatureInput in;
    if (data instanceof ApacheData) {
        if (log.isDebugEnabled()) {
            log.debug("ApacheData = true");
        }
        in = ((ApacheData) data).getXMLSignatureInput();
    } else if (data instanceof NodeSetData) {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = true");
        }
        if (data instanceof DOMSubTreeData) {
            if (log.isDebugEnabled()) {
                log.debug("DOMSubTreeData = true");
            }
            DOMSubTreeData subTree = (DOMSubTreeData) data;
            in = new XMLSignatureInput(subTree.getRoot());
            in.setExcludeComments(subTree.excludeComments());
        } else {
            @SuppressWarnings("unchecked")
            Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData) data).iterator());
            in = new XMLSignatureInput(nodeSet);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = false");
        }
        try {
            in = new XMLSignatureInput(((OctetStreamData) data).getOctetStream());
        } catch (Exception ex) {
            throw new TransformException(ex);
        }
    }

    try {
        if (os != null) {
            in = apacheTransform.performTransform(in, os);
            if (!in.isNodeSet() && !in.isElement()) {
                return null;
            }
        } else {
            in = apacheTransform.performTransform(in);
        }
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception ex) {
        throw new TransformException(ex);
    }
}

From source file:org.jcp.xml.dsig.internal.dom.ApacheCanonicalizer.java

public Data transform(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException {
    if (data == null) {
        throw new NullPointerException("data must not be null");
    }//from w  w  w  .j  a v  a 2 s. c  om
    if (os == null) {
        throw new NullPointerException("output stream must not be null");
    }

    if (ownerDoc == null) {
        throw new TransformException("transform must be marshalled");
    }

    if (apacheTransform == null) {
        try {
            apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
            apacheTransform.setElement(transformElem, xc.getBaseURI());
            if (log.isDebugEnabled()) {
                log.debug("Created transform for algorithm: " + getAlgorithm());
            }
        } catch (Exception ex) {
            throw new TransformException("Couldn't find Transform for: " + getAlgorithm(), ex);
        }
    }

    XMLSignatureInput in;
    if (data instanceof ApacheData) {
        if (log.isDebugEnabled()) {
            log.debug("ApacheData = true");
        }
        in = ((ApacheData) data).getXMLSignatureInput();
    } else if (data instanceof NodeSetData) {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = true");
        }
        if (data instanceof DOMSubTreeData) {
            DOMSubTreeData subTree = (DOMSubTreeData) data;
            in = new XMLSignatureInput(subTree.getRoot());
            in.setExcludeComments(subTree.excludeComments());
        } else {
            Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData) data).iterator());
            in = new XMLSignatureInput(nodeSet);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = false");
        }
        try {
            in = new XMLSignatureInput(((OctetStreamData) data).getOctetStream());
        } catch (Exception ex) {
            throw new TransformException(ex);
        }
    }

    try {
        in = apacheTransform.performTransform(in, os);
        if (!in.isNodeSet() && !in.isElement()) {
            return null;
        }
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception ex) {
        throw new TransformException(ex);
    }
}

From source file:org.jcp.xml.dsig.internal.dom.ApacheTransform.java

private Data transformIt(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException {
    if (ownerDoc == null) {
        throw new TransformException("transform must be marshalled");
    }//from  ww  w. j  av a2 s .  com

    if (apacheTransform == null) {
        try {
            apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
            apacheTransform.setElement(transformElem, xc.getBaseURI());
            if (log.isDebugEnabled()) {
                log.debug("Created transform for algorithm: " + getAlgorithm());
            }
        } catch (Exception ex) {
            throw new TransformException("Couldn't find Transform for: " + getAlgorithm(), ex);
        }
    }

    XMLSignatureInput in;
    if (data instanceof ApacheData) {
        if (log.isDebugEnabled()) {
            log.debug("ApacheData = true");
        }
        in = ((ApacheData) data).getXMLSignatureInput();
    } else if (data instanceof NodeSetData) {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = true");
        }
        if (data instanceof DOMSubTreeData) {
            if (log.isDebugEnabled()) {
                log.debug("DOMSubTreeData = true");
            }
            DOMSubTreeData subTree = (DOMSubTreeData) data;
            in = new XMLSignatureInput(subTree.getRoot());
            in.setExcludeComments(subTree.excludeComments());
        } else {
            Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData) data).iterator());
            in = new XMLSignatureInput(nodeSet);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("isNodeSet() = false");
        }
        try {
            in = new XMLSignatureInput(((OctetStreamData) data).getOctetStream());
        } catch (Exception ex) {
            throw new TransformException(ex);
        }
    }

    try {
        if (os != null) {
            in = apacheTransform.performTransform(in, os);
            if (!in.isNodeSet() && !in.isElement()) {
                return null;
            }
        } else {
            in = apacheTransform.performTransform(in);
        }
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception ex) {
        throw new TransformException(ex);
    }
}