jaxp/src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLEventWriterImpl.java
author joehw
Thu, 15 Dec 2016 13:57:04 -0800
changeset 42802 2a03abb03c06
parent 41432 c4036f85c0c5
permissions -rw-r--r--
8170556: Warnings cleanup related to JDK-8167340 Reviewed-by: dfuchs, lancea, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
41432
c4036f85c0c5 8139584: XMLStreamWriterImpl does not write 'standalone' property
joehw
parents: 25868
diff changeset
     2
 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    10
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * accompanied this code).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
 * questions.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
package com.sun.xml.internal.stream.writers;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    28
import java.util.Iterator;
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    29
import javax.xml.namespace.NamespaceContext;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
import javax.xml.namespace.QName;
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    31
import javax.xml.stream.XMLEventReader;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
import javax.xml.stream.XMLEventWriter;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    33
import javax.xml.stream.XMLStreamException;
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    34
import javax.xml.stream.XMLStreamWriter;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
import javax.xml.stream.events.Attribute;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    36
import javax.xml.stream.events.Characters;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    37
import javax.xml.stream.events.Comment;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    38
import javax.xml.stream.events.DTD;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
import javax.xml.stream.events.EntityReference;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    40
import javax.xml.stream.events.Namespace;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    41
import javax.xml.stream.events.ProcessingInstruction;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    42
import javax.xml.stream.events.StartDocument;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    43
import javax.xml.stream.events.StartElement;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
import javax.xml.stream.events.XMLEvent;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 *
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    48
 * @author Neeraj Bajaj, Sun Microsystems.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    51
