HTML exporter

From AbiWiki

Revision as of 05:57, 19 August 2011 by Volodymyr (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

HTML plugin allows Abiword users to export their documents to such file formats as HTML and XHTML. It supports several exportin goptions that customize contents of the generated document. Because this plugin is being developed for a long time and every it`s part become to tightly connected with each other(In fact generation of tags, css, saving images and listening to Abiword document contents were located in one big class called s_HTML_Listener), plugin`s code refactoring was done.

Contents

HTML plugin structure

To reduce dependencies between different parts of HTML plugin it`s functionality was split into several parts - Abiword document contents recognition( sections, blocks, etc) and translation into form, that is suitable to generate tags, tag generation, CSS generation and exporting data items.

Abiword document contents recognition and translation

To explore contents of the document being exported PL_Listener should be used. But to make exporting document to some XML/HTML based file format we need to take in account that listener won`t notify us if some block of document is ended - it will only tell that new block started. In case if need to close some tags if we are leaving some block/section it`s little uncomfortable. So to make exporting process little easier two classes were developed - IE_Exp_HTML_Listener and IE_Exp_HTML_ListenerImpl (such methodic is used in opendocument plugin).

IE_Exp_HTML_ListenerImpl

This class should be used as a base class if we want to implement exporting to HTML/XHTML. It contains set of all needed methods to generate correct HTML/XHTML document. All it`s methods are virtual and by default do nothing. So derived class just need to override them.

IE_Exp_HTML_Listener

This class inheriths PL_Listener and translates it`s calls to instance of IE_Exp_HTML_ListenerImpl, so correct document can be generated. E.g. if IE_Exp_HTML_Listener found a document block - it calls IE_Exp_HTML_ListenerImpl::openBlock and then, when end of the block is riched - IE_Exp_HTML_ListenerImpl::closeBlock.

Tag generation

To generate tags for the exported document set of utility classes were developed. Because HTML exporter supports both simple HTML/XHTML and multipart documents (MHT), interface for output was created - it`s abstract class OutputWriter that declare`s only one method - write. This interface is implemented by two derived classes - IE_Exp_FileWriter( for normal document export to filesystem) and IE_Exp_StringWriter (for exporting document into MHT archive). To generate tags IE_Exp_HTML_TagWriter class should be used. It contains most of the methods that are needed to generate HTML/XML tags - it supports generating pair and single tags, adding attributes, data and comments and switching between XML/HTML tag styles. Also, code that produced by IE_Exp_HTML_TagWriter is aligned according to document structure. IE_Exp_HTML_TagWriter doesn`t depends on type of the generated document - it uses pointer to IE_Exp_OutputWriter, so it can be used both for HTML/XHTML and MHT. To provide generation of basic HTML/XHTML tags and minimize copypasting, IE_Exp_HTML_DocumentWriter class was created. It supports generation of common set of tags for HTML/XHTML using IE_Exp_HTML_TagWriter so to completely implement export to HTML 4 we just need to create class that is inherited from IE_Exp_HTML_DocumentWriter and overrides such method as _insertDTD_ to add correct DTD and setting HTML-style tag generation for IE_Exp_HTML_TagWriter. For XHTML document insertDTD and openBody(to insert link to XML namespace) methods should be overrided.

CSS generation

To generate CSS styles based on Abiword document styles two classes are used - IE_Exp_HTML_StyleListener and IE_Exp_HTML_StyleWriter. These classes are result of dividing s_HTML_StyleTree into two logical parts - listener and style tree builder. Together they are working as good old s_HTML_Listener.

Exporting Data Items

To export data items to filesystem and MHT archive common interface is used IE_Exp_HTML_DataExporter - it allows to export data items by their dataid, save some string buffer to place where are all files used by html are stored (e.g. <filename>_files), encode dataitem using base64 encoding.

Personal tools