src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/DOM2TO.java
author joehw
Thu, 14 Nov 2019 18:41:04 +0000
changeset 59091 1c071f73949a
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233686: XML transformer uses excessive amount of memory Summary: remove unnecessary object creation and also update xalan.md file Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
59091
1c071f73949a 8233686: XML transformer uses excessive amount of memory
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     5
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xalan.internal.xsltc.trax;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import org.w3c.dom.NamedNodeMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import org.xml.sax.DTDHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.xml.sax.EntityResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import org.xml.sax.ErrorHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.xml.sax.ext.Locator2;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import org.xml.sax.SAXNotRecognizedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import org.xml.sax.SAXNotSupportedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import org.xml.sax.XMLReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.serializer.NamespaceMappings;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * @author Sunitha Reddy
59091
1c071f73949a 8233686: XML transformer uses excessive amount of memory
joehw
parents: 47216
diff changeset
    44
 * @LastModified: Nov 2019
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
public class DOM2TO implements XMLReader, Locator2 {
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    private final static String EMPTYSTRING = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    private static final String XMLNS_PREFIX = "xmlns";
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
     * A reference to the DOM to be traversed.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    private Node _dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
     * A reference to the output handler receiving the events.
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    private SerializationHandler _handler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    private String xmlVersion = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    private String xmlEncoding = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    public DOM2TO(Node root, SerializationHandler handler) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
        _dom = root;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
        _handler = handler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    public ContentHandler getContentHandler() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    public void setContentHandler(ContentHandler handler) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        // Empty
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    public void parse(InputSource unused) throws IOException, SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        parse(_dom);
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    public void parse() throws IOException, SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        if (_dom != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
            boolean isIncomplete =
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
                (_dom.getNodeType() != org.w3c.dom.Node.DOCUMENT_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
            if (isIncomplete) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
                _handler.startDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
                parse(_dom);
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
                _handler.endDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
                parse(_dom);
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     * Traverse the DOM and generate TO events for a handler. Notice that
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     * we need to handle implicit namespace declarations too.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    private void parse(Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        throws IOException, SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        if (node == null) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        switch (node.getNodeType()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        case Node.ATTRIBUTE_NODE:         // handled by ELEMENT_NODE
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        case Node.DOCUMENT_TYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        case Node.ENTITY_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
        case Node.ENTITY_REFERENCE_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        case Node.NOTATION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            // These node types are ignored!!!
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        case Node.CDATA_SECTION_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
            _handler.startCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
            _handler.characters(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
            _handler.endCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        case Node.COMMENT_NODE:           // should be handled!!!
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
            _handler.comment(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
        case Node.DOCUMENT_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
             setDocumentInfo((Document)node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
             _handler.setDocumentLocator(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
             _handler.startDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
            Node next = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            while (next != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
                parse(next);
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
                next = next.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            _handler.endDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        case Node.DOCUMENT_FRAGMENT_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
            next = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
            while (next != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                parse(next);
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                next = next.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        case Node.ELEMENT_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
            // Generate SAX event to start element
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
            final String qname = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
            _handler.startElement(null, null, qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            int colon;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
            String prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
            final NamedNodeMap map = node.getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
            final int length = map.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            // Process all namespace attributes first
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                final Node attr = map.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
                final String qnameAttr = attr.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
                // Is this a namespace declaration?
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
                if (qnameAttr.startsWith(XMLNS_PREFIX)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                    final String uriAttr = attr.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
                    colon = qnameAttr.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                    prefix = (colon > 0) ? qnameAttr.substring(colon + 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                                         : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                    _handler.namespaceAfterStartElement(prefix, uriAttr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
            // Process all non-namespace attributes next
59091
1c071f73949a 8233686: XML transformer uses excessive amount of memory
joehw
parents: 47216
diff changeset
   174
            NamespaceMappings nm = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
                final Node attr = map.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
                final String qnameAttr = attr.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
                // Is this a regular attribute?
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
                if (!qnameAttr.startsWith(XMLNS_PREFIX)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
                    final String uriAttr = attr.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
                    // Uri may be implicitly declared
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
                    if (uriAttr != null && !uriAttr.equals(EMPTYSTRING) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
                        colon = qnameAttr.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
                        // Fix for bug 26319
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
                        // For attributes not given an prefix explictly
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
                        // but having a namespace uri we need
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
                        // to explicitly generate the prefix
59091
1c071f73949a 8233686: XML transformer uses excessive amount of memory
joehw
parents: 47216
diff changeset
   190
                        if (nm == null) nm = new NamespaceMappings();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
                        String newPrefix = nm.lookupPrefix(uriAttr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
                        if (newPrefix == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
                            newPrefix = nm.generateNextPrefix();
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                        prefix = (colon > 0) ? qnameAttr.substring(0, colon)
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                            : newPrefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                        _handler.namespaceAfterStartElement(prefix, uriAttr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                        _handler.addAttribute((prefix + ":" + qnameAttr),
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                            attr.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                    } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
                         _handler.addAttribute(qnameAttr, attr.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            // Now element namespace and children
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
            final String uri = node.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            final String localName = node.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            // Uri may be implicitly declared
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
            if (uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
                colon = qname.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                prefix = (colon > 0) ? qname.substring(0, colon) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
                _handler.namespaceAfterStartElement(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            }else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
                  // Fix for bug 26319
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
                  // If an element foo is created using
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                  // createElementNS(null,locName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
                  // then the  element should be serialized
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                  // <foo xmlns=" "/>
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                  if (uri == null  && localName != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                     prefix = EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                     _handler.namespaceAfterStartElement(prefix, EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
                 }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
            // Traverse all child nodes of the element (if any)
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            next = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
            while (next != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                parse(next);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                next = next.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            // Generate SAX event to close element
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
            _handler.endElement(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        case Node.PROCESSING_INSTRUCTION_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            _handler.processingInstruction(node.getNodeName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
                                           node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        case Node.TEXT_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            _handler.characters(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    public DTDHandler getDTDHandler() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    public ErrorHandler getErrorHandler() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    public boolean getFeature(String name) throws SAXNotRecognizedException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        SAXNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    public void setFeature(String name, boolean value) throws
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        SAXNotRecognizedException, SAXNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
    public void parse(String sysId) throws IOException, SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        throw new IOException("This method is not yet implemented.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    public void setDTDHandler(DTDHandler handler) throws NullPointerException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    public void setEntityResolver(EntityResolver resolver) throws
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        NullPointerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    public EntityResolver getEntityResolver() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
    public void setErrorHandler(ErrorHandler handler) throws
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        NullPointerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    public void setProperty(String name, Object value) throws
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        SAXNotRecognizedException, SAXNotSupportedException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    public Object getProperty(String name) throws SAXNotRecognizedException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        SAXNotSupportedException
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    public int getColumnNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        return 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    public int getLineNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        return 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
    public String getPublicId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
     * This class is only used internally so this method should never
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
     * be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
    private void setDocumentInfo(Document document) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        if (!document.getXmlStandalone())
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
            _handler.setStandalone(Boolean.toString(document.getXmlStandalone()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        setXMLVersion(document.getXmlVersion());
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        setEncoding(document.getXmlEncoding());
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
    public String getXMLVersion() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        return xmlVersion;
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
    private void setXMLVersion(String version) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        if (version != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
            xmlVersion = version;
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
            _handler.setVersion(xmlVersion);
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
    public String getEncoding() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        return xmlEncoding;
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
    private void setEncoding(String encoding) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
        if (encoding != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
            xmlEncoding = encoding;
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
            _handler.setEncoding(encoding);
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    // Debugging
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    private String getNodeTypeFromCode(short code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        String retval = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        case Node.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
            retval = "ATTRIBUTE_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
        case Node.CDATA_SECTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
            retval = "CDATA_SECTION_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        case Node.COMMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
            retval = "COMMENT_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        case Node.DOCUMENT_FRAGMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
            retval = "DOCUMENT_FRAGMENT_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
        case Node.DOCUMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
            retval = "DOCUMENT_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        case Node.DOCUMENT_TYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
            retval = "DOCUMENT_TYPE_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
        case Node.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
            retval = "ELEMENT_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
        case Node.ENTITY_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
            retval = "ENTITY_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
        case Node.ENTITY_REFERENCE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
            retval = "ENTITY_REFERENCE_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        case Node.NOTATION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            retval = "NOTATION_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
        case Node.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
            retval = "PROCESSING_INSTRUCTION_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
        case Node.TEXT_NODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
            retval = "TEXT_NODE"; break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        return retval;
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
}