001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: DTMDocument.java 468638 2006-10-28 06:52:06Z minchau $
020     */
021    
022    package org.apache.xalan.lib.sql;
023    
024    import java.io.File;
025    import java.io.FileOutputStream;
026    import java.io.IOException;
027    import java.io.PrintStream;
028    
029    import javax.xml.transform.SourceLocator;
030    
031    import org.apache.xml.dtm.DTM;
032    import org.apache.xml.dtm.DTMAxisIterator;
033    import org.apache.xml.dtm.DTMAxisTraverser;
034    import org.apache.xml.dtm.DTMManager;
035    import org.apache.xml.dtm.ref.DTMDefaultBaseIterators;
036    import org.apache.xml.utils.FastStringBuffer;
037    import org.apache.xml.utils.StringBufferPool;
038    import org.apache.xml.utils.SuballocatedIntVector;
039    import org.apache.xml.utils.XMLString;
040    
041    import org.w3c.dom.Node;
042    
043    import org.xml.sax.ContentHandler;
044    import org.xml.sax.DTDHandler;
045    import org.xml.sax.EntityResolver;
046    import org.xml.sax.ErrorHandler;
047    import org.xml.sax.ext.DeclHandler;
048    import org.xml.sax.ext.LexicalHandler;
049    
050    /**
051     * The SQL Document is the main controlling class the executesa SQL Query
052     */
053    public class DTMDocument extends DTMDefaultBaseIterators
054    {
055    
056      /**
057       */
058      public interface CharacterNodeHandler
059      {
060        /**
061         * @param node
062         *
063         * @throws org.xml.sax.SAXException
064         */
065        public void characters( Node node )throws org.xml.sax.SAXException ;
066      }
067    
068      /**
069       */
070      private boolean DEBUG = false;
071    
072      /**
073       */
074      protected static final String S_NAMESPACE = "http://xml.apache.org/xalan/SQLExtension";
075    
076      /**
077       */
078      protected static final String S_ATTRIB_NOT_SUPPORTED = "Not Supported";
079      /**
080       */
081      protected static final String S_ISTRUE = "true";
082      /**
083       */
084      protected static final String S_ISFALSE = "false";
085    
086      /**
087       */
088      protected static final String S_DOCUMENT = "#root";
089      /**
090       */
091      protected static final String S_TEXT_NODE = "#text";
092      /**
093       */
094      protected static final String S_ELEMENT_NODE = "#element";
095    
096      /**
097       */
098      protected int m_Document_TypeID = 0;
099      /**
100       */
101      protected int m_TextNode_TypeID = 0;
102    
103    
104      /**
105       * Store the SQL Data in this growable array
106       */
107      protected ObjectArray m_ObjectArray = new ObjectArray();
108    
109      /**
110       * For each element node, there can be zero or more attributes. If Attributes
111       * are assigned, the first attribute for that element will be use here.
112       * Subsequent elements will use the m_nextsib, m_prevsib array. The sibling
113       * arrays are not meeant to hold indexes to attribute information but as
114       * long as there is not direct connection back into the main DTM tree
115       * we should be OK.
116       */
117      protected SuballocatedIntVector m_attribute;
118    
119      /**
120       * The Document Index will most likely be 0, but we will reference it
121       * by variable in case that paradigm falls through.
122       */
123      protected int m_DocumentIdx;
124    
125    
126      /**
127       * @param mgr
128       * @param ident
129       */
130      public DTMDocument( DTMManager mgr, int ident )
131      {
132        super(mgr, null, ident,
133          null, mgr.getXMLStringFactory(), true);
134    
135        m_attribute = new SuballocatedIntVector(DEFAULT_BLOCKSIZE);
136      }
137    
138      /**
139       * A common routine that allocates an Object from the Object Array.
140       * One of the common bugs in this code was to allocate an Object and
141       * not incerment m_size, using this method will assure that function.
142       * @param o
143       *
144       */
145      private int allocateNodeObject( Object o )
146      {
147        // Need to keep this counter going even if we don't use it.
148        m_size++;
149        return m_ObjectArray.append(o);
150      }
151    
152      /**
153       * @param o
154       * @param level
155       * @param extendedType
156       * @param parent
157       * @param prevsib
158       *
159       */
160      protected int addElementWithData( Object o, int level, int extendedType, int parent, int prevsib )
161      {
162        int elementIdx = addElement(level,extendedType,parent,prevsib);
163    
164        int data = allocateNodeObject(o);
165        m_firstch.setElementAt(data,elementIdx);
166    
167        m_exptype.setElementAt(m_TextNode_TypeID, data);
168        // m_level.setElementAt((byte)(level), data);
169        m_parent.setElementAt(elementIdx, data);
170    
171        m_prevsib.setElementAt(DTM.NULL, data);
172        m_nextsib.setElementAt(DTM.NULL, data);
173        m_attribute.setElementAt(DTM.NULL, data);
174        m_firstch.setElementAt(DTM.NULL, data);
175    
176        return elementIdx;
177      }
178    
179      /**
180       * @param level
181       * @param extendedType
182       * @param parent
183       * @param prevsib
184       *
185       */
186      protected int addElement( int level, int extendedType, int parent, int prevsib )
187      {
188        int node = DTM.NULL;
189    
190        try
191        {
192          // Add the Node and adjust its Extended Type
193          node = allocateNodeObject(S_ELEMENT_NODE);
194    
195          m_exptype.setElementAt(extendedType, node);
196          m_nextsib.setElementAt(DTM.NULL, node);
197          m_prevsib.setElementAt(prevsib, node);
198    
199          m_parent.setElementAt(parent, node);
200          m_firstch.setElementAt(DTM.NULL, node);
201          // m_level.setElementAt((byte)level, node);
202          m_attribute.setElementAt(DTM.NULL, node);
203    
204          if (prevsib != DTM.NULL)
205          {
206            // If the previous sibling is already assigned, then we are
207            // inserting a value into the chain.
208            if (m_nextsib.elementAt(prevsib) != DTM.NULL)
209              m_nextsib.setElementAt(m_nextsib.elementAt(prevsib), node);
210    
211            // Tell the proevious sibling that they have a new bother/sister.
212            m_nextsib.setElementAt(node, prevsib);
213          }
214    
215           // So if we have a valid parent and the new node ended up being first
216          // in the list, i.e. no prevsib, then set the new node up as the
217          // first child of the parent. Since we chained the node in the list,
218          // there should be no reason to worry about the current first child
219          // of the parent node.
220          if ((parent != DTM.NULL) && (m_prevsib.elementAt(node) == DTM.NULL))
221          {
222            m_firstch.setElementAt(node, parent);
223          }
224        }
225        catch(Exception e)
226        {
227          error("Error in addElement: "+e.getMessage());
228        }
229    
230        return node;
231      }
232    
233      /**
234       * Link an attribute to a node, if the node already has one or more
235       * attributes assigned, then just link this one to the attribute list.
236       * The first attribute is attached to the Parent Node (pnode) through the
237       * m_attribute array, subsequent attributes are linked through the
238       * m_prevsib, m_nextsib arrays.
239       * @param o
240       * @param extendedType
241       * @param pnode
242       *
243       */
244      protected int addAttributeToNode( Object o, int extendedType, int pnode )
245      {
246        int attrib = DTM.NULL;
247        //int prevsib = DTM.NULL;
248        int lastattrib = DTM.NULL;
249        // int value = DTM.NULL;
250    
251        try
252        {
253          // Add the Node and adjust its Extended Type
254          attrib = allocateNodeObject(o);
255    
256          m_attribute.setElementAt(DTM.NULL, attrib);
257          m_exptype.setElementAt(extendedType, attrib);
258          // m_level.setElementAt((byte)0, attrib);
259    
260          // Clear the sibling references
261          m_nextsib.setElementAt(DTM.NULL, attrib);
262          m_prevsib.setElementAt(DTM.NULL,attrib);
263          // Set the parent, although the was we are using attributes
264          // in the SQL extension this reference will more than likly
265          // be wrong
266          m_parent.setElementAt(pnode, attrib);
267          m_firstch.setElementAt(DTM.NULL, attrib);
268    
269          if (m_attribute.elementAt(pnode) != DTM.NULL)
270          {
271            // OK, we already have an attribute assigned to this
272            // Node, Insert us into the head of the list.
273            lastattrib = m_attribute.elementAt(pnode);
274            m_nextsib.setElementAt(lastattrib, attrib);
275            m_prevsib.setElementAt(attrib, lastattrib);
276          }
277          // Okay set the new attribute up as the first attribute
278          // for the node.
279          m_attribute.setElementAt(attrib, pnode);
280        }
281        catch(Exception e)
282        {
283          error("Error in addAttributeToNode: "+e.getMessage());
284        }
285    
286        return attrib;
287      }
288    
289      /**
290       * Allow two nodes to share the same set of attributes. There may be some
291       * problems because the parent of any attribute will be the original node
292       * they were assigned to. Need to see how the attribute walker works, then
293       * we should be able to fake it out.
294       * @param toNode
295       * @param fromNode
296       *
297       */
298      protected void cloneAttributeFromNode( int toNode, int fromNode )
299      {
300       try
301        {
302          if (m_attribute.elementAt(toNode) != DTM.NULL)
303          {
304            error("Cloneing Attributes, where from Node already had addtibures assigned");
305          }
306    
307          m_attribute.setElementAt(m_attribute.elementAt(fromNode), toNode);
308        }
309        catch(Exception e)
310        {
311          error("Cloning attributes");
312        }
313      }
314    
315    
316      /**
317       * @param parm1
318       *
319       */
320      public int getFirstAttribute( int parm1 )
321      {
322        if (DEBUG) System.out.println("getFirstAttribute("+ parm1+")");
323        int nodeIdx = makeNodeIdentity(parm1);
324        if (nodeIdx != DTM.NULL)
325        {
326          int attribIdx =  m_attribute.elementAt(nodeIdx);
327          return makeNodeHandle(attribIdx);
328        }
329        else return DTM.NULL;
330      }
331    
332     /**
333       * @param parm1
334       *
335       */
336      public String getNodeValue( int parm1 )
337      {
338        if (DEBUG) System.out.println("getNodeValue(" + parm1 + ")");
339        try
340        {
341          Object o = m_ObjectArray.getAt(makeNodeIdentity(parm1));
342          if (o != null && o != S_ELEMENT_NODE)
343          {
344            return o.toString();
345          }
346          else
347          {
348            return "";
349          }
350        }
351        catch(Exception e)
352        {
353          error("Getting String Value");
354          return null;
355        }
356      }
357    
358    
359      /**
360       * Get the string-value of a node as a String object
361       * (see http://www.w3.org/TR/xpath#data-model
362       * for the definition of a node's string-value).
363       *
364       * @param nodeHandle The node ID.
365       *
366       * @return A string object that represents the string-value of the given node.
367       */
368      public XMLString getStringValue(int nodeHandle)
369      {
370        int nodeIdx = makeNodeIdentity(nodeHandle);
371        if (DEBUG) System.out.println("getStringValue(" + nodeIdx + ")");
372    
373          Object o = m_ObjectArray.getAt(nodeIdx);
374        if ( o == S_ELEMENT_NODE )
375          {
376            FastStringBuffer buf = StringBufferPool.get();
377            String s;
378    
379            try
380            {
381              getNodeData(nodeIdx, buf);
382    
383              s = (buf.length() > 0) ? buf.toString() : "";
384            }
385            finally
386            {
387              StringBufferPool.free(buf);
388            }
389    
390            return m_xstrf.newstr( s );
391          }
392          else if( o != null )
393          {
394            return m_xstrf.newstr(o.toString());
395        }
396        else
397          return(m_xstrf.emptystr());
398      }
399    
400      /**
401       * Retrieve the text content of a DOM subtree, appending it into a
402       * user-supplied FastStringBuffer object. Note that attributes are
403       * not considered part of the content of an element.
404       * <p>
405       * There are open questions regarding whitespace stripping.
406       * Currently we make no special effort in that regard, since the standard
407       * DOM doesn't yet provide DTD-based information to distinguish
408       * whitespace-in-element-context from genuine #PCDATA. Note that we
409       * should probably also consider xml:space if/when we address this.
410       * DOM Level 3 may solve the problem for us.
411       * <p>
412       * %REVIEW% Actually, since this method operates on the DOM side of the
413       * fence rather than the DTM side, it SHOULDN'T do
414       * any special handling. The DOM does what the DOM does; if you want
415       * DTM-level abstractions, use DTM-level methods.
416       *
417       * @param nodeIdx Index of node whose subtree is to be walked, gathering the
418       * contents of all Text or CDATASection nodes.
419       * @param buf FastStringBuffer into which the contents of the text
420       * nodes are to be concatenated.
421       */
422      protected void getNodeData(int nodeIdx, FastStringBuffer buf)
423      {
424        for ( int child = _firstch(nodeIdx) ; child != DTM.NULL ; child = _nextsib(child) )
425        {
426          Object o = m_ObjectArray.getAt(child);
427          if ( o == S_ELEMENT_NODE )
428            getNodeData(child, buf);
429          else if ( o != null )
430            buf.append(o.toString());
431        }
432      }
433    
434    
435    
436    
437      /**
438       * @param parm1
439       *
440       */
441      public int getNextAttribute( int parm1 )
442      {
443        int nodeIdx = makeNodeIdentity(parm1);
444        if (DEBUG) System.out.println("getNextAttribute(" + nodeIdx + ")");
445        if (nodeIdx != DTM.NULL) return makeNodeHandle(m_nextsib.elementAt(nodeIdx));
446        else return DTM.NULL;
447      }
448    
449    
450      /**
451       *
452       */
453      protected int getNumberOfNodes( )
454      {
455        if (DEBUG) System.out.println("getNumberOfNodes()");
456        return m_size;
457      }
458    
459      /**
460       *
461       */
462      protected boolean nextNode( )
463      {
464        if (DEBUG) System.out.println("nextNode()");
465        return false;
466      }
467    
468    
469      /**
470       * The Expanded Name table holds all of our Node names. The Base class
471       * will add the common element types, need to call this function from
472       * the derived class.
473       *
474       */
475      protected void createExpandedNameTable( )
476      {
477        m_Document_TypeID =
478          m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_DOCUMENT, DTM.DOCUMENT_NODE);
479    
480        m_TextNode_TypeID =
481          m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_TEXT_NODE, DTM.TEXT_NODE);
482      }
483    
484    
485      /**
486       *
487       */
488      public void dumpDTM( )
489      {
490        try
491        {
492    //      File f = new File("DTMDump"+((Object)this).hashCode()+".txt");
493          File f = new File("DTMDump.txt");
494          System.err.println("Dumping... "+f.getAbsolutePath());
495          PrintStream ps = new PrintStream(new FileOutputStream(f));
496    
497          while (nextNode()){}
498    
499          int nRecords = m_size;
500    
501          ps.println("Total nodes: " + nRecords);
502    
503          for (int i = 0; i < nRecords; i++)
504          {
505            ps.println("=========== " + i + " ===========");
506            ps.println("NodeName: " + getNodeName(makeNodeHandle(i)));
507            ps.println("NodeNameX: " + getNodeNameX(makeNodeHandle(i)));
508            ps.println("LocalName: " + getLocalName(makeNodeHandle(i)));
509            ps.println("NamespaceURI: " + getNamespaceURI(makeNodeHandle(i)));
510            ps.println("Prefix: " + getPrefix(makeNodeHandle(i)));
511    
512            int exTypeID = getExpandedTypeID(makeNodeHandle(i));
513    
514            ps.println("Expanded Type ID: "
515                               + Integer.toHexString(exTypeID));
516    
517            int type = getNodeType(makeNodeHandle(i));
518            String typestring;
519    
520            switch (type)
521            {
522            case DTM.ATTRIBUTE_NODE :
523              typestring = "ATTRIBUTE_NODE";
524              break;
525            case DTM.CDATA_SECTION_NODE :
526              typestring = "CDATA_SECTION_NODE";
527              break;
528            case DTM.COMMENT_NODE :
529              typestring = "COMMENT_NODE";
530              break;
531            case DTM.DOCUMENT_FRAGMENT_NODE :
532              typestring = "DOCUMENT_FRAGMENT_NODE";
533              break;
534            case DTM.DOCUMENT_NODE :
535              typestring = "DOCUMENT_NODE";
536              break;
537            case DTM.DOCUMENT_TYPE_NODE :
538              typestring = "DOCUMENT_NODE";
539              break;
540            case DTM.ELEMENT_NODE :
541              typestring = "ELEMENT_NODE";
542              break;
543            case DTM.ENTITY_NODE :
544              typestring = "ENTITY_NODE";
545              break;
546            case DTM.ENTITY_REFERENCE_NODE :
547              typestring = "ENTITY_REFERENCE_NODE";
548              break;
549            case DTM.NAMESPACE_NODE :
550              typestring = "NAMESPACE_NODE";
551              break;
552            case DTM.NOTATION_NODE :
553              typestring = "NOTATION_NODE";
554              break;
555            case DTM.NULL :
556              typestring = "NULL";
557              break;
558            case DTM.PROCESSING_INSTRUCTION_NODE :
559              typestring = "PROCESSING_INSTRUCTION_NODE";
560              break;
561            case DTM.TEXT_NODE :
562              typestring = "TEXT_NODE";
563              break;
564            default :
565              typestring = "Unknown!";
566              break;
567            }
568    
569            ps.println("Type: " + typestring);
570    
571            int firstChild = _firstch(i);
572    
573            if (DTM.NULL == firstChild)
574              ps.println("First child: DTM.NULL");
575            else if (NOTPROCESSED == firstChild)
576              ps.println("First child: NOTPROCESSED");
577            else
578              ps.println("First child: " + firstChild);
579    
580            int prevSibling = _prevsib(i);
581    
582            if (DTM.NULL == prevSibling)
583              ps.println("Prev sibling: DTM.NULL");
584            else if (NOTPROCESSED == prevSibling)
585              ps.println("Prev sibling: NOTPROCESSED");
586            else
587              ps.println("Prev sibling: " + prevSibling);
588    
589            int nextSibling = _nextsib(i);
590    
591            if (DTM.NULL == nextSibling)
592              ps.println("Next sibling: DTM.NULL");
593            else if (NOTPROCESSED == nextSibling)
594              ps.println("Next sibling: NOTPROCESSED");
595            else
596              ps.println("Next sibling: " + nextSibling);
597    
598            int parent = _parent(i);
599    
600            if (DTM.NULL == parent)
601              ps.println("Parent: DTM.NULL");
602            else if (NOTPROCESSED == parent)
603              ps.println("Parent: NOTPROCESSED");
604            else
605              ps.println("Parent: " + parent);
606    
607            int level = _level(i);
608    
609            ps.println("Level: " + level);
610            ps.println("Node Value: " + getNodeValue(i));
611            ps.println("String Value: " + getStringValue(i));
612    
613            ps.println("First Attribute Node: " + m_attribute.elementAt(i));
614          }
615    
616        }
617        catch(IOException ioe)
618        {
619          ioe.printStackTrace(System.err);
620          throw new RuntimeException(ioe.getMessage());
621        }
622      }
623    
624    
625      /**
626       * Retrieve the text content of a DOM subtree, appending it into a
627       * user-supplied FastStringBuffer object. Note that attributes are
628       * not considered part of the content of an element.
629       * <p>
630       * There are open questions regarding whitespace stripping.
631       * Currently we make no special effort in that regard, since the standard
632       * DOM doesn't yet provide DTD-based information to distinguish
633       * whitespace-in-element-context from genuine #PCDATA. Note that we
634       * should probably also consider xml:space if/when we address this.
635       * DOM Level 3 may solve the problem for us.
636       * <p>
637       * %REVIEW% Note that as a DOM-level operation, it can be argued that this
638       * routine _shouldn't_ perform any processing beyond what the DOM already
639       * does, and that whitespace stripping and so on belong at the DTM level.
640       * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
641       * @param node Node whose subtree is to be walked, gathering the
642       * contents of all Text or CDATASection nodes.
643       * @param ch
644       * @param depth
645       *
646       * @throws org.xml.sax.SAXException
647       */
648      protected static void dispatchNodeData( Node node, ContentHandler ch, int depth )throws org.xml.sax.SAXException
649      {
650    
651        switch (node.getNodeType())
652        {
653        case Node.DOCUMENT_FRAGMENT_NODE :
654        case Node.DOCUMENT_NODE :
655        case Node.ELEMENT_NODE :
656        {
657          for (Node child = node.getFirstChild(); null != child;
658                  child = child.getNextSibling())
659          {
660            dispatchNodeData(child, ch, depth+1);
661          }
662        }
663        break;
664        case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
665        case Node.COMMENT_NODE :
666          if(0 != depth)
667            break;
668            // NOTE: Because this operation works in the DOM space, it does _not_ attempt
669            // to perform Text Coalition. That should only be done in DTM space.
670        case Node.TEXT_NODE :
671        case Node.CDATA_SECTION_NODE :
672        case Node.ATTRIBUTE_NODE :
673          String str = node.getNodeValue();
674          if(ch instanceof CharacterNodeHandler)
675          {
676            ((CharacterNodeHandler)ch).characters(node);
677          }
678          else
679          {
680            ch.characters(str.toCharArray(), 0, str.length());
681          }
682          break;
683    //    /* case Node.PROCESSING_INSTRUCTION_NODE :
684    //      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
685    //      break; */
686        default :
687          // ignore
688          break;
689        }
690      }
691    
692      /*********************************************************************/
693      /*********************************************************************/
694      /******************* End of Functions we Wrote ***********************/
695      /*********************************************************************/
696      /*********************************************************************/
697    
698    
699      /**
700       * For the moment all the run time properties are ignored by this
701       * class.
702       * @param property a <code>String</code> value
703       * @param value an <code>Object</code> value
704       *
705       */
706      public void setProperty( String property, Object value )
707      {
708      }
709    
710      /**
711       * No source information is available for DOM2DTM, so return
712       * <code>null</code> here.
713       * @param node an <code>int</code> value
714       * @return null
715       */
716      public SourceLocator getSourceLocatorFor( int node )
717      {
718        return null;
719      }
720    
721      /**
722       * @param parm1
723       *
724       */
725      protected int getNextNodeIdentity( int parm1 )
726      {
727        if (DEBUG) System.out.println("getNextNodeIdenty(" + parm1 + ")");
728        return DTM.NULL;
729      }
730    
731      /**
732       * @param parm1
733       * @param parm2
734       * @param parm3
735       *
736       */
737      public int getAttributeNode( int parm1, String parm2, String parm3 )
738      {
739        if (DEBUG)
740        {
741          System.out.println(
742            "getAttributeNode(" +
743            parm1 + "," +
744            parm2 + "," +
745            parm3 + ")");
746        }
747        return DTM.NULL;
748      }
749    
750      /**
751       * @param parm1
752       *
753       */
754      public String getLocalName( int parm1 )
755      {
756    //    int exID = this.getExpandedTypeID( makeNodeIdentity(parm1) );
757          int exID = getExpandedTypeID(parm1);
758    
759        if (DEBUG)
760        {
761          DEBUG = false;
762          System.out.print("getLocalName(" + parm1 + ") -> ");
763          System.out.println("..." + getLocalNameFromExpandedNameID(exID) );
764          DEBUG = true;
765        }
766    
767        return getLocalNameFromExpandedNameID(exID);
768      }
769    
770      /**
771       * @param parm1
772       *
773       */
774      public String getNodeName( int parm1 )
775      {
776    //    int exID = getExpandedTypeID( makeNodeIdentity(parm1) );
777        int exID = getExpandedTypeID( parm1 );
778        if (DEBUG)
779        {
780          DEBUG = false;
781          System.out.print("getLocalName(" + parm1 + ") -> ");
782          System.out.println("..." + getLocalNameFromExpandedNameID(exID) );
783          DEBUG = true;
784        }
785        return getLocalNameFromExpandedNameID(exID);
786      }
787    
788       /**
789       * @param parm1
790       *
791       */
792      public boolean isAttributeSpecified( int parm1 )
793      {
794        if (DEBUG) System.out.println("isAttributeSpecified(" + parm1 + ")");
795        return false;
796      }
797    
798      /**
799       * @param parm1
800       *
801       */
802      public String getUnparsedEntityURI( String parm1 )
803      {
804        if (DEBUG) System.out.println("getUnparsedEntityURI(" + parm1 + ")");
805        return "";
806      }
807    
808      /**
809       *
810       */
811      public DTDHandler getDTDHandler( )
812      {
813        if (DEBUG) System.out.println("getDTDHandler()");
814        return null;
815      }
816    
817      /**
818       * @param parm1
819       *
820       */
821      public String getPrefix( int parm1 )
822      {
823        if (DEBUG) System.out.println("getPrefix(" + parm1  + ")");
824        return "";
825      }
826    
827      /**
828       *
829       */
830      public EntityResolver getEntityResolver( )
831      {
832        if (DEBUG) System.out.println("getEntityResolver()");
833        return null;
834      }
835    
836      /**
837       *
838       */
839      public String getDocumentTypeDeclarationPublicIdentifier( )
840      {
841        if (DEBUG) System.out.println("get_DTD_PubId()");
842        return "";
843      }
844    
845      /**
846       *
847       */
848      public LexicalHandler getLexicalHandler( )
849      {
850        if (DEBUG) System.out.println("getLexicalHandler()");
851        return null;
852      }
853      /**
854       *
855       */
856      public boolean needsTwoThreads( )
857      {
858        if (DEBUG) System.out.println("needsTwoThreads()");
859        return false;
860      }
861    
862      /**
863       *
864       */
865      public ContentHandler getContentHandler( )
866      {
867        if (DEBUG) System.out.println("getContentHandler()");
868        return null;
869      }
870    
871      /**
872       * @param parm1
873       * @param parm2
874       *
875       * @throws org.xml.sax.SAXException
876       */
877      public void dispatchToEvents( int parm1, ContentHandler parm2 )throws org.xml.sax.SAXException
878      {
879        if (DEBUG)
880        {
881          System.out.println(
882          "dispathcToEvents(" +
883          parm1 + "," +
884          parm2 + ")");
885        }
886        return;
887      }
888    
889      /**
890       * @param parm1
891       *
892       */
893      public String getNamespaceURI( int parm1 )
894      {
895        if (DEBUG) System.out.println("getNamespaceURI(" +parm1+")");
896        return "";
897      }
898    
899      /**
900       * @param nodeHandle
901       * @param ch
902       * @param normalize
903       *
904       * @throws org.xml.sax.SAXException
905       */
906      public void dispatchCharactersEvents( int nodeHandle, ContentHandler ch, boolean normalize )throws org.xml.sax.SAXException
907      {
908        if (DEBUG)
909        {
910          System.out.println("dispatchCharacterEvents(" +
911          nodeHandle + "," +
912          ch + "," +
913          normalize + ")");
914        }
915    
916        if(normalize)
917        {
918          XMLString str = getStringValue(nodeHandle);
919          str = str.fixWhiteSpace(true, true, false);
920          str.dispatchCharactersEvents(ch);
921        }
922        else
923        {
924          Node node = getNode(nodeHandle);
925          dispatchNodeData(node, ch, 0);
926        }
927      }
928    
929      /**
930       * Event overriding for Debug
931       *
932       */
933      public boolean supportsPreStripping( )
934      {
935        if (DEBUG) System.out.println("supportsPreStripping()");
936        return super.supportsPreStripping();
937      }
938    
939      /**
940       * @param parm1
941       *
942       */
943      protected int _exptype( int parm1 )
944      {
945        if (DEBUG) System.out.println("_exptype(" + parm1 + ")");
946        return super._exptype( parm1);
947      }
948    
949      /**
950       * @param parm1
951       *
952       */
953      protected SuballocatedIntVector findNamespaceContext( int parm1 )
954      {
955        if (DEBUG) System.out.println("SuballocatedIntVector(" + parm1 + ")");
956        return super.findNamespaceContext( parm1);
957      }
958    
959      /**
960       * @param parm1
961       *
962       */
963      protected int _prevsib( int parm1 )
964      {
965        if (DEBUG) System.out.println("_prevsib(" + parm1+ ")");
966        return super._prevsib( parm1);
967      }
968    
969    
970      /**
971       * @param parm1
972       *
973       */
974      protected short _type( int parm1 )
975      {
976        if (DEBUG) System.out.println("_type(" + parm1 + ")");
977        return super._type( parm1);
978      }
979    
980      /**
981       * @param parm1
982       *
983       */
984      public Node getNode( int parm1 )
985      {
986        if (DEBUG) System.out.println("getNode(" + parm1 + ")");
987        return super.getNode( parm1);
988      }
989    
990      /**
991       * @param parm1
992       *
993       */
994      public int getPreviousSibling( int parm1 )
995      {
996        if (DEBUG) System.out.println("getPrevSib(" + parm1 + ")");
997        return super.getPreviousSibling( parm1);
998      }
999    
1000      /**
1001       * @param parm1
1002       *
1003       */
1004      public String getDocumentStandalone( int parm1 )
1005      {
1006        if (DEBUG) System.out.println("getDOcStandAlone(" + parm1 + ")");
1007        return super.getDocumentStandalone( parm1);
1008      }
1009    
1010      /**
1011       * @param parm1
1012       *
1013       */
1014      public String getNodeNameX( int parm1 )
1015      {
1016        if (DEBUG) System.out.println("getNodeNameX(" + parm1 + ")");
1017        //return super.getNodeNameX( parm1);
1018        return getNodeName(parm1);
1019    
1020      }
1021    
1022      /**
1023       * @param parm1
1024       * @param parm2
1025       *
1026       */
1027      public void setFeature( String parm1, boolean parm2 )
1028      {
1029        if (DEBUG)
1030        {
1031          System.out.println(
1032            "setFeature(" +
1033            parm1 + "," +
1034            parm2 + ")");
1035        }
1036        super.setFeature( parm1,  parm2);
1037      }
1038    
1039      /**
1040       * @param parm1
1041       *
1042       */
1043      protected int _parent( int parm1 )
1044      {
1045        if (DEBUG) System.out.println("_parent(" + parm1 + ")");
1046        return super._parent( parm1);
1047      }
1048    
1049      /**
1050       * @param parm1
1051       * @param parm2
1052       *
1053       */
1054      protected void indexNode( int parm1, int parm2 )
1055      {
1056        if (DEBUG) System.out.println("indexNode("+parm1+","+parm2+")");
1057        super.indexNode( parm1,  parm2);
1058      }
1059    
1060      /**
1061       *
1062       */
1063      protected boolean getShouldStripWhitespace( )
1064      {
1065        if (DEBUG) System.out.println("getShouldStripWS()");
1066        return super.getShouldStripWhitespace();
1067      }
1068    
1069      /**
1070       *
1071       */
1072      protected void popShouldStripWhitespace( )
1073      {
1074        if (DEBUG) System.out.println("popShouldStripWS()");
1075        super.popShouldStripWhitespace();
1076      }
1077    
1078      /**
1079       * @param parm1
1080       * @param parm2
1081       *
1082       */
1083      public boolean isNodeAfter( int parm1, int parm2 )
1084      {
1085        if (DEBUG) System.out.println("isNodeAfter(" + parm1 + "," + parm2 + ")");
1086        return super.isNodeAfter( parm1,  parm2);
1087      }
1088    
1089      /**
1090       * @param parm1
1091       *
1092       */
1093      public int getNamespaceType( int parm1 )
1094      {
1095        if (DEBUG) System.out.println("getNamespaceType(" + parm1 + ")");
1096        return super.getNamespaceType( parm1);
1097      }
1098    
1099      /**
1100       * @param parm1
1101       *
1102       */
1103      protected int _level( int parm1 )
1104      {
1105        if (DEBUG) System.out.println("_level(" + parm1 + ")");
1106        return super._level( parm1);
1107      }
1108    
1109    
1110      /**
1111       * @param parm1
1112       *
1113       */
1114      protected void pushShouldStripWhitespace( boolean parm1 )
1115      {
1116        if (DEBUG) System.out.println("push_ShouldStripWS(" + parm1 + ")");
1117        super.pushShouldStripWhitespace( parm1);
1118      }
1119    
1120      /**
1121       * @param parm1
1122       *
1123       */
1124      public String getDocumentVersion( int parm1 )
1125      {
1126        if (DEBUG) System.out.println("getDocVer("+parm1+")");
1127        return super.getDocumentVersion( parm1);
1128      }
1129    
1130      /**
1131       * @param parm1
1132       * @param parm2
1133       *
1134       */
1135      public boolean isSupported( String parm1, String parm2 )
1136      {
1137        if (DEBUG) System.out.println("isSupported("+parm1+","+parm2+")");
1138        return super.isSupported( parm1,  parm2);
1139      }
1140    
1141    
1142      /**
1143       * @param parm1
1144       *
1145       */
1146      protected void setShouldStripWhitespace( boolean parm1 )
1147      {
1148        if (DEBUG) System.out.println("set_ShouldStripWS("+parm1+")");
1149        super.setShouldStripWhitespace( parm1);
1150      }
1151    
1152    
1153      /**
1154       * @param parm1
1155       * @param parm2
1156       *
1157       */
1158      protected void ensureSizeOfIndex( int parm1, int parm2 )
1159      {
1160        if (DEBUG) System.out.println("ensureSizeOfIndex("+parm1+","+parm2+")");
1161        super.ensureSizeOfIndex( parm1,  parm2);
1162      }
1163    
1164      /**
1165       * @param parm1
1166       *
1167       */
1168      protected void ensureSize( int parm1 )
1169      {
1170        if (DEBUG) System.out.println("ensureSize("+parm1+")");
1171    
1172        // IntVectors in DTMDefaultBase are now self-sizing, and ensureSize()
1173        // is being dropped.
1174        //super.ensureSize( parm1);
1175      }
1176    
1177      /**
1178       * @param parm1
1179       *
1180       */
1181      public String getDocumentEncoding( int parm1 )
1182      {
1183        if (DEBUG) System.out.println("getDocumentEncoding("+parm1+")");
1184        return super.getDocumentEncoding( parm1);
1185      }
1186    
1187      /**
1188       * @param parm1
1189       * @param parm2
1190       * @param parm3
1191       *
1192       */
1193      public void appendChild( int parm1, boolean parm2, boolean parm3 )
1194      {
1195        if (DEBUG)
1196        {
1197          System.out.println(
1198            "appendChild(" +
1199            parm1 + "," +
1200            parm2 + "," +
1201            parm3 + ")");
1202        }
1203        super.appendChild( parm1,  parm2,  parm3);
1204      }
1205    
1206      /**
1207       * @param parm1
1208       *
1209       */
1210      public short getLevel( int parm1 )
1211      {
1212        if (DEBUG) System.out.println("getLevel("+parm1+")");
1213        return super.getLevel( parm1);
1214      }
1215    
1216      /**
1217       *
1218       */
1219      public String getDocumentBaseURI( )
1220      {
1221        if (DEBUG) System.out.println("getDocBaseURI()");
1222        return super.getDocumentBaseURI();
1223      }
1224    
1225      /**
1226       * @param parm1
1227       * @param parm2
1228       * @param parm3
1229       *
1230       */
1231      public int getNextNamespaceNode( int parm1, int parm2, boolean parm3 )
1232      {
1233        if (DEBUG)
1234        {
1235          System.out.println(
1236          "getNextNamesapceNode(" +
1237          parm1 + "," +
1238          parm2 + "," +
1239          parm3 + ")");
1240        }
1241        return super.getNextNamespaceNode( parm1,  parm2,  parm3);
1242      }
1243    
1244      /**
1245       * @param parm1
1246       *
1247       */
1248      public void appendTextChild( String parm1 )
1249      {
1250        if (DEBUG) System.out.println("appendTextChild(" + parm1 + ")");
1251        super.appendTextChild( parm1);
1252      }
1253    
1254      /**
1255       * @param parm1
1256       * @param parm2
1257       * @param parm3
1258       * @param parm4
1259       *
1260       */
1261      protected int findGTE( int[] parm1, int parm2, int parm3, int parm4 )
1262      {
1263        if (DEBUG)
1264        {
1265          System.out.println(
1266          "findGTE("+
1267          parm1 + "," +
1268          parm2 + "," +
1269          parm3 + ")");
1270        }
1271        return super.findGTE( parm1,  parm2,  parm3,  parm4);
1272      }
1273    
1274      /**
1275       * @param parm1
1276       * @param parm2
1277       *
1278       */
1279      public int getFirstNamespaceNode( int parm1, boolean parm2 )
1280      {
1281        if (DEBUG) System.out.println("getFirstNamespaceNode()");
1282        return super.getFirstNamespaceNode( parm1,  parm2);
1283      }
1284    
1285      /**
1286       * @param parm1
1287       *
1288       */
1289      public int getStringValueChunkCount( int parm1 )
1290      {
1291        if (DEBUG) System.out.println("getStringChunkCount(" + parm1 + ")");
1292        return super.getStringValueChunkCount( parm1);
1293      }
1294    
1295      /**
1296       * @param parm1
1297       *
1298       */
1299      public int getLastChild( int parm1 )
1300      {
1301        if (DEBUG) System.out.println("getLastChild(" + parm1 + ")");
1302        return super.getLastChild( parm1);
1303      }
1304    
1305      /**
1306       * @param parm1
1307       *
1308       */
1309      public boolean hasChildNodes( int parm1 )
1310      {
1311        if (DEBUG) System.out.println("hasChildNodes(" + parm1 + ")");
1312        return super.hasChildNodes( parm1);
1313      }
1314    
1315      /**
1316       * @param parm1
1317       *
1318       */
1319      public short getNodeType( int parm1 )
1320      {
1321        if (DEBUG)
1322        {
1323          DEBUG=false;
1324          System.out.print("getNodeType(" + parm1 + ") ");
1325          int exID = getExpandedTypeID(parm1);
1326          String name = getLocalNameFromExpandedNameID(exID);
1327          System.out.println(
1328            ".. Node name [" + name + "]" +
1329            "[" + getNodeType( parm1) + "]");
1330    
1331          DEBUG=true;
1332        }
1333    
1334        return super.getNodeType( parm1);
1335      }
1336    
1337      /**
1338       * @param parm1
1339       *
1340       */
1341      public boolean isCharacterElementContentWhitespace( int parm1 )
1342      {
1343        if (DEBUG) System.out.println("isCharacterElementContentWhitespace(" + parm1 +")");
1344        return super.isCharacterElementContentWhitespace( parm1);
1345      }
1346    
1347      /**
1348       * @param parm1
1349       *
1350       */
1351      public int getFirstChild( int parm1 )
1352      {
1353        if (DEBUG) System.out.println("getFirstChild(" + parm1 + ")");
1354        return super.getFirstChild( parm1);
1355      }
1356    
1357      /**
1358       * @param parm1
1359       *
1360       */
1361      public String getDocumentSystemIdentifier( int parm1 )
1362      {
1363        if (DEBUG) System.out.println("getDocSysID(" + parm1 + ")");
1364        return super.getDocumentSystemIdentifier( parm1);
1365      }
1366    
1367      /**
1368       * @param parm1
1369       * @param parm2
1370       *
1371       */
1372      protected void declareNamespaceInContext( int parm1, int parm2 )
1373      {
1374        if (DEBUG) System.out.println("declareNamespaceContext("+parm1+","+parm2+")");
1375        super.declareNamespaceInContext( parm1,  parm2);
1376      }
1377    
1378      /**
1379       * @param parm1
1380       *
1381       */
1382      public String getNamespaceFromExpandedNameID( int parm1 )
1383      {
1384        if (DEBUG)
1385        {
1386          DEBUG = false;
1387          System.out.print("getNamespaceFromExpandedNameID("+parm1+")");
1388          System.out.println("..." + super.getNamespaceFromExpandedNameID( parm1) );
1389          DEBUG = true;
1390        }
1391        return super.getNamespaceFromExpandedNameID( parm1);
1392      }
1393    
1394      /**
1395       * @param parm1
1396       *
1397       */
1398      public String getLocalNameFromExpandedNameID( int parm1 )
1399      {
1400        if (DEBUG)
1401        {
1402          DEBUG = false;
1403          System.out.print("getLocalNameFromExpandedNameID("+parm1+")");
1404          System.out.println("..." + super.getLocalNameFromExpandedNameID( parm1));
1405          DEBUG = true;
1406        }
1407        return super.getLocalNameFromExpandedNameID( parm1);
1408      }
1409    
1410      /**
1411       * @param parm1
1412       *
1413       */
1414      public int getExpandedTypeID( int parm1 )
1415      {
1416        if (DEBUG) System.out.println("getExpandedTypeID("+parm1+")");
1417        return super.getExpandedTypeID( parm1);
1418      }
1419    
1420      /**
1421       *
1422       */
1423      public int getDocument( )
1424      {
1425        if (DEBUG) System.out.println("getDocument()");
1426        return super.getDocument();
1427      }
1428    
1429    
1430      /**
1431       * @param parm1
1432       * @param parm2
1433       *
1434       */
1435      protected int findInSortedSuballocatedIntVector( SuballocatedIntVector parm1, int parm2 )
1436      {
1437        if (DEBUG)
1438        {
1439          System.out.println(
1440          "findInSortedSubAlloctedVector(" +
1441          parm1 + "," +
1442          parm2 + ")");
1443        }
1444        return super.findInSortedSuballocatedIntVector( parm1,  parm2);
1445      }
1446    
1447      /**
1448       * @param parm1
1449       *
1450       */
1451      public boolean isDocumentAllDeclarationsProcessed( int parm1 )
1452      {
1453        if (DEBUG) System.out.println("isDocumentAllDeclProc("+parm1+")");
1454        return super.isDocumentAllDeclarationsProcessed( parm1);
1455      }
1456    
1457      /**
1458       * @param parm1
1459       *
1460       */
1461      protected void error( String parm1 )
1462      {
1463        if (DEBUG) System.out.println("error("+parm1+")");
1464        super.error( parm1);
1465      }
1466    
1467    
1468      /**
1469       * @param parm1
1470       *
1471       */
1472      protected int _firstch( int parm1 )
1473      {
1474        if (DEBUG) System.out.println("_firstch("+parm1+")");
1475        return super._firstch( parm1);
1476      }
1477    
1478      /**
1479       * @param parm1
1480       *
1481       */
1482      public int getOwnerDocument( int parm1 )
1483      {
1484        if (DEBUG) System.out.println("getOwnerDoc("+parm1+")");
1485        return super.getOwnerDocument( parm1);
1486      }
1487    
1488      /**
1489       * @param parm1
1490       *
1491       */
1492      protected int _nextsib( int parm1 )
1493      {
1494        if (DEBUG) System.out.println("_nextSib("+parm1+")");
1495        return super._nextsib( parm1);
1496      }
1497    
1498      /**
1499       * @param parm1
1500       *
1501       */
1502      public int getNextSibling( int parm1 )
1503      {
1504        if (DEBUG) System.out.println("getNextSibling("+parm1+")");
1505        return super.getNextSibling( parm1);
1506      }
1507    
1508    
1509      /**
1510       *
1511       */
1512      public boolean getDocumentAllDeclarationsProcessed( )
1513      {
1514        if (DEBUG) System.out.println("getDocAllDeclProc()");
1515        return super.getDocumentAllDeclarationsProcessed();
1516      }
1517    
1518      /**
1519       * @param parm1
1520       *
1521       */
1522      public int getParent( int parm1 )
1523      {
1524        if (DEBUG) System.out.println("getParent("+parm1+")");
1525        return super.getParent( parm1);
1526      }
1527    
1528      /**
1529       * @param parm1
1530       * @param parm2
1531       * @param parm3
1532       *
1533       */
1534      public int getExpandedTypeID( String parm1, String parm2, int parm3 )
1535      {
1536        if (DEBUG) System.out.println("getExpandedTypeID()");
1537        return super.getExpandedTypeID( parm1,  parm2,  parm3);
1538      }
1539    
1540      /**
1541       * @param parm1
1542       *
1543       */
1544      public void setDocumentBaseURI( String parm1 )
1545      {
1546        if (DEBUG) System.out.println("setDocBaseURI()");
1547        super.setDocumentBaseURI( parm1);
1548      }
1549    
1550      /**
1551       * @param parm1
1552       * @param parm2
1553       * @param parm3
1554       *
1555       */
1556      public char[] getStringValueChunk( int parm1, int parm2, int[] parm3 )
1557      {
1558        if (DEBUG)
1559        {
1560          System.out.println("getStringChunkValue(" +
1561          parm1 + "," +
1562          parm2 + ")");
1563        }
1564        return super.getStringValueChunk( parm1,  parm2,  parm3);
1565      }
1566    
1567      /**
1568       * @param parm1
1569       *
1570       */
1571      public DTMAxisTraverser getAxisTraverser( int parm1 )
1572      {
1573        if (DEBUG) System.out.println("getAxixTraverser("+parm1+")");
1574        return super.getAxisTraverser( parm1);
1575      }
1576    
1577      /**
1578       * @param parm1
1579       * @param parm2
1580       *
1581       */
1582      public DTMAxisIterator getTypedAxisIterator( int parm1, int parm2 )
1583      {
1584        if (DEBUG) System.out.println("getTypedAxisIterator("+parm1+","+parm2+")");
1585        return super.getTypedAxisIterator( parm1,  parm2);
1586      }
1587    
1588      /**
1589       * @param parm1
1590       *
1591       */
1592      public DTMAxisIterator getAxisIterator( int parm1 )
1593      {
1594        if (DEBUG) System.out.println("getAxisIterator("+parm1+")");
1595        return super.getAxisIterator( parm1);
1596      }
1597      /**
1598       * @param parm1
1599       *
1600       */
1601      public int getElementById( String parm1 )
1602      {
1603        if (DEBUG) System.out.println("getElementByID("+parm1+")");
1604        return DTM.NULL;
1605      }
1606    
1607      /**
1608       *
1609       */
1610      public DeclHandler getDeclHandler( )
1611      {
1612        if (DEBUG) System.out.println("getDeclHandler()");
1613        return null;
1614      }
1615    
1616      /**
1617       *
1618       */
1619      public ErrorHandler getErrorHandler( )
1620      {
1621        if (DEBUG) System.out.println("getErrorHandler()");
1622        return null;
1623      }
1624    
1625      /**
1626       *
1627       */
1628      public String getDocumentTypeDeclarationSystemIdentifier( )
1629      {
1630        if (DEBUG) System.out.println("get_DTD-SID()");
1631        return null;
1632      }
1633    
1634    
1635    }