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.Canonicalizer20010315OmitComments; |
| 29 | import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; |
| 30 | import com.sun.org.apache.xml.internal.security.transforms.TransformSpi; |
| 31 | import com.sun.org.apache.xml.internal.security.transforms.Transforms; |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * Implements the <CODE>http://www.w3.org/TR/2001/REC-xml-c14n-20010315</CODE> |
| 36 | * transform. |
| 37 | * |
| 38 | * @author Christian Geuer-Pollmann |
| 39 | */ |
| 40 | public class TransformC14N extends TransformSpi { |
| 41 | |
| 42 | /** Field implementedTransformURI */ |
| 43 | public static final String implementedTransformURI = |
| 44 | Transforms.TRANSFORM_C14N_OMIT_COMMENTS; |
| 45 | |
| 46 | |
| 47 | /** |
| 48 | * @inheritDoc |
| 49 | */ |
| 50 | protected String engineGetURI() { |
| 51 | return TransformC14N.implementedTransformURI; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @inheritDoc |
| 56 | */ |
| 57 | protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input) |
| 58 | throws CanonicalizationException { |
| 59 | return enginePerformTransform(input,null); |
| 60 | } |
| 61 | protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream os) |
| 62 | throws CanonicalizationException { |
| 63 | Canonicalizer20010315OmitComments c14n = new Canonicalizer20010315OmitComments(); |
| 64 | if (os!=null) { |
| 65 | c14n.setWriter(os); |
| 66 | } |
| 67 | byte[] result = null; |
| 68 | input.setNeedsToBeExpanded(true); |
| 69 | result=c14n.engineCanonicalize(input); |
| 70 | XMLSignatureInput output=new XMLSignatureInput(result); |
| 71 | if (os!=null) { |
| 72 | output.setOutputStream(os); |
| 73 | } |
| 74 | return output; |
| 75 | } |
| 76 | } |