A example document that contains plain boring old text
and saves it to ascii files. Here you can see some sample
implementations of the open, save, saveAs, and close methods.
You should also notice that this class adds methods for accessing
the contained document's data in an application-useful format.
(In this case, there are just simple getText and setText methods.)
The setText properly realized that the document's data has been changed
and sets the Dirty flag. This is used in the application
tutorial by the StoragePolicy to prevent a user from closing the document
without saving changes.
This class also contains a DocumentFactory for documents of this type.
The document factory is used by an application to create documents of
Create an text document for the given application containing an
public void close()
Close the document. Do not attempt to save the document first
or do any other user-interface things like that. This method
can thrown an exception if there is a failure, but it should
only do do if there is no way it can recover. Note that actions
such as querying the user to save a modified document and so on
are the responsibility of the application, not the Document
java.lang.Exception - If the close operation fails.
public void save()
Save the document to its current file or URL. Throw an
exception if the operation failed. Reasons for failure might
include the fact that the file is not writable, or that the
document has a URL but we haven't implemented HTTP-DAV support
java.lang.Exception - If the save operation fails.
public void saveAs(java.io.File file)
Save the document to the given file. Throw an exception if
the operation failed. Return true if successful, false if
not. Do not change the file attribute to the new File
object as that is the responsibility of the application, which
it will do according to its storage policy.
public void saveAs(java.net.URL url)
Save the document to the given URL. Throw an exception if the
operation failed. Do not change the URL attribute to
the new URL object as that is the responsibility of the
application, which it will do according to its storage policy.