src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/dom2dtm/DOM2DTM.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 47477 115ed64c7822
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * 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
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * 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
    10
 * (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
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.dtm.ref.dom2dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xml.internal.dtm.DTMManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBaseIterators;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.dtm.ref.ExpandedNameTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.dtm.ref.IncrementalSAXSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.res.XMLErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.res.XMLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.utils.FastStringBuffer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.utils.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.utils.StringBufferPool;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.utils.TreeWalker;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.utils.XMLCharacterRecognizer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.utils.XMLString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    40
import java.util.ArrayList;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    41
import java.util.List;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    42
import javax.xml.transform.SourceLocator;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    43
import javax.xml.transform.dom.DOMSource;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import org.w3c.dom.Attr;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import org.w3c.dom.DocumentType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import org.w3c.dom.Element;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import org.w3c.dom.Entity;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import org.w3c.dom.NamedNodeMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
/** The <code>DOM2DTM</code> class serves up a DOM's contents via the
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * DTM API.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * Note that it doesn't necessarily represent a full Document
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * tree. You can wrap a DOM2DTM around a specific node and its subtree
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * and the right things should happen. (I don't _think_ we currently
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * support DocumentFrgment nodes as roots, though that might be worth
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * considering.)
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * Note too that we do not currently attempt to track document
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * mutation. If you alter the DOM after wrapping DOM2DTM around it,
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * all bets are off.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 * */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
public class DOM2DTM extends DTMDefaultBaseIterators
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  static final boolean JJK_DEBUG=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  static final boolean JJK_NEWCODE=true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  /** Manefest constant
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  static final String NAMESPACE_DECL_NS="http://www.w3.org/XML/1998/namespace";
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  /** The current position in the DOM tree. Last node examined for
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   * possible copying to DTM. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  transient private Node m_pos;
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  /** The current position in the DTM tree. Who children get appended to. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  private int m_last_parent=0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
  /** The current position in the DTM tree. Who children reference as their
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * previous sib. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
  private int m_last_kid=NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  /** The top of the subtree.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   * %REVIEW%: 'may not be the same as m_context if "//foo" pattern.'
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  transient private Node m_root;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  /** True iff the first element has been processed. This is used to control
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
      synthesis of the implied xml: namespace declaration node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  boolean m_processedFirstElement=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
  /** true if ALL the nodes in the m_root subtree have been processed;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * false if our incremental build has not yet finished scanning the
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * DOM tree.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
  transient private boolean m_nodesAreProcessed;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  /** The node objects.  The instance part of the handle indexes
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * directly into this vector.  Each DTM node may actually be
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * composed of several DOM nodes (for example, if logically-adjacent
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * Text/CDATASection nodes in the DOM have been coalesced into a
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   * single DTM Text node); this table points only to the first in
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   * that sequence. */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   104
  protected List<Node> m_nodes = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   * Construct a DOM2DTM object from a DOM node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * @param mgr The DTMManager who owns this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * @param domSource the DOM source that this DTM will wrap.
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * @param dtmIdentity The DTM identity ID for this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * @param whiteSpaceFilter The white space filter for this DTM, which may
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   *                         be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * @param xstringfactory XMLString factory for creating character content.
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * @param doIndexing true if the caller considers it worth it to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   *                   indexing schemes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  public DOM2DTM(DTMManager mgr, DOMSource domSource,
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                 int dtmIdentity, DTMWSFilter whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                 XMLStringFactory xstringfactory,
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                 boolean doIndexing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    super(mgr, domSource, dtmIdentity, whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
          xstringfactory, doIndexing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    // Initialize DOM navigation
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    m_pos=m_root = domSource.getNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    // Initialize DTM navigation
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    m_last_parent=m_last_kid=NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    // Apparently the domSource root may not actually be the
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    // Document node. If it's an Element node, we need to immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    // add its attributes. Adapted from nextNode().
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    // %REVIEW% Move this logic into addNode and recurse? Cleaner!
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    // (If it's an EntityReference node, we're probably scrod. For now
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                //
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                // %ISSUE% What about inherited namespaces in this case?
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                // Do we need to special-case initialize them into the DTM model?
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    if(ELEMENT_NODE == m_root.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
      NamedNodeMap attrs=m_root.getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
      int attrsize=(attrs==null) ? 0 : attrs.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
      if(attrsize>0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        int attrIndex=NULL; // start with no previous sib
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
        for(int i=0;i<attrsize;++i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
          // No need to force nodetype in this case;
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
          // addNode() will take care of switching it from
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
          // Attr to Namespace if necessary.
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
          attrIndex=addNode(attrs.item(i),0,attrIndex,NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
          m_firstch.setElementAt(DTM.NULL,attrIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        // Terminate list of attrs, and make sure they aren't
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
        // considered children of the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        m_nextsib.setElementAt(DTM.NULL,attrIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
      } // if attrs exist
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    } //if(ELEMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    // Initialize DTM-completed status
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    m_nodesAreProcessed = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
   * Construct the node map from the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   * @param node The node that is to be added to the DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   * @param parentIndex The current parent index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * @param previousSibling The previous sibling index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * @param forceNodeType If not DTM.NULL, overrides the DOM node type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   *    Used to force nodes to Text rather than CDATASection when their
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   *    coalesced value includes ordinary Text nodes (current DTM behavior).
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
   * @return The index identity of the node that was added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
  protected int addNode(Node node, int parentIndex,
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
                        int previousSibling, int forceNodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    int nodeIndex = m_nodes.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    // Have we overflowed a DTM Identity's addressing range?
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    if(m_dtmIdent.size() == (nodeIndex>>>DTMManager.IDENT_DTM_NODE_BITS))
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        if(m_mgr==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
          throw new ClassCastException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                                // Handle as Extended Addressing
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        DTMManagerDefault mgrD=(DTMManagerDefault)m_mgr;
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        int id=mgrD.getFirstFreeDTMID();
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
        mgrD.addDTM(this,id,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        m_dtmIdent.addElement(id<<DTMManager.IDENT_DTM_NODE_BITS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
      catch(ClassCastException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        // %REVIEW% Wrong error message, but I've been told we're trying
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        // not to add messages right not for I18N reasons.
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        // %REVIEW% Should this be a Fatal Error?
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
        error(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DTMIDS_AVAIL, null));//"No more DTM IDs are available";
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    m_size++;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    // ensureSize(nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    int type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    if(NULL==forceNodeType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
        type = node.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        type=forceNodeType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    // %REVIEW% The Namespace Spec currently says that Namespaces are
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    // processed in a non-namespace-aware manner, by matching the
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    // QName, even though there is in fact a namespace assigned to
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    // these nodes in the DOM. If and when that changes, we will have
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    // to consider whether we check the namespace-for-namespaces
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    // rather than the node name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    // %TBD% Note that the DOM does not necessarily explicitly declare
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    // all the namespaces it uses. DOM Level 3 will introduce a
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    // namespace-normalization operation which reconciles that, and we
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    // can request that users invoke it or otherwise ensure that the
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
    // tree is namespace-well-formed before passing the DOM to Xalan.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
    // But if they don't, what should we do about it? We probably
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    // don't want to alter the source DOM (and may not be able to do
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    // so if it's read-only). The best available answer might be to
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    // synthesize additional DTM Namespace Nodes that don't correspond
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    // to DOM Attr Nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    if (Node.ATTRIBUTE_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
      String name = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
      if (name.startsWith("xmlns:") || name.equals("xmlns"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        type = DTM.NAMESPACE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   245
    m_nodes.add(node);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    m_firstch.setElementAt(NOTPROCESSED,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    m_nextsib.setElementAt(NOTPROCESSED,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    m_prevsib.setElementAt(previousSibling,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
    m_parent.setElementAt(parentIndex,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    if(DTM.NULL != parentIndex &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
       type != DTM.ATTRIBUTE_NODE &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
       type != DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
      // If the DTM parent had no children, this becomes its first child.
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
      if(NOTPROCESSED == m_firstch.elementAt(parentIndex))
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
        m_firstch.setElementAt(nodeIndex,parentIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
    String nsURI = node.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    // Deal with the difference between Namespace spec and XSLT
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
    // definitions of local name. (The former says PIs don't have
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    // localnames; the latter says they do.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    String localName =  (type == Node.PROCESSING_INSTRUCTION_NODE) ?
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
                         node.getNodeName() :
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
                         node.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    // Hack to make DOM1 sort of work...
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    if(((type == Node.ELEMENT_NODE) || (type == Node.ATTRIBUTE_NODE))
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        && null == localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
      localName = node.getNodeName(); // -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    ExpandedNameTable exnt = m_expandedNameTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    // %TBD% Nodes created with the old non-namespace-aware DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    // calls createElement() and createAttribute() will never have a
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    // localname. That will cause their expandedNameID to be just the
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    // nodeType... which will keep them from being matched
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    // successfully by name. Since the DOM makes no promise that
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    // those will participate in namespace processing, this is
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
    // officially accepted as Not Our Fault. But it might be nice to
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    // issue a diagnostic message!
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    if(node.getLocalName()==null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
       (type==Node.ELEMENT_NODE || type==Node.ATTRIBUTE_NODE))
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        // warning("DOM 'level 1' node "+node.getNodeName()+" won't be mapped properly in DOM2DTM.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
    int expandedNameID = (null != localName)
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
       ? exnt.getExpandedTypeID(nsURI, localName, type) :
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
         exnt.getExpandedTypeID(type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    m_exptype.setElementAt(expandedNameID,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    indexNode(expandedNameID, nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    if (DTM.NULL != previousSibling)
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
      m_nextsib.setElementAt(nodeIndex,previousSibling);
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    // This should be done after m_exptype has been set, and probably should
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
    // always be the last thing we do
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    if (type == DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        declareNamespaceInContext(parentIndex,nodeIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    return nodeIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   * Get the number of nodes that have been added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
  public int getNumberOfNodes()
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    return m_nodes.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
 /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * This method iterates to the next node that will be added to the table.
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   * Each call to this method adds a new node to the table, unless the end
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   * is reached, in which case it returns null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   * @return The true if a next node is found or false if
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
   *         there are no more nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
  protected boolean nextNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    // Non-recursive one-fetch-at-a-time depth-first traversal with
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    // attribute/namespace nodes and white-space stripping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    // Navigating the DOM is simple, navigating the DTM is simple;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    // keeping track of both at once is a trifle baroque but at least
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
    // we've avoided most of the special cases.
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    if (m_nodesAreProcessed)
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
    // %REVIEW% Is this local copy Really Useful from a performance
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
    // point of view?  Or is this a false microoptimization?
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    Node pos=m_pos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    Node next=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
    int nexttype=NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
    // Navigate DOM tree
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
    do
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        // Look down to first child.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        if (pos.hasChildNodes())
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
            next = pos.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
            // %REVIEW% There's probably a more elegant way to skip
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
            // the doctype. (Just let it go and Suppress it?
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
            if(next!=null && DOCUMENT_TYPE_NODE==next.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
              next=next.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
            // Push DTM context -- except for children of Entity References,
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
            // which have no DTM equivalent and cause no DTM navigation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
            if(ENTITY_REFERENCE_NODE!=pos.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                m_last_parent=m_last_kid;
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
                m_last_kid=NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
                // Whitespace-handler context stacking
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
                if(null != m_wsfilter)
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                  short wsv =
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
                    m_wsfilter.getShouldStripSpace(makeNodeHandle(m_last_parent),this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                  boolean shouldStrip = (DTMWSFilter.INHERIT == wsv)
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
                    ? getShouldStripWhitespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
                    : (DTMWSFilter.STRIP == wsv);
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
                  pushShouldStripWhitespace(shouldStrip);
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
                } // if(m_wsfilter)
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        // If that fails, look up and right (but not past root!)
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
            if(m_last_kid!=NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
                // Last node posted at this level had no more children
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
                // If it has _no_ children, we need to record that.
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
                if(m_firstch.elementAt(m_last_kid)==NOTPROCESSED)
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
                  m_firstch.setElementAt(NULL,m_last_kid);
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
            while(m_last_parent != NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
                // %REVIEW% There's probably a more elegant way to
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
                // skip the doctype. (Just let it go and Suppress it?
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
                next = pos.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
                if(next!=null && DOCUMENT_TYPE_NODE==next.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
                  next=next.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
                if(next!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
                  break; // Found it!
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
                // No next-sibling found. Pop the DOM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
                pos=pos.getParentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                if(pos==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
                    // %TBD% Should never arise, but I want to be sure of that...
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
                    if(JJK_DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
                      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
                        System.out.println("***** DOM2DTM Pop Control Flow problem");
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
                        for(;;); // Freeze right here!
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
                      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
                // The only parents in the DTM are Elements.  However,
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
                // the DOM could contain EntityReferences.  If we
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
                // encounter one, pop it _without_ popping DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                if(pos!=null && ENTITY_REFERENCE_NODE == pos.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
                    // Nothing needs doing
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                    if(JJK_DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                      System.out.println("***** DOM2DTM popping EntRef");
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
                    popShouldStripWhitespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
                    // Fix and pop DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                    if(m_last_kid==NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
                      m_firstch.setElementAt(NULL,m_last_parent); // Popping from an element
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                      m_nextsib.setElementAt(NULL,m_last_kid); // Popping from anything else
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
                    m_last_parent=m_parent.elementAt(m_last_kid=m_last_parent);
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            if(m_last_parent==NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
              next=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
        if(next!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
          nexttype=next.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        // If it's an entity ref, advance past it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
        // %REVIEW% Should we let this out the door and just suppress it?
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        // More work, but simpler code, more likely to be correct, and
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
        // it doesn't happen very often. We'd get rid of the loop too.
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        if (ENTITY_REFERENCE_NODE == nexttype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
          pos=next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
    while (ENTITY_REFERENCE_NODE == nexttype);
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    // Did we run out of the tree?
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
    if(next==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        m_nextsib.setElementAt(NULL,0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
        m_nodesAreProcessed = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        m_pos=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
        if(JJK_DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
            System.out.println("***** DOM2DTM Crosscheck:");
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
            for(int i=0;i<m_nodes.size();++i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
              System.out.println(i+":\t"+m_firstch.elementAt(i)+"\t"+m_nextsib.elementAt(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
    // Text needs some special handling:
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
    // DTM may skip whitespace. This is handled by the suppressNode flag, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
    // when true will keep the DTM node from being created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
    // DTM only directly records the first DOM node of any logically-contiguous
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
    // sequence. The lastTextNode value will be set to the last node in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
    // contiguous sequence, and -- AFTER the DTM addNode -- can be used to
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
    // advance next over this whole block. Should be simpler than special-casing
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
    // the above loop for "Was the logically-preceeding sibling a text node".
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
    // Finally, a DTM node should be considered a CDATASection only if all the
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
    // contiguous text it covers is CDATASections. The first Text should
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
    // force DTM to Text.
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
    boolean suppressNode=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    Node lastTextNode=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
    nexttype=next.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
    // nexttype=pos.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
    if(TEXT_NODE == nexttype || CDATA_SECTION_NODE == nexttype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
        // If filtering, initially assume we're going to suppress the node
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
        suppressNode=((null != m_wsfilter) && getShouldStripWhitespace());
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
        // Scan logically contiguous text (siblings, plus "flattening"
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
        // of entity reference boundaries).
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
        Node n=next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        while(n!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
            lastTextNode=n;
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
            // Any Text node means DTM considers it all Text
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
            if(TEXT_NODE == n.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
              nexttype=TEXT_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
            // Any non-whitespace in this sequence blocks whitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
            // suppression
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
            suppressNode &=
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
              XMLCharacterRecognizer.isWhiteSpace(n.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
            n=logicalNextDOMTextNode(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
    // Special handling for PIs: Some DOMs represent the XML
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
    // Declaration as a PI. This is officially incorrect, per the DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
    // spec, but is considered a "wrong but tolerable" temporary
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
    // workaround pending proper handling of these fields in DOM Level
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
    // 3. We want to recognize and reject that case.
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
    else if(PROCESSING_INSTRUCTION_NODE==nexttype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
        suppressNode = (pos.getNodeName().toLowerCase().equals("xml"));
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
    if(!suppressNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
        // Inserting next. NOTE that we force the node type; for
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
        // coalesced Text, this records CDATASections adjacent to
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
        // ordinary Text as Text.
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        int nextindex=addNode(next,m_last_parent,m_last_kid,
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
                              nexttype);
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
        m_last_kid=nextindex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
        if(ELEMENT_NODE == nexttype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
            int attrIndex=NULL; // start with no previous sib
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
            // Process attributes _now_, rather than waiting.
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
            // Simpler control flow, makes NS cache available immediately.
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
            NamedNodeMap attrs=next.getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
            int attrsize=(attrs==null) ? 0 : attrs.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
            if(attrsize>0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
                for(int i=0;i<attrsize;++i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
                    // No need to force nodetype in this case;
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                    // addNode() will take care of switching it from
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
                    // Attr to Namespace if necessary.
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                    attrIndex=addNode(attrs.item(i),
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                                      nextindex,attrIndex,NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                    m_firstch.setElementAt(DTM.NULL,attrIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                    // If the xml: prefix is explicitly declared
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
                    // we don't need to synthesize one.
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
                    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
                    // NOTE that XML Namespaces were not originally
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                    // defined as being namespace-aware (grrr), and
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
                    // while the W3C is planning to fix this it's
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
                    // safer for now to test the QName and trust the
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                    // parsers to prevent anyone from redefining the
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
                    // reserved xmlns: prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
                    if(!m_processedFirstElement
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
                       && "xmlns:xml".equals(attrs.item(i).getNodeName()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
                      m_processedFirstElement=true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
                // Terminate list of attrs, and make sure they aren't
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
                // considered children of the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
              } // if attrs exist
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
            if(!m_processedFirstElement)
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
              // The DOM might not have an explicit declaration for the
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
              // implicit "xml:" prefix, but the XPath data model
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
              // requires that this appear as a Namespace Node so we
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
              // have to synthesize one. You can think of this as
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
              // being a default attribute defined by the XML
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
              // Namespaces spec rather than by the DTD.
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
              attrIndex=addNode(new DOM2DTMdefaultNamespaceDeclarationNode(
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                                                                                                                                        (Element)next,"xml",NAMESPACE_DECL_NS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                                                                                                                                        makeNodeHandle(((attrIndex==NULL)?nextindex:attrIndex)+1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
                                                                                                                                        ),
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
                                nextindex,attrIndex,NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
              m_firstch.setElementAt(DTM.NULL,attrIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
              m_processedFirstElement=true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
            if(attrIndex!=NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
              m_nextsib.setElementAt(DTM.NULL,attrIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
          } //if(ELEMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
      } // (if !suppressNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
    // Text postprocessing: Act on values stored above
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
    if(TEXT_NODE == nexttype || CDATA_SECTION_NODE == nexttype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
        // %TBD% If nexttype was forced to TEXT, patch the DTM node
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
        next=lastTextNode;      // Advance the DOM cursor over contiguous text
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    // Remember where we left off.
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
    m_pos=next;
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
   * Return an DOM node for the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
   * @return A node representation of the DTM node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
  public Node getNode(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
    int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   608
    return m_nodes.get(identity);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
   * Get a Node from an identity index.
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
   * NEEDSDOC @param nodeIdentity
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
   * NEEDSDOC ($objectName$) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
  protected Node lookupNode(int nodeIdentity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
  {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   620
    return m_nodes.get(nodeIdentity);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
   * Get the next node identity value in the list, and call the iterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
   * if it hasn't been added yet.
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
   * @param identity The node identity (index).
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
   * @return identity+1, or DTM.NULL.
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
  protected int getNextNodeIdentity(int identity)
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
    identity += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
    if (identity >= m_nodes.size())
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
      if (!nextNode())
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
        identity = DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
    return identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
   * Get the handle from a Node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
   * <p>%OPT% This will be pretty slow.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
   * <p>%OPT% An XPath-like search (walk up DOM to root, tracking path;
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
   * walk down DTM reconstructing path) might be considerably faster
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
   * on later nodes in large documents. That might also imply improving
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
   * this call to handle nodes which would be in this DTM but
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
   * have not yet been built, which might or might not be a Good Thing.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
   * %REVIEW% This relies on being able to test node-identity via
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
   * object-identity. DTM2DOM proxying is a great example of a case where
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
   * that doesn't work. DOM Level 3 will provide the isSameNode() method
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
   * to fix that, but until then this is going to be flaky.
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
   * @param node A node, which may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
   * @return The node handle or <code>DTM.NULL</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
  private int getHandleFromNode(Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
    if (null != node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
      int len = m_nodes.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
      boolean isMore;
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
      int i = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
      do
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
        for (; i < len; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   674
          if (m_nodes.get(i) == node)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
            return makeNodeHandle(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        isMore = nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
        len = m_nodes.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
      while(isMore || i < len);
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
  /** Get the handle from a Node. This is a more robust version of
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
   * getHandleFromNode, intended to be usable by the public.
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
   * <p>%OPT% This will be pretty slow.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
   * %REVIEW% This relies on being able to test node-identity via
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
   * object-identity. DTM2DOM proxying is a great example of a case where
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
   * that doesn't work. DOM Level 3 will provide the isSameNode() method
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
   * to fix that, but until then this is going to be flaky.
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
   * @param node A node, which may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
   * @return The node handle or <code>DTM.NULL</code>.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
  public int getHandleOfNode(Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
    if (null != node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
      // Is Node actually within the same document? If not, don't search!
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
      // This would be easier if m_root was always the Document node, but
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
      // we decided to allow wrapping a DTM around a subtree.
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
      if((m_root==node) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
         (m_root.getNodeType()==DOCUMENT_NODE &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
          m_root==node.getOwnerDocument()) ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
         (m_root.getNodeType()!=DOCUMENT_NODE &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
          m_root.getOwnerDocument()==node.getOwnerDocument())
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
         )
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
          // If node _is_ in m_root's tree, find its handle
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
          //
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
          // %OPT% This check may be improved significantly when DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
          // Level 3 nodeKey and relative-order tests become
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
          // available!
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
          for(Node cursor=node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
              cursor!=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
              cursor=
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
                (cursor.getNodeType()!=ATTRIBUTE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
                ? cursor.getParentNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
                : ((org.w3c.dom.Attr)cursor).getOwnerElement())
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
              if(cursor==m_root)
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
                // We know this node; find its handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
                return getHandleFromNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
            } // for ancestors of node
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
        } // if node and m_root in same Document
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
    } // if node!=null
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
   * Retrieves an attribute node by by qualified name and namespace URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
   * @param nodeHandle int Handle of the node upon which to look up this attribute..
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
   * @param namespaceURI The namespace URI of the attribute to
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
   *   retrieve, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
   * @param name The local name of the attribute to
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
   *   retrieve.
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
   * @return The attribute node handle with the specified name (
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
   *   <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
   *   attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
  public int getAttributeNode(int nodeHandle, String namespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
                              String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    // %OPT% This is probably slower than it needs to be.
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
    if (null == namespaceURI)
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
      namespaceURI = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
    int type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
    if (DTM.ELEMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
      // Assume that attributes immediately follow the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
      int identity = makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
      while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
        // Assume this can not be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
        type = _type(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
                                // %REVIEW%
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
                                // Should namespace nodes be retrievable DOM-style as attrs?
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
                                // If not we need a separate function... which may be desirable
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
                                // architecturally, but which is ugly from a code point of view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
                                // (If we REALLY insist on it, this code should become a subroutine
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
                                // of both -- retrieve the node, then test if the type matches
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
                                // what you're looking for.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
        if (type == DTM.ATTRIBUTE_NODE || type==DTM.NAMESPACE_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
          Node node = lookupNode(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
          String nodeuri = node.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
          if (null == nodeuri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
            nodeuri = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
          String nodelocalname = node.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
          if (nodeuri.equals(namespaceURI) && name.equals(nodelocalname))
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
            return makeNodeHandle(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
        else // if (DTM.NAMESPACE_NODE != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
   * Get the string-value of a node as a String object
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
   * (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
   * for the definition of a node's string-value).
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
   * @return A string object that represents the string-value of the given node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
  public XMLString getStringValue(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
    int type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
    Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
    // %TBD% If an element only has one text node, we should just use it
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
    // directly.
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
    if(DTM.ELEMENT_NODE == type || DTM.DOCUMENT_NODE == type
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
    || DTM.DOCUMENT_FRAGMENT_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
      FastStringBuffer buf = StringBufferPool.get();
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
      String s;
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
        getNodeData(node, buf);
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
        s = (buf.length() > 0) ? buf.toString() : "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
      finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        StringBufferPool.free(buf);
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
      return m_xstrf.newstr( s );
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
    else if(TEXT_NODE == type || CDATA_SECTION_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
      // If this is a DTM text node, it may be made of multiple DOM text
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
      // nodes -- including navigating into Entity References. DOM2DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
      // records the first node in the sequence and requires that we
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
      // pick up the others when we retrieve the DTM node's value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
      //
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
      // %REVIEW% DOM Level 3 is expected to add a "whole text"
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
      // retrieval method which performs this function for us.
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
      FastStringBuffer buf = StringBufferPool.get();
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
      while(node!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
        buf.append(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
        node=logicalNextDOMTextNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
      String s=(buf.length() > 0) ? buf.toString() : "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
      StringBufferPool.free(buf);
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
      return m_xstrf.newstr( s );
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
      return m_xstrf.newstr( node.getNodeValue() );
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
   * Determine if the string-value of a node is whitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
   * @param nodeHandle The node Handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
   * @return Return true if the given node is whitespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
  public boolean isWhitespace(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
        int type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
    Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
        if(TEXT_NODE == type || CDATA_SECTION_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
      // If this is a DTM text node, it may be made of multiple DOM text
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
      // nodes -- including navigating into Entity References. DOM2DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
      // records the first node in the sequence and requires that we
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
      // pick up the others when we retrieve the DTM node's value.
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
      //
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
      // %REVIEW% DOM Level 3 is expected to add a "whole text"
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
      // retrieval method which performs this function for us.
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
      FastStringBuffer buf = StringBufferPool.get();
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
      while(node!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
        buf.append(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
        node=logicalNextDOMTextNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
     boolean b = buf.isWhitespace(0, buf.length());
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
      StringBufferPool.free(buf);
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
     return b;
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
   * Retrieve the text content of a DOM subtree, appending it into a
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
   * user-supplied FastStringBuffer object. Note that attributes are
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
   * not considered part of the content of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
   * There are open questions regarding whitespace stripping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
   * Currently we make no special effort in that regard, since the standard
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
   * DOM doesn't yet provide DTD-based information to distinguish
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
   * whitespace-in-element-context from genuine #PCDATA. Note that we
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
   * should probably also consider xml:space if/when we address this.
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
   * DOM Level 3 may solve the problem for us.
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
   * %REVIEW% Actually, since this method operates on the DOM side of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
   * fence rather than the DTM side, it SHOULDN'T do
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
   * any special handling. The DOM does what the DOM does; if you want
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
   * DTM-level abstractions, use DTM-level methods.
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
   * @param node Node whose subtree is to be walked, gathering the
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
   * contents of all Text or CDATASection nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
   * @param buf FastStringBuffer into which the contents of the text
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
   * nodes are to be concatenated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
  protected static void getNodeData(Node node, FastStringBuffer buf)
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
    switch (node.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
    case Node.DOCUMENT_FRAGMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
    case Node.DOCUMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
    case Node.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
      for (Node child = node.getFirstChild(); null != child;
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
              child = child.getNextSibling())
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
        getNodeData(child, buf);
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
    case Node.TEXT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
    case Node.CDATA_SECTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
    case Node.ATTRIBUTE_NODE :  // Never a child but might be our starting node
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
      buf.append(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
    case Node.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
      // ignore
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
   * Given a node handle, return its DOM-style node name. This will
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
   * include names such as #text or #document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
   * @return String Name of this node, which may be an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
   * %REVIEW% Document when empty string is possible...
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
   * %REVIEW-COMMENT% It should never be empty, should it?
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
  public String getNodeName(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
    Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
    // Assume non-null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
    return node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
   * Given a node handle, return the XPath node name.  This should be
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
   * the name as described by the XPath data model, NOT the DOM-style
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
   * name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
   * @return String Name of this node, which may be an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
  public String getNodeNameX(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
    String name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
    short type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
    switch (type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
    case DTM.NAMESPACE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
      Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
      // assume not null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
      name = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
      if(name.startsWith("xmlns:"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
        name = QName.getLocalPart(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
      else if(name.equals("xmlns"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
        name = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
    case DTM.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
    case DTM.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
    case DTM.ENTITY_REFERENCE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
    case DTM.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
      Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
      // assume not null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
      name = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
      name = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
    return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
   * Given a node handle, return its XPath-style localname.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
   * (As defined in Namespaces, this is the portion of the name after any
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
   * colon character).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
   * @return String Local name of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
  public String getLocalName(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
    if(JJK_NEWCODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
      int id=makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
      if(NULL==id) return null;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1027
      Node newnode=m_nodes.get(id);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
      String newname=newnode.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
      if (null == newname)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
        // XSLT treats PIs, and possibly other things, as having QNames.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
        String qname = newnode.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
        if('#'==qname.charAt(0))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
          //  Match old default for this function
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
          // This conversion may or may not be necessary
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
          newname="";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
          int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
          newname = (index < 0) ? qname : qname.substring(index + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
      return newname;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
      String name;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
      short type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
      switch (type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
      case DTM.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
      case DTM.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
      case DTM.ENTITY_REFERENCE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
      case DTM.NAMESPACE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
      case DTM.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
          Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
          // assume not null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
          name = node.getLocalName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
          if (null == name)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
            String qname = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
            int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
            name = (index < 0) ? qname : qname.substring(index + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
        name = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
      return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
   * Given a namespace handle, return the prefix that the namespace decl is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
   * mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
   * Given a node handle, return the prefix used to map to the namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
   * <p> %REVIEW% Are you sure you want "" for no prefix?  </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
   * <p> %REVIEW-COMMENT% I think so... not totally sure. -sb  </p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
   * @return String prefix of this node's name, or "" if no explicit
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
   * namespace prefix was given.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
  public String getPrefix(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
    String prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
    short type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
    switch (type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
    case DTM.NAMESPACE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
      Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
      // assume not null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
      String qname = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
      int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
      prefix = (index < 0) ? "" : qname.substring(index + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
    case DTM.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
    case DTM.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
      Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
      // assume not null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
      String qname = node.getNodeName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
      int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
      prefix = (index < 0) ? "" : qname.substring(0, index);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
      prefix = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
    return prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
   * Given a node handle, return its DOM-style namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
   * (As defined in Namespaces, this is the declared URI which this node's
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
   * prefix -- or default in lieu thereof -- was mapped to.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
   * <p>%REVIEW% Null or ""? -sb</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
   * @param nodeHandle the id of the node.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
   * @return String URI value of this node's namespace, or null if no
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
   * namespace was resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
  public String getNamespaceURI(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
    if(JJK_NEWCODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
      int id=makeNodeIdentity(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
      if(id==NULL) return null;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1147
      Node node=m_nodes.get(id);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
      return node.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
      String nsuri;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
      short type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
      switch (type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
      case DTM.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
      case DTM.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
      case DTM.ENTITY_REFERENCE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
      case DTM.NAMESPACE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
      case DTM.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
          Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
          // assume not null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
          nsuri = node.getNamespaceURI();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
          // %TBD% Handle DOM1?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
        nsuri = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
      return nsuri;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
  /** Utility function: Given a DOM Text node, determine whether it is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
   * logically followed by another Text or CDATASection node. This may
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
   * involve traversing into Entity References.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
   * %REVIEW% DOM Level 3 is expected to add functionality which may
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
   * allow us to retire this.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
  private Node logicalNextDOMTextNode(Node n)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
        Node p=n.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
        if(p==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
                // Walk out of any EntityReferenceNodes that ended with text
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
                for(n=n.getParentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
                        n!=null && ENTITY_REFERENCE_NODE == n.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
                        n=n.getParentNode())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
                        p=n.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
                        if(p!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
                                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
        n=p;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
        while(n!=null && ENTITY_REFERENCE_NODE == n.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
                // Walk into any EntityReferenceNodes that start with text
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
                if(n.hasChildNodes())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
                        n=n.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
                        n=n.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
        if(n!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
                // Found a logical next sibling. Is it text?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
                int ntype=n.getNodeType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
                if(TEXT_NODE != ntype && CDATA_SECTION_NODE != ntype)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
                        n=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
        return n;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
   * Given a node handle, return its node value. This is mostly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
   * as defined by the DOM, but may ignore some conveniences.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
   * @param nodeHandle The node id.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
   * @return String Value of this node, or null if not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
   * meaningful for this node type.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
  public String getNodeValue(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
    // The _type(nodeHandle) call was taking the lion's share of our
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
    // time, and was wrong anyway since it wasn't coverting handle to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
    // identity. Inlined it.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
    int type = _exptype(makeNodeIdentity(nodeHandle));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
    type=(NULL != type) ? getNodeType(nodeHandle) : NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
    if(TEXT_NODE!=type && CDATA_SECTION_NODE!=type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
      return getNode(nodeHandle).getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
    // If this is a DTM text node, it may be made of multiple DOM text
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
    // nodes -- including navigating into Entity References. DOM2DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
    // records the first node in the sequence and requires that we
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
    // pick up the others when we retrieve the DTM node's value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
    // %REVIEW% DOM Level 3 is expected to add a "whole text"
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
    // retrieval method which performs this function for us.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
    Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
    Node n=logicalNextDOMTextNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
    if(n==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
      return node.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
    FastStringBuffer buf = StringBufferPool.get();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
        buf.append(node.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
    while(n!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
      buf.append(n.getNodeValue());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
      n=logicalNextDOMTextNode(n);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
    String s = (buf.length() > 0) ? buf.toString() : "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
    StringBufferPool.free(buf);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
    return s;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
   *   A document type declaration information item has the following properties:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
   *     1. [system identifier] The system identifier of the external subset, if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
   *        it exists. Otherwise this property has no value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
   * @return the system identifier String object, or null if there is none.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
  public String getDocumentTypeDeclarationSystemIdentifier()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
    Document doc;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
    if (m_root.getNodeType() == Node.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
      doc = (Document) m_root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
      doc = m_root.getOwnerDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
    if (null != doc)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
      DocumentType dtd = doc.getDoctype();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
      if (null != dtd)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
        return dtd.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
   * Return the public identifier of the external subset,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
   * normalized as described in 4.2.2 External Entities [XML]. If there is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
   * no external subset or if it has no public identifier, this property
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
   * has no value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
   * @return the public identifier String object, or null if there is none.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
  public String getDocumentTypeDeclarationPublicIdentifier()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
    Document doc;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
    if (m_root.getNodeType() == Node.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
      doc = (Document) m_root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
      doc = m_root.getOwnerDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
    if (null != doc)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
      DocumentType dtd = doc.getDoctype();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
      if (null != dtd)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
        return dtd.getPublicId();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
   * Returns the <code>Element</code> whose <code>ID</code> is given by
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
   * <code>elementId</code>. If no such element exists, returns
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
   * <code>DTM.NULL</code>. Behavior is not defined if more than one element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
   * has this <code>ID</code>. Attributes (including those
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
   * with the name "ID") are not of type ID unless so defined by DTD/Schema
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
   * information available to the DTM implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
   * Implementations that do not know whether attributes are of type ID or
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
   * not are expected to return <code>DTM.NULL</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
   * <p>%REVIEW% Presumably IDs are still scoped to a single document,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
   * and this operation searches only within a single document, right?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
   * Wouldn't want collisions between DTMs in the same process.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
   * @param elementId The unique <code>id</code> value for an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
   * @return The handle of the matching element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
  public int getElementById(String elementId)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
    Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
        ? (Document) m_root : m_root.getOwnerDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
    if(null != doc)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
      Node elem = doc.getElementById(elementId);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
      if(null != elem)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
        int elemHandle = getHandleFromNode(elem);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
        if(DTM.NULL == elemHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
          int identity = m_nodes.size()-1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
          while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
            Node node = getNode(identity);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
            if(node == elem)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
              elemHandle = getHandleFromNode(elem);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
              break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
           }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
        return elemHandle;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
    return DTM.NULL;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
   * The getUnparsedEntityURI function returns the URI of the unparsed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
   * entity with the specified name in the same document as the context
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
   * node (see [3.3 Unparsed Entities]). It returns the empty string if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
   * there is no such entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
   * XML processors may choose to use the System Identifier (if one
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
   * is provided) to resolve the entity, rather than the URI in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
   * Public Identifier. The details are dependent on the processor, and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
   * we would have to support some form of plug-in resolver to handle
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
   * this properly. Currently, we simply return the System Identifier if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
   * present, and hope that it a usable URI or that our caller can
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
   * map it to one.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
   * TODO: Resolve Public Identifiers... or consider changing function name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
   * If we find a relative URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
   * reference, XML expects it to be resolved in terms of the base URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
   * of the document. The DOM doesn't do that for us, and it isn't
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
   * entirely clear whether that should be done here; currently that's
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
   * pushed up to a higher level of our application. (Note that DOM Level
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
   * 1 didn't store the document's base URI.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
   * TODO: Consider resolving Relative URIs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
   * (The DOM's statement that "An XML processor may choose to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
   * completely expand entities before the structure model is passed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
   * to the DOM" refers only to parsed entities, not unparsed, and hence
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
   * doesn't affect this function.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
   * @param name A string containing the Entity Name of the unparsed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
   * entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
   * @return String containing the URI of the Unparsed Entity, or an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
   * empty string if no such entity exists.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
  public String getUnparsedEntityURI(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
    String url = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
    Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
        ? (Document) m_root : m_root.getOwnerDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
    if (null != doc)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
      DocumentType doctype = doc.getDoctype();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
      if (null != doctype)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
        NamedNodeMap entities = doctype.getEntities();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
        if(null == entities)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
          return url;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
        Entity entity = (Entity) entities.getNamedItem(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
        if(null == entity)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
          return url;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
        String notationName = entity.getNotationName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1433
7f561c08de6b Initial load
duke
parents:
diff changeset
  1434
        if (null != notationName)  // then it's unparsed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1436
          // The draft says: "The XSLT processor may use the public
7f561c08de6b Initial load
duke
parents:
diff changeset
  1437
          // identifier to generate a URI for the entity instead of the URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1438
          // specified in the system identifier. If the XSLT processor does
7f561c08de6b Initial load
duke
parents:
diff changeset
  1439
          // not use the public identifier to generate the URI, it must use
7f561c08de6b Initial load
duke
parents:
diff changeset
  1440
          // the system identifier; if the system identifier is a relative
7f561c08de6b Initial load
duke
parents:
diff changeset
  1441
          // URI, it must be resolved into an absolute URI using the URI of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1442
          // the resource containing the entity declaration as the base
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
          // URI [RFC2396]."
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
          // So I'm falling a bit short here.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
          url = entity.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
          if (null == url)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
            url = entity.getPublicId();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
            // This should be resolved to an absolute URL, but that's hard
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
            // to do from here.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
7f561c08de6b Initial load
duke
parents:
diff changeset
  1460
    return url;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
   *     5. [specified] A flag indicating whether this attribute was actually
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
   *        specified in the start-tag of its element, or was defaulted from the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
   *        DTD.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
   * @param attributeHandle the attribute handle
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
   * @return <code>true</code> if the attribute was specified;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
   *         <code>false</code> if it was defaulted.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
  public boolean isAttributeSpecified(int attributeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
    int type = getNodeType(attributeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
    if (DTM.ATTRIBUTE_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
      Attr attr = (Attr)getNode(attributeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
      return attr.getSpecified();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
  /** Bind an IncrementalSAXSource to this DTM. NOT RELEVANT for DOM2DTM, since
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
   * we're wrapped around an existing DOM.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
   * @param source The IncrementalSAXSource that we want to recieve events from
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
   * on demand.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
  public void setIncrementalSAXSource(IncrementalSAXSource source)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
  /** getContentHandler returns "our SAX builder" -- the thing that
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
   * someone else should send SAX events to in order to extend this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
   * DTM model.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
   * @return null if this model doesn't respond to SAX events,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
   * "this" if the DTM object has a built-in SAX ContentHandler,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
   * the IncrmentalSAXSource if we're bound to one and should receive
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
   * the SAX stream via it for incremental build purposes...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
  public org.xml.sax.ContentHandler getContentHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
   * Return this DTM's lexical handler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1511
   * %REVIEW% Should this return null if constrution already done/begun?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
   * @return null if this model doesn't respond to lexical SAX events,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
   * "this" if the DTM object has a built-in SAX ContentHandler,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
   * the IncrementalSAXSource if we're bound to one and should receive
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
   * the SAX stream via it for incremental build purposes...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
  public org.xml.sax.ext.LexicalHandler getLexicalHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1523
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
   * Return this DTM's EntityResolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1527
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
   * @return null if this model doesn't respond to SAX entity ref events.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
  public org.xml.sax.EntityResolver getEntityResolver()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
   * Return this DTM's DTDHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
   * @return null if this model doesn't respond to SAX dtd events.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1541
  public org.xml.sax.DTDHandler getDTDHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1543
7f561c08de6b Initial load
duke
parents:
diff changeset
  1544
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1545
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1546
7f561c08de6b Initial load
duke
parents:
diff changeset
  1547
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
   * Return this DTM's ErrorHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
   * @return null if this model doesn't respond to SAX error events.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
  public org.xml.sax.ErrorHandler getErrorHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1556
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1557
7f561c08de6b Initial load
duke
parents:
diff changeset
  1558
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1559
   * Return this DTM's DeclHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1560
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1561
   * @return null if this model doesn't respond to SAX Decl events.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1562
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1563
  public org.xml.sax.ext.DeclHandler getDeclHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1564
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1565
7f561c08de6b Initial load
duke
parents:
diff changeset
  1566
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1567
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1568
7f561c08de6b Initial load
duke
parents:
diff changeset
  1569
  /** @return true iff we're building this model incrementally (eg
7f561c08de6b Initial load
duke
parents:
diff changeset
  1570
   * we're partnered with a IncrementalSAXSource) and thus require that the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1571
   * transformation and the parse run simultaneously. Guidance to the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1572
   * DTMManager.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1573
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1574
  public boolean needsTwoThreads()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1575
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1576
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1577
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1578
7f561c08de6b Initial load
duke
parents:
diff changeset
  1579
  // ========== Direct SAX Dispatch, for optimization purposes ========
7f561c08de6b Initial load
duke
parents:
diff changeset
  1580
7f561c08de6b Initial load
duke
parents:
diff changeset
  1581
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1582
   * Returns whether the specified <var>ch</var> conforms to the XML 1.0 definition
7f561c08de6b Initial load
duke
parents:
diff changeset
  1583
   * of whitespace.  Refer to <A href="http://www.w3.org/TR/1998/REC-xml-19980210#NT-S">
7f561c08de6b Initial load
duke
parents:
diff changeset
  1584
   * the definition of <CODE>S</CODE></A> for details.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1585
   * @param   ch      Character to check as XML whitespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1586
   * @return          =true if <var>ch</var> is XML whitespace; otherwise =false.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1587
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1588
  private static boolean isSpace(char ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1589
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1590
    return XMLCharacterRecognizer.isWhiteSpace(ch);  // Take the easy way out for now.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1591
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1592
7f561c08de6b Initial load
duke
parents:
diff changeset
  1593
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1594
   * Directly call the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1595
   * characters method on the passed ContentHandler for the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1596
   * string-value of the given node (see http://www.w3.org/TR/xpath#data-model
7f561c08de6b Initial load
duke
parents:
diff changeset
  1597
   * for the definition of a node's string-value). Multiple calls to the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1598
   * ContentHandler's characters methods may well occur for a single call to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1599
   * this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1600
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1601
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1602
   * @param ch A non-null reference to a ContentHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
   * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1606
  public void dispatchCharactersEvents(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
          int nodeHandle, org.xml.sax.ContentHandler ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
          boolean normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
            throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
    if(normalize)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
      XMLString str = getStringValue(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
      str = str.fixWhiteSpace(true, true, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
      str.dispatchCharactersEvents(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
      int type = getNodeType(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
      Node node = getNode(nodeHandle);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
      dispatchNodeData(node, ch, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
          // Text coalition -- a DTM text node may represent multiple
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
          // DOM nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
          if(TEXT_NODE == type || CDATA_SECTION_NODE == type)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
                  while( null != (node=logicalNextDOMTextNode(node)) )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
                  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
                      dispatchNodeData(node, ch, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1631
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1632
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1633
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
   * Retrieve the text content of a DOM subtree, appending it into a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
   * user-supplied FastStringBuffer object. Note that attributes are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
   * not considered part of the content of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
   * There are open questions regarding whitespace stripping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
   * Currently we make no special effort in that regard, since the standard
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
   * DOM doesn't yet provide DTD-based information to distinguish
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
   * whitespace-in-element-context from genuine #PCDATA. Note that we
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
   * should probably also consider xml:space if/when we address this.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
   * DOM Level 3 may solve the problem for us.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
   * %REVIEW% Note that as a DOM-level operation, it can be argued that this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
   * routine _shouldn't_ perform any processing beyond what the DOM already
7f561c08de6b Initial load
duke
parents:
diff changeset
  1648
   * does, and that whitespace stripping and so on belong at the DTM level.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
   * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1650
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1651
   * @param node Node whose subtree is to be walked, gathering the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1652
   * contents of all Text or CDATASection nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1653
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
  protected static void dispatchNodeData(Node node,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1655
                                         org.xml.sax.ContentHandler ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
                                         int depth)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
            throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
    switch (node.getNodeType())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
    case Node.DOCUMENT_FRAGMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
    case Node.DOCUMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1664
    case Node.ELEMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1666
      for (Node child = node.getFirstChild(); null != child;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1667
              child = child.getNextSibling())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1668
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1669
        dispatchNodeData(child, ch, depth+1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1671
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1672
    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
    case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
7f561c08de6b Initial load
duke
parents:
diff changeset
  1674
    case Node.COMMENT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
      if(0 != depth)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
        // NOTE: Because this operation works in the DOM space, it does _not_ attempt
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
        // to perform Text Coalition. That should only be done in DTM space.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
    case Node.TEXT_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
    case Node.CDATA_SECTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
    case Node.ATTRIBUTE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
      String str = node.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
      if(ch instanceof CharacterNodeHandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
        ((CharacterNodeHandler)ch).characters(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
        ch.characters(str.toCharArray(), 0, str.length());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
//    /* case Node.PROCESSING_INSTRUCTION_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
//      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1694
//      break; */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
    default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
      // ignore
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
      break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
  TreeWalker m_walker = new TreeWalker(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
   * Directly create SAX parser events from a subtree.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1706
   * @param nodeHandle The node ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
   * @param ch A non-null reference to a ContentHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1708
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1709
   * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1711
  public void dispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1712
          throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1714
    TreeWalker treeWalker = m_walker;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
    ContentHandler prevCH = treeWalker.getContentHandler();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
    if(null != prevCH)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
      treeWalker = new TreeWalker(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
    treeWalker.setContentHandler(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1722
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
      Node node = getNode(nodeHandle);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1726
      treeWalker.traverseFragment(node);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
    finally
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
      treeWalker.setContentHandler(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
  public interface CharacterNodeHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
    public void characters(Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
            throws org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
   * For the moment all the run time properties are ignored by this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
   * class.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
   * @param property a <code>String</code> value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
   * @param value an <code>Object</code> value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
  public void setProperty(String property, Object value)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1750
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
   * No source information is available for DOM2DTM, so return
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
   * <code>null</code> here.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1754
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
   * @param node an <code>int</code> value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1756
   * @return null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1757
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
  public SourceLocator getSourceLocatorFor(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
}