Class DefaultConfigurationBuilder
Configurations from XML,
via a SAX2 compliant parser.
XML namespace support is optional, and disabled by default to preserve
backwards-compatibility. To enable it, pass the DefaultConfigurationBuilder(boolean) constructor the flag true, or pass
a namespace-enabled XMLReader to the DefaultConfigurationBuilder(XMLReader) constructor.
The mapping from XML namespaces to Configuration namespaces is pretty
straightforward, with one caveat: attribute namespaces are (deliberately) not
supported. Enabling namespace processing has the following effects:
- Attributes starting with
xmlns:are interpreted as declaring a prefix:namespaceURI mapping, and won't result in the creation ofxmlns-prefixed attributes in theConfiguration. -
Prefixed XML elements, like <doc:title xmlns:doc="http://foo.com">,
will result in a
ConfigurationwithandgetName().equals("title").getNamespace().equals("http://foo.com")
Whitespace handling. Since mixed content is not allowed in the
configurations, whitespace is completely discarded in non-leaf nodes.
For the leaf nodes the default behavior is to trim the space
surrounding the value. This can be changed by specifying
xml:space attribute with value of preserve
in that case the whitespace is left intact.
- Version:
- CVS $Revision: 1.33 $ $Date: 2004/04/03 23:55:54 $
- Author:
- Avalon Development Team
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a Configuration Builder with a default XMLReader that ignores namespaces.DefaultConfigurationBuilder(boolean enableNamespaces) Create a Configuration Builder, specifying a flag that determines namespace support.DefaultConfigurationBuilder(XMLReader parser) Create a Configuration Builder with your own XMLReader. -
Method Summary
Modifier and TypeMethodDescriptionbuild(InputStream inputStream) Build a configuration object using an InputStream.build(InputStream inputStream, String systemId) Build a configuration object using an InputStream; supplying a systemId to make messages about all kinds of errors more meaningfull.Build a configuration object using an URIbuild(InputSource input) Build a configuration object using an XML InputSource objectbuildFromFile(File file) Build a configuration object from a file using a File object.buildFromFile(String filename) Build a configuration object from a file using a filename.protected SAXConfigurationHandlerGet a SAXConfigurationHandler for your configuration reading.voidsetEntityResolver(EntityResolver resolver) Sets theEntityResolverto be used by parser.
-
Constructor Details
-
DefaultConfigurationBuilder
public DefaultConfigurationBuilder()Create a Configuration Builder with a default XMLReader that ignores namespaces. In order to enable namespaces, use either the constructor that has a boolean or that allows you to pass in your own namespace-enabled XMLReader. -
DefaultConfigurationBuilder
public DefaultConfigurationBuilder(boolean enableNamespaces) Create a Configuration Builder, specifying a flag that determines namespace support.- Parameters:
enableNamespaces- Iftrue, a namespace-awareSAXParseris used. Iffalse, the default JAXPSAXParser(without namespace support) is used.- Since:
- 4.1
-
DefaultConfigurationBuilder
Create a Configuration Builder with your own XMLReader.- Parameters:
parser- anXMLReader
-
-
Method Details
-
getHandler
Get a SAXConfigurationHandler for your configuration reading.- Returns:
- a
SAXConfigurationHandler
-
buildFromFile
public Configuration buildFromFile(String filename) throws SAXException, IOException, ConfigurationException Build a configuration object from a file using a filename.- Parameters:
filename- name of the file- Returns:
- a
Configurationobject - Throws:
SAXException- if a parsing error occursIOException- if an I/O error occursConfigurationException- if an error occurs
-
buildFromFile
public Configuration buildFromFile(File file) throws SAXException, IOException, ConfigurationException Build a configuration object from a file using a File object.- Parameters:
file- aFileobject- Returns:
- a
Configurationobject - Throws:
SAXException- if a parsing error occursIOException- if an I/O error occursConfigurationException- if an error occurs
-
build
public Configuration build(InputStream inputStream) throws SAXException, IOException, ConfigurationException Build a configuration object using an InputStream.- Parameters:
inputStream- anInputStreamvalue- Returns:
- a
Configurationobject - Throws:
SAXException- if a parsing error occursIOException- if an I/O error occursConfigurationException- if an error occurs
-
build
public Configuration build(InputStream inputStream, String systemId) throws SAXException, IOException, ConfigurationException Build a configuration object using an InputStream; supplying a systemId to make messages about all kinds of errors more meaningfull.- Parameters:
inputStream- anInputStreamvaluesystemId- the systemId to set on the intermediate sax inputSource- Returns:
- a
Configurationobject - Throws:
SAXException- if a parsing error occursIOException- if an I/O error occursConfigurationException- if an error occurs
-
build
Build a configuration object using an URI- Parameters:
uri- aStringvalue- Returns:
- a
Configurationobject - Throws:
SAXException- if a parsing error occursIOException- if an I/O error occursConfigurationException- if an error occurs
-
build
public Configuration build(InputSource input) throws SAXException, IOException, ConfigurationException Build a configuration object using an XML InputSource object- Parameters:
input- anInputSourcevalue- Returns:
- a
Configurationobject - Throws:
SAXException- if a parsing error occursIOException- if an I/O error occursConfigurationException- if an error occurs
-
setEntityResolver
Sets theEntityResolverto be used by parser. Useful when dealing with xml files that reference external entities.- Parameters:
resolver- implementation ofEntityResolver
-