286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: DOMBuilder.java,v 1.2.4.1 2005/09/15 08:15:39 suresh_emailid Exp $
286N/A */
286N/Apackage com.sun.org.apache.xml.internal.utils;
286N/A
286N/Aimport java.util.Stack;
286N/A
286N/Aimport com.sun.org.apache.xml.internal.res.XMLErrorResources;
286N/Aimport com.sun.org.apache.xml.internal.res.XMLMessages;
286N/A
286N/Aimport org.w3c.dom.Document;
286N/Aimport org.w3c.dom.DocumentFragment;
286N/Aimport org.w3c.dom.Element;
286N/Aimport org.w3c.dom.Node;
286N/Aimport org.w3c.dom.Text;
286N/Aimport org.w3c.dom.CDATASection;
286N/A
286N/Aimport org.xml.sax.Attributes;
286N/Aimport org.xml.sax.ContentHandler;
286N/Aimport org.xml.sax.Locator;
286N/Aimport org.xml.sax.ext.LexicalHandler;
286N/A/**
286N/A * This class takes SAX events (in addition to some extra events
286N/A * that SAX doesn't handle yet) and adds the result to a document
286N/A * or document fragment.
286N/A * @xsl.usage general
286N/A */
286N/Apublic class DOMBuilder
286N/A implements ContentHandler, LexicalHandler
286N/A{
286N/A
286N/A /** Root document */
286N/A public Document m_doc;
286N/A
286N/A /** Current node */
286N/A protected Node m_currentNode = null;
286N/A
286N/A /** The root node */
286N/A protected Node m_root = null;
286N/A
286N/A /** The next sibling node */
286N/A protected Node m_nextSibling = null;
286N/A
286N/A /** First node of document fragment or null if not a DocumentFragment */
286N/A public DocumentFragment m_docFrag = null;
286N/A
286N/A /** Vector of element nodes */
286N/A protected Stack m_elemStack = new Stack();
286N/A
286N/A /**
286N/A * DOMBuilder instance constructor... it will add the DOM nodes
286N/A * to the document fragment.
286N/A *
286N/A * @param doc Root document
286N/A * @param node Current node
286N/A */
286N/A public DOMBuilder(Document doc, Node node)
286N/A {
286N/A m_doc = doc;
286N/A m_currentNode = m_root = node;
286N/A
286N/A if (node instanceof Element)
286N/A m_elemStack.push(node);
286N/A }
286N/A
286N/A /**
286N/A * DOMBuilder instance constructor... it will add the DOM nodes
286N/A * to the document fragment.
286N/A *
286N/A * @param doc Root document
286N/A * @param docFrag Document fragment
286N/A */
286N/A public DOMBuilder(Document doc, DocumentFragment docFrag)
286N/A {
286N/A m_doc = doc;
286N/A m_docFrag = docFrag;
286N/A }
286N/A
286N/A /**
286N/A * DOMBuilder instance constructor... it will add the DOM nodes
286N/A * to the document.
286N/A *
286N/A * @param doc Root document
286N/A */
286N/A public DOMBuilder(Document doc)
286N/A {
286N/A m_doc = doc;
286N/A }
286N/A
286N/A /**
286N/A * Get the root document or DocumentFragment of the DOM being created.
286N/A *
286N/A * @return The root document or document fragment if not null
286N/A */
286N/A public Node getRootDocument()
286N/A {
286N/A return (null != m_docFrag) ? (Node) m_docFrag : (Node) m_doc;
286N/A }
286N/A
286N/A /**
286N/A * Get the root node of the DOM tree.
286N/A */
286N/A public Node getRootNode()
286N/A {
286N/A return m_root;
286N/A }
286N/A
286N/A /**
286N/A * Get the node currently being processed.
286N/A *
286N/A * @return the current node being processed
286N/A */
286N/A public Node getCurrentNode()
286N/A {
286N/A return m_currentNode;
286N/A }
286N/A
286N/A /**
286N/A * Set the next sibling node, which is where the result nodes
286N/A * should be inserted before.
286N/A *
286N/A * @param nextSibling the next sibling node.
286N/A */
286N/A public void setNextSibling(Node nextSibling)
286N/A {
286N/A m_nextSibling = nextSibling;
286N/A }
286N/A
286N/A /**
286N/A * Return the next sibling node.
286N/A *
286N/A * @return the next sibling node.
286N/A */
286N/A public Node getNextSibling()
286N/A {
286N/A return m_nextSibling;
286N/A }
286N/A
286N/A /**
286N/A * Return null since there is no Writer for this class.
286N/A *
286N/A * @return null
286N/A */
286N/A public java.io.Writer getWriter()
286N/A {
286N/A return null;
286N/A }
286N/A
286N/A /**
286N/A * Append a node to the current container.
286N/A *
286N/A * @param newNode New node to append
286N/A */
286N/A protected void append(Node newNode) throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A Node currentNode = m_currentNode;
286N/A
286N/A if (null != currentNode)
286N/A {
286N/A if (currentNode == m_root && m_nextSibling != null)
286N/A currentNode.insertBefore(newNode, m_nextSibling);
286N/A else
286N/A currentNode.appendChild(newNode);
286N/A
286N/A // System.out.println(newNode.getNodeName());
286N/A }
286N/A else if (null != m_docFrag)
286N/A {
286N/A if (m_nextSibling != null)
286N/A m_docFrag.insertBefore(newNode, m_nextSibling);
286N/A else
286N/A m_docFrag.appendChild(newNode);
286N/A }
286N/A else
286N/A {
286N/A boolean ok = true;
286N/A short type = newNode.getNodeType();
286N/A
286N/A if (type == Node.TEXT_NODE)
286N/A {
286N/A String data = newNode.getNodeValue();
286N/A
286N/A if ((null != data) && (data.trim().length() > 0))
286N/A {
286N/A throw new org.xml.sax.SAXException(
286N/A XMLMessages.createXMLMessage(
286N/A XMLErrorResources.ER_CANT_OUTPUT_TEXT_BEFORE_DOC, null)); //"Warning: can't output text before document element! Ignoring...");
286N/A }
286N/A
286N/A ok = false;
286N/A }
286N/A else if (type == Node.ELEMENT_NODE)
286N/A {
286N/A if (m_doc.getDocumentElement() != null)
286N/A {
286N/A ok = false;
286N/A
286N/A throw new org.xml.sax.SAXException(
286N/A XMLMessages.createXMLMessage(
286N/A XMLErrorResources.ER_CANT_HAVE_MORE_THAN_ONE_ROOT, null)); //"Can't have more than one root on a DOM!");
286N/A }
286N/A }
286N/A
286N/A if (ok)
286N/A {
286N/A if (m_nextSibling != null)
286N/A m_doc.insertBefore(newNode, m_nextSibling);
286N/A else
286N/A m_doc.appendChild(newNode);
286N/A }
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Receive an object for locating the origin of SAX document events.
286N/A *
286N/A * <p>SAX parsers are strongly encouraged (though not absolutely
286N/A * required) to supply a locator: if it does so, it must supply
286N/A * the locator to the application by invoking this method before
286N/A * invoking any of the other methods in the ContentHandler
286N/A * interface.</p>
286N/A *
286N/A * <p>The locator allows the application to determine the end
286N/A * position of any document-related event, even if the parser is
286N/A * not reporting an error. Typically, the application will
286N/A * use this information for reporting its own errors (such as
286N/A * character content that does not match an application's
286N/A * business rules). The information returned by the locator
286N/A * is probably not sufficient for use with a search engine.</p>
286N/A *
286N/A * <p>Note that the locator will return correct information only
286N/A * during the invocation of the events in this interface. The
286N/A * application should not attempt to use it at any other time.</p>
286N/A *
286N/A * @param locator An object that can return the location of
286N/A * any SAX document event.
286N/A * @see org.xml.sax.Locator
286N/A */
286N/A public void setDocumentLocator(Locator locator)
286N/A {
286N/A
286N/A // No action for the moment.
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of the beginning of a document.
286N/A *
286N/A * <p>The SAX parser will invoke this method only once, before any
286N/A * other methods in this interface or in DTDHandler (except for
286N/A * setDocumentLocator).</p>
286N/A */
286N/A public void startDocument() throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A // No action for the moment.
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of the end of a document.
286N/A *
286N/A * <p>The SAX parser will invoke this method only once, and it will
286N/A * be the last method invoked during the parse. The parser shall
286N/A * not invoke this method until it has either abandoned parsing
286N/A * (because of an unrecoverable error) or reached the end of
286N/A * input.</p>
286N/A */
286N/A public void endDocument() throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A // No action for the moment.
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of the beginning of an element.
286N/A *
286N/A * <p>The Parser will invoke this method at the beginning of every
286N/A * element in the XML document; there will be a corresponding
286N/A * endElement() event for every startElement() event (even when the
286N/A * element is empty). All of the element's content will be
286N/A * reported, in order, before the corresponding endElement()
286N/A * event.</p>
286N/A *
286N/A * <p>If the element name has a namespace prefix, the prefix will
286N/A * still be attached. Note that the attribute list provided will
286N/A * contain only attributes with explicit values (specified or
286N/A * defaulted): #IMPLIED attributes will be omitted.</p>
286N/A *
286N/A *
286N/A * @param ns The namespace of the node
286N/A * @param localName The local part of the qualified name
286N/A * @param name The element name.
286N/A * @param atts The attributes attached to the element, if any.
286N/A * @see #endElement
286N/A * @see org.xml.sax.Attributes
286N/A */
286N/A public void startElement(
286N/A String ns, String localName, String name, Attributes atts)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A Element elem;
286N/A
286N/A // Note that the namespace-aware call must be used to correctly
286N/A // construct a Level 2 DOM, even for non-namespaced nodes.
286N/A if ((null == ns) || (ns.length() == 0))
286N/A elem = m_doc.createElementNS(null,name);
286N/A else
286N/A elem = m_doc.createElementNS(ns, name);
286N/A
286N/A append(elem);
286N/A
286N/A try
286N/A {
286N/A int nAtts = atts.getLength();
286N/A
286N/A if (0 != nAtts)
286N/A {
286N/A for (int i = 0; i < nAtts; i++)
286N/A {
286N/A
286N/A //System.out.println("type " + atts.getType(i) + " name " + atts.getLocalName(i) );
286N/A // First handle a possible ID attribute
286N/A if (atts.getType(i).equalsIgnoreCase("ID"))
286N/A setIDAttribute(atts.getValue(i), elem);
286N/A
286N/A String attrNS = atts.getURI(i);
286N/A
286N/A if("".equals(attrNS))
286N/A attrNS = null; // DOM represents no-namespace as null
286N/A
286N/A // System.out.println("attrNS: "+attrNS+", localName: "+atts.getQName(i)
286N/A // +", qname: "+atts.getQName(i)+", value: "+atts.getValue(i));
286N/A // Crimson won't let us set an xmlns: attribute on the DOM.
286N/A String attrQName = atts.getQName(i);
286N/A
286N/A // In SAX, xmlns[:] attributes have an empty namespace, while in DOM they
286N/A // should have the xmlns namespace
286N/A if (attrQName.startsWith("xmlns:") || attrQName.equals("xmlns")) {
286N/A attrNS = "http://www.w3.org/2000/xmlns/";
286N/A }
286N/A
286N/A // ALWAYS use the DOM Level 2 call!
286N/A elem.setAttributeNS(attrNS,attrQName, atts.getValue(i));
286N/A }
286N/A }
286N/A
286N/A // append(elem);
286N/A
286N/A m_elemStack.push(elem);
286N/A
286N/A m_currentNode = elem;
286N/A
286N/A // append(elem);
286N/A }
286N/A catch(java.lang.Exception de)
286N/A {
286N/A // de.printStackTrace();
286N/A throw new org.xml.sax.SAXException(de);
286N/A }
286N/A
286N/A }
286N/A
286N/A /**
286N/A
286N/A
286N/A
286N/A * Receive notification of the end of an element.
286N/A *
286N/A * <p>The SAX parser will invoke this method at the end of every
286N/A * element in the XML document; there will be a corresponding
286N/A * startElement() event for every endElement() event (even when the
286N/A * element is empty).</p>
286N/A *
286N/A * <p>If the element name has a namespace prefix, the prefix will
286N/A * still be attached to the name.</p>
286N/A *
286N/A *
286N/A * @param ns the namespace of the element
286N/A * @param localName The local part of the qualified name of the element
286N/A * @param name The element name
286N/A */
286N/A public void endElement(String ns, String localName, String name)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A m_elemStack.pop();
286N/A m_currentNode = m_elemStack.isEmpty() ? null : (Node)m_elemStack.peek();
286N/A }
286N/A
286N/A /**
286N/A * Set an ID string to node association in the ID table.
286N/A *
286N/A * @param id The ID string.
286N/A * @param elem The associated ID.
286N/A */
286N/A public void setIDAttribute(String id, Element elem)
286N/A {
286N/A
286N/A // Do nothing. This method is meant to be overiden.
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of character data.
286N/A *
286N/A * <p>The Parser will call this method to report each chunk of
286N/A * character data. SAX parsers may return all contiguous character
286N/A * data in a single chunk, or they may split it into several
286N/A * chunks; however, all of the characters in any single event
286N/A * must come from the same external entity, so that the Locator
286N/A * provides useful information.</p>
286N/A *
286N/A * <p>The application must not attempt to read from the array
286N/A * outside of the specified range.</p>
286N/A *
286N/A * <p>Note that some parsers will report whitespace using the
286N/A * ignorableWhitespace() method rather than this one (validating
286N/A * parsers must do so).</p>
286N/A *
286N/A * @param ch The characters from the XML document.
286N/A * @param start The start position in the array.
286N/A * @param length The number of characters to read from the array.
286N/A * @see #ignorableWhitespace
286N/A * @see org.xml.sax.Locator
286N/A */
286N/A public void characters(char ch[], int start, int length) throws org.xml.sax.SAXException
286N/A {
286N/A if(isOutsideDocElem()
286N/A && com.sun.org.apache.xml.internal.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
286N/A return; // avoid DOM006 Hierarchy request error
286N/A
286N/A if (m_inCData)
286N/A {
286N/A cdata(ch, start, length);
286N/A
286N/A return;
286N/A }
286N/A
286N/A String s = new String(ch, start, length);
286N/A Node childNode;
286N/A childNode = m_currentNode != null ? m_currentNode.getLastChild(): null;
286N/A if( childNode != null && childNode.getNodeType() == Node.TEXT_NODE ){
286N/A ((Text)childNode).appendData(s);
286N/A }
286N/A else{
286N/A Text text = m_doc.createTextNode(s);
286N/A append(text);
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * If available, when the disable-output-escaping attribute is used,
286N/A * output raw text without escaping. A PI will be inserted in front
286N/A * of the node with the name "lotusxsl-next-is-raw" and a value of
286N/A * "formatter-to-dom".
286N/A *
286N/A * @param ch Array containing the characters
286N/A * @param start Index to start of characters in the array
286N/A * @param length Number of characters in the array
286N/A */
286N/A public void charactersRaw(char ch[], int start, int length)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A if(isOutsideDocElem()
286N/A && com.sun.org.apache.xml.internal.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
286N/A return; // avoid DOM006 Hierarchy request error
286N/A
286N/A
286N/A String s = new String(ch, start, length);
286N/A
286N/A append(m_doc.createProcessingInstruction("xslt-next-is-raw",
286N/A "formatter-to-dom"));
286N/A append(m_doc.createTextNode(s));
286N/A }
286N/A
286N/A /**
286N/A * Report the beginning of an entity.
286N/A *
286N/A * The start and end of the document entity are not reported.
286N/A * The start and end of the external DTD subset are reported
286N/A * using the pseudo-name "[dtd]". All other events must be
286N/A * properly nested within start/end entity events.
286N/A *
286N/A * @param name The name of the entity. If it is a parameter
286N/A * entity, the name will begin with '%'.
286N/A * @see #endEntity
286N/A * @see org.xml.sax.ext.DeclHandler#internalEntityDecl
286N/A * @see org.xml.sax.ext.DeclHandler#externalEntityDecl
286N/A */
286N/A public void startEntity(String name) throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A // Almost certainly the wrong behavior...
286N/A // entityReference(name);
286N/A }
286N/A
286N/A /**
286N/A * Report the end of an entity.
286N/A *
286N/A * @param name The name of the entity that is ending.
286N/A * @see #startEntity
286N/A */
286N/A public void endEntity(String name) throws org.xml.sax.SAXException{}
286N/A
286N/A /**
286N/A * Receive notivication of a entityReference.
286N/A *
286N/A * @param name name of the entity reference
286N/A */
286N/A public void entityReference(String name) throws org.xml.sax.SAXException
286N/A {
286N/A append(m_doc.createEntityReference(name));
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of ignorable whitespace in element content.
286N/A *
286N/A * <p>Validating Parsers must use this method to report each chunk
286N/A * of ignorable whitespace (see the W3C XML 1.0 recommendation,
286N/A * section 2.10): non-validating parsers may also use this method
286N/A * if they are capable of parsing and using content models.</p>
286N/A *
286N/A * <p>SAX parsers may return all contiguous whitespace in a single
286N/A * chunk, or they may split it into several chunks; however, all of
286N/A * the characters in any single event must come from the same
286N/A * external entity, so that the Locator provides useful
286N/A * information.</p>
286N/A *
286N/A * <p>The application must not attempt to read from the array
286N/A * outside of the specified range.</p>
286N/A *
286N/A * @param ch The characters from the XML document.
286N/A * @param start The start position in the array.
286N/A * @param length The number of characters to read from the array.
286N/A * @see #characters
286N/A */
286N/A public void ignorableWhitespace(char ch[], int start, int length)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A if(isOutsideDocElem())
286N/A return; // avoid DOM006 Hierarchy request error
286N/A
286N/A String s = new String(ch, start, length);
286N/A
286N/A append(m_doc.createTextNode(s));
286N/A }
286N/A
286N/A /**
286N/A * Tell if the current node is outside the document element.
286N/A *
286N/A * @return true if the current node is outside the document element.
286N/A */
286N/A private boolean isOutsideDocElem()
286N/A {
286N/A return (null == m_docFrag) && m_elemStack.size() == 0 && (null == m_currentNode || m_currentNode.getNodeType() == Node.DOCUMENT_NODE);
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of a processing instruction.
286N/A *
286N/A * <p>The Parser will invoke this method once for each processing
286N/A * instruction found: note that processing instructions may occur
286N/A * before or after the main document element.</p>
286N/A *
286N/A * <p>A SAX parser should never report an XML declaration (XML 1.0,
286N/A * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
286N/A * using this method.</p>
286N/A *
286N/A * @param target The processing instruction target.
286N/A * @param data The processing instruction data, or null if
286N/A * none was supplied.
286N/A */
286N/A public void processingInstruction(String target, String data)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A append(m_doc.createProcessingInstruction(target, data));
286N/A }
286N/A
286N/A /**
286N/A * Report an XML comment anywhere in the document.
286N/A *
286N/A * This callback will be used for comments inside or outside the
286N/A * document element, including comments in the external DTD
286N/A * subset (if read).
286N/A *
286N/A * @param ch An array holding the characters in the comment.
286N/A * @param start The starting position in the array.
286N/A * @param length The number of characters to use from the array.
286N/A */
286N/A public void comment(char ch[], int start, int length) throws org.xml.sax.SAXException
286N/A {
286N/A append(m_doc.createComment(new String(ch, start, length)));
286N/A }
286N/A
286N/A /** Flag indicating that we are processing a CData section */
286N/A protected boolean m_inCData = false;
286N/A
286N/A /**
286N/A * Report the start of a CDATA section.
286N/A *
286N/A * @see #endCDATA
286N/A */
286N/A public void startCDATA() throws org.xml.sax.SAXException
286N/A {
286N/A m_inCData = true;
286N/A append(m_doc.createCDATASection(""));
286N/A }
286N/A
286N/A /**
286N/A * Report the end of a CDATA section.
286N/A *
286N/A * @see #startCDATA
286N/A */
286N/A public void endCDATA() throws org.xml.sax.SAXException
286N/A {
286N/A m_inCData = false;
286N/A }
286N/A
286N/A /**
286N/A * Receive notification of cdata.
286N/A *
286N/A * <p>The Parser will call this method to report each chunk of
286N/A * character data. SAX parsers may return all contiguous character
286N/A * data in a single chunk, or they may split it into several
286N/A * chunks; however, all of the characters in any single event
286N/A * must come from the same external entity, so that the Locator
286N/A * provides useful information.</p>
286N/A *
286N/A * <p>The application must not attempt to read from the array
286N/A * outside of the specified range.</p>
286N/A *
286N/A * <p>Note that some parsers will report whitespace using the
286N/A * ignorableWhitespace() method rather than this one (validating
286N/A * parsers must do so).</p>
286N/A *
286N/A * @param ch The characters from the XML document.
286N/A * @param start The start position in the array.
286N/A * @param length The number of characters to read from the array.
286N/A * @see #ignorableWhitespace
286N/A * @see org.xml.sax.Locator
286N/A */
286N/A public void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException
286N/A {
286N/A if(isOutsideDocElem()
286N/A && com.sun.org.apache.xml.internal.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
286N/A return; // avoid DOM006 Hierarchy request error
286N/A
286N/A String s = new String(ch, start, length);
286N/A
286N/A CDATASection section =(CDATASection) m_currentNode.getLastChild();
286N/A section.appendData(s);
286N/A }
286N/A
286N/A /**
286N/A * Report the start of DTD declarations, if any.
286N/A *
286N/A * Any declarations are assumed to be in the internal subset
286N/A * unless otherwise indicated.
286N/A *
286N/A * @param name The document type name.
286N/A * @param publicId The declared public identifier for the
286N/A * external DTD subset, or null if none was declared.
286N/A * @param systemId The declared system identifier for the
286N/A * external DTD subset, or null if none was declared.
286N/A * @see #endDTD
286N/A * @see #startEntity
286N/A */
286N/A public void startDTD(String name, String publicId, String systemId)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A // Do nothing for now.
286N/A }
286N/A
286N/A /**
286N/A * Report the end of DTD declarations.
286N/A *
286N/A * @see #startDTD
286N/A */
286N/A public void endDTD() throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A // Do nothing for now.
286N/A }
286N/A
286N/A /**
286N/A * Begin the scope of a prefix-URI Namespace mapping.
286N/A *
286N/A * <p>The information from this event is not necessary for
286N/A * normal Namespace processing: the SAX XML reader will
286N/A * automatically replace prefixes for element and attribute
286N/A * names when the http://xml.org/sax/features/namespaces
286N/A * feature is true (the default).</p>
286N/A *
286N/A * <p>There are cases, however, when applications need to
286N/A * use prefixes in character data or in attribute values,
286N/A * where they cannot safely be expanded automatically; the
286N/A * start/endPrefixMapping event supplies the information
286N/A * to the application to expand prefixes in those contexts
286N/A * itself, if necessary.</p>
286N/A *
286N/A * <p>Note that start/endPrefixMapping events are not
286N/A * guaranteed to be properly nested relative to each-other:
286N/A * all startPrefixMapping events will occur before the
286N/A * corresponding startElement event, and all endPrefixMapping
286N/A * events will occur after the corresponding endElement event,
286N/A * but their order is not guaranteed.</p>
286N/A *
286N/A * @param prefix The Namespace prefix being declared.
286N/A * @param uri The Namespace URI the prefix is mapped to.
286N/A * @see #endPrefixMapping
286N/A * @see #startElement
286N/A */
286N/A public void startPrefixMapping(String prefix, String uri)
286N/A throws org.xml.sax.SAXException
286N/A {
286N/A
286N/A /*
286N/A // Not sure if this is needed or wanted
286N/A // Also, it fails in the stree.
286N/A if((null != m_currentNode)
286N/A && (m_currentNode.getNodeType() == Node.ELEMENT_NODE))
286N/A {
286N/A String qname;
286N/A if(((null != prefix) && (prefix.length() == 0))
286N/A || (null == prefix))
286N/A qname = "xmlns";
286N/A else
286N/A qname = "xmlns:"+prefix;
286N/A
286N/A Element elem = (Element)m_currentNode;
286N/A String val = elem.getAttribute(qname); // Obsolete, should be DOM2...?
286N/A if(val == null)
286N/A {
286N/A elem.setAttributeNS("http://www.w3.org/XML/1998/namespace",
286N/A qname, uri);
286N/A }
286N/A }
286N/A */
286N/A }
286N/A
286N/A /**
286N/A * End the scope of a prefix-URI mapping.
286N/A *
286N/A * <p>See startPrefixMapping for details. This event will
286N/A * always occur after the corresponding endElement event,
286N/A * but the order of endPrefixMapping events is not otherwise
286N/A * guaranteed.</p>
286N/A *
286N/A * @param prefix The prefix that was being mapping.
286N/A * @see #startPrefixMapping
286N/A * @see #endElement
286N/A */
286N/A public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException{}
286N/A
286N/A /**
286N/A * Receive notification of a skipped entity.
286N/A *
286N/A * <p>The Parser will invoke this method once for each entity
286N/A * skipped. Non-validating processors may skip entities if they
286N/A * have not seen the declarations (because, for example, the
286N/A * entity was declared in an external DTD subset). All processors
286N/A * may skip external entities, depending on the values of the
286N/A * http://xml.org/sax/features/external-general-entities and the
286N/A * http://xml.org/sax/features/external-parameter-entities
286N/A * properties.</p>
286N/A *
286N/A * @param name The name of the skipped entity. If it is a
286N/A * parameter entity, the name will begin with '%'.
286N/A */
286N/A public void skippedEntity(String name) throws org.xml.sax.SAXException{}
286N/A}