blob: 954ce7c575ad036ee87d2fb2396c6a07345b248f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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 */
21package com.sun.org.apache.xml.internal.security.transforms.implementations;
22
23
24
25import java.io.OutputStream;
26
27import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
28import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
29import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
30import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
31import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
32import com.sun.org.apache.xml.internal.security.transforms.Transforms;
33import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces;
34import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
35import org.w3c.dom.Element;
36
37
38/**
39 * Class TransformC14NExclusive
40 *
41 * @author $Author: raul $
42 */
43public class TransformC14NExclusive extends TransformSpi {
44
45 /** Field implementedTransformURI */
46 public static final String implementedTransformURI =
47 Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS;
48
49
50 /**
51 * Method engineGetURI
52 *
53 * @inheritDoc
54 */
55 protected String engineGetURI() {
56 return implementedTransformURI;
57 }
58
59 /**
60 * Method enginePerformTransform
61 *
62 * @param input
63 * @return the transformed of the input
64 * @throws CanonicalizationException
65 */
66 protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input)
67 throws CanonicalizationException {
68 return enginePerformTransform(input,null);
69 }
70 protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream os)
71 throws CanonicalizationException {
72 try {
73 String inclusiveNamespaces = null;
74
75 if (this._transformObject
76 .length(InclusiveNamespaces
77 .ExclusiveCanonicalizationNamespace, InclusiveNamespaces
78 ._TAG_EC_INCLUSIVENAMESPACES) == 1) {
79 Element inclusiveElement =
80 XMLUtils.selectNode(
81 this._transformObject.getElement().getFirstChild(),
82 InclusiveNamespaces.ExclusiveCanonicalizationNamespace,
83 InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,0);
84
85 inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement,
86 this._transformObject.getBaseURI()).getInclusiveNamespaces();
87 }
88
89 Canonicalizer20010315ExclOmitComments c14n =
90 new Canonicalizer20010315ExclOmitComments();
91 if (os!=null) {
92 c14n.setWriter(os);
93 }
94 byte []result;
95 input.setNeedsToBeExpanded(true);
96 result =c14n.engineCanonicalize(input, inclusiveNamespaces);
97
98 XMLSignatureInput output=new XMLSignatureInput(result);
99 if (os!=null) {
100 output.setOutputStream(os);
101 }
102 return output;
103 } catch (XMLSecurityException ex) {
104 throw new CanonicalizationException("empty", ex);
105 }
106 }
107}