661N/A/*
661N/A * reserved comment block
661N/A * DO NOT REMOVE OR ALTER!
661N/A */
661N/A/*
661N/A * Copyright 2008 The Apache Software Foundation.
661N/A *
661N/A * Licensed under the Apache License, Version 2.0 (the "License");
661N/A * you may not use this file except in compliance with the License.
661N/A * You may obtain a copy of the License at
661N/A *
661N/A * http://www.apache.org/licenses/LICENSE-2.0
661N/A *
661N/A * Unless required by applicable law or agreed to in writing, software
661N/A * distributed under the License is distributed on an "AS IS" BASIS,
661N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
661N/A * See the License for the specific language governing permissions and
661N/A * limitations under the License.
661N/A *
661N/A */
661N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
661N/A */
661N/A/*
661N/A * $Id: DOMCanonicalXMLC14N11Method.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
661N/A */
661N/Apackage org.jcp.xml.dsig.internal.dom;
661N/A
661N/Aimport javax.xml.crypto.*;
661N/Aimport javax.xml.crypto.dsig.*;
661N/Aimport javax.xml.crypto.dsig.spec.TransformParameterSpec;
661N/A
661N/Aimport java.security.InvalidAlgorithmParameterException;
661N/A
661N/Aimport com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
661N/Aimport com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
661N/A
661N/A/**
661N/A * DOM-based implementation of CanonicalizationMethod for Canonical XML 1.1
661N/A * (with or without comments). Uses Apache XML-Sec Canonicalizer.
661N/A *
661N/A * @author Sean Mullan
661N/A */
661N/Apublic final class DOMCanonicalXMLC14N11Method extends ApacheCanonicalizer {
661N/A
661N/A public static final String C14N_11 = "http://www.w3.org/2006/12/xml-c14n11";
661N/A public static final String C14N_11_WITH_COMMENTS
661N/A = "http://www.w3.org/2006/12/xml-c14n11#WithComments";
661N/A
661N/A public void init(TransformParameterSpec params)
661N/A throws InvalidAlgorithmParameterException {
661N/A if (params != null) {
661N/A throw new InvalidAlgorithmParameterException("no parameters " +
661N/A "should be specified for Canonical XML 1.1 algorithm");
661N/A }
661N/A }
661N/A
661N/A public Data transform(Data data, XMLCryptoContext xc)
661N/A throws TransformException {
661N/A
661N/A // ignore comments if dereferencing same-document URI that requires
661N/A // you to omit comments, even if the Transform says otherwise -
661N/A // this is to be compliant with section 4.3.3.3 of W3C Rec.
661N/A if (data instanceof DOMSubTreeData) {
661N/A DOMSubTreeData subTree = (DOMSubTreeData) data;
661N/A if (subTree.excludeComments()) {
661N/A try {
661N/A apacheCanonicalizer = Canonicalizer.getInstance(C14N_11);
661N/A } catch (InvalidCanonicalizerException ice) {
661N/A throw new TransformException
661N/A ("Couldn't find Canonicalizer for: " +
661N/A C14N_11 + ": " + ice.getMessage(), ice);
661N/A }
661N/A }
661N/A }
661N/A
661N/A return canonicalize(data, xc);
661N/A }
661N/A}