src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLEventWriterImpl.java
author joehw
Wed, 28 Aug 2019 19:02:51 +0000
changeset 57915 8570f22b9b6a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
57915
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, 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..
57915
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
    54
    private final XMLStreamWriter 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
    /**
57915
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
    58
     * Constructs an XMLEventWriterImpl that implements the standard XMLStreamWriter
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
    59
     * interface.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
     * @param streamWriter
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    62
    public XMLEventWriterImpl(XMLStreamWriter streamWriter) {
57915
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
    63
        fStreamWriter = streamWriter;
12005
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
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
     * @param xMLEventReader
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    71
    public void add(XMLEventReader xMLEventReader) throws XMLStreamException {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    72
        if (xMLEventReader == null) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    73
            throw new XMLStreamException("Event reader shouldn't be null");
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    74
        }
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    75
        while (xMLEventReader.hasNext()) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
            add(xMLEventReader.nextEvent());
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
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
     * @param xMLEvent
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    85
    public void add(XMLEvent xMLEvent) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
        int type = xMLEvent.getEventType();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    87
        switch (type) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    88
            case XMLEvent.DTD: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    89
                DTD dtd = (DTD) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    90
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    91
                    System.out.println("Adding DTD = " + dtd.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    92
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
                fStreamWriter.writeDTD(dtd.getDocumentTypeDeclaration());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    96
            case XMLEvent.START_DOCUMENT: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    97
                StartDocument startDocument = (StartDocument) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    98
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
    99
                    System.out.println("Adding StartDocument = " + startDocument.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   100
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
                try {
57915
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   102
                    if (XMLStreamWriterBase.class.isAssignableFrom(fStreamWriter.getClass())) {
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   103
                        // internal impl uses the extended interface
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   104
                        ((XMLStreamWriterBase)fStreamWriter).writeStartDocument(
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   105
                                startDocument.getCharacterEncodingScheme(),
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   106
                                startDocument.getVersion(),
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   107
                                startDocument.isStandalone(),
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   108
                                startDocument.standaloneSet());
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   109
                    } else {
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   110
                        fStreamWriter.writeStartDocument(
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   111
                                startDocument.getCharacterEncodingScheme(),
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   112
                                startDocument.getVersion());
8570f22b9b6a 8230094: CCE in createXMLEventWriter(Result) over an arbitrary XMLStreamWriter
joehw
parents: 47216
diff changeset
   113
                    }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   114
                } catch (XMLStreamException e) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
                    fStreamWriter.writeStartDocument(startDocument.getVersion());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   119
            case XMLEvent.START_ELEMENT: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   120
                StartElement startElement = xMLEvent.asStartElement();
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   121
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   122
                    System.out.println("Adding startelement = " + startElement.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   123
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
                QName qname = startElement.getName();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   125
                fStreamWriter.writeStartElement(qname.getPrefix(), qname.getLocalPart(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   126
                        qname.getNamespaceURI());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   128
                /*
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   129
                  getNamespaces() Returns an Iterator of namespaces declared on this element.
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   130
                This Iterator does not contain previously declared namespaces unless they
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   131
                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
   132
                namespaces and duplicate namespace declarations. Use the getNamespaceContext()
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   133
                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
   134
                using getNamespaces() to write namespace declarations for this START_ELEMENT
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   135
                */
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   136
                Iterator<? extends Namespace> iterator = startElement.getNamespaces();
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   137
                while (iterator.hasNext()) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   138
                    Namespace namespace = iterator.next();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
                    fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
                //REVISIT: What about writing attributes ?
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   142
                Iterator<? extends Attribute> attributes = startElement.getAttributes();
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   143
                while (attributes.hasNext()) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   144
                    Attribute attribute = attributes.next();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   145
                    QName aqname = attribute.getName();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   146
                    fStreamWriter.writeAttribute(aqname.getPrefix(), aqname.getNamespaceURI(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   147
                            aqname.getLocalPart(), attribute.getValue());
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
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   151
            case XMLEvent.NAMESPACE: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   152
                Namespace namespace = (Namespace) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   153
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   154
                    System.out.println("Adding namespace = " + namespace.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   155
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
                fStreamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   157
                break;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
            case XMLEvent.COMMENT: {
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   160
                Comment comment = (Comment) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   161
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   162
                    System.out.println("Adding comment = " + comment.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   163
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
                fStreamWriter.writeComment(comment.getText());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   166
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   167
            case XMLEvent.PROCESSING_INSTRUCTION: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   168
                ProcessingInstruction processingInstruction = (ProcessingInstruction) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   169
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   170
                    System.out.println("Adding processing instruction = " + processingInstruction.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   171
                }
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   172
                fStreamWriter.writeProcessingInstruction(processingInstruction.getTarget(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   173
                        processingInstruction.getData());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   176
            case XMLEvent.CHARACTERS: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
                Characters characters = xMLEvent.asCharacters();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   178
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   179
                    System.out.println("Adding characters = " + characters.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   180
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
                //check if the CHARACTERS are CDATA
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   182
                if (characters.isCData()) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   183
                    fStreamWriter.writeCData(characters.getData());
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   184
                } else {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
                    fStreamWriter.writeCharacters(characters.getData());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   188
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   189
            case XMLEvent.ENTITY_REFERENCE: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   190
                EntityReference entityReference = (EntityReference) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   191
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   192
                    System.out.println("Adding Entity Reference = " + entityReference.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   193
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
                fStreamWriter.writeEntityRef(entityReference.getName());
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.ATTRIBUTE: {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   198
                Attribute attribute = (Attribute) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   199
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   200
                    System.out.println("Adding Attribute = " + attribute.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   201
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
                QName qname = attribute.getName();
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   203
                fStreamWriter.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(),
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   204
                        qname.getLocalPart(), attribute.getValue());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   207
            case XMLEvent.CDATA: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
                //there is no separate CDATA datatype but CDATA event can be reported
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
                //by using vendor specific CDATA property.
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   210
                Characters characters = (Characters) xMLEvent;
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   211
                if (DEBUG) {
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   212
                    System.out.println("Adding characters = " + characters.toString());
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   213
                }
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   214
                if (characters.isCData()) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
                    fStreamWriter.writeCData(characters.getData());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   217
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
            //xxx: Why there isn't any event called Notation.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
            //case XMLEvent.NOTATION_DECLARATION:{
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
            //}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   223
            case XMLEvent.END_ELEMENT: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
                fStreamWriter.writeEndElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
            }
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   227
            case XMLEvent.END_DOCUMENT: {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
                fStreamWriter.writeEndDocument();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
                break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
            //throw new XMLStreamException("Unknown Event type = " + type);
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
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   238
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   240
    public void close() throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
        fStreamWriter.close();
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
     *
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   246
     * @throws XMLStreamException will inturn call flush on the stream to which
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   247
     * data is being written.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   249
    public void flush() throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   250
        fStreamWriter.flush();
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
     * @return
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 NamespaceContext getNamespaceContext() {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
        return fStreamWriter.getNamespaceContext();
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 namespaceURI 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
     * @return prefix associated with the URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   267
    public String getPrefix(String namespaceURI) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   268
        return fStreamWriter.getPrefix(namespaceURI);
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
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   273
     * @param uri Namespace URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   274
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   275
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   276
    public void setDefaultNamespace(String uri) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   277
        fStreamWriter.setDefaultNamespace(uri);
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 namespaceContext Namespace Context
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   283
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   285
    public void setNamespaceContext(NamespaceContext namespaceContext)
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   286
            throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
        fStreamWriter.setNamespaceContext(namespaceContext);
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
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
     * @param prefix namespace prefix associated with the uri.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
     * @param uri Namespace URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
     * @throws XMLStreamException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
     */
42802
2a03abb03c06 8170556: Warnings cleanup related to JDK-8167340
joehw
parents: 41432
diff changeset
   296
    public void setPrefix(String prefix, String uri) throws XMLStreamException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   297
        fStreamWriter.setPrefix(prefix, uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   299
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   300
}//XMLEventWriterImpl