jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMXSLTTransform.java
changeset 2 90ce3da70b43
child 1337 e8d6cef36199
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMXSLTTransform.java	Sat Dec 01 00:00:00 2007 +0000
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * $Id: DOMXSLTTransform.java,v 1.15 2005/05/10 18:15:36 mullan Exp $
+ */
+package org.jcp.xml.dsig.internal.dom;
+
+import java.security.InvalidAlgorithmParameterException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import javax.xml.crypto.*;
+import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.dsig.spec.TransformParameterSpec;
+import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
+
+/**
+ * DOM-based implementation of XSLT Transform.
+ * (Uses Apache XML-Sec Transform implementation)
+ *
+ * @author Sean Mullan
+ */
+public final class DOMXSLTTransform extends ApacheTransform {
+
+    public void init(TransformParameterSpec params)
+        throws InvalidAlgorithmParameterException {
+        if (params == null) {
+            throw new InvalidAlgorithmParameterException("params are required");
+        }
+        if (!(params instanceof XSLTTransformParameterSpec)) {
+            throw new InvalidAlgorithmParameterException("unrecognized params");
+        }
+        this.params = params;
+    }
+
+    public void init(XMLStructure parent, XMLCryptoContext context)
+        throws InvalidAlgorithmParameterException {
+
+        super.init(parent, context);
+        unmarshalParams(DOMUtils.getFirstChildElement(transformElem));
+    }
+
+    private void unmarshalParams(Element sheet) {
+        this.params = new XSLTTransformParameterSpec
+            (new javax.xml.crypto.dom.DOMStructure(sheet));
+    }
+
+    public void marshalParams(XMLStructure parent, XMLCryptoContext context)
+        throws MarshalException {
+        super.marshalParams(parent, context);
+        XSLTTransformParameterSpec xp =
+            (XSLTTransformParameterSpec) getParameterSpec();
+        Node xsltElem =
+            ((javax.xml.crypto.dom.DOMStructure) xp.getStylesheet()).getNode();
+        DOMUtils.appendChild(transformElem, xsltElem);
+    }
+}