1 17 package com.sun.org.apache.xml.internal.security.transforms; 18 19 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; 25 import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; 26 import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException; 27 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 28 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException; 29 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; 30 import com.sun.org.apache.xml.internal.security.utils.Constants; 31 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; 32 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 33 import org.w3c.dom.DOMException ; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.Element ; 36 import org.w3c.dom.NodeList ; 37 38 39 48 public class Transforms extends SignatureElementProxy { 49 50 51 static java.util.logging.Logger log = 52 java.util.logging.Logger.getLogger(Transforms.class.getName()); 53 55 public static final String TRANSFORM_C14N_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS; 56 57 public static final String TRANSFORM_C14N_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS; 58 59 public static final String TRANSFORM_C14N_EXCL_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS; 60 61 public static final String TRANSFORM_C14N_EXCL_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS; 62 63 public static final String TRANSFORM_XSLT = "http://www.w3.org/TR/1999/REC-xslt-19991116"; 64 65 public static final String TRANSFORM_BASE64_DECODE = Constants.SignatureSpecNS + "base64"; 66 67 public static final String TRANSFORM_XPATH = "http://www.w3.org/TR/1999/REC-xpath-19991116"; 68 69 public static final String TRANSFORM_ENVELOPED_SIGNATURE = Constants.SignatureSpecNS + "enveloped-signature"; 70 71 public static final String TRANSFORM_XPOINTER = "http://www.w3.org/TR/2001/WD-xptr-20010108"; 72 73 public static final String TRANSFORM_XPATH2FILTER04 = "http://www.w3.org/2002/04/xmldsig-filter2"; 74 75 public static final String TRANSFORM_XPATH2FILTER = "http://www.w3.org/2002/06/xmldsig-filter2"; 76 77 public static final String TRANSFORM_XPATHFILTERCHGP = "http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/#xpathFilter"; 78 Element []transforms; 80 85 public Transforms(Document doc) { 86 87 super(doc); 88 89 XMLUtils.addReturnToElement(this._constructionElement); 90 } 91 92 103 public Transforms(Element element, String BaseURI) 104 throws DOMException , XMLSignatureException, 105 InvalidTransformException, TransformationException, 106 XMLSecurityException { 107 108 super(element, BaseURI); 109 110 int numberOfTransformElems = this.getLength(); 111 112 if (numberOfTransformElems == 0) { 113 114 Object exArgs[] = { Constants._TAG_TRANSFORM, 116 Constants._TAG_TRANSFORMS }; 117 118 throw new TransformationException("xml.WrongContent", exArgs); 119 } 120 } 121 122 128 public void addTransform(String transformURI) 129 throws TransformationException { 130 131 try { 132 if (true) 133 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Transforms.addTransform(" + transformURI + ")"); 134 135 Transform transform = Transform.getInstance(this._doc, transformURI); 136 137 this.addTransform(transform); 138 } catch (InvalidTransformException ex) { 139 throw new TransformationException("empty", ex); 140 } 141 } 142 143 151 public void addTransform(String transformURI, Element contextElement) 152 throws TransformationException { 153 154 try { 155 if (true) 156 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Transforms.addTransform(" + transformURI + ")"); 157 158 Transform transform = Transform.getInstance(this._doc, transformURI, 159 contextElement); 160 161 this.addTransform(transform); 162 } catch (InvalidTransformException ex) { 163 throw new TransformationException("empty", ex); 164 } 165 } 166 167 175 public void addTransform(String transformURI, NodeList contextNodes) 176 throws TransformationException { 177 178 try { 179 Transform transform = Transform.getInstance(this._doc, transformURI, 180 contextNodes); 181 182 this.addTransform(transform); 183 } catch (InvalidTransformException ex) { 184 throw new TransformationException("empty", ex); 185 } 186 } 187 188 193 private void addTransform(Transform transform) { 194 if (true) 195 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Transforms.addTransform(" + transform.getURI() + ")"); 196 197 Element transformElement = transform.getElement(); 198 199 this._constructionElement.appendChild(transformElement); 200 XMLUtils.addReturnToElement(this._constructionElement); 201 } 202 203 210 public XMLSignatureInput performTransforms( 211 XMLSignatureInput xmlSignatureInput) throws TransformationException { 212 return performTransforms(xmlSignatureInput,null); 213 } 214 215 223 public XMLSignatureInput performTransforms( 224 XMLSignatureInput xmlSignatureInput,OutputStream os) throws TransformationException { 225 226 try { 227 int last=this.getLength()-1; 228 for (int i = 0; i < last; i++) { 229 Transform t = this.item(i); 230 if (true) { 231 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Preform the (" + i + ")th " + t.getURI() + " transform"); 232 } 233 xmlSignatureInput = t.performTransform(xmlSignatureInput); 234 } 235 if (last>=0) { 236 Transform t = this.item(last); 237 xmlSignatureInput = t.performTransform(xmlSignatureInput, os); 238 } 239 240 241 return xmlSignatureInput; 242 } catch (IOException ex) { 243 throw new TransformationException("empty", ex); 244 } catch (CanonicalizationException ex) { 247 throw new TransformationException("empty", ex); 248 } catch (InvalidCanonicalizerException ex) { 249 throw new TransformationException("empty", ex); 250 } 251 } 252 253 258 public int getLength() 259 { 260 266 if (transforms==null) { 267 transforms=XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(), 268 "Transform"); 269 } 270 return transforms.length; 271 } 272 273 281 public Transform item(int i) throws TransformationException { 282 283 try { 284 if (transforms==null) { 285 transforms=XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(), 286 "Transform"); 287 } 288 return new Transform(transforms[i], this._baseURI); 289 } catch (XMLSecurityException ex) { 290 throw new TransformationException("empty", ex); 291 } 292 } 293 294 295 public String getBaseLocalName() { 296 return Constants._TAG_TRANSFORMS; 297 } 298 } 299 | Popular Tags |