KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > transforms > implementations > TransformC14NExclusiveWithComments


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package com.sun.org.apache.xml.internal.security.transforms.implementations;
18
19
20
21 import java.io.OutputStream JavaDoc;
22
23 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
24 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
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 JavaDoc;
32
33
34 /**
35  * Implements the <CODE>http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments</CODE>
36  * transform.
37  *
38  * @author Christian Geuer-Pollmann
39  */

40 public class TransformC14NExclusiveWithComments extends TransformSpi {
41
42    /** Field implementedTransformURI */
43    public static final String JavaDoc implementedTransformURI =
44       Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS;
45
46
47    /**
48     * Method engineGetURI
49     *@inheritDoc
50     *
51     */

52    protected String JavaDoc engineGetURI() {
53       return implementedTransformURI;
54    }
55
56    /**
57     * @inheritDoc
58     */

59    protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input)
60            throws CanonicalizationException {
61         return enginePerformTransform(input,null);
62    }
63     protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream JavaDoc os)
64     throws CanonicalizationException {
65      try {
66         String JavaDoc inclusiveNamespaces = null;
67
68         if (this._transformObject
69                 .length(InclusiveNamespaces
70                    .ExclusiveCanonicalizationNamespace, InclusiveNamespaces
71                    ._TAG_EC_INCLUSIVENAMESPACES) == 1) {
72            Element JavaDoc inclusiveElement =
73                XMLUtils.selectNode(
74               this._transformObject.getElement().getFirstChild(),
75                  InclusiveNamespaces.ExclusiveCanonicalizationNamespace,
76                  InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,0);
77
78            inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement,
79                    this._transformObject.getBaseURI()).getInclusiveNamespaces();
80         }
81
82         Canonicalizer20010315ExclWithComments c14n =
83             new Canonicalizer20010315ExclWithComments();
84         if (os!=null) {
85            c14n.setWriter( os);
86         }
87         input.setNeedsToBeExpanded(true);
88         byte []result;
89         result =c14n.engineCanonicalize(input, inclusiveNamespaces);
90         XMLSignatureInput output=new XMLSignatureInput(result);
91         
92         return output;
93      } catch (XMLSecurityException ex) {
94         throw new CanonicalizationException("empty", ex);
95      }
96    }
97 }
98
Popular Tags