org.n52.security.common.xml
Class DOMParser

java.lang.Object
  extended by org.n52.security.common.xml.DOMParser

public abstract class DOMParser
extends Object

Encapsulates the common usage of the DocumentBuilder class within a helpful DOMParser class.

At first it is designed for performance, such as you can discover a pooling DomParser, what is recommended. Only in very few situations you need a non pooling DOMParser.

Best is to use the DOMParser.createNew() method.

At next the DOMParser class uses a ClasspathEntityResolver, which ensures that the wrapped DocumentBuilder can always parse an XMLFile and entities are only discovered within the classpath.

The DOMParser class uses the factory method pattern, there with you can create DOMParsers by using the static methods createPoolingParser() and createNonPoolingParser().

For fast creation of empty xml documents, or for in memory creation of DOM documents use the createEmptyDocument() method.

Version:
$Revision: $
Author:
Marko Reiprecht Created on 24.03.2008

Constructor Summary
DOMParser()
           
 
Method Summary
protected static DocumentBuilder createDocumentBuilder(DOMParserOptions parseroptions)
          Creates a new DocumentBuilder with the given attributes.
static Document createEmptyDocument()
           
static Document createEmptyDocument(DOMParserOptions options)
           
static DOMParser createNew()
          Creates a new DOMParser.
static DOMParser createNew(DOMParserOptions options)
          Creates a new DOMParser.
static DOMParser createNonPoolingParser()
          Creates a non pooling Parser, with default options.
static DOMParser createNonPoolingParser(DOMParserOptions options)
          Creates a non pooling Parser, with the given options.
static DOMParser createPoolingParser()
          Creates a pooling Parser with default options and using the global DocumentBuilder pool.
static DOMParser createPoolingParser(DOMParserOptions options)
          Creates a pooling Parser with the given options, using the global DocumentBuilder pool.
static DOMParser createPoolingParser(DOMParserOptions options, DocumentBuilderPool pool)
          Creates a pooling Parser with the given options, which uses the given document builder pool.
static EntityResolver getDefaultEntityResolver()
          By default this method creates a ClasspathEntityResolver in quite mode, which means the parsing will never fail because of non existing entities (e.g.
static DocumentBuilderPool getDocumentBuilderPool()
          Gets the documentBuilderPool used by pooled parsers.
 Document parse(InputSource inputSource)
          Parses the inputsource.
 Document parse(InputSource inputSource, ErrorHandler errorhandler)
          Parses the inputsource and informs the error handler about errors.
abstract  Document parse(InputSource source, ErrorHandler errorhandler, EntityResolver entityResolver)
          Parses the inputsource using the errorhandler and entityresolver.
static void setDefaultEntityResolver(EntityResolver defaultresolver)
          Sets the defaultEntityResolver.
static void setDocumentBuilderPool(DocumentBuilderPool builderPool)
          Sets the documentBuilderPool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMParser

public DOMParser()
Method Detail

getDefaultEntityResolver

public static EntityResolver getDefaultEntityResolver()
By default this method creates a ClasspathEntityResolver in quite mode, which means the parsing will never fail because of non existing entities (e.g. dtd's).

Returns:
EntityResolver.

setDefaultEntityResolver

public static void setDefaultEntityResolver(EntityResolver defaultresolver)
Sets the defaultEntityResolver.

The default entity resolver is set on each newly created DocumentBuilder.


getDocumentBuilderPool

public static DocumentBuilderPool getDocumentBuilderPool()
Gets the documentBuilderPool used by pooled parsers.

Returns:
DocumentBuilderPool.

setDocumentBuilderPool

public static void setDocumentBuilderPool(DocumentBuilderPool builderPool)
Sets the documentBuilderPool.

Parameters:
builderPool - the documentBuilderPool.

createDocumentBuilder

protected static DocumentBuilder createDocumentBuilder(DOMParserOptions parseroptions)
Creates a new DocumentBuilder with the given attributes.

Parameters:
parseroptions - options for the new parser.
Returns:
DocumentBuilder.

createEmptyDocument

public static Document createEmptyDocument()

createEmptyDocument

public static Document createEmptyDocument(DOMParserOptions options)

createNew

public static DOMParser createNew()
Creates a new DOMParser. This method shall be used by dependend classes, it will delegate to createPoolingParser() methods, so it uses the fastest approach.

Returns:
DOMParser.

createNew

public static DOMParser createNew(DOMParserOptions options)
Creates a new DOMParser. This method shall be used by dependend classes, it will delegate to createPoolingParser() methods, so it uses the fastest aproach.

Parameters:
options - the options.
Returns:
DOMParser.

createNonPoolingParser

public static DOMParser createNonPoolingParser()
Creates a non pooling Parser, with default options.

Returns:
DOMParser.

createNonPoolingParser

public static DOMParser createNonPoolingParser(DOMParserOptions options)
Creates a non pooling Parser, with the given options.

Parameters:
options - the options.
Returns:
DOMParser.

createPoolingParser

public static DOMParser createPoolingParser()
Creates a pooling Parser with default options and using the global DocumentBuilder pool.

Returns:
DOMParser.

createPoolingParser

public static DOMParser createPoolingParser(DOMParserOptions options)
Creates a pooling Parser with the given options, using the global DocumentBuilder pool.

Parameters:
options - the options.
Returns:
DOMParser.

createPoolingParser

public static DOMParser createPoolingParser(DOMParserOptions options,
                                            DocumentBuilderPool pool)
Creates a pooling Parser with the given options, which uses the given document builder pool.

Returns:
DOMParser.

parse

public Document parse(InputSource inputSource,
                      ErrorHandler errorhandler)
               throws DOMParserException
Parses the inputsource and informs the error handler about errors.

Throws:
DOMParserException - if an SAXException or IOException occurs.

parse

public abstract Document parse(InputSource source,
                               ErrorHandler errorhandler,
                               EntityResolver entityResolver)
                        throws DOMParserException
Parses the inputsource using the errorhandler and entityresolver.

Throws:
DOMParserException - if an SAXException or IOException occurs.

parse

public Document parse(InputSource inputSource)
               throws DOMParserException
Parses the inputsource.

Throws:
DOMParserException - if an SAXException or IOException occurs.


Copyright © 2004–2013 52north.org. All rights reserved.