Top Description Fields Constructors Methods
org.apache.tools.ant.util

public Class JAXPUtils

extends Object
Class Inheritance
Imports
java.io.File, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .FactoryConfigurationError, .ParserConfigurationException, .SAXParser, .SAXParserFactory, org.apache.tools.ant.BuildException, org.xml.sax.Parser, .SAXException, .XMLReader

Collection of helper methods that retrieve a ParserFactory or Parsers and Readers.

This class will create only a single factory instance.

Since
Ant 1.5

Field Summary

Modifier and TypeField and Description
private static DocumentBuilderFactory
builderFactory

Parser factory to use to create document builders.

private static final FileUtils
FILE_UTILS

Helper for systemId.

private static SAXParserFactory
nsParserFactory

Parser Factory to create Namespace aware parsers.

private static SAXParserFactory
parserFactory

Parser factory to use to create parsers.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static BuildException
convertToBuildException(SAXException e)

Translate a SAXException into a BuildException

public static DocumentBuilder

Returns:

a DocumentBuilder.
getDocumentBuilder
()

Returns a newly created DocumentBuilder.

private static synchronized DocumentBuilderFactory
getDocumentBuilderFactory()

Obtains the default builder factory if not already.

public static XMLReader

Returns:

a SAX 2 XMLReader.
getNamespaceXMLReader
()

Returns a newly created SAX 2 XMLReader, which is namespace aware

public static synchronized SAXParserFactory

Returns:

a SAXParserFactory to use which supports manufacture of namespace aware parsers.
getNSParserFactory
()

Returns the parser factory to use to create namespace aware parsers.

public static Parser

Returns:

a SAX 1 Parser.
getParser
()

Deprecated as a consequence of Parser being deprecated.
Returns a newly created SAX 1 Parser, using the default parser factory.
public static synchronized SAXParserFactory

Returns:

a SAXParserFactory to use.
getParserFactory
()

Returns the parser factory to use.

public static String

Returns:

the systemid corresponding to the given file.
getSystemId
(File
the file to create the system id from.
file
)

This is a best attempt to provide a URL.toExternalForm() from a file URL.

public static XMLReader

Returns:

a SAX 2 XMLReader.
getXMLReader
()

Returns a newly created SAX 2 XMLReader, using the default parser factory.

public static SAXParserFactory

Returns:

the parser factory.
newParserFactory
()

Returns a new parser factory instance.

private static SAXParser

Returns:

a new SAXParser instance as helper for getParser and getXMLReader.
newSAXParser
(SAXParserFactory factory)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

builderFactoryback to summary
private static DocumentBuilderFactory builderFactory

Parser factory to use to create document builders.

Since
Ant 1.6
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS

Helper for systemId.

Since
Ant 1.6
nsParserFactoryback to summary
private static SAXParserFactory nsParserFactory

Parser Factory to create Namespace aware parsers.

Since
Ant 1.6
parserFactoryback to summary
private static SAXParserFactory parserFactory

Parser factory to use to create parsers.

Since
Ant 1.5
See Also
getParserFactory

Constructor Detail

JAXPUtilsback to summary
public JAXPUtils()

Method Detail

convertToBuildExceptionback to summary
private static BuildException convertToBuildException(SAXException e)

Translate a SAXException into a BuildException

Since
Ant 1.5
getDocumentBuilderback to summary
public static DocumentBuilder getDocumentBuilder() throws BuildException

Returns a newly created DocumentBuilder.

Returns:DocumentBuilder

a DocumentBuilder.

Exceptions
BuildException:
on error.
Since
Ant 1.6
getDocumentBuilderFactoryback to summary
private static synchronized DocumentBuilderFactory getDocumentBuilderFactory() throws BuildException

Obtains the default builder factory if not already.

Since
Ant 1.6
getNamespaceXMLReaderback to summary
public static XMLReader getNamespaceXMLReader() throws BuildException

Returns a newly created SAX 2 XMLReader, which is namespace aware

Returns:XMLReader

a SAX 2 XMLReader.

Exceptions
BuildException:
on error.
Since
Ant 1.6
See Also
getParserFactory
getNSParserFactoryback to summary
public static synchronized SAXParserFactory getNSParserFactory() throws BuildException

Returns the parser factory to use to create namespace aware parsers.

Returns:SAXParserFactory

a SAXParserFactory to use which supports manufacture of namespace aware parsers.

Exceptions
BuildException:
on error.
Since
Ant 1.6
getParserback to summary
public static Parser getParser() throws BuildException

Deprecated

as a consequence of Parser being deprecated. See corresponding docs for further information.

Returns a newly created SAX 1 Parser, using the default parser factory.

Returns:Parser

a SAX 1 Parser.

Exceptions
BuildException:
on error.
Since
Ant 1.5
See Also
getParserFactory
getParserFactoryback to summary
public static synchronized SAXParserFactory getParserFactory() throws BuildException

Returns the parser factory to use. Only one parser factory is ever created by this method and is then cached for future use.

Returns:SAXParserFactory

a SAXParserFactory to use.

Exceptions
BuildException:
on error.
Since
Ant 1.5
getSystemIdback to summary
public static String getSystemId(File file)

This is a best attempt to provide a URL.toExternalForm() from a file URL. Some parsers like Crimson choke on uri that are made of backslashed paths (ie windows) as it is does not conform URI specifications.

Parameters
file:File

the file to create the system id from.

Returns:String

the systemid corresponding to the given file.

Since
Ant 1.5.2
getXMLReaderback to summary
public static XMLReader getXMLReader() throws BuildException

Returns a newly created SAX 2 XMLReader, using the default parser factory.

Returns:XMLReader

a SAX 2 XMLReader.

Exceptions
BuildException:
on error.
Since
Ant 1.5
See Also
getParserFactory
newParserFactoryback to summary
public static SAXParserFactory newParserFactory() throws BuildException

Returns a new parser factory instance.

Returns:SAXParserFactory

the parser factory.

Exceptions
BuildException:
on error.
Since
Ant 1.5
newSAXParserback to summary
private static SAXParser newSAXParser(SAXParserFactory factory) throws BuildException
Returns:SAXParser

a new SAXParser instance as helper for getParser and getXMLReader.

Since
Ant 1.5