001: /*
002: * $Id: BaseXMLOutputFactory.java,v 1.2 2004/07/15 02:51:33 cniles Exp $
003: *
004: * Copyright (c) 2004, Christian Niles, unit12.net
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * * Neither the name of Christian Niles, Unit12, nor the names of its
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
025: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
031: * POSSIBILITY OF SUCH DAMAGE.
032: *
033: */
034: package javanet.staxutils;
035:
036: import java.io.OutputStream;
037: import java.io.OutputStreamWriter;
038: import java.io.UnsupportedEncodingException;
039: import java.io.Writer;
040:
041: import javanet.staxutils.XMLStreamEventWriter;
042:
043: import javax.xml.stream.XMLEventWriter;
044: import javax.xml.stream.XMLOutputFactory;
045: import javax.xml.stream.XMLStreamException;
046: import javax.xml.stream.XMLStreamWriter;
047: import javax.xml.transform.Result;
048:
049: /**
050: * Base {@link XMLOutputFactory} that provides common event functionality.
051: *
052: * @author Christian Niles
053: * @version $Revision: 1.2 $
054: */
055: public abstract class BaseXMLOutputFactory extends XMLOutputFactory {
056:
057: public XMLEventWriter createXMLEventWriter(OutputStream stream,
058: String encoding) throws XMLStreamException {
059:
060: try {
061:
062: return createXMLEventWriter(new OutputStreamWriter(stream,
063: encoding));
064:
065: } catch (UnsupportedEncodingException e) {
066:
067: throw new XMLStreamException(e);
068:
069: }
070:
071: }
072:
073: public XMLEventWriter createXMLEventWriter(OutputStream stream)
074: throws XMLStreamException {
075:
076: return createXMLEventWriter(new OutputStreamWriter(stream));
077:
078: }
079:
080: public XMLStreamWriter createXMLStreamWriter(OutputStream stream,
081: String encoding) throws XMLStreamException {
082:
083: try {
084:
085: return createXMLStreamWriter(new OutputStreamWriter(stream,
086: encoding));
087:
088: } catch (UnsupportedEncodingException e) {
089:
090: throw new XMLStreamException(e);
091:
092: }
093:
094: }
095:
096: public XMLStreamWriter createXMLStreamWriter(OutputStream stream)
097: throws XMLStreamException {
098:
099: return createXMLStreamWriter(new OutputStreamWriter(stream));
100:
101: }
102:
103: public XMLEventWriter createXMLEventWriter(Result result)
104: throws XMLStreamException {
105:
106: return createXMLEventWriter(createXMLStreamWriter(result));
107:
108: }
109:
110: /**
111: * Creates an {@link XMLEventWriter} that writes to the provided
112: * {@link XMLStreamWriter}.
113: *
114: * @param writer The destination stream.
115: * @return An {@link XMLEventWriter} that writes to the provided
116: * {@link XMLStreamWriter}.
117: */
118: public XMLEventWriter createXMLEventWriter(XMLStreamWriter writer) {
119:
120: return new XMLStreamEventWriter(writer);
121:
122: }
123:
124: public XMLEventWriter createXMLEventWriter(Writer stream)
125: throws XMLStreamException {
126:
127: return createXMLEventWriter(createXMLStreamWriter(stream));
128:
129: }
130:
131: public XMLStreamWriter createXMLStreamWriter(Result result)
132: throws XMLStreamException {
133:
134: // FIXME Support TrAX
135: throw new UnsupportedOperationException(
136: "TrAX result not supported");
137:
138: }
139:
140: public Object getProperty(String name)
141: throws IllegalArgumentException {
142:
143: throw new IllegalArgumentException(name
144: + " property isn't supported");
145:
146: }
147:
148: public boolean isPropertySupported(String name) {
149:
150: return false;
151:
152: }
153:
154: public void setProperty(String name, Object value)
155: throws IllegalArgumentException {
156:
157: throw new IllegalArgumentException(name
158: + " property isn't supported");
159:
160: }
161:
162: }
|