donaldp 2003/04/04 20:11:18
Modified: src/java/org/apache/avalon/phoenix/tools/configuration
ConfigurationBuilder.java
Log:
Upgrade to useing entity resolver based on catalog. Also simplify interface to that
which is actually used.
Revision Changes Path
1.15 +20 -86
avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/configuration/ConfigurationBuilder.java
Index: ConfigurationBuilder.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/configuration/ConfigurationBuilder.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ConfigurationBuilder.java 22 Mar 2003 12:07:15 -0000 1.14
+++ ConfigurationBuilder.java 5 Apr 2003 04:11:18 -0000 1.15
@@ -59,6 +59,8 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+import org.xml.sax.EntityResolver;
+import org.realityforge.configkit.ResolverFactory;
/**
* Utility class used to load Configuration trees from XML files.
@@ -68,57 +70,26 @@
*/
public class ConfigurationBuilder
{
- private static final DTDInfo[] c_dtdInfo = new DTDInfo[]
- {
- new DTDInfo( "-//PHOENIX/Assembly DTD Version 1.0//EN",
- "http://jakarta.apache.org/phoenix/assembly_1_0.dtd",
- "org/apache/avalon/phoenix/tools/assembly.dtd" ),
- new DTDInfo( "-//PHOENIX/Mx Info DTD Version 1.0//EN",
- "http://jakarta.apache.org/phoenix/mxinfo_1_0.dtd",
- "org/apache/avalon/phoenix/tools/mxinfo.dtd" ),
- new DTDInfo( "-//PHOENIX/Assembly DTD Version 1.0//EN",
-
"http://jakarta.apache.org/avalon/dtds/phoenix/assembly_1_0.dtd",
- "org/apache/avalon/phoenix/tools/assembly.dtd" ),
- new DTDInfo( "-//PHOENIX/Mx Info DTD Version 1.0//EN",
- "http://jakarta.apache.org/avalon/dtds/phoenix/mxinfo_1_0.dtd",
- "org/apache/avalon/phoenix/tools/mxinfo.dtd" ),
- new DTDInfo( "-//PHOENIX/Assembly DTD Version 1.0//EN",
- "http://jakarta.apache.org/phoenix/assembly_1.0.dtd",
- "org/apache/avalon/phoenix/tools/assembly.dtd" ),
- new DTDInfo( "-//PHOENIX/Mx Info DTD Version 1.0//EN",
- "http://jakarta.apache.org/phoenix/mxinfo_1.0.dtd",
- "org/apache/avalon/phoenix/tools/mxinfo.dtd" ),
- new DTDInfo( "-//PHOENIX/Assembly DTD Version 1.0//EN",
-
"http://jakarta.apache.org/avalon/dtds/phoenix/assembly_1.0.dtd",
- "org/apache/avalon/phoenix/tools/assembly.dtd" ),
- new DTDInfo( "-//PHOENIX/Mx Info DTD Version 1.0//EN",
- "http://jakarta.apache.org/avalon/dtds/phoenix/mxinfo_1.0.dtd",
- "org/apache/avalon/phoenix/tools/mxinfo.dtd" ),
- new DTDInfo( "-//PHOENIX/Assembly DTD Version 1.1//EN",
- "http://jakarta.apache.org/phoenix/assembly_1.1.dtd",
- "org/apache/avalon/phoenix/tools/assembly.dtd" )
- };
-
- private static final DTDResolver c_resolver =
- new DTDResolver( c_dtdInfo, ConfigurationBuilder.class.getClassLoader() );
-
/**
- * Private constructor to block instantiation.
+ * The resolver that builder uses.
*/
- private ConfigurationBuilder()
- {
- }
+ private static EntityResolver c_resolver;
/**
- * Utility method to create a new XML reader.
+ * Build a configuration object using an XML InputSource object, and
+ * optionally validate the xml against the DTD.
*/
- private static XMLReader createXMLReader()
- throws SAXException, ParserConfigurationException
+ public static Configuration build( final InputSource input, final boolean
validate )
+ throws SAXException, ParserConfigurationException, IOException
{
final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware( false );
final SAXParser saxParser = saxParserFactory.newSAXParser();
- return saxParser.getXMLReader();
+ final XMLReader reader = saxParser.getXMLReader();
+ final SAXConfigurationHandler handler = new SAXConfigurationHandler();
+ setupXMLReader( reader, handler, validate );
+ reader.parse( input );
+ return handler.getConfiguration();
}
/**
@@ -127,8 +98,13 @@
private static void setupXMLReader( final XMLReader reader,
final SAXConfigurationHandler handler,
final boolean validate )
- throws SAXException
+ throws SAXException, IOException, ParserConfigurationException
{
+ if( null == c_resolver )
+ {
+ c_resolver =
+ ResolverFactory.createResolver(
ConfigurationBuilder.class.getClassLoader() );
+ }
reader.setEntityResolver( c_resolver );
reader.setContentHandler( handler );
reader.setErrorHandler( handler );
@@ -138,47 +114,5 @@
// Request validation
reader.setFeature( "http://xml.org/sax/features/validation", true );
}
- }
-
- /**
- * Build a configuration object using an URI
- */
- public static Configuration build( final String uri )
- throws SAXException, ParserConfigurationException, IOException
- {
- return build( new InputSource( uri ) );
- }
-
- /**
- * Build a configuration object using an URI, and
- * optionally validate the xml against the DTD.
- */
- public static Configuration build( final String uri, final boolean validate )
- throws SAXException, ParserConfigurationException, IOException
- {
- return build( new InputSource( uri ), validate );
- }
-
- /**
- * Build a configuration object using an XML InputSource object
- */
- public static Configuration build( final InputSource input )
- throws SAXException, ParserConfigurationException, IOException
- {
- return build( input, false );
- }
-
- /**
- * Build a configuration object using an XML InputSource object, and
- * optionally validate the xml against the DTD.
- */
- public static Configuration build( final InputSource input, final boolean
validate )
- throws SAXException, ParserConfigurationException, IOException
- {
- final XMLReader reader = createXMLReader();
- final SAXConfigurationHandler handler = new SAXConfigurationHandler();
- setupXMLReader( reader, handler, validate );
- reader.parse( input );
- return handler.getConfiguration();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]