/*--
$Id: SAXHandler.java,v 1.19 2001/08/01 00:30:28 bmclaugh Exp $
Copyright (C) 2000 Brett McLaughlin & Jason Hunter.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the disclaimer that follows
these conditions in the documentation and/or other materials
provided with the distribution.
3. The name "JDOM" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact license@jdom.org.
4. Products derived from this software may not be called "JDOM", nor
may "JDOM" appear in their name, without prior written permission
from the JDOM Project Management (pm@jdom.org).
In addition, we request (but do not require) that you include in the
end-user documentation provided with the redistribution and/or in the
software itself an acknowledgement equivalent to the following:
"This product includes software developed by the
JDOM Project (http://www.jdom.org/)."
Alternatively, the acknowledgment may be graphical using the logos
available at http://www.jdom.org/images/logos.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
This software consists of voluntary contributions made by many
individuals on behalf of the JDOM Project and was originally
created by Brett McLaughlin and
Jason Hunter . For more information on the
JDOM Project, please see .
*/
package org.jdom.input;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;
import org.jdom.*;
import org.xml.sax.*;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
/**
*

* This sets whether or not to expand entities during the build.
* A true means to expand entities as normal content. A false means to
* leave entities unexpanded as EntityRef objects. The
* default is true.
*

* Specifies whether or not the parser should elminate whitespace in
* element content (sometimes known as "ignorable whitespace") when
* building the document. Only whitespace which is contained within
* element content that has an element only content model will be
* eliminated (see XML Rec 3.2.1). For this setting to take effect
* requires that validation be turned on. The default value of this
* setting is false.
*

*
* @param ignoringWhite Whether to ignore ignorable whitespace
*/
public void setIgnoringElementContentWhitespace(boolean ignoringWhite) {
this.ignoringWhite = ignoringWhite;
}
// PHIL
/**
* End the current text processing.
*/
private void endPendingText() {
/**
* This is commented out because of some problems with
* the inline DTDs that Xerces seems to have.
if (!inDTD) {
if (inEntity) {
((Entity)stack.peek()).setContent(getPendingString(pendingText,false));
} else {
Element e = (Element)stack.peek();
e.addContent(getPendingString(pendingText,false));
}
*/
if (inCDATA) {
((Element)stack.peek()).addContent(factory.cdata(getPendingString(pendingText,true)));
}
else {
Element e = (Element)stack.peek();
// Since all the text is already aggregated, we can safetly add the text to the list
// NOTE: this only works with patched JDOM, where getContent() does not create a temporary partial list
//e.addContent(stringBuffer.toString());
e.getContent().add(getPendingString(pendingText,false));
}
pendingText.setLength(0);
}
protected String getPendingString( StringBuffer buffer, boolean inCDATA ) {
// PHIL: because strings and string buffers share the character buffer, we force the
// string class to create a new buffer from the string buffer data. This is done
// by extracting the substring. This saves LOTS of memory
return buffer.substring(0);
}
//END PHIL
/**
* This is called when the parser encounters an external entity
* declaration.
*

*
* @param prefix String namespace prefix.
* @param uri String namespace URI.
*/
public void endPrefixMapping(String prefix)
throws SAXException {
if (suppress) return;
// Remove the namespace from the available list
// (Should find the namespace fast because recent adds
// are at the front of the list. It may not be the head
// tho because endPrefixMapping calls on the same element
// can come in any order.)
Iterator itr = availableNamespaces.iterator();
while (itr.hasNext()) {
Namespace ns = (Namespace) itr.next();
if (prefix.equals(ns.getPrefix())) {
itr.remove();
return;
}
}
}
/**
*

* This reports the occurrence of an actual element. It will include
* the element's attributes, with the exception of XML vocabulary
* specific attributes, such as
* xmlns:[namespace prefix] and
* xsi:schemaLocation.
*