001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: package com.sun.xml.ws.security.opt.impl.dsig;
024:
025: import com.sun.xml.ws.security.opt.crypto.dsig.Reference;
026: import com.sun.xml.wss.impl.c14n.StAXEXC14nCanonicalizerImpl;
027: import javax.xml.namespace.NamespaceContext;
028: import javax.xml.stream.XMLStreamException;
029: import javax.xml.stream.XMLStreamWriter;
030: import org.jcp.xml.dsig.internal.DigesterOutputStream;
031:
032: /**
033: *
034: * @author K.Venugopal@sun.com
035: */
036: public class EnvelopedTransformWriter implements XMLStreamWriter {
037: private StAXEXC14nCanonicalizerImpl stAXC14n = null;
038: private JAXBSignatureHeaderElement signature = null;
039: private Reference ref = null;
040: private DigesterOutputStream dos = null;
041: private int index = 0;
042: private XMLStreamWriter writer = null;
043:
044: /** Creates a new instance of EnvelopedTransform */
045: public EnvelopedTransformWriter(XMLStreamWriter writer,
046: StAXEXC14nCanonicalizerImpl stAXC14n, Reference ref,
047: JAXBSignatureHeaderElement signature,
048: DigesterOutputStream dos) {
049: this .stAXC14n = stAXC14n;
050: this .writer = writer;
051: this .ref = ref;
052: this .signature = signature;
053: this .dos = dos;
054: }
055:
056: public NamespaceContext getNamespaceContext() {
057: return writer.getNamespaceContext();
058: }
059:
060: public void close() throws XMLStreamException {
061: //writer.close();
062: }
063:
064: public void flush() throws XMLStreamException {
065: writer.flush();
066: }
067:
068: public void writeEndDocument() throws XMLStreamException {
069: for (int i = 0; i < index; i++) {
070: stAXC14n.writeEndElement();
071: writer.writeEndElement();
072: }
073: }
074:
075: public void writeEndElement() throws XMLStreamException {
076: if (index == 0) {
077: return;
078: }
079: --index;
080: stAXC14n.writeEndElement();
081: ref.setDigestValue(dos.getDigestValue());
082:
083: signature.sign();
084:
085: signature.writeTo(writer);
086: writer.writeEndElement();
087: }
088:
089: public void writeStartDocument() throws XMLStreamException {
090: stAXC14n.writeStartDocument();
091: writer.writeStartDocument();
092: }
093:
094: public void writeCharacters(char[] c, int index, int len)
095: throws XMLStreamException {
096: stAXC14n.writeCharacters(c, index, len);
097: writer.writeCharacters(c, index, len);
098: }
099:
100: public void setDefaultNamespace(String string)
101: throws XMLStreamException {
102: writer.setDefaultNamespace(string);
103: stAXC14n.setDefaultNamespace(string);
104: }
105:
106: public void writeCData(String string) throws XMLStreamException {
107: stAXC14n.writeCData(string);
108: writer.writeCData(string);
109: }
110:
111: public void writeCharacters(String string)
112: throws XMLStreamException {
113: stAXC14n.writeCharacters(string);
114: writer.writeCharacters(string);
115: }
116:
117: public void writeComment(String string) throws XMLStreamException {
118: stAXC14n.writeComment(string);
119: writer.writeComment(string);
120: }
121:
122: public void writeDTD(String string) throws XMLStreamException {
123: stAXC14n.writeDTD(string);
124: writer.writeDTD(string);
125: }
126:
127: public void writeDefaultNamespace(String string)
128: throws XMLStreamException {
129: stAXC14n.writeDefaultNamespace(string);
130: writer.writeDefaultNamespace(string);
131: }
132:
133: public void writeEmptyElement(String string)
134: throws XMLStreamException {
135: stAXC14n.writeEmptyElement(string);
136: writer.writeEmptyElement(string);
137: }
138:
139: public void writeEntityRef(String string) throws XMLStreamException {
140: stAXC14n.writeEntityRef(string);
141: writer.writeEntityRef(string);
142: }
143:
144: public void writeProcessingInstruction(String string)
145: throws XMLStreamException {
146: stAXC14n.writeProcessingInstruction(string);
147: writer.writeProcessingInstruction(string);
148: }
149:
150: public void writeStartDocument(String string)
151: throws XMLStreamException {
152: stAXC14n.writeStartDocument(string);
153: writer.writeStartDocument(string);
154: }
155:
156: public void writeStartElement(String string)
157: throws XMLStreamException {
158: index++;
159: stAXC14n.writeStartElement(string);
160: writer.writeStartElement(string);
161: }
162:
163: public void setNamespaceContext(NamespaceContext namespaceContext)
164: throws XMLStreamException {
165: writer.setNamespaceContext(namespaceContext);
166: }
167:
168: public Object getProperty(String string)
169: throws IllegalArgumentException {
170: return writer.getProperty(string);
171: }
172:
173: public String getPrefix(String string) throws XMLStreamException {
174: return writer.getPrefix(string);
175: }
176:
177: public void setPrefix(String string, String string0)
178: throws XMLStreamException {
179: stAXC14n.setPrefix(string, string0);
180: writer.setPrefix(string, string0);
181: }
182:
183: public void writeAttribute(String string, String string0)
184: throws XMLStreamException {
185: stAXC14n.writeAttribute(string, string0);
186: writer.writeAttribute(string, string0);
187: }
188:
189: public void writeEmptyElement(String string, String string0)
190: throws XMLStreamException {
191: stAXC14n.writeEmptyElement(string, string0);
192: writer.writeEmptyElement(string, string0);
193: }
194:
195: public void writeNamespace(String string, String string0)
196: throws XMLStreamException {
197: stAXC14n.writeNamespace(string, string0);
198: writer.writeNamespace(string, string0);
199: }
200:
201: public void writeProcessingInstruction(String string, String string0)
202: throws XMLStreamException {
203: stAXC14n.writeProcessingInstruction(string, string0);
204: writer.writeProcessingInstruction(string, string0);
205: }
206:
207: public void writeStartDocument(String string, String string0)
208: throws XMLStreamException {
209: stAXC14n.writeStartDocument(string, string0);
210: writer.writeStartDocument(string, string0);
211: }
212:
213: public void writeStartElement(String string, String string0)
214: throws XMLStreamException {
215: index++;
216: stAXC14n.writeStartElement(string, string0);
217: writer.writeStartElement(string, string0);
218: }
219:
220: public void writeAttribute(String string, String string0,
221: String string1) throws XMLStreamException {
222: stAXC14n.writeAttribute(string, string0, string1);
223: writer.writeAttribute(string, string0, string1);
224: }
225:
226: public void writeEmptyElement(String string, String string0,
227: String string1) throws XMLStreamException {
228: stAXC14n.writeEmptyElement(string, string0, string1);
229: writer.writeEmptyElement(string, string0, string1);
230: }
231:
232: public void writeStartElement(String string, String string0,
233: String string1) throws XMLStreamException {
234: index++;
235: stAXC14n.writeStartElement(string, string0, string1);
236: writer.writeStartElement(string, string0, string1);
237: }
238:
239: public void writeAttribute(String string, String string0,
240: String string1, String string2) throws XMLStreamException {
241: stAXC14n.writeAttribute(string, string0, string1, string2);
242: writer.writeAttribute(string, string0, string1, string2);
243: }
244:
245: }
|