Saving documents

To persistently store a newly created document or to save changes to an existing one, application SimplyHTML uses an object of class HTMLWriter which package javax.swing holds especially for HTMLDocuments. Again, to simply call HTMLWriter's write method is not enough to meet saving requirements of SimplyHTML. Class DocumentPane uses methods saveDocument and saveDefaultStyleSheet to put together its own save routine.

Method saveDocument

In method saveDocument class DocumentPane uses its field sourceUrl to tell HTMLWriter where to save a document. Field sourceUrl usually has been set previously either by method loadDocument or saveDocumentAs. If no soureUrl is set for any reason, saveDocument does nothing.

When field sourceUrl is properly set, saveDocument creates a FileOutputStream for respective URL, attaches it to a new OutputStreamWriter and creates an instance of HTMLWriter with these parameters. HTMLWriter completely takes care of transforming the model of object HTMLDocument to an HTML file when its method write is called.

Once the HTML file is saved, its associated style sheet is saved by calling method saveStyleSheet. Finally field textChanged is set to false to indicate that the document of this DocumentPane does not contain changes which need to be saved.