1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2005 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 * 20 */ 21 /* 22 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. 23 */ 24 /* 25 * $Id: DOMXSLTTransform.java,v 1.2 2008/07/24 15:20:32 mullan Exp $ 26 */ 27 package org.jcp.xml.dsig.internal.dom; 28 29 import java.security.InvalidAlgorithmParameterException; 30 import org.w3c.dom.Element; 31 import org.w3c.dom.Node; 32 33 import javax.xml.crypto.*; 34 import javax.xml.crypto.dsig.*; 35 import javax.xml.crypto.dsig.spec.TransformParameterSpec; 36 import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec; 37 38 /** 39 * DOM-based implementation of XSLT Transform. 40 * (Uses Apache XML-Sec Transform implementation) 41 * 42 * @author Sean Mullan 43 */ 44 public final class DOMXSLTTransform extends ApacheTransform { 45 46 public void init(TransformParameterSpec params) 47 throws InvalidAlgorithmParameterException { 48 if (params == null) { 49 throw new InvalidAlgorithmParameterException("params are required"); 50 } 51 if (!(params instanceof XSLTTransformParameterSpec)) { 52 throw new InvalidAlgorithmParameterException("unrecognized params"); 53 } 54 this.params = params; 55 } 56 57 public void init(XMLStructure parent, XMLCryptoContext context) 58 throws InvalidAlgorithmParameterException { 59 60 super.init(parent, context); 61 unmarshalParams(DOMUtils.getFirstChildElement(transformElem)); 62 } 63 64 private void unmarshalParams(Element sheet) { 65 this.params = new XSLTTransformParameterSpec 66 (new javax.xml.crypto.dom.DOMStructure(sheet)); 67 } 68 69 public void marshalParams(XMLStructure parent, XMLCryptoContext context) 70 throws MarshalException { 71 super.marshalParams(parent, context); 72 XSLTTransformParameterSpec xp = 73 (XSLTTransformParameterSpec) getParameterSpec(); 74 Node xsltElem = 75 ((javax.xml.crypto.dom.DOMStructure) xp.getStylesheet()).getNode(); 76 DOMUtils.appendChild(transformElem, xsltElem); 77 } 78 }