org.openxml
Class DOMFactory

java.lang.Object
  |
  +--org.openxml.DOMFactory

public class DOMFactory
extends java.lang.Object

Factory for XML, HTML and DTD documents, parsers and printers. The factory has methods for creating new documents, parsers and printers. The exact type is determined by the document class, this might be Document (DOCUMENT_XML), HTMLDocument (DOCUMENT_HTML), DocumentType (DOCUMENT_DTD) or a user document derived from XMLDocument.

The default document type is controlled by the openxml.document.class propety in the OpenXML properties file ( openxml.prop). The parser and printer classes for XML, HTML and DTD documents are also controlled by the property file.

The method createDocument(java.lang.Class) does not guarantee that it will return Document, although this is the default behavior. To obtain a Document either pass its class as argument, or call createXMLDocument().

A newly created parser is only guaranteed to extend Parser, even if DOCUMENT_XML has been specified as the document type. To create a document from a user class, either use Source, or the following code:

 Parser    parser;

 parser = DOMFactory.createParser( reader, sourceURI, docClass );
 if ( parser instanceof XMLParser )
     doc = ( (XMLParser) parser ).parseDocument( null, docClass );
 else
     doc = parser.parseDocument();
 

Version:
$Revision: 1.7 $ $Date: 1999/03/30 06:49:02 $
Author:
Assaf Arkin
See Also:
Document, XMLElement, XMLCollection

Field Summary
static java.lang.Class DOCUMENT_DTD
          DTD document class.
static java.lang.Class DOCUMENT_HTML
          HTML document class.
static java.lang.Class DOCUMENT_XML
          XML document class.
 
Constructor Summary
DOMFactory()
           
 
Method Summary
static Document createDocument(java.lang.Class docClass)
          Creates and returns a new XML/HTML/DTD document.
static DTDDocument createDTDDocument()
          Creates and returns a new DTD document.
static HTMLDocument createHTMLDocument()
          Creates and returns a new HTML document.
static org.openxml.io.Parser createParser(java.io.InputStream stream, java.lang.String sourceName)
          Creates and returns a new XML parser.
static org.openxml.io.Parser createParser(java.io.InputStream stream, java.lang.String sourceName, java.lang.Class docClass)
          Creates and returns a new XML/HTML/DTD parser.
static org.openxml.io.Parser createParser(java.io.Reader reader, java.lang.String sourceName)
          Creates and returns a new XML parser.
static org.openxml.io.Parser createParser(java.io.Reader reader, java.lang.String sourceURI, java.lang.Class docClass)
          Creates and returns a new XML/HTML/DTD parser.
static org.openxml.io.Printer createPrinter(java.io.OutputStream stream, int mode)
          Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
static org.openxml.io.Printer createPrinter(java.io.OutputStream stream, int mode, java.lang.Class docClass)
          Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
static org.openxml.io.Printer createPrinter(java.io.Writer writer, int mode)
          Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
static org.openxml.io.Printer createPrinter(java.io.Writer writer, int mode, java.lang.Class docClass)
          Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
static Document createXMLDocument()
          Creates and returns a new XML document.
static java.lang.Class getDocClass(java.lang.Class docClass)
          Returns the specified document class, or the properties file specified class, or the default.
static HolderFinder getHolderFinder()
          Returns a singleton holder finder.
static java.util.Properties getProperties()
          Returns the properties list from the OpenXML properties file.
static java.lang.String getProperty(java.lang.String name)
          Returns the property from the OpenXML properties file.
static Source newSource()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCUMENT_XML

public static final java.lang.Class DOCUMENT_XML
XML document class. Can be used to request a new XML document, XML parser or XML printer. Will produce a document of type Document.

DOCUMENT_HTML

public static final java.lang.Class DOCUMENT_HTML
HTML document class. Can be used to request a new HTML document, HTML parser or HTML printer. Will produce a document of type HTMLDocument.

DOCUMENT_DTD

public static final java.lang.Class DOCUMENT_DTD
DTD document class. Can be used to request a new DTD document, DTD parser or DTD printer. Will produce a document of type DTDDocument.
Constructor Detail

DOMFactory

public DOMFactory()
Method Detail

createXMLDocument

public static Document createXMLDocument()
Creates and returns a new XML document. The document type is Document.
Returns:
A new XML document
See Also:
Document

createHTMLDocument

public static HTMLDocument createHTMLDocument()
Creates and returns a new HTML document. The document type is HTMLDocument.
Returns:
A new XML document
See Also:
HTMLDocument

createDTDDocument

public static DTDDocument createDTDDocument()
Creates and returns a new DTD document. The document type is DTDDocument.
Returns:
A new DTD document
See Also:
DTDDocument

createDocument

public static Document createDocument(java.lang.Class docClass)
Creates and returns a new XML/HTML/DTD document. The document type is based on docClass, which dictates whether the document is XML, HTML or DTD. If docClass is null, the class type is read from the property openxml.document.class, and if that property is missing, the default Document is used.

Note that the returned document type may or may not be Document, but it must extend Document, and that is also true for non-XML documents.

Returns:
A new XML/HTML/DTD document
See Also:
Document

createParser

public static org.openxml.io.Parser createParser(java.io.Reader reader,
                                                 java.lang.String sourceURI,
                                                 java.lang.Class docClass)
