1 17 package com.sun.org.apache.xml.internal.security.transforms.implementations; 18 19 20 21 import java.io.OutputStream ; 22 23 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; 24 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments; 25 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 26 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 27 import com.sun.org.apache.xml.internal.security.transforms.TransformSpi; 28 import com.sun.org.apache.xml.internal.security.transforms.Transforms; 29 import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces; 30 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 31 import org.w3c.dom.Element ; 32 33 34 40 public class TransformC14NExclusive extends TransformSpi { 41 42 43 public static final String implementedTransformURI = 44 Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS; 45 46 47 52 protected String engineGetURI() { 53 return implementedTransformURI; 54 } 55 56 63 protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input) 64 throws CanonicalizationException { 65 return enginePerformTransform(input,null); 66 } 67 protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream os) 68 throws CanonicalizationException { 69 try { 70 String inclusiveNamespaces = null; 71 72 if (this._transformObject 73 .length(InclusiveNamespaces 74 .ExclusiveCanonicalizationNamespace, InclusiveNamespaces 75 ._TAG_EC_INCLUSIVENAMESPACES) == 1) { 76 Element inclusiveElement = 77 XMLUtils.selectNode( 78 this._transformObject.getElement().getFirstChild(), 79 InclusiveNamespaces.ExclusiveCanonicalizationNamespace, 80 InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,0); 81 82 inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, 83 this._transformObject.getBaseURI()).getInclusiveNamespaces(); 84 } 85 86 Canonicalizer20010315ExclOmitComments c14n = 87 new Canonicalizer20010315ExclOmitComments(); 88 if (os!=null) { 89 c14n.setWriter(os); 90 } 91 byte []result; 92 input.setNeedsToBeExpanded(true); 93 result =c14n.engineCanonicalize(input, inclusiveNamespaces); 94 95 XMLSignatureInput output=new XMLSignatureInput(result); 96 if (os!=null) { 97 output.setOutputStream(os); 98 } 99 return output; 100 } catch (XMLSecurityException ex) { 101 throw new CanonicalizationException("empty", ex); 102 } 103 } 104 } 105 | Popular Tags |