blob: a6035a8f31de48b914df1ee7e8908142aa1a21fa [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: Transform.java,v 1.5 2005/05/10 16:03:48 mullan Exp $
27 */
28package javax.xml.crypto.dsig;
29
30import java.io.OutputStream;
31import java.security.spec.AlgorithmParameterSpec;
32import javax.xml.crypto.AlgorithmMethod;
33import javax.xml.crypto.Data;
34import javax.xml.crypto.OctetStreamData;
35import javax.xml.crypto.XMLCryptoContext;
36import javax.xml.crypto.XMLStructure;
37import javax.xml.crypto.dsig.spec.TransformParameterSpec;
38
39/**
40 * A representation of the XML <code>Transform</code> element as
41 * defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
42 * W3C Recommendation for XML-Signature Syntax and Processing</a>.
43 * The XML Schema Definition is defined as:
44 *
45 * <pre>
46 * &lt;element name="Transform" type="ds:TransformType"/&gt;
47 * &lt;complexType name="TransformType" mixed="true"&gt;
48 * &lt;choice minOccurs="0" maxOccurs="unbounded"&gt;
49 * &lt;any namespace="##other" processContents="lax"/&gt;
50 * &lt;!-- (1,1) elements from (0,unbounded) namespaces --&gt;
51 * &lt;element name="XPath" type="string"/&gt;
52 * &lt;/choice&gt;
53 * &lt;attribute name="Algorithm" type="anyURI" use="required"/&gt;
54 * &lt;/complexType&gt;
55 * </pre>
56 *
57 * A <code>Transform</code> instance may be created by invoking the
58 * {@link XMLSignatureFactory#newTransform newTransform} method
59 * of the {@link XMLSignatureFactory} class.
60 *
61 * @author Sean Mullan
62 * @author JSR 105 Expert Group
63 * @since 1.6
64 * @see XMLSignatureFactory#newTransform(String, TransformParameterSpec)
65 */
66public interface Transform extends XMLStructure, AlgorithmMethod {
67
68 /**
69 * The <a href="http://www.w3.org/2000/09/xmldsig#base64">Base64</a>
70 * transform algorithm URI.
71 */
72 final static String BASE64 = "http://www.w3.org/2000/09/xmldsig#base64";
73
74 /**
75 * The <a href="http://www.w3.org/2000/09/xmldsig#enveloped-signature">
76 * Enveloped Signature</a> transform algorithm URI.
77 */
78 final static String ENVELOPED =
79 "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
80
81 /**
82 * The <a href="http://www.w3.org/TR/1999/REC-xpath-19991116">XPath</a>
83 * transform algorithm URI.
84 */
85 final static String XPATH = "http://www.w3.org/TR/1999/REC-xpath-19991116";
86
87 /**
88 * The <a href="http://www.w3.org/2002/06/xmldsig-filter2">
89 * XPath Filter 2</a> transform algorithm URI.
90 */
91 final static String XPATH2 = "http://www.w3.org/2002/06/xmldsig-filter2";
92
93 /**
94 * The <a href="http://www.w3.org/TR/1999/REC-xslt-19991116">XSLT</a>
95 * transform algorithm URI.
96 */
97 final static String XSLT = "http://www.w3.org/TR/1999/REC-xslt-19991116";
98
99 /**
100 * Returns the algorithm-specific input parameters associated with this
101 * <code>Transform</code>.
102 * <p>
103 * The returned parameters can be typecast to a
104 * {@link TransformParameterSpec} object.
105 *
106 * @return the algorithm-specific input parameters (may be <code>null</code>
107 * if not specified)
108 */
109 AlgorithmParameterSpec getParameterSpec();
110
111 /**
112 * Transforms the specified data using the underlying transform algorithm.
113 *
114 * @param data the data to be transformed
115 * @param context the <code>XMLCryptoContext</code> containing
116 * additional context (may be <code>null</code> if not applicable)
117 * @return the transformed data
118 * @throws NullPointerException if <code>data</code> is <code>null</code>
119 * @throws TransformException if an error occurs while executing the
120 * transform
121 */
122 public abstract Data transform(Data data, XMLCryptoContext context)
123 throws TransformException;
124
125 /**
126 * Transforms the specified data using the underlying transform algorithm.
127 * If the output of this transform is an <code>OctetStreamData</code>, then
128 * this method returns <code>null</code> and the bytes are written to the
129 * specified <code>OutputStream</code>. Otherwise, the
130 * <code>OutputStream</code> is ignored and the method behaves as if
131 * {@link #transform(Data, XMLCryptoContext)} were invoked.
132 *
133 * @param data the data to be transformed
134 * @param context the <code>XMLCryptoContext</code> containing
135 * additional context (may be <code>null</code> if not applicable)
136 * @param os the <code>OutputStream</code> that should be used to write
137 * the transformed data to
138 * @return the transformed data (or <code>null</code> if the data was
139 * written to the <code>OutputStream</code> parameter)
140 * @throws NullPointerException if <code>data</code> or <code>os</code>
141 * is <code>null</code>
142 * @throws TransformException if an error occurs while executing the
143 * transform
144 */
145 public abstract Data transform
146 (Data data, XMLCryptoContext context, OutputStream os)
147 throws TransformException;
148}