Creates and returns a new XML/HTML/DTD parser. The parser type is determined by the document class provided in docClass, which dictates whether the parser is XML, HTML or DTD. If docClass is null, the same rules that govern createDocument(java.lang.Class) apply here.

The parser is only guaranteed to extend Parser and will use createDocument(java.lang.Class) to create an instance of the parsed document. To create a document of a user class, either use Source, or the following code:

 Parser    parser;

 parser = DOMFactory.createParser( reader, sourceURI, docClass );
 if ( parser instanceof XMLParser )
     doc = ( (XMLParser) parser ).parseDocument( null, docClass );
 else
     doc = parser.parseDocument();
 
Parameters:
reader - A reader to the document source
sourceURI - The source URI
docClass - The requested document type
Returns:
A new parser

createParser

public static org.openxml.io.Parser createParser(java.io.Reader reader,
                                                 java.lang.String sourceName)
                                          throws java.io.IOException
Creates and returns a new XML parser.
Parameters:
reader - A reader to the document source
sourceURI - The source URI
Returns:
A new parser

createParser

public static org.openxml.io.Parser createParser(java.io.InputStream stream,
                                                 java.lang.String sourceName,
                                                 java.lang.Class docClass)
                                          throws java.io.IOException
Creates and returns a new XML/HTML/DTD parser. The parser type is determined by the document class provided in docClass, which dictates whether the parser is XML, HTML or DTD. If docClass is null, the same rules that govern createDocument(java.lang.Class) apply here.

The parser is only guaranteed to extend Parser and will use createDocument(java.lang.Class) to create an instance of the parsed document. To create a document of a user class, either use Source, or the following code:

 Parser    parser;

 parser = DOMFactory.createParser( reader, sourceURI, docClass );
 if ( parser instanceof XMLParser )
     doc = ( (XMLParser) parser ).parseDocument( null, docClass );
 else
     doc = parser.parseDocument();
 
Parameters:
input - An input stream to the document source
sourceURI - The source URI
docClass - The requested document type
Returns:
A new parser

createParser

public static org.openxml.io.Parser createParser(java.io.InputStream stream,
                                                 java.lang.String sourceName)
                                          throws java.io.IOException
Creates and returns a new XML parser.
Parameters:
input - An input stream to the document source
sourceURI - The source URI
Returns:
A new parser

createPrinter

public static org.openxml.io.Printer createPrinter(java.io.Writer writer,
                                                   int mode,
                                                   java.lang.Class docClass)
                                            throws java.io.IOException
Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
Creates and returns a new XML/HTML/DTD printer. The printer type is determined by the document class provided in docClass, which dictates whether the printer is XML, HTML or DTD. If docClass is null, the same rules that govern createDocument(java.lang.Class) apply here.
Parameters:
writer - A writer for the document output
mode - The printing mode
docClass - The document type
Returns:
A new printer

createPrinter

public static org.openxml.io.Printer createPrinter(java.io.Writer writer,
                                                   int mode)
                                            throws java.io.IOException
Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
Creates and returns a new XML printer.
Parameters:
writer - A writer for the document output
mode - The printing mode
Returns:
A new printer

createPrinter

public static org.openxml.io.Printer createPrinter(java.io.OutputStream stream,
                                                   int mode,
                                                   java.lang.Class docClass)
                                            throws java.io.IOException
Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
Creates and returns a new XML/HTML/DTD printer. The printer type is determined by the document class provided in docClass, which dictates whether the printer is XML, HTML or DTD. If docClass is null, the same rules that govern createDocument(java.lang.Class) apply here.
Parameters:
output - A stream for the document output
mode - The printing mode
docClass - The document type
Returns:
A new printer

createPrinter

public static org.openxml.io.Printer createPrinter(java.io.OutputStream stream,
                                                   int mode)
                                            throws java.io.IOException
Deprecated. This method has become obsolete in favor of the X3P Publisher and Producer APIs. This method is temporarily provided for backward compatibility but will not be included in release 1.1.
Creates and returns a new XML printer.
Parameters:
output - A stream for the document output
mode - The printing mode
Returns:
A new printer

getProperty

public static java.lang.String getProperty(java.lang.String name)
Returns the property from the OpenXML properties file.
Parameters:
name - The property name
Returns:
Property value or null

getProperties

public static java.util.Properties getProperties()
Returns the properties list from the OpenXML properties file. If this property list is changed, changes will affect the behavior of the factory and other OpenXML elements.
Returns:
The properties list

getDocClass

public static java.lang.Class getDocClass(java.lang.Class docClass)
Returns the specified document class, or the properties file specified class, or the default. If the specified document class is not valid, a runtime exception is thrown. If the specified class is null, the name is read from the properties file and used as the based class. If that property is missing or not a valid class, the default document class (Document) is used.
Parameters:
docClass - The specified document class, or null
Returns:
A valid document class, extending Document

newSource

public static Source newSource()

getHolderFinder

public static HolderFinder getHolderFinder()
Returns a singleton holder finder. This finder has default holder factories registered for handling network, file, JAR and CLASSPATH document sources, and mapping for built-in DTDs. Additional holder factories and Xcatalogs may be specified in the properties file and are loaded and registered the first time this method is called.
Returns:
An holder finder