A formatter provides new export options for case books. Using the plug-in architecture, formatters can be packaged in easy to install plug-in bundles.
When the Export command is executed on a case book, the FormatterFactory is queried for a list of currently registered formatters. If there is only one class registered (the built-in FormatHTML formatter), it is chosen implicitly and the user is prompted to choose a file. If there are multiple classes registered, the user is presented with a list whose entries are based upon the names returned by getExportName(). Once an export format is selected, the user is prompted to choose a file based upon the extension returned by getExportFileExtension(). Finally, the selected formatter will be instantiated, used to format the case book, and then asked to write the results to an output stream created from the selected file.
A case book formatter extends ca.cgjennings.apps.arkham.casebook.Formatter. To be used as a formatter for exports, the formatter must implement isExportFormatter() (to return true), as well as getExportName() and getExportFileExtension(), and it must override exportFormat( OutputStream out ). (It is exportFormat that is finally called to generate a data stream in the appropriate file format.)
If you can convert to the desired format from HTML, you may find it convenient to extend the built-in FormatHTML class. This class is already a valid export formatter, although you should still customize the name, and possibly the extension. Override the exportFormat method to call getHTML(), transform HTML as desired, and then write out the result. (You can also base an exporter on the FormatPrint class, which is used to print case books and uses the SE mark-up and layout engine directly without converting to HTML. Note, however, that it is not an export formatter, so you must add appropriate implementations of all of the above methods.)
In order for SE to be aware of your formatter, its class must be registered by calling FormatterFactory.register( MyFormatter.class ), where MyFormatter.class is the class for your formatter. Formatter registration can be automated for the user by writing a plug-in to register the class and packaging it as a plug-in (or extension) bundle. See Example 1 for details.
Starting with version 2.00 beta 2, SE supports the creation of case book formatters that may require more control over the export process or that might not be able to export to an OutputStream. To provide this support, the export process has been modified to proceed as follows: