aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.org.jvnet.staxex; aoqi@0: aoqi@0: import javax.activation.DataHandler; aoqi@0: import javax.xml.stream.XMLStreamException; aoqi@0: import javax.xml.stream.XMLStreamWriter; aoqi@0: import java.io.OutputStream; aoqi@0: aoqi@0: /** aoqi@0: * {@link XMLStreamWriter} extended to support XOP. aoqi@0: * aoqi@0: *

aoqi@0: * Some infoset serializer (such as XOP encoder, FastInfoset) uses a format aoqi@0: * that can represent binary data more efficiently than base64 encoding. aoqi@0: * Such infoset serializer may choose to implement this interface, to allow aoqi@0: * the caller to pass in binary data more efficiently without first converting aoqi@0: * it to binary data. aoqi@0: * aoqi@0: *

aoqi@0: * Callers capable of using this interface can see if the serializer supports aoqi@0: * it by simply downcasting {@link XMLStreamWriter} to {@link XMLStreamWriterEx}. aoqi@0: * aoqi@0: *

TODO

aoqi@0: *
    aoqi@0: *
  1. aoqi@0: * Add methods to write other primitive types, such as hex and integers aoqi@0: * (and arrays of). aoqi@0: * A textual implementation would write characters in accordance aoqi@0: * to the canonical lexical definitions specified in W3C XML Schema: datatypes. aoqi@0: * A MTOM implementation would write characters except for the case where octets aoqi@0: * that would otherwise be base64 encoded when using the textual implementation. aoqi@0: * A Fast Infoset implementation would encoded binary data the primitive types in aoqi@0: * binary form. aoqi@0: *
  2. aoqi@0: * Consider renaming writeBinary to writeBytesAsBase64 to be consistent with aoqi@0: * infoset abstraction. aoqi@0: *
  3. aoqi@0: * Add the ability to writeStart and writeEnd on attributes so that the same aoqi@0: * methods for writing primitive types (and characters, which will require new methods) aoqi@0: * can be used for writing attribute values as well as element content. aoqi@0: *
aoqi@0: * aoqi@0: * @see XMLStreamReaderEx aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: * @author Paul Sandoz aoqi@0: */ aoqi@0: public interface XMLStreamWriterEx extends XMLStreamWriter { aoqi@0: aoqi@0: /** aoqi@0: * Write the binary data. aoqi@0: * aoqi@0: *

aoqi@0: * Conceptually (infoset-wise), this produces the base64-encoded binary data on the aoqi@0: * output. But this allows implementations like FastInfoset or XOP to do the smart aoqi@0: * thing. aoqi@0: * aoqi@0: *

aoqi@0: * The use of this method has some restriction to support XOP. Namely, this method aoqi@0: * must be invoked as a sole content of an element. aoqi@0: * aoqi@0: *

aoqi@0: * (data,start,len) triplet identifies the binary data to be written. aoqi@0: * After the method invocation, the callee owns the buffer. aoqi@0: * aoqi@0: * @param contentType aoqi@0: * this mandatory parameter identifies the MIME type of the binary data. aoqi@0: * If the MIME type isn't known by the caller, "application/octet-stream" can aoqi@0: * be always used to indicate "I don't know." Never null. aoqi@0: */ aoqi@0: void writeBinary(byte[] data, int start, int len, String contentType) throws XMLStreamException; aoqi@0: aoqi@0: /** aoqi@0: * Writes the binary data. aoqi@0: * aoqi@0: *

aoqi@0: * This method works like the {@link #writeBinary(byte[], int, int, String)} method, aoqi@0: * except that it takes the binary data in the form of {@link DataHandler}, which aoqi@0: * contains a MIME type ({@link DataHandler#getContentType()} as well as the payload aoqi@0: * {@link DataHandler#getInputStream()}. aoqi@0: * aoqi@0: * @param data aoqi@0: * always non-null. After this method call, the callee owns the data handler. aoqi@0: */ aoqi@0: void writeBinary(DataHandler data) throws XMLStreamException; aoqi@0: aoqi@0: /** aoqi@0: * Writes the binary data. aoqi@0: * aoqi@0: *

aoqi@0: * This version of the writeBinary method allows the caller to produce aoqi@0: * the binary data by writing it to {@link OutputStream}. aoqi@0: * aoqi@0: *

aoqi@0: * It is the caller's responsibility to write and close aoqi@0: * a stream before it invokes any other methods on {@link XMLStreamWriter}. aoqi@0: * aoqi@0: * TODO: experimental. appreciate feedback aoqi@0: * @param contentType aoqi@0: * See the content-type parameter of aoqi@0: * {@link #writeBinary(byte[], int, int, String)}. Must not be null. aoqi@0: * aoqi@0: * @return aoqi@0: * always return a non-null {@link OutputStream}. aoqi@0: */ aoqi@0: OutputStream writeBinary(String contentType) throws XMLStreamException; aoqi@0: aoqi@0: /** aoqi@0: * Writes like {@link #writeCharacters(String)} but hides aoqi@0: * actual data format. aoqi@0: * aoqi@0: * @param data aoqi@0: * The {@link CharSequence} that represents the aoqi@0: * character infoset items to be written. aoqi@0: * aoqi@0: *

aoqi@0: * The {@link CharSequence} is normally a {@link String}, aoqi@0: * but can be any other {@link CharSequence} implementation. aoqi@0: * For binary data, however, use of {@link Base64Data} is aoqi@0: * recommended (so that the consumer interested in seeing it aoqi@0: * as binary data may take advantage of mor efficient aoqi@0: * data representation.) aoqi@0: * aoqi@0: */ aoqi@0: void writePCDATA(CharSequence data) throws XMLStreamException; aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: NamespaceContextEx getNamespaceContext(); aoqi@0: }