[jdom-interest] Urgent Request to Add a method in SAXBuilder class
Alex Rosen
arosen at silverstream.com
Tue Jul 31 07:45:30 PDT 2001
I agree that this is important. Jason has concerns, however. See the
discussion that starts here:
http://www.servlets.com/archive/servlet/ReadMsg?msgId=6801&listName=jdom
-interest.
With the refactoring of SAXBuilder in Beta 7, you can work around this
yourself. Here is a subclass of SAXBuilder that lets you set features
and properties.
Alex
import java.util.*;
import org.jdom.input.*;
import org.xml.sax.*;
// This is a JDOM SAXBuilder that can set particular features or
properties
// on the underlying SAX parser (XMLReader). NOTE: The base JDOM
SAXBuilder
// sets certain properties and features of the parser as well, and may
not
// function properly if those settings are changed. However, there are
many
// settings that can certainly be changed without a problem, such as the
// "allow-java-encodings" feature.
public class OurSAXBuilder extends SAXBuilder
{
public OurSAXBuilder()
{
}
public void setFeature(String name, boolean value)
{
// Save the specified feature for later.
m_features.put(name, new Boolean(value));
}
public void setProperty(String name, Object value)
{
// Save the specified property for later.
m_properties.put(name, value);
}
protected void configureParser(XMLReader parser, SAXHandler
contentHandler)
throws Exception
{
super.configureParser(parser, contentHandler);
// Set any specified features on the underlying parser.
Iterator iter = m_features.keySet().iterator();
while(iter.hasNext())
{
String name = (String)iter.next();
Boolean value = (Boolean)m_features.get(name);
parser.setFeature(name, value.booleanValue());
}
// Set any specified properties on the underlying parser.
iter = m_properties.keySet().iterator();
while(iter.hasNext())
{
String name = (String)iter.next();
Object value = m_properties.get(name);
parser.setProperty(name, value);
}
}
private HashMap m_features = new HashMap(5);
private HashMap m_properties = new HashMap(5);
}
More information about the jdom-interest
mailing list