1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /** 6 * Licensed to the Apache Software Foundation (ASF) under one 7 * or more contributor license agreements. See the NOTICE file 8 * distributed with this work for additional information 9 * regarding copyright ownership. The ASF licenses this file 10 * to you under the Apache License, Version 2.0 (the 11 * "License"); you may not use this file except in compliance 12 * with the License. You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, 17 * software distributed under the License is distributed on an 18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 * KIND, either express or implied. See the License for the 20 * specific language governing permissions and limitations 21 * under the License. 22 */ 23 package com.sun.org.apache.xml.internal.security.transforms.implementations; 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.Canonicalizer20010315ExclOmitComments; 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.Transform; 32 import com.sun.org.apache.xml.internal.security.transforms.TransformSpi; 33 import com.sun.org.apache.xml.internal.security.transforms.Transforms; 34 import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces; 35 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 36 import org.w3c.dom.Element; 37 38 /** 39 * Class TransformC14NExclusive 40 * 41 */ 42 public class TransformC14NExclusive extends TransformSpi { 43 44 /** Field implementedTransformURI */ 45 public static final String implementedTransformURI = 46 Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS; 47 48 /** 49 * Method engineGetURI 50 * 51 * @inheritDoc 52 */ 53 protected String engineGetURI() { 54 return implementedTransformURI; 55 } 56 57 protected XMLSignatureInput enginePerformTransform( 58 XMLSignatureInput input, OutputStream os, Transform transformObject 59 ) throws CanonicalizationException { 60 try { 61 String inclusiveNamespaces = null; 62 63 if (transformObject.length( 64 InclusiveNamespaces.ExclusiveCanonicalizationNamespace, 65 InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1 66 ) { 67 Element inclusiveElement = 68 XMLUtils.selectNode( 69 transformObject.getElement().getFirstChild(), 70 InclusiveNamespaces.ExclusiveCanonicalizationNamespace, 71 InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 72 0 73 ); 74 75 inclusiveNamespaces = 76 new InclusiveNamespaces( 77 inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces(); 78 } 79 80 Canonicalizer20010315ExclOmitComments c14n = 81 new Canonicalizer20010315ExclOmitComments(); 82 if (os != null) { 83 c14n.setWriter(os); 84 } 85 byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces); 86 87 XMLSignatureInput output = new XMLSignatureInput(result); 88 if (os != null) { 89 output.setOutputStream(os); 90 } 91 return output; 92 } catch (XMLSecurityException ex) { 93 throw new CanonicalizationException("empty", ex); 94 } 95 } 96 }