|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.openxml.source.Source | +--org.openxml.source.holders.SourceImpl | +--org.openxml.beans.SourceBean
Defines the source for an XML document and parses the document. This class supports a bean-like and utility interfaces. An XML source is constructed to describe the location of an XML document, the document type and the default encoding. The document is then parsed and returned, including any errors generated during parsing.
The bean-like interface is realized through get/set methods that affect
its properties. The document is then retrieved by calling SourceImpl.getDocument()
. If a new document is required, the properties can be
changed and the document retrieved by calling SourceImpl.forget()
first.
A source is identified by four parameters. The URI specifies a source that can be a network URL, file URL, resource contained in JAR file, etc. The public identifier is an alternative named that may be mapped to a URI. A default character encoding may be specified and will be used, unless the document source enforces another encoding, e.g. in the content type returned from a Web server, or in the document declaration.
A specific document type may be requested and will be returned, unless
the document source indicates a different document type, e.g. in the
content type returned from a Web server. The document type is specified
by requesting an XML document (null, or Source.DOCUMENT_XML
), an HTML
document (Source.DOCUMENT_HTML
) or an HTML document (Source.DOCUMENT_HTML
). User XML documents may also be requested by passing
a class that extends XMLDocument
, see the later for
more details.
setReadOnly(boolean)
may be set to request a read only image of the document.
That document may not be edited, but may wholly or partly cloned into an
editable document. The default behavior returns a new document instance each
time and that document may be modified without affecting previously returned
instances. Put otherwise, getDocument() != getDocument().
The source is parsed and retrieved by calling SourceImpl.getDocument()
. This
will return a document of the requested class, unless the source forced
a different class to be parsed. If the document cannot be found or parsed
completely, null is returned. The error exception may be obtained by calling
SourceImpl.getLastException()
. The returned exception class may be castable
to ParseException
.
The source may be parsed asynchronously by calling SourceImpl.asynch()
. A new
thread will be initiated for parsing the document in the background.
SourceImpl.getDocument()
will then return that document. Some setter methods
will be blocked until SourceImpl.asynch()
completes parsing the document.
A number of static methods are provided for directly reading documents
or known types. These methods simply wrap a source constructor and call
to SourceImpl.getDocument()
.
XML sources benefit from parsed document caching, public identifier mapping, and support for resourc documents that is provided by the holder mechanism. The following URI formats are natively supported by this mechanism:
Class.getResource(java.lang.String)
Field Summary | |
protected java.beans.PropertyChangeSupport |
_propChange
Helper object to implement property change events and listeners. |
Fields inherited from class org.openxml.source.holders.SourceImpl |
_asyncThread,
_docClass,
_document,
_encoding,
_holder,
_lastException,
_publicId,
_readOnly,
_uri |
Fields inherited from class org.openxml.source.Source |
DOCUMENT_DTD,
DOCUMENT_HTML,
DOCUMENT_XML |
Constructor Summary | |
SourceBean()
Constructs a new source with no parameters. |
|
SourceBean(java.lang.String uri)
Constructs a new source with the supplied parameters. |
|
SourceBean(java.lang.String uri,
java.lang.Class docClass)
Constructs a new source with the supplied parameters. |
|
SourceBean(java.lang.String uri,
java.lang.String encoding)
Constructs a new source with the supplied parameters. |
|
SourceBean(java.lang.String uri,
java.lang.String publicId,
java.lang.String encoding)
Constructs a new source with the supplied parameters. |
|
SourceBean(java.lang.String uri,
java.lang.String publicId,
java.lang.String encoding,
java.lang.Class docClass)
Constructs a new source with the supplied parameters. |
Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Assigns a property change listener. |
java.lang.String |
getDocClassName()
Returns the document class. |
protected void |
notifyComplete()
|
static Document |
readDTD(java.io.File file,
java.lang.String encoding)
Reads and returns an DTD document from the file. |
static Document |
readDTD(java.lang.String uri,
java.lang.String encoding)
Reads and returns an DTD document from the URI. |
static Document |
readHTML(java.io.File file,
java.lang.String encoding)
Reads and returns an HTML document from the file. |
static Document |
readHTML(java.lang.String uri,
java.lang.String encoding)
Reads and returns an HTML document from the URI. |
static Document |
readXML(java.io.File file,
java.lang.String encoding)
Reads and returns an XML document from the file. |
static Document |
readXML(java.lang.String uri,
java.lang.String encoding)
Reads and returns an XML document from the URI. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a property change listener. |
void |
setDocClass(java.lang.Class docClass)
Sets the requested document class. |
void |
setDocClassName(java.lang.String className)
Sets the requested document class. |
void |
setEncoding(java.lang.String encoding)
Sets the default source encoding. |
void |
setPublicId(java.lang.String publicId)
Sets the public identifier for this document. |
void |
setReadOnly(boolean readOnly)
If true, requests a read-only instance of the document that may be read, clones, but not modified. |
void |
setURI(java.lang.String uri)
Sets the URI for this document. |
Methods inherited from class org.openxml.source.holders.SourceImpl |
asynch,
forget,
getClassDTD,
getClassHTML,
getClassXML,
getDocClass,
getDocument,
getEncoding,
getLastException,
getPublicId,
getURI,
run,
toString |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected transient java.beans.PropertyChangeSupport _propChange
Constructor Detail |
public SourceBean(java.lang.String uri, java.lang.String publicId, java.lang.String encoding, java.lang.Class docClass)
uri
- The source URI, or nullpublicId
- The source public identifier, or nullencoding
- Default encoding, or nulldocClass
- Requested document class, or nullpublic SourceBean(java.lang.String uri, java.lang.String publicId, java.lang.String encoding)
uri
- The source URI, or nullpublicId
- The source public identifier, or nullencoding
- Default encoding, or nullpublic SourceBean(java.lang.String uri, java.lang.String encoding)
uri
- The source URI, or nullencoding
- Default encoding, or nullpublic SourceBean(java.lang.String uri, java.lang.Class docClass)
uri
- The source URI, or nulldocClass
- Requested document class, or nullpublic SourceBean(java.lang.String uri)
uri
- The source URI, or nullpublic SourceBean()
Method Detail |
public static Document readXML(java.lang.String uri, java.lang.String encoding)
uri
- The source URIencoding
- The source encoding, or nullpublic static Document readXML(java.io.File file, java.lang.String encoding)
file
- The source fileencoding
- The source encoding, or nullpublic static Document readHTML(java.lang.String uri, java.lang.String encoding)
uri
- The source URIencoding
- The source encoding, or nullpublic static Document readHTML(java.io.File file, java.lang.String encoding)
file
- The source fileencoding
- The source encoding, or nullpublic static Document readDTD(java.lang.String uri, java.lang.String encoding)
uri
- The source URIencoding
- The source encoding, or nullpublic static Document readDTD(java.io.File file, java.lang.String encoding)
file
- The source fileencoding
- The source encoding, or nullpublic void setURI(java.lang.String uri)
SourceImpl.forget()
is called.uri
- The document URI, or nullpublic void setPublicId(java.lang.String publicId)
SourceImpl.forget()
is called.publicId
- The document public identifer, or nullpublic void setDocClass(java.lang.Class docClass)
Document
; HTMLDocument
, DTDDocument
or any class derived from XMLDocument
may be used.className
- The requested document classpublic void setReadOnly(boolean readOnly)
readOnly
- True if read-only instance is requiredpublic void setEncoding(java.lang.String encoding)
encoding
- The default document encoding, or nullpublic void setDocClassName(java.lang.String className)
Document
; HTMLDocument
, DTDDocument
or any class derived from XMLDocument
may be used.className
- The requested document classpublic java.lang.String getDocClassName()
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Property change events are fired for changed on the following properties:
setDocClassName(java.lang.String)
) or class (setDocClass(java.lang.Class)
),
or in response to source document being parsed
listener
- The listener to assignpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener to removeprotected void notifyComplete()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |