19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: DOMBuilder.java 472634 2006-11-08 20:43:55Z jycli $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.utils;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Stack;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Vector;
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.res.XMLErrorResources;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.res.XMLMessages;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Document;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.DocumentFragment;
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Element;
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Node;
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Text;
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.CDATASection;
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Attributes;
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.ContentHandler;
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.Locator;
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.ext.LexicalHandler;
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This class takes SAX events (in addition to some extra events
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * that SAX doesn't handle yet) and adds the result to a document
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or document fragment.
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage general
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class DOMBuilder
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        implements ContentHandler, LexicalHandler
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** Root document          */
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Document m_doc;
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** Current node           */
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected Node m_currentNode = null;
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** The root node          */
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected Node m_root = null;
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** The next sibling node  */
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected Node m_nextSibling = null;
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** First node of document fragment or null if not a DocumentFragment     */
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public DocumentFragment m_docFrag = null;
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** Vector of element nodes          */
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected Stack m_elemStack = new Stack();
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** Namespace support */
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected Vector m_prefixMappings = new Vector();
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * DOMBuilder instance constructor... it will add the DOM nodes
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to the document fragment.
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param doc Root document
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param node Current node
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public DOMBuilder(Document doc, Node node)
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_doc = doc;
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_currentNode = m_root = node;
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (node instanceof Element)
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_elemStack.push(node);
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * DOMBuilder instance constructor... it will add the DOM nodes
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to the document fragment.
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param doc Root document
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param docFrag Document fragment
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public DOMBuilder(Document doc, DocumentFragment docFrag)
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_doc = doc;
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_docFrag = docFrag;
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * DOMBuilder instance constructor... it will add the DOM nodes
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to the document.
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param doc Root document
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public DOMBuilder(Document doc)
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_doc = doc;
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the root document or DocumentFragment of the DOM being created.
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The root document or document fragment if not null
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Node getRootDocument()
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return (null != m_docFrag) ? (Node) m_docFrag : (Node) m_doc;
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the root node of the DOM tree.
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Node getRootNode()
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_root;
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the node currently being processed.
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the current node being processed
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Node getCurrentNode()
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_currentNode;
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the next sibling node, which is where the result nodes
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * should be inserted before.
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param nextSibling the next sibling node.
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setNextSibling(Node nextSibling)
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_nextSibling = nextSibling;
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the next sibling node.
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the next sibling node.
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public Node getNextSibling()
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_nextSibling;
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return null since there is no Writer for this class.
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return null
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public java.io.Writer getWriter()
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return null;
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Append a node to the current container.
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param newNode New node to append
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected void append(Node newNode) throws org.xml.sax.SAXException
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    Node currentNode = m_currentNode;
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != currentNode)
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (currentNode == m_root && m_nextSibling != null)
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        currentNode.insertBefore(newNode, m_nextSibling);
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        currentNode.appendChild(newNode);
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // System.out.println(newNode.getNodeName());
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else if (null != m_docFrag)
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (m_nextSibling != null)
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        m_docFrag.insertBefore(newNode, m_nextSibling);
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        m_docFrag.appendChild(newNode);
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      boolean ok = true;
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      short type = newNode.getNodeType();
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (type == Node.TEXT_NODE)
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        String data = newNode.getNodeValue();
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if ((null != data) && (data.trim().length() > 0))
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw new org.xml.sax.SAXException(
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            XMLMessages.createXMLMessage(
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              XMLErrorResources.ER_CANT_OUTPUT_TEXT_BEFORE_DOC, null));  //"Warning: can't output text before document element!  Ignoring...");
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        ok = false;
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else if (type == Node.ELEMENT_NODE)
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (m_doc.getDocumentElement() != null)
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          ok = false;
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throw new org.xml.sax.SAXException(
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            XMLMessages.createXMLMessage(
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              XMLErrorResources.ER_CANT_HAVE_MORE_THAN_ONE_ROOT, null));  //"Can't have more than one root on a DOM!");
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (ok)
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (m_nextSibling != null)
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          m_doc.insertBefore(newNode, m_nextSibling);
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        else
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          m_doc.appendChild(newNode);
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive an object for locating the origin of SAX document events.
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>SAX parsers are strongly encouraged (though not absolutely
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * required) to supply a locator: if it does so, it must supply
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the locator to the application by invoking this method before
2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * invoking any of the other methods in the ContentHandler
2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * interface.</p>
2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The locator allows the application to determine the end
2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * position of any document-related event, even if the parser is
2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * not reporting an error.  Typically, the application will
2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * use this information for reporting its own errors (such as
2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * character content that does not match an application's
2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * business rules).  The information returned by the locator
2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is probably not sufficient for use with a search engine.</p>
2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>Note that the locator will return correct information only
2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * during the invocation of the events in this interface.  The
2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * application should not attempt to use it at any other time.</p>
2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param locator An object that can return the location of
2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *                any SAX document event.
2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.xml.sax.Locator
2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setDocumentLocator(Locator locator)
2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // No action for the moment.
2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of the beginning of a document.
2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The SAX parser will invoke this method only once, before any
2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * other methods in this interface or in DTDHandler (except for
2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * setDocumentLocator).</p>
2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void startDocument() throws org.xml.sax.SAXException
2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // No action for the moment.
2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of the end of a document.
2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The SAX parser will invoke this method only once, and it will
2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * be the last method invoked during the parse.  The parser shall
2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * not invoke this method until it has either abandoned parsing
2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * (because of an unrecoverable error) or reached the end of
2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * input.</p>
2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endDocument() throws org.xml.sax.SAXException
2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // No action for the moment.
2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of the beginning of an element.
2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The Parser will invoke this method at the beginning of every
2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * element in the XML document; there will be a corresponding
3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * endElement() event for every startElement() event (even when the
3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * element is empty). All of the element's content will be
3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * reported, in order, before the corresponding endElement()
3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * event.</p>
3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>If the element name has a namespace prefix, the prefix will
3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * still be attached.  Note that the attribute list provided will
3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * contain only attributes with explicit values (specified or
3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * defaulted): #IMPLIED attributes will be omitted.</p>
3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ns The namespace of the node
3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param localName The local part of the qualified name
3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name The element name.
3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param atts The attributes attached to the element, if any.
3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #endElement
3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.xml.sax.Attributes
3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void startElement(
3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          String ns, String localName, String name, Attributes atts)
3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            throws org.xml.sax.SAXException
3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    Element elem;
3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	// Note that the namespace-aware call must be used to correctly
3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	// construct a Level 2 DOM, even for non-namespaced nodes.
3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if ((null == ns) || (ns.length() == 0))
3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      elem = m_doc.createElementNS(null,name);
3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else
3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      elem = m_doc.createElementNS(ns, name);
3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(elem);
3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    try
3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      int nAtts = atts.getLength();
3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (0 != nAtts)
3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        for (int i = 0; i < nAtts; i++)
3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          //System.out.println("type " + atts.getType(i) + " name " + atts.getLocalName(i) );
3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // First handle a possible ID attribute
3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (atts.getType(i).equalsIgnoreCase("ID"))
3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            setIDAttribute(atts.getValue(i), elem);
3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          String attrNS = atts.getURI(i);
3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if("".equals(attrNS))
3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            attrNS = null; // DOM represents no-namespace as null
3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // System.out.println("attrNS: "+attrNS+", localName: "+atts.getQName(i)
3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          //                   +", qname: "+atts.getQName(i)+", value: "+atts.getValue(i));
3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // Crimson won't let us set an xmlns: attribute on the DOM.
3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          String attrQName = atts.getQName(i);
3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // In SAX, xmlns[:] attributes have an empty namespace, while in DOM they
3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // should have the xmlns namespace
3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (attrQName.startsWith("xmlns:") || attrQName.equals("xmlns")) {
3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            attrNS = "http://www.w3.org/2000/xmlns/";
3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          }
3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          // ALWAYS use the DOM Level 2 call!
3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          elem.setAttributeNS(attrNS,attrQName, atts.getValue(i));
3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      /*
3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       * Adding namespace nodes to the DOM tree;
3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       */
3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      int nDecls = m_prefixMappings.size();
3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      String prefix, declURL;
3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      for (int i = 0; i < nDecls; i += 2)
3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        prefix = (String) m_prefixMappings.elementAt(i);
3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (prefix == null)
3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          continue;
3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        declURL = (String) m_prefixMappings.elementAt(i + 1);
3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        elem.setAttributeNS("http://www.w3.org/2000/xmlns/", prefix, declURL);
3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_prefixMappings.clear();
3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // append(elem);
3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_elemStack.push(elem);
3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_currentNode = elem;
3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // append(elem);
3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    catch(java.lang.Exception de)
3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // de.printStackTrace();
4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      throw new org.xml.sax.SAXException(de);
4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of the end of an element.
4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The SAX parser will invoke this method at the end of every
4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * element in the XML document; there will be a corresponding
4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * startElement() event for every endElement() event (even when the
4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * element is empty).</p>
4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>If the element name has a namespace prefix, the prefix will
4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * still be attached to the name.</p>
4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ns the namespace of the element
4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param localName The local part of the qualified name of the element
4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name The element name
4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endElement(String ns, String localName, String name)
4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws org.xml.sax.SAXException
4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_elemStack.pop();
4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_currentNode = m_elemStack.isEmpty() ? null : (Node)m_elemStack.peek();
4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set an ID string to node association in the ID table.
4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param id The ID string.
4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param elem The associated ID.
4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setIDAttribute(String id, Element elem)
4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Do nothing. This method is meant to be overiden.
4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of character data.
4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The Parser will call this method to report each chunk of
4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * character data.  SAX parsers may return all contiguous character
4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * data in a single chunk, or they may split it into several
4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * chunks; however, all of the characters in any single event
4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * must come from the same external entity, so that the Locator
4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * provides useful information.</p>
4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The application must not attempt to read from the array
4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * outside of the specified range.</p>
4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>Note that some parsers will report whitespace using the
4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * ignorableWhitespace() method rather than this one (validating
4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * parsers must do so).</p>
4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ch The characters from the XML document.
4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param start The start position in the array.
4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param length The number of characters to read from the array.
4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #ignorableWhitespace
4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.xml.sax.Locator
4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void characters(char ch[], int start, int length) throws org.xml.sax.SAXException
4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(isOutsideDocElem()
4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return;  // avoid DOM006 Hierarchy request error
4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (m_inCData)
4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      cdata(ch, start, length);
4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return;
4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    String s = new String(ch, start, length);
4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    Node childNode;
4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    childNode =  m_currentNode != null ? m_currentNode.getLastChild(): null;
4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if( childNode != null && childNode.getNodeType() == Node.TEXT_NODE ){
4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       ((Text)childNode).appendData(s);
4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else{
4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       Text text = m_doc.createTextNode(s);
4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       append(text);
4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * If available, when the disable-output-escaping attribute is used,
4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * output raw text without escaping.  A PI will be inserted in front
4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of the node with the name "lotusxsl-next-is-raw" and a value of
4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * "formatter-to-dom".
4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ch Array containing the characters
4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param start Index to start of characters in the array
5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param length Number of characters in the array
5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void charactersRaw(char ch[], int start, int length)
5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws org.xml.sax.SAXException
5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(isOutsideDocElem()
5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return;  // avoid DOM006 Hierarchy request error
5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    String s = new String(ch, start, length);
5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createProcessingInstruction("xslt-next-is-raw",
5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                             "formatter-to-dom"));
5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createTextNode(s));
5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report the beginning of an entity.
5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The start and end of the document entity are not reported.
5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The start and end of the external DTD subset are reported
5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * using the pseudo-name "[dtd]".  All other events must be
5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * properly nested within start/end entity events.
5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name The name of the entity.  If it is a parameter
5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *        entity, the name will begin with '%'.
5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #endEntity
5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.xml.sax.ext.DeclHandler#internalEntityDecl
5299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.xml.sax.ext.DeclHandler#externalEntityDecl
5309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void startEntity(String name) throws org.xml.sax.SAXException
5329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Almost certainly the wrong behavior...
5359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // entityReference(name);
5369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report the end of an entity.
5409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name The name of the entity that is ending.
5429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #startEntity
5439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endEntity(String name) throws org.xml.sax.SAXException{}
5459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notivication of a entityReference.
5489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name name of the entity reference
5509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void entityReference(String name) throws org.xml.sax.SAXException
5529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createEntityReference(name));
5549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of ignorable whitespace in element content.
5589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>Validating Parsers must use this method to report each chunk
5609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of ignorable whitespace (see the W3C XML 1.0 recommendation,
5619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * section 2.10): non-validating parsers may also use this method
5629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * if they are capable of parsing and using content models.</p>
5639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>SAX parsers may return all contiguous whitespace in a single
5659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * chunk, or they may split it into several chunks; however, all of
5669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the characters in any single event must come from the same
5679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * external entity, so that the Locator provides useful
5689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * information.</p>
5699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The application must not attempt to read from the array
5719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * outside of the specified range.</p>
5729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ch The characters from the XML document.
5749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param start The start position in the array.
5759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param length The number of characters to read from the array.
5769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #characters
5779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void ignorableWhitespace(char ch[], int start, int length)
5799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws org.xml.sax.SAXException
5809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(isOutsideDocElem())
5829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return;  // avoid DOM006 Hierarchy request error
5839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    String s = new String(ch, start, length);
5859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createTextNode(s));
5879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tell if the current node is outside the document element.
5919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return true if the current node is outside the document element.
5939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   private boolean isOutsideDocElem()
5959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   {
5969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return (null == m_docFrag) && m_elemStack.size() == 0 && (null == m_currentNode || m_currentNode.getNodeType() == Node.DOCUMENT_NODE);
5979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   }
5989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of a processing instruction.
6019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The Parser will invoke this method once for each processing
6039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * instruction found: note that processing instructions may occur
6049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * before or after the main document element.</p>
6059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>A SAX parser should never report an XML declaration (XML 1.0,
6079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
6089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * using this method.</p>
6099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param target The processing instruction target.
6119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param data The processing instruction data, or null if
6129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *        none was supplied.
6139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void processingInstruction(String target, String data)
6159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws org.xml.sax.SAXException
6169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
6179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createProcessingInstruction(target, data));
6189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
6199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report an XML comment anywhere in the document.
6229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This callback will be used for comments inside or outside the
6249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * document element, including comments in the external DTD
6259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * subset (if read).
6269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ch An array holding the characters in the comment.
6289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param start The starting position in the array.
6299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param length The number of characters to use from the array.
6309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void comment(char ch[], int start, int length) throws org.xml.sax.SAXException
6329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
6339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createComment(new String(ch, start, length)));
6349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
6359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /** Flag indicating that we are processing a CData section          */
6379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected boolean m_inCData = false;
6389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report the start of a CDATA section.
6419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #endCDATA
6439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void startCDATA() throws org.xml.sax.SAXException
6459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
6469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_inCData = true;
6479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    append(m_doc.createCDATASection(""));
6489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
6499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report the end of a CDATA section.
6529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #startCDATA
6549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endCDATA() throws org.xml.sax.SAXException
6569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
6579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_inCData = false;
6589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
6599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of cdata.
6629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The Parser will call this method to report each chunk of
6649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * character data.  SAX parsers may return all contiguous character
6659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * data in a single chunk, or they may split it into several
6669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * chunks; however, all of the characters in any single event
6679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * must come from the same external entity, so that the Locator
6689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * provides useful information.</p>
6699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The application must not attempt to read from the array
6719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * outside of the specified range.</p>
6729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>Note that some parsers will report whitespace using the
6749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * ignorableWhitespace() method rather than this one (validating
6759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * parsers must do so).</p>
6769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param ch The characters from the XML document.
6789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param start The start position in the array.
6799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param length The number of characters to read from the array.
6809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #ignorableWhitespace
6819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.xml.sax.Locator
6829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
6839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException
6849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
6859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(isOutsideDocElem()
6869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
6879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return;  // avoid DOM006 Hierarchy request error
6889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    String s = new String(ch, start, length);
6909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    CDATASection section  =(CDATASection) m_currentNode.getLastChild();
6929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    section.appendData(s);
6939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
6949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
6959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
6969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report the start of DTD declarations, if any.
6979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
6989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Any declarations are assumed to be in the internal subset
6999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * unless otherwise indicated.
7009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name The document type name.
7029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param publicId The declared public identifier for the
7039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *        external DTD subset, or null if none was declared.
7049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param systemId The declared system identifier for the
7059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *        external DTD subset, or null if none was declared.
7069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #endDTD
7079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #startEntity
7089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
7099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void startDTD(String name, String publicId, String systemId)
7109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws org.xml.sax.SAXException
7119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
7129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
7139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Do nothing for now.
7149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
7159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
7169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
7179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Report the end of DTD declarations.
7189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #startDTD
7209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
7219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endDTD() throws org.xml.sax.SAXException
7229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
7239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
7249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Do nothing for now.
7259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
7269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
7279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
7289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Begin the scope of a prefix-URI Namespace mapping.
7299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The information from this event is not necessary for
7319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * normal Namespace processing: the SAX XML reader will
7329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * automatically replace prefixes for element and attribute
7339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * names when the http://xml.org/sax/features/namespaces
7349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * feature is true (the default).</p>
7359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>There are cases, however, when applications need to
7379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * use prefixes in character data or in attribute values,
7389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * where they cannot safely be expanded automatically; the
7399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * start/endPrefixMapping event supplies the information
7409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * to the application to expand prefixes in those contexts
7419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * itself, if necessary.</p>
7429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>Note that start/endPrefixMapping events are not
7449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * guaranteed to be properly nested relative to each-other:
7459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * all startPrefixMapping events will occur before the
7469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * corresponding startElement event, and all endPrefixMapping
7479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * events will occur after the corresponding endElement event,
7489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * but their order is not guaranteed.</p>
7499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param prefix The Namespace prefix being declared.
7519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param uri The Namespace URI the prefix is mapped to.
7529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #endPrefixMapping
7539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #startElement
7549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
7559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void startPrefixMapping(String prefix, String uri)
7569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws org.xml.sax.SAXException
7579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
7589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      if(null == prefix || prefix.equals(""))
7599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	        prefix = "xmlns";
7609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      else prefix = "xmlns:"+prefix;
7619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      m_prefixMappings.addElement(prefix);
7629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson	      m_prefixMappings.addElement(uri);
7639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
7649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
7659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
7669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * End the scope of a prefix-URI mapping.
7679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>See startPrefixMapping for details.  This event will
7699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * always occur after the corresponding endElement event,
7709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * but the order of endPrefixMapping events is not otherwise
7719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * guaranteed.</p>
7729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param prefix The prefix that was being mapping.
7749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #startPrefixMapping
7759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see #endElement
7769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
7779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException{}
7789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
7799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
7809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Receive notification of a skipped entity.
7819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * <p>The Parser will invoke this method once for each entity
7839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * skipped.  Non-validating processors may skip entities if they
7849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * have not seen the declarations (because, for example, the
7859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * entity was declared in an external DTD subset).  All processors
7869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * may skip external entities, depending on the values of the
7879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * http://xml.org/sax/features/external-general-entities and the
7889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * http://xml.org/sax/features/external-parameter-entities
7899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * properties.</p>
7909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
7919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param name The name of the skipped entity.  If it is a
7929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *        parameter entity, the name will begin with '%'.
7939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
7949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void skippedEntity(String name) throws org.xml.sax.SAXException{}
7959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
796