[jdom-interest] Urgent Request to Add a method in SAXBuilder class
Jason Hunter
jhunter at acm.org
Tue Jul 31 15:41:49 PDT 2001
I'm OK with adding the setFeature() feature. The TODO gives my
thoughts:
* Consider a builder.setFeature() pass-through method that allows any
features to be set that aren't in the http://xml.org namespace. Make
those in http://xml.org not to be touched because either we have
specific
requirements for them to be set one way, or we have the feature
exposed
through a Java method.
We'd have to document the method as one to use as a last resort and
point out that changing settings might break JDOM parsing today, and
even if it doesn't break anything today it might break parsing in a
future JDOM version because what JDOM parsers require in parser feature
settings may change over time.
Alex, do you want to create a patch? Your builder patches last time
were excellent! :-)
-jh-
Alex Rosen wrote:
>
> 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);
> }
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list