|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jsxe.dom.XMLDocument
The XMLDocument class represents an XML document as a tree structure that has nodes, implemented as AdapterNodes, as well as text. Methods are provided to allow user objects to interact with the XML document as text or as a tree structure seamlessly.
AdapterNode
Field Summary | |
static String |
ENCODING
The property key for the encoding of this XML document |
static String |
FORMAT_XML
The property key for the boolean property specifying that the XML text should be formatted to look pleasing to the eye. |
static String |
INDENT
The property key for the property defining the size of a tab when the document is displayed as text or otherwise. |
static String |
IS_USING_SOFT_TABS
The property key for the property defining whether to serialize using soft tabs (tabs replaced by the number of spaces specified in the INDENT property). |
static String |
IS_VALIDATING
The property key for the property defining whether to validate the document with a DTD or Schema |
static String |
LINE_SEPARATOR
The property key for the property defining what line separator to use when serializing a document. |
static String |
WS_IN_ELEMENT_CONTENT
The property key for the boolean property specifying if whitespace is allowed in element content. |
Constructor Summary | |
XMLDocument(URI uri,
InputStream reader)
Creates a new XMLDocument for a document that can be read by the given Reader. |
|
XMLDocument(URI uri,
InputStream reader,
EntityResolver resolver)
Creates a new XMLDocument for a document that can be read by the given Reader. |
|
XMLDocument(URI uri,
InputStream reader,
EntityResolver resolver,
Properties properties)
Creates a new XMLDocument for a document that can be read by the given Reader. |
Method Summary | |
void |
addXMLDocumentListener(XMLDocumentListener listener)
Registers a change listener with the XMLDocument |
boolean |
checkWellFormedness()
Checks the wellformedness of the document and throws appropriate exceptions based on the errors encountered during parsing. |
boolean |
entityDeclared(String entityName)
Determines if the entity was declared by the DTD/Schema. |
protected void |
fireStructureChanged(AdapterNode location)
Called when the structure of the document has changed. |
AdapterNode |
getAdapterNode()
Returns the AdapterNode object for the root of the XML document. |
List |
getAllowedEntities()
Get the entities defined for this document. |
protected HashMap |
getCompletionInfoMappings()
Gets the namespace uri to CompletionInfo Mappings for this document. |
AdapterNode |
getDocType()
Returns the document type node for this XMLDocument or null if there is none. |
Document |
getDocumentCopy()
Gets a copy of the underlying Document object. |
ElementDecl |
getElementDecl(String name)
Gets an element declaration for a qualified name. |
EntityDecl |
getEntityDecl(String name)
Gets the entity declaration with the given name |
List |
getErrors()
Gets a list of non-fatal errors that were encountered when the document was parsed last. |
int |
getLength()
Gets the total number of characters in the document. |
Properties |
getProperties()
Gets all properties associated with this document. |
String |
getProperty(String key)
Gets a property for the key given. |
String |
getProperty(String key,
String defaultValue)
Gets a property for the key given or returns the default value if there is no property for the given key. |
AdapterNode |
getRootElementNode()
A convenience method that returns the root element node of the document. |
Segment |
getSegment(int start,
int length)
Gets the text at a specified location in the document. |
String |
getText(int start,
int length)
Gets the text at a specified location in the document. |
URI |
getURI()
Gets the URI for the location of this document. |
void |
insertText(int offset,
String text)
Inserts text into the document at the specified location |
boolean |
isValid()
Returns true if the document is valid i.e. |
boolean |
isWellFormed()
Indicates if the document is well formed. |
AdapterNode |
newAdapterNode(AdapterNode parent,
Node node)
Factory method that creates a new AdapterNode object wrapping the Node object and AdapterNode object wrapping the Node's parent Node object. |
AdapterNode |
newAdapterNode(AdapterNode parent,
String name,
String value,
short type)
Creates a new AdapterNode in this document. |
void |
parseDocument()
Parses the document with the current options. |
void |
parseWithoutUpdate()
Parses the document without updating the DOM. |
void |
removeText(int offset,
int length)
Removes text at the specifed character offset. |
void |
removeXMLDocumentListener(XMLDocumentListener listener)
Unregisters a change listener from this document |
void |
serialize(OutputStream out)
Writes the XML document to the output stream specified. |
String |
serializeNodeToString(AdapterNode node)
Serializes a child node to a string using the properties specified in this XMLDocument object. |
void |
setEntityResolver(EntityResolver resolver)
Sets the EntityResolver object that is used when resolving external entities. |
protected void |
setModel(InputStream stream)
Sets up the XMLDocument given a Reader. |
String |
setProperty(String key,
String value)
Sets a property of the XMLDocument |
void |
setURI(URI uri)
Sets the URI for the location of this document. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String ENCODING
public static final String WS_IN_ELEMENT_CONTENT
public static final String FORMAT_XML
public static final String INDENT
public static final String IS_USING_SOFT_TABS
public static final String IS_VALIDATING
public static final String LINE_SEPARATOR
Constructor Detail |
public XMLDocument(URI uri, InputStream reader) throws IOException
uri
- the uri for the location of this document. Can be null.reader
- the Reader object to read the XML document from.
IOException
- if there was a problem reading the documentpublic XMLDocument(URI uri, InputStream reader, EntityResolver resolver) throws IOException
reader
- the Reader object to read the XML document from.resolver
- the EntityResolver to use when resolving external
entities.
IOException
- if there was a problem reading the documentpublic XMLDocument(URI uri, InputStream reader, EntityResolver resolver, Properties properties) throws IOException
reader
- the Reader object to read the XML document from.resolver
- the EntityResolver to use when resolving external
entities.
IOException
- if there was a problem reading the documentMethod Detail |
public boolean checkWellFormedness() throws SAXParseException, SAXException, ParserConfigurationException, IOException
SAXParseException
- if there was a SAX error when parsing.
SAXException
- if there was a problem with the SAX parser.
ParserConfigurationException
- if the parser is not configured properly
IOException
- if there was a problem reading the documentpublic String setProperty(String key, String value)
key
- the key to the propertyvalue
- the value of the property
public Document getDocumentCopy()
public AdapterNode getDocType()
public Properties getProperties()
public String getProperty(String key)
key
- the key to the properties list
public String getProperty(String key, String defaultValue)
key
- the key to the properties listdefaultValue
- the default value for the property requested
public AdapterNode getRootElementNode()
public AdapterNode getAdapterNode()
public AdapterNode newAdapterNode(AdapterNode parent, Node node)
parent
- the AdapterNode for the parent of the new node. Can be null.node
- the Node object that the new AdapterNode should wrap
public AdapterNode newAdapterNode(AdapterNode parent, String name, String value, short type)
parent
- The parent of the node to create. Can be null.name
- the qualified name of the new nodevalue
- the value of the new node to createtype
- the type of node to create. Uses the types defined in the Node class.public String getText(int start, int length) throws IOException
start
- the starting index of the text to retrievelength
- the length of the text needed
IOException
public Segment getSegment(int start, int length) throws IOException
start
- the starting index of the text to retrievelength
- the length of the text needed
IOException
public int getLength()
public List getErrors()
public boolean isWellFormed() throws IOException
IOException
- if there was a problem checking the wellformednesspublic boolean isValid() throws IOException
IOException
- if there was a problem checking the validity of the documentpublic boolean entityDeclared(String entityName)
entityName
- the name of the entity
public ElementDecl getElementDecl(String name)
public EntityDecl getEntityDecl(String name)
public List getAllowedEntities()
public void serialize(OutputStream out) throws IOException, UnsupportedEncodingException
out
- the output stream to write the document to.
IOException
- if there was a problem writing the document
UnsupportedEncodingException
- if the encoding specified in the
properties is not supported.public String serializeNodeToString(AdapterNode node)
node
- the node to serialize
public void setEntityResolver(EntityResolver resolver)
resolver
- the entity resolverpublic void setURI(URI uri)
uri
- the uri specifying the location of this document. Can be null.public URI getURI()
public void insertText(int offset, String text) throws IOException
offset
- the character offset where the text should be insertedtext
- the text to insert
IOException
- if the text could not be insertedpublic void removeText(int offset, int length) throws IOException
offset
- the character offset where the text is removed formlength
- the length of the text segment to remove
IOException
- if the text could not be removedprotected void setModel(InputStream stream) throws IOException
IOException
public void addXMLDocumentListener(XMLDocumentListener listener)
listener
- the listener to register with this documentpublic void removeXMLDocumentListener(XMLDocumentListener listener)
listener
- the listener to unregisterprotected void fireStructureChanged(AdapterNode location)
location
- the location of the change. null if unknownprotected HashMap getCompletionInfoMappings()
public void parseDocument() throws SAXParseException, SAXException, ParserConfigurationException, IOException
SAXParseException
SAXException
ParserConfigurationException
IOException
public void parseWithoutUpdate()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |