Components/DataProcessor

Data Processor

The Data Processor is responsible for transforming the input and output data in the editor. Theoretically, all incoming and outgoing data from the editor should pass through it.

Data input in FCKeditor is commonly done by (expect keyboard typing):

  • Setting the editor contents at startup;
  • Switching back from the Source View;
  • Paste operations;
  • Drag in operations;
  • JavaScript API operations (mainly SetHTML and InsertHtml).

Data output instead is achieved by the following actions:

  • Updating the hidden field in a form posting;
  • Cut or copy to clipboard;
  • Drag out operations;
  • JavaScript API operations (mainly GetXHTML).

Unfortunately browsers give us very little control over clipboard and dragging operations. In a second moment we could try controlling them, at least on those browsers that give us ways to do that. All other operations should involve the Data Processor instead.

The FCKDataProcessor Class

The FCKDataProcessor class is the default implementation of the Data Processor. Even if FCKeditor will be using only one instance of it, it has been defined as a class, so custom implementations can inherit from or make references to it.

The class implementation provides a Data Processor for XHTML, based on a DTD. Further Data Processor will much probably be available as plugins.

The following could be considered its definition.

var FCKDataProcessor = function()
{}

FCKDataProcessor.prototype = 
{
    /*
     * Returns a string representing the HTML format of "data". The returned
     * value will be loaded in the editor. 
     * The HTML must be from <html> to </html>, eventually including
     * the DOCTYPE.
     *     @param {String} data The data to be converted in the 
     *            DataProcessor specific format.
     */
    ConvertToHtml : function( data )
    {},
    
    /*
     * Converts a DOM (sub-)tree to a string in the data format.
     *     @param {Object} rootNode The node that contains the DOM tree to be
     *            converted to the data format.
     *     @param {Boolean} excludeRoot Indicated that the root node must not
     *            be included in the conversion, only its children.
     */
    ConvertToDataFormat : function( rootNode, excludeRoot )
    {}

    /*
     * Makes any necessary changes to a piece of HTML for insertion in the 
     * editor selection position.
     *     @param {String} html The HTML to be fixed.
     */
    FixHtml : function( html )
    {}
} ;

FCK.DataProcessor = new FCKDataProcessor() ;

Customization

Developers must be able to create plugins that define custom Data Processors, to satisfy specific needs. For example, there could be Data Processors for Wiki markup, BBCode, DocBook markup, etc.

To customize it, one of the following options could be used:

FCK.DataProcessor.ConvertToDataFormat = function( rootNode, excludeRoot )
{
    // My custom implementation for only one function.
}
FCK.DataProcessor = 
{
    // My custom implementation for all FCKDataProcessor functions.
}
var MyDataProcessor = function()
{}

// Inherit all definitions of FCKDataProcessor.
MyDataProcessor.prototype = new FCKDataProcessor() ;

MyDataProcessor.prototype.ConvertToDataFormat = function( rootNode, excludeRoot )
{
    // My custom implementation for only one function.
}

FCK.DataProcessor = new MyDataProcessor () ;

Comments