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/* 24 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 25 */ 26/* 27 * $Id: DOMCanonicalXMLC14NMethod.java 1197150 2011-11-03 14:34:57Z coheigea $ 28 */ 29package org.jcp.xml.dsig.internal.dom; 30 31import javax.xml.crypto.*; 32import javax.xml.crypto.dsig.*; 33import javax.xml.crypto.dsig.spec.TransformParameterSpec; 34 35import java.security.InvalidAlgorithmParameterException; 36 37import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; 38import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException; 39 40/** 41 * DOM-based implementation of CanonicalizationMethod for Canonical XML 42 * (with or without comments). Uses Apache XML-Sec Canonicalizer. 43 * 44 * @author Sean Mullan 45 */ 46public final class DOMCanonicalXMLC14NMethod extends ApacheCanonicalizer { 47 48 public void init(TransformParameterSpec params) 49 throws InvalidAlgorithmParameterException { 50 if (params != null) { 51 throw new InvalidAlgorithmParameterException("no parameters " + 52 "should be specified for Canonical XML C14N algorithm"); 53 } 54 } 55 56 public Data transform(Data data, XMLCryptoContext xc) 57 throws TransformException { 58 59 // ignore comments if dereferencing same-document URI that requires 60 // you to omit comments, even if the Transform says otherwise - 61 // this is to be compliant with section 4.3.3.3 of W3C Rec. 62 if (data instanceof DOMSubTreeData) { 63 DOMSubTreeData subTree = (DOMSubTreeData) data; 64 if (subTree.excludeComments()) { 65 try { 66 apacheCanonicalizer = Canonicalizer.getInstance 67 (CanonicalizationMethod.INCLUSIVE); 68 } catch (InvalidCanonicalizerException ice) { 69 throw new TransformException 70 ("Couldn't find Canonicalizer for: " + 71 CanonicalizationMethod.INCLUSIVE + ": " + 72 ice.getMessage(), ice); 73 } 74 } 75 } 76 77 return canonicalize(data, xc); 78 } 79} 80