org.mmbase.util.xml
Class DocumentReader

java.lang.Object
  extended byorg.mmbase.util.xml.DocumentReader
Direct Known Subclasses:
DatabaseStorageLookup, DocumentWriter, StorageReader, XMLBasicReader

public class DocumentReader
extends java.lang.Object

The DocumentReader class provides methods for loading a xml document in memory. It serves as the base class for DocumentWriter (which adds ways to write a document), and XMLBasicReader, which adds path-like methods with which to retrieve elements.

Version:
$Id: DocumentReader.java,v 1.1 2003/08/18 16:50:52 pierre Exp $
Author:
Case Roule, Rico Jansen, Pierre van Rooden, Michiel Meeuwissen

Field Summary
protected  org.w3c.dom.Document document
           
static java.lang.String DTD_ERROR
          DTD respource filename of the most recent Error DTD
static java.lang.String DTD_ERROR_1_0
          DTD resource filename of the Error DTD version 1.0
protected static java.lang.String FILENOTFOUND
           
static java.lang.String PUBLIC_ID_ERROR
          Public ID of the most recent Error DTD
static java.lang.String PUBLIC_ID_ERROR_1_0
          Public ID of the Error DTD version 1.0
 
Constructor Summary
protected DocumentReader()
          Creates an empty document reader.
  DocumentReader(org.xml.sax.InputSource source)
          Constructs the document by reading it from a source.
  DocumentReader(org.xml.sax.InputSource source, boolean validating, java.lang.Class resolveBase)
          Constructs the document by reading it from a source.
  DocumentReader(java.lang.String path)
          Constructs the document by reading it from a file.
  DocumentReader(java.lang.String path, boolean validating, java.lang.Class resolveBase)
          Constructs the document by reading it from a source.
 
Method Summary
static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
          Creates a DocumentBuilder with default settings for handler, resolver, or validation, obtaining it from the cache if available.
static javax.xml.parsers.DocumentBuilder getDocumentBuilder(boolean validating, org.xml.sax.ErrorHandler handler, org.xml.sax.EntityResolver resolver)
          Creates a DocumentBuilder.
 java.lang.String getFileName()
          Returns the systemID of the InputSource used to read the document.
 java.lang.String getNodeTextValue(org.w3c.dom.Node n)
          Return the text value of a node.
static void registerPublicIDs()
          Register the Public Ids for DTDs used by XMLBasicReader This method is called by XMLEntityResolver.
protected static boolean validate()
          Returns the default setting for validation for DocumentReaders.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILENOTFOUND

protected static final java.lang.String FILENOTFOUND
See Also:
Constant Field Values

PUBLIC_ID_ERROR_1_0

public static final java.lang.String PUBLIC_ID_ERROR_1_0
Public ID of the Error DTD version 1.0

See Also:
Constant Field Values

DTD_ERROR_1_0

public static final java.lang.String DTD_ERROR_1_0
DTD resource filename of the Error DTD version 1.0

See Also:
Constant Field Values

PUBLIC_ID_ERROR

public static final java.lang.String PUBLIC_ID_ERROR
Public ID of the most recent Error DTD

See Also:
Constant Field Values

DTD_ERROR

public static final java.lang.String DTD_ERROR
DTD respource filename of the most recent Error DTD

See Also:
Constant Field Values

document

protected org.w3c.dom.Document document
Constructor Detail

DocumentReader

protected DocumentReader()
Creates an empty document reader.


DocumentReader

public DocumentReader(java.lang.String path)
Constructs the document by reading it from a file.

Parameters:
path - the path to the file from which to read the document

DocumentReader

public DocumentReader(java.lang.String path,
                      boolean validating,
                      java.lang.Class resolveBase)
Constructs the document by reading it from a source. You can pass a resolve class to this constructor, allowing you to indicate the package in which the dtd of the document read is to be found. The dtd sould be in the resources package under the package of the class passed.

Parameters:
path - the path to the file from which to read the document
validating - whether to validate the document
resolveBase - the base class whose package is used to resolve dtds, set to null if unknown

DocumentReader

public DocumentReader(org.xml.sax.InputSource source)
Constructs the document by reading it from a source.

Parameters:
source - the input source from which to read the document

DocumentReader

public DocumentReader(org.xml.sax.InputSource source,
                      boolean validating,
                      java.lang.Class resolveBase)
Constructs the document by reading it from a source. You can pass a resolve class to this constructor, allowing you to indicate the package in which the dtd of the document read is to be found. The dtd sould be in the resources package under the package of the class passed.

Parameters:
source - the input source from which to read the document
validating - whether to validate the document
resolveBase - the base class whose package is used to resolve dtds, set to null if unknown
Method Detail

registerPublicIDs

public static void registerPublicIDs()
Register the Public Ids for DTDs used by XMLBasicReader This method is called by XMLEntityResolver.


validate

protected static final boolean validate()
Returns the default setting for validation for DocumentReaders.

Returns:
true if validation is on
To Do:
add a way to configure this value, so validation can be turned off in i.e. production environments

getDocumentBuilder

public static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
Creates a DocumentBuilder with default settings for handler, resolver, or validation, obtaining it from the cache if available.

Returns:
a DocumentBuilder instance, or null if none could be created

getDocumentBuilder

public static javax.xml.parsers.DocumentBuilder getDocumentBuilder(boolean validating,
                                                                   org.xml.sax.ErrorHandler handler,
                                                                   org.xml.sax.EntityResolver resolver)
Creates a DocumentBuilder. DocumentBuilders that use the default error handler or entity resolver are cached (one for validating, one for non-validating document buidlers).

Parameters:
validating - if true, the documentbuilder will validate documents read
handler - a ErrorHandler class to use for catching parsing errors, pass null to use the default handler
resolver - a EntityResolver class used for resolving the document's dtd, pass null to use the default resolver
Returns:
a DocumentBuilder instance, or null if none could be created

getNodeTextValue

public java.lang.String getNodeTextValue(org.w3c.dom.Node n)
Return the text value of a node. It includes the contents of all child textnodes and CDATA sections, but ignores everything else (such as comments) The code trims excessive whitespace unless it is included in a CDATA section.

Parameters:
n - the Node whose value to determine
Returns:
a String representing the node's textual value

getFileName

public java.lang.String getFileName()
Returns the systemID of the InputSource used to read the document. This is generally the document's file path.

Returns:
the systemID as a String


MMBase build 1.7.1.20041002