blob: 96a0a9a21d38fbacd67cf5b90116ea7243951c71 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25/*
26 * $Id: DOMXSLTTransform.java,v 1.15 2005/05/10 18:15:36 mullan Exp $
27 */
28package org.jcp.xml.dsig.internal.dom;
29
30import java.security.InvalidAlgorithmParameterException;
31import org.w3c.dom.Element;
32import org.w3c.dom.Node;
33
34import javax.xml.crypto.*;
35import javax.xml.crypto.dsig.*;
36import javax.xml.crypto.dsig.spec.TransformParameterSpec;
37import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
38
39/**
40 * DOM-based implementation of XSLT Transform.
41 * (Uses Apache XML-Sec Transform implementation)
42 *
43 * @author Sean Mullan
44 */
45public final class DOMXSLTTransform extends ApacheTransform {
46
47 public void init(TransformParameterSpec params)
48 throws InvalidAlgorithmParameterException {
49 if (params == null) {
50 throw new InvalidAlgorithmParameterException("params are required");
51 }
52 if (!(params instanceof XSLTTransformParameterSpec)) {
53 throw new InvalidAlgorithmParameterException("unrecognized params");
54 }
55 this.params = params;
56 }
57
58 public void init(XMLStructure parent, XMLCryptoContext context)
59 throws InvalidAlgorithmParameterException {
60
61 super.init(parent, context);
62 unmarshalParams(DOMUtils.getFirstChildElement(transformElem));
63 }
64
65 private void unmarshalParams(Element sheet) {
66 this.params = new XSLTTransformParameterSpec
67 (new javax.xml.crypto.dom.DOMStructure(sheet));
68 }
69
70 public void marshalParams(XMLStructure parent, XMLCryptoContext context)
71 throws MarshalException {
72 super.marshalParams(parent, context);
73 XSLTTransformParameterSpec xp =
74 (XSLTTransformParameterSpec) getParameterSpec();
75 Node xsltElem =
76 ((javax.xml.crypto.dom.DOMStructure) xp.getStylesheet()).getNode();
77 DOMUtils.appendChild(transformElem, xsltElem);
78 }
79}