J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * reserved comment block |
| 3 | * DO NOT REMOVE OR ALTER! |
| 4 | */ |
| 5 | /* |
| 6 | * Copyright 1999-2004 The Apache Software Foundation. |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | * |
| 20 | */ |
| 21 | package com.sun.org.apache.xml.internal.security.transforms.implementations; |
| 22 | |
| 23 | |
| 24 | |
| 25 | import java.io.OutputStream; |
| 26 | |
| 27 | import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException; |
| 28 | import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments; |
| 29 | import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; |
| 30 | import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; |
| 31 | import com.sun.org.apache.xml.internal.security.transforms.TransformSpi; |
| 32 | import com.sun.org.apache.xml.internal.security.transforms.Transforms; |
| 33 | import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces; |
| 34 | import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
| 35 | import org.w3c.dom.Element; |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Implements the <CODE>http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments</CODE> |
| 40 | * transform. |
| 41 | * |
| 42 | * @author Christian Geuer-Pollmann |
| 43 | */ |
| 44 | public class TransformC14NExclusiveWithComments extends TransformSpi { |
| 45 | |
| 46 | /** Field implementedTransformURI */ |
| 47 | public static final String implementedTransformURI = |
| 48 | Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS; |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * Method engineGetURI |
| 53 | *@inheritDoc |
| 54 | * |
| 55 | */ |
| 56 | protected String engineGetURI() { |
| 57 | return implementedTransformURI; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @inheritDoc |
| 62 | */ |
| 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 | Canonicalizer20010315ExclWithComments c14n = |
| 87 | new Canonicalizer20010315ExclWithComments(); |
| 88 | if (os!=null) { |
| 89 | c14n.setWriter( os); |
| 90 | } |
| 91 | input.setNeedsToBeExpanded(true); |
| 92 | byte []result; |
| 93 | result =c14n.engineCanonicalize(input, inclusiveNamespaces); |
| 94 | XMLSignatureInput output=new XMLSignatureInput(result); |
| 95 | |
| 96 | return output; |
| 97 | } catch (XMLSecurityException ex) { |
| 98 | throw new CanonicalizationException("empty", ex); |
| 99 | } |
| 100 | } |
| 101 | } |