XNGR XML Browser

org.xngr
Interface XDocument


public interface XDocument

The representation of a document for the xngr application. The implementation of this interface gives the service a reference to a document within the system and allows the service to save and get document specific parameters like the URL and the root element. It also allows for a listener to be added to listen for changes in the document.

Version:
$Revision: 1.4 $, $Date: 2003/01/31 17:25:34 $
Author:
Edwin Dankert

Method Summary
 void addListener(XDocumentListener listener)
          Adds a document listener to the document.
 XElement getElement(String xpath)
          Gets an element from this document for the specified XPath expression.
 XElement[] getElements(String xpath)
          Gets a list of elements from this document for the specified XPath expression.
 String getName()
          Returns the name for this document as set by the user.
 XElement getRoot()
          Returns the root element for this document.
 URL getURL()
          Returns the URL for this document.
 boolean isUpdated()
          Find out wether the document in memory is different to the document on disk.
 void load()
          Loads the document from disk and informs the listeners about the update.
 void removeListener(XDocumentListener listener)
          Removes a document listener from the document.
 void save()
          Saves the document to disk and informs the listeners about the update.
 

Method Detail

getElement

public XElement getElement(String xpath)
                    throws Exception
Gets an element from this document for the specified XPath expression. Returns Null, if the element could not be found.

Parameters:
xpath - the XPath expression to the element.
Returns:
the element.
Throws:
Exception - throws an Exception when the XML information in the document could not been parser, this can be an IOException or SAXParseException.

getElements

public XElement[] getElements(String xpath)
                       throws Exception
Gets a list of elements from this document for the specified XPath expression. Returns Null, if no element could be found.

Parameters:
xpath - the XPath expression to the element(s).
Returns:
the element(s).
Throws:
Exception - throws an Exception when the XML information in the document could not been parser, this can be an IOException or SAXParseException.

getRoot

public XElement getRoot()
                 throws Exception
Returns the root element for this document.

Returns:
the root element.
Throws:
Exception - throws an Exception when the XML information in the document could not been parser, this can be an IOException or SAXParseException.

getURL

public URL getURL()
Returns the URL for this document. Can be used to get file specific information.

Returns:
the URL for this document.

getName

public String getName()
Returns the name for this document as set by the user.

Returns:
the name for this document.

save

public void save()
          throws IOException
Saves the document to disk and informs the listeners about the update.

Throws:
IOException - if the document cannot be saved.

load

public void load()
          throws IOException,
                 org.xml.sax.SAXParseException
Loads the document from disk and informs the listeners about the update.

Throws:
IOException - if the document cannot be found.
org.xml.sax.SAXParseException - if the information in the document cannot be parsed.

isUpdated

public boolean isUpdated()
Find out wether the document in memory is different to the document on disk.

Returns:
true when the document has been updated since the last save/load operation!

addListener

public void addListener(XDocumentListener listener)
Adds a document listener to the document. The listener is invoked when the document has been updated or deleted.

Parameters:
listener - the listener for changes in the document.

removeListener

public void removeListener(XDocumentListener listener)
Removes a document listener from the document.

Parameters:
listener - the listener for changes in the document.

XNGR XML Browser

Copyright © 2002 - 2005, Edwin Dankert, All Rights Reserved