public class XMLEventWriterImpl implements XMLEventWriter {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
    //delegate everything to XMLStreamWriter..
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    54
    private final XMLStreamWriterBase fStreamWriter;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
    private static final boolean DEBUG = false;
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    56
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
     * @param streamWriter
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    61
    public XMLEventWriterImpl(XMLStreamWriter streamWriter) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    62
        fStreamWriter = (XMLStreamWriterBase) streamWriter;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
     * @param xMLEventReader
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    70
    public void add(XMLEventReader xMLEventReader) throws XMLStreamException {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    71
        if (xMLEventReader == null) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    72
            throw new XMLStreamException("Event reader shouldn't be null");
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    73
        }
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    74
        while (xMLEventReader.hasNext()) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
            add(xMLEventReader.nextEvent());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
     * @param xMLEvent
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    84
    public void add(XMLEvent xMLEvent) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
        int type = xMLEvent.getEventType();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    86
        switch (type) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    87
            case XMLEvent.DTD: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    88
                DTD dtd = (DTD) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    89
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    90
                    System.out.println("Adding DTD = " + dtd.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    91
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
                fStreamWriter.writeDTD(dtd.getDocumentTypeDeclaration());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    95
            case XMLEvent.START_DOCUMENT: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    96
                StartDocument startDocument = (StartDocument) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    97
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    98
                    System.out.println("Adding StartDocument = " + startDocument.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    99
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
                try {
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   101
                    fStreamWriter.writeStartDocument(startDocument.getCharacterEncodingScheme(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   102
                            startDocument.getVersion(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   103
                            startDocument.isStandalone(), startDocument.standaloneSet());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   104
                } catch (XMLStreamException e) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
                    fStreamWriter.writeStartDocument(startDocument.getVersion());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   109
            case XMLEvent.START_ELEMENT: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   110
                StartElement startElement = xMLEvent.asStartElement();
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   111
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   112
                    System.out.println("Adding startelement = " + startElement.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   113
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
                QName qname = startElement.getName();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   115
                fStreamWriter.writeStartElement(qname.getPrefix(), qname.getLocalPart(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   116
                        qname.getNamespaceURI());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   118
                /*
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   119
                  getNamespaces() Returns an Iterator of namespaces declared on this element.
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   120
                This Iterator does not contain previously declared namespaces unless they
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   121
                appear on the current START_ELEMENT. Therefore this list may contain redeclared
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   122
                namespaces and duplicate namespace declarations. Use the getNamespaceContext()
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   123
                method to get the current context of namespace declarations. We should be
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   124
                using getNamespaces() to write namespace declarations for this START_ELEMENT
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   125
                */
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   126
                Iterator<? extends Namespace> iterator = startElement.getNamespaces();
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   127
                while (iterator.hasNext()) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   128
                    Namespace namespace = iterator.next();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
                    fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
                //REVISIT: What about writing attributes ?
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   132
                Iterator<? extends Attribute> attributes = startElement.getAttributes();
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   133
                while (attributes.hasNext()) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   134
                    Attribute attribute = attributes.next();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
                    QName aqname = attribute.getName();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   136
                    fStreamWriter.writeAttribute(aqname.getPrefix(), aqname.getNamespaceURI(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   137
                            aqname.getLocalPart(), attribute.getValue());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   141
            case XMLEvent.NAMESPACE: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   142
                Namespace namespace = (Namespace) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   143
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   144
                    System.out.println("Adding namespace = " + namespace.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   145
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   146
                fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   147
                break;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
            case XMLEvent.COMMENT: {
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   150
                Comment comment = (Comment) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   151
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   152
                    System.out.println("Adding comment = " + comment.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   153
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
                fStreamWriter.writeComment(comment.getText());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   157
            case XMLEvent.PROCESSING_INSTRUCTION: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   158
                ProcessingInstruction processingInstruction = (ProcessingInstruction) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   159
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   160
                    System.out.println("Adding processing instruction = " + processingInstruction.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   161
                }
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   162
                fStreamWriter.writeProcessingInstruction(processingInstruction.getTarget(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   163
                        processingInstruction.getData());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   166
            case XMLEvent.CHARACTERS: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
                Characters characters = xMLEvent.asCharacters();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   168
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   169
                    System.out.println("Adding characters = " + characters.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   170
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   171
                //check if the CHARACTERS are CDATA
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   172
                if (characters.isCData()) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
                    fStreamWriter.writeCData(characters.getData());
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   174
                } else {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
                    fStreamWriter.writeCharacters(characters.getData());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   179
            case XMLEvent.ENTITY_REFERENCE: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   180
                EntityReference entityReference = (EntityReference) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   181
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   182
                    System.out.println("Adding Entity Reference = " + entityReference.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   183
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
                fStreamWriter.writeEntityRef(entityReference.getName());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   187
            case XMLEvent.ATTRIBUTE: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   188
                Attribute attribute = (Attribute) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   189
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   190
                    System.out.println("Adding Attribute = " + attribute.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   191
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
                QName qname = attribute.getName();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   193
                fStreamWriter.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   194
                        qname.getLocalPart(), attribute.getValue());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   195
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   196
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   197
            case XMLEvent.CDATA: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
                //there is no separate CDATA datatype but CDATA event can be reported
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
                //by using vendor specific CDATA property.
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   200
                Characters characters = (Characters) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   201
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   202
                    System.out.println("Adding characters = " + characters.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   203
                }
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   204
                if (characters.isCData()) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
                    fStreamWriter.writeCData(characters.getData());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   207
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
            //xxx: Why there isn't any event called Notation.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
            //case XMLEvent.NOTATION_DECLARATION:{
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
            //}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   213
            case XMLEvent.END_ELEMENT: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
                fStreamWriter.writeEndElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   217
            case XMLEvent.END_DOCUMENT: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
                fStreamWriter.writeEndDocument();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
            //throw new XMLStreamException("Unknown Event type = " + type);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
        };
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   230
    public void close() throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
        fStreamWriter.close();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   232
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
     *
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   236
     * @throws XMLStreamException will inturn call flush on the stream to which
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   237
     * data is being written.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   238
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   239
    public void flush() throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   240
        fStreamWriter.flush();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   242
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   243
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   244
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   245
     * @return
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   246
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   247
    public NamespaceContext getNamespaceContext() {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
        return fStreamWriter.getNamespaceContext();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   250
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   252
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   253
     * @param namespaceURI Namespace URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
     * @return prefix associated with the URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   256
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   257
    public String getPrefix(String namespaceURI) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
        return fStreamWriter.getPrefix(namespaceURI);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   259
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   261
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   262
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
     * @param uri Namespace URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   264
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   265
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   266
    public void setDefaultNamespace(String uri) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   267
        fStreamWriter.setDefaultNamespace(uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   268
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   269
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   270
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   271
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   272
     * @param namespaceContext Namespace Context
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   273
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   274
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   275
    public void setNamespaceContext(NamespaceContext namespaceContext)
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   276
            throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   277
        fStreamWriter.setNamespaceContext(namespaceContext);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   278
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   279
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   280
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   281
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   282
     * @param prefix namespace prefix associated with the uri.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   283
     * @param uri Namespace URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   286
    public void setPrefix(String prefix, String uri) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
        fStreamWriter.setPrefix(prefix, uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
}//XMLEventWriterImpl