src/java.base/share/classes/jdk/internal/util/xml/impl/XMLStreamWriterImpl.java
author rriggs
Fri, 23 Feb 2018 16:00:44 -0500
changeset 48944 25aa8b9f1dae
parent 48252 77b88d8f8380
child 53018 8bf9268df0e2
permissions -rw-r--r--
8198645: Use System.lineSeparator() instead of getProperty("line.separator") Reviewed-by: lancea, xuelei, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     1
/*
48944
25aa8b9f1dae 8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents: 48252
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     4
 *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    10
 *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    15
 * accompanied this code).
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    16
 *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    20
 *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    23
 * questions.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    24
 */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    25
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    26
package jdk.internal.util.xml.impl;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    27
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    28
import java.io.OutputStream;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    29
import java.io.UnsupportedEncodingException;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    30
import java.nio.charset.Charset;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    31
import java.nio.charset.IllegalCharsetNameException;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    32
import java.nio.charset.UnsupportedCharsetException;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    33
import jdk.internal.util.xml.XMLStreamException;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    34
import jdk.internal.util.xml.XMLStreamWriter;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    35
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    36
/**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    37
 * Implementation of a reduced version of XMLStreamWriter
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    38
 *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    39
 * @author Joe Wang
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    40
 */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    41
public class XMLStreamWriterImpl implements XMLStreamWriter {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    42
    //Document state
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    43
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    44
    static final int STATE_XML_DECL = 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    45
    static final int STATE_PROLOG = 2;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    46
    static final int STATE_DTD_DECL = 3;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    47
    static final int STATE_ELEMENT = 4;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    48
    //Element state
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    49
    static final int ELEMENT_STARTTAG_OPEN = 10;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    50
    static final int ELEMENT_STARTTAG_CLOSE = 11;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    51
    static final int ELEMENT_ENDTAG_OPEN = 12;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    52
    static final int ELEMENT_ENDTAG_CLOSE = 13;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    53
    public static final char CLOSE_START_TAG = '>';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    54
    public static final char OPEN_START_TAG = '<';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    55
    public static final String OPEN_END_TAG = "</";
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    56
    public static final char CLOSE_END_TAG = '>';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    57
    public static final String START_CDATA = "<![CDATA[";
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    58
    public static final String END_CDATA = "]]>";
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    59
    public static final String CLOSE_EMPTY_ELEMENT = "/>";
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    60
    public static final String ENCODING_PREFIX = "&#x";
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    61
    public static final char SPACE = ' ';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    62
    public static final char AMPERSAND = '&';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    63
    public static final char DOUBLEQUOT = '"';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    64
    public static final char SEMICOLON = ';';
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    65
    //current state
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    66
    private int _state = 0;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    67
    private Element _currentEle;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    68
    private XMLWriter _writer;
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    69
    private Charset _charset;
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    70
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    71
     * This flag can be used to turn escaping off for content. It does
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    72
     * not apply to attribute content.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    73
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    74
    boolean _escapeCharacters = true;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    75
    //pretty print by default
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    76
    private boolean _doIndent = true;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    77
    //The system line separator for writing out line breaks.
48944
25aa8b9f1dae 8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents: 48252
diff changeset
    78
    private char[] _lineSep = System.lineSeparator().toCharArray();
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    79
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    80
    public XMLStreamWriterImpl(OutputStream os) throws XMLStreamException {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    81
        this(os, XMLStreamWriter.DEFAULT_CHARSET);
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    82
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    83
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    84
    public XMLStreamWriterImpl(OutputStream os, Charset cs)
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    85
        throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    86
    {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    87
        if (cs == null) {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    88
            _charset = XMLStreamWriter.DEFAULT_CHARSET;
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    89
        } else {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    90
            try {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    91
                _charset = checkCharset(cs);
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    92
            } catch (UnsupportedEncodingException e) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    93
                throw new XMLStreamException(e);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    94
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    95
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    96
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    97
        _writer = new XMLWriter(os, null, _charset);
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    98
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
    99
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   100
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   101
     * Write the XML Declaration. Defaults the XML version to 1.0, and the
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   102
     * encoding to utf-8.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   103
     *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   104
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   105
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   106
    public void writeStartDocument() throws XMLStreamException {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   107
        writeStartDocument(_charset.name(), XMLStreamWriter.DEFAULT_XML_VERSION);
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   108
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   109
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   110
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   111
     * Write the XML Declaration. Defaults the encoding to utf-8
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   112
     *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   113
     * @param version version of the xml document
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   114
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   115
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   116
    public void writeStartDocument(String version) throws XMLStreamException {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   117
        writeStartDocument(_charset.name(), version, null);
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   118
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   119
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   120
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   121
     * Write the XML Declaration. Note that the encoding parameter does not set
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   122
     * the actual encoding of the underlying output. That must be set when the
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   123
     * instance of the XMLStreamWriter is created
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   124
     *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   125
     * @param encoding encoding of the xml declaration
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   126
     * @param version version of the xml document
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   127
     * @throws XMLStreamException If given encoding does not match encoding of the
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   128
     * underlying stream
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   129
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   130
    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   131
        writeStartDocument(encoding, version, null);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   132
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   133
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   134
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   135
     * Write the XML Declaration. Note that the encoding parameter does not set
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   136
     * the actual encoding of the underlying output. That must be set when the
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   137
     * instance of the XMLStreamWriter is created
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   138
     *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   139
     * @param encoding encoding of the xml declaration
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   140
     * @param version version of the xml document
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   141
     * @param standalone indicate if the xml document is standalone
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   142
     * @throws XMLStreamException If given encoding does not match encoding of the
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   143
     * underlying stream
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   144
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   145
    public void writeStartDocument(String encoding, String version, String standalone)
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   146
        throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   147
    {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   148
        if (_state > 0) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   149
            throw new XMLStreamException("XML declaration must be as the first line in the XML document.");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   150
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   151
        _state = STATE_XML_DECL;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   152
        String enc = encoding;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   153
        if (enc == null) {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   154
            enc = _charset.name();
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   155
        } else {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   156
            //check if the encoding is supported
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   157
            try {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   158
                getCharset(encoding);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   159
            } catch (UnsupportedEncodingException e) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   160
                throw new XMLStreamException(e);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   161
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   162
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   163
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   164
        if (version == null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   165
            version = XMLStreamWriter.DEFAULT_XML_VERSION;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   166
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   167
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   168
        _writer.write("<?xml version=\"");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   169
        _writer.write(version);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   170
        _writer.write(DOUBLEQUOT);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   171
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   172
        if (enc != null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   173
            _writer.write(" encoding=\"");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   174
            _writer.write(enc);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   175
            _writer.write(DOUBLEQUOT);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   176
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   177
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   178
        if (standalone != null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   179
            _writer.write(" standalone=\"");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   180
            _writer.write(standalone);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   181
            _writer.write(DOUBLEQUOT);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   182
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   183
        _writer.write("?>");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   184
        writeLineSeparator();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   185
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   186
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   187
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   188
     * Write a DTD section.  This string represents the entire doctypedecl production
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   189
     * from the XML 1.0 specification.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   190
     *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   191
     * @param dtd the DTD to be written
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   192
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   193
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   194
    public void writeDTD(String dtd) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   195
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   196
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   197
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   198
        _writer.write(dtd);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   199
        writeLineSeparator();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   200
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   201
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   202
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   203
     * Writes a start tag to the output.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   204
     * @param localName local name of the tag, may not be null
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   205
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   206
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   207
    public void writeStartElement(String localName) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   208
        if (localName == null || localName.length() == 0) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   209
            throw new XMLStreamException("Local Name cannot be null or empty");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   210
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   211
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   212
        _state = STATE_ELEMENT;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   213
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   214
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   215
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   216
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   217
        _currentEle = new Element(_currentEle, localName, false);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   218
        openStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   219
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   220
        _writer.write(localName);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   221
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   222
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   223
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   224
     * Writes an empty element tag to the output
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   225
     * @param localName local name of the tag, may not be null
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   226
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   227
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   228
    public void writeEmptyElement(String localName) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   229
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   230
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   231
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   232
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   233
        _currentEle = new Element(_currentEle, localName, true);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   234
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   235
        openStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   236
        _writer.write(localName);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   237
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   238
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   239
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   240
     * Writes an attribute to the output stream without a prefix.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   241
     * @param localName the local name of the attribute
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   242
     * @param value the value of the attribute
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   243
     * @throws IllegalStateException if the current state does not allow Attribute writing
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   244
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   245
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   246
    public void writeAttribute(String localName, String value) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   247
        if (_currentEle.getState() != ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   248
            throw new XMLStreamException(
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   249
                    "Attribute not associated with any element");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   250
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   251
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   252
        _writer.write(SPACE);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   253
        _writer.write(localName);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   254
        _writer.write("=\"");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   255
        writeXMLContent(
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   256
                value,
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   257
                true, // true = escapeChars
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   258
                true);  // true = escapeDoubleQuotes
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   259
        _writer.write(DOUBLEQUOT);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   260
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   261
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   262
    public void writeEndDocument() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   263
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   264
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   265
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   266
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   267
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   268
         * close unclosed elements if any
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   269
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   270
        while (_currentEle != null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   271
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   272
            if (!_currentEle.isEmpty()) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   273
                _writer.write(OPEN_END_TAG);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   274
                _writer.write(_currentEle.getLocalName());
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   275
                _writer.write(CLOSE_END_TAG);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   276
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   277
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   278
            _currentEle = _currentEle.getParent();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   279
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   280
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   281
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   282
    public void writeEndElement() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   283
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   284
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   285
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   286
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   287
        if (_currentEle == null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   288
            throw new XMLStreamException("No element was found to write");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   289
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   290
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   291
        if (_currentEle.isEmpty()) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   292
            return;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   293
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   294
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   295
        _writer.write(OPEN_END_TAG);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   296
        _writer.write(_currentEle.getLocalName());
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   297
        _writer.write(CLOSE_END_TAG);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   298
        writeLineSeparator();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   299
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   300
        _currentEle = _currentEle.getParent();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   301
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   302
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   303
    public void writeCData(String cdata) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   304
        if (cdata == null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   305
            throw new XMLStreamException("cdata cannot be null");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   306
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   307
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   308
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   309
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   310
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   311
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   312
        _writer.write(START_CDATA);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   313
        _writer.write(cdata);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   314
        _writer.write(END_CDATA);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   315
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   316
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   317
    public void writeCharacters(String data) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   318
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   319
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   320
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   321
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   322
        writeXMLContent(data);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   323
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   324
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   325
    public void writeCharacters(char[] data, int start, int len)
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   326
            throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   327
        if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   328
            closeStartTag();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   329
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   330
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   331
        writeXMLContent(data, start, len, _escapeCharacters);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   332
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   333
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   334
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   335
     * Close this XMLStreamWriter by closing underlying writer.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   336
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   337
    public void close() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   338
        if (_writer != null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   339
            _writer.close();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   340
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   341
        _writer = null;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   342
        _currentEle = null;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   343
        _state = 0;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   344
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   345
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   346
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   347
     * Flush this XMLStreamWriter by flushing underlying writer.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   348
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   349
    public void flush() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   350
        if (_writer != null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   351
            _writer.flush();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   352
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   353
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   354
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   355
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   356
     * Set the flag to indicate if the writer should add line separator
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   357
     * @param doIndent
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   358
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   359
    public void setDoIndent(boolean doIndent) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   360
        _doIndent = doIndent;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   361
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   362
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   363
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   364
     * Writes XML content to underlying writer. Escapes characters unless
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   365
     * escaping character feature is turned off.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   366
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   367
    private void writeXMLContent(char[] content, int start, int length, boolean escapeChars)
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   368
        throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   369
    {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   370
        if (!escapeChars) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   371
            _writer.write(content, start, length);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   372
            return;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   373
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   374
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   375
        // Index of the next char to be written
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   376
        int startWritePos = start;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   377
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   378
        final int end = start + length;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   379
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   380
        for (int index = start; index < end; index++) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   381
            char ch = content[index];
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   382
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   383
            if (!_writer.canEncode(ch)) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   384
                _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   385
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   386
                // Escape this char as underlying encoder cannot handle it
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   387
                _writer.write(ENCODING_PREFIX);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   388
                _writer.write(Integer.toHexString(ch));
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   389
                _writer.write(SEMICOLON);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   390
                startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   391
                continue;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   392
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   393
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   394
            switch (ch) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   395
                case OPEN_START_TAG:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   396
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   397
                    _writer.write("&lt;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   398
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   399
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   400
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   401
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   402
                case AMPERSAND:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   403
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   404
                    _writer.write("&amp;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   405
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   406
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   407
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   408
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   409
                case CLOSE_START_TAG:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   410
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   411
                    _writer.write("&gt;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   412
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   413
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   414
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   415
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   416
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   417
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   418
        // Write any pending data
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   419
        _writer.write(content, startWritePos, end - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   420
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   421
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   422
    private void writeXMLContent(String content) throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   423
        if ((content != null) && (content.length() > 0)) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   424
            writeXMLContent(content,
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   425
                    _escapeCharacters, // boolean = escapeChars
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   426
                    false);             // false = escapeDoubleQuotes
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   427
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   428
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   429
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   430
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   431
     * Writes XML content to underlying writer. Escapes characters unless
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   432
     * escaping character feature is turned off.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   433
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   434
    private void writeXMLContent(
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   435
            String content,
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   436
            boolean escapeChars,
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   437
            boolean escapeDoubleQuotes)
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   438
        throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   439
    {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   440
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   441
        if (!escapeChars) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   442
            _writer.write(content);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   443
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   444
            return;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   445
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   446
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   447
        // Index of the next char to be written
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   448
        int startWritePos = 0;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   449
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   450
        final int end = content.length();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   451
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   452
        for (int index = 0; index < end; index++) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   453
            char ch = content.charAt(index);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   454
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   455
            if (!_writer.canEncode(ch)) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   456
                _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   457
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   458
                // Escape this char as underlying encoder cannot handle it
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   459
                _writer.write(ENCODING_PREFIX);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   460
                _writer.write(Integer.toHexString(ch));
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   461
                _writer.write(SEMICOLON);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   462
                startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   463
                continue;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   464
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   465
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   466
            switch (ch) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   467
                case OPEN_START_TAG:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   468
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   469
                    _writer.write("&lt;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   470
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   471
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   472
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   473
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   474
                case AMPERSAND:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   475
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   476
                    _writer.write("&amp;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   477
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   478
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   479
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   480
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   481
                case CLOSE_START_TAG:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   482
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   483
                    _writer.write("&gt;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   484
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   485
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   486
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   487
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   488
                case DOUBLEQUOT:
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   489
                    _writer.write(content, startWritePos, index - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   490
                    if (escapeDoubleQuotes) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   491
                        _writer.write("&quot;");
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   492
                    } else {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   493
                        _writer.write(DOUBLEQUOT);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   494
                    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   495
                    startWritePos = index + 1;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   496
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   497
                    break;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   498
            }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   499
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   500
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   501
        // Write any pending data
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   502
        _writer.write(content, startWritePos, end - startWritePos);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   503
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   504
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   505
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   506
     * marks open of start tag and writes the same into the writer.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   507
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   508
    private void openStartTag() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   509
        _currentEle.setState(ELEMENT_STARTTAG_OPEN);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   510
        _writer.write(OPEN_START_TAG);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   511
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   512
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   513
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   514
     * marks close of start tag and writes the same into the writer.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   515
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   516
    private void closeStartTag() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   517
        if (_currentEle.isEmpty()) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   518
            _writer.write(CLOSE_EMPTY_ELEMENT);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   519
        } else {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   520
            _writer.write(CLOSE_START_TAG);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   521
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   522
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   523
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   524
        if (_currentEle.getParent() == null) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   525
            writeLineSeparator();
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   526
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   527
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   528
        _currentEle.setState(ELEMENT_STARTTAG_CLOSE);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   529
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   530
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   531
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   532
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   533
     * Write a line separator
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   534
     * @throws XMLStreamException
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   535
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   536
    private void writeLineSeparator() throws XMLStreamException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   537
        if (_doIndent) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   538
            _writer.write(_lineSep, 0, _lineSep.length);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   539
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   540
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   541
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   542
    /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   543
     * Returns a charset object for the specified encoding
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   544
     * @param encoding
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   545
     * @return a charset object
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   546
     * @throws UnsupportedEncodingException if the encoding is not supported
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   547
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   548
    private Charset getCharset(String encoding) throws UnsupportedEncodingException {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   549
        if (encoding.equalsIgnoreCase("UTF-32")) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   550
            throw new UnsupportedEncodingException("The basic XMLWriter does "
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   551
                    + "not support " + encoding);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   552
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   553
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   554
        Charset cs;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   555
        try {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   556
            cs = Charset.forName(encoding);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   557
        } catch (IllegalCharsetNameException | UnsupportedCharsetException ex) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   558
            throw new UnsupportedEncodingException(encoding);
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   559
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   560
        return cs;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   561
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   562
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   563
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   564
     * Checks for charset support.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   565
     * @param charset the specified charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   566
     * @return the charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   567
     * @throws UnsupportedEncodingException if the charset is not supported
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   568
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   569
    private Charset checkCharset(Charset charset) throws UnsupportedEncodingException {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   570
        if (charset.name().equalsIgnoreCase("UTF-32")) {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   571
            throw new UnsupportedEncodingException("The basic XMLWriter does "
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   572
                    + "not support " + charset.name());
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   573
        }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   574
        return charset;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   575
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   576
14908
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   577
    /*
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   578
     * Start of Internal classes.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   579
     *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   580
     */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   581
    protected class Element {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   582
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   583
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   584
         * the parent element
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   585
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   586
        protected Element _parent;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   587
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   588
         * The size of the stack.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   589
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   590
        protected short _Depth;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   591
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   592
         * indicate if an element is an empty one
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   593
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   594
        boolean _isEmptyElement = false;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   595
        String _localpart;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   596
        int _state;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   597
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   598
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   599
         * Default constructor.
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   600
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   601
        public Element() {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   602
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   603
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   604
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   605
         * @param parent the parent of the element
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   606
         * @param localpart name of the element
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   607
         * @param isEmpty indicate if the element is an empty one
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   608
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   609
        public Element(Element parent, String localpart, boolean isEmpty) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   610
            _parent = parent;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   611
            _localpart = localpart;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   612
            _isEmptyElement = isEmpty;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   613
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   614
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   615
        public Element getParent() {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   616
            return _parent;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   617
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   618
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   619
        public String getLocalName() {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   620
            return _localpart;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   621
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   622
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   623
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   624
         * get the state of the element
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   625
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   626
        public int getState() {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   627
            return _state;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   628
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   629
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   630
        /**
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   631
         * Set the state of the element
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   632
         *
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   633
         * @param state the state of the element
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   634
         */
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   635
        public void setState(int state) {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   636
            _state = state;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   637
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   638
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   639
        public boolean isEmpty() {
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   640
            return _isEmptyElement;
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   641
        }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   642
    }
1d01112e9ce5 8004371: (props) Properties.loadFromXML needs small footprint XML parser as fallback when JAXP is not present
joehw
parents:
diff changeset
   643
}