7.2. Using custom code to extend the CSS style sheet

In the rare cases where Cascading Style Sheets (CSS) are not powerful enough to style certain elements of a class of documents, it is possible to use custom code written in the Java™ language to do so.

@extension "extension_class_name parameter ... parameter"; must be used to declare the Java™ class implementing the CSS extension.

Example (XHTML):

@extension "com.xmlmind.xmleditapp.xhtml.TableSupport black 'rgb(238, 238, 224)'";

In the above example, com.xmlmind.xmleditapp.xhtml.TableSupport is a class which is used to style XHTML (that is, HTML 4) tables. The two parameters which follow the class name specify colors used to draw table and cell borders. Parameters are optional and can be quoted if they contain white spaces.

The same CSS style sheet can contain several @extension constructs. For example, an extension class may be used to style HTML tables and an other extension class may be used to localize generated content. If two @extensions reference the same class name, the last declared one will be used by the CSS engine. For example, redeclaring an extension class imported from another CSS style sheet may be useful to change its parameters.

How to write such extension class is explained in detail in the Chapter 8, Writing style sheet extensions in XMLmind XML Editor - Developer's Guide.

The extension class may have methods which have been written to dynamically evaluate property values. These methods are invoked using the following syntax: invoke(method_name, parameter, ...., parameter). Parameters are optional.

Example (Email schema used as an example in the Chapter 8, Writing style sheet extensions in XMLmind XML Editor - Developer's Guide):

from:before {
    content: invoke("localize", "From:");
}

In the above example, method localize of class StyleExtension is used to translate string "From:" to the language specified by the xml:lang attribute (if found on the email root element). For example, if xml:lang is set to fr (French), the generated content will contain "De:" instead of "From:".

Methods used to dynamically evaluate property values must have the following signature (see Chapter 8, Writing style sheet extensions in XMLmind XML Editor - Developer's Guide): com.xmlmind.xmledit.stylesheet.StyleValue Method(com.xmlmind.xmledit.stylesheet.StyleValue[] parameters, com.xmlmind.xmledit.doc.Node contextNode, com.xmlmind.xmledit.styledview.StyledViewFactory factory).

If several extensions classes have dynamic property value methods with identical names (even if this unlikely to happen), the method actually used by the CSS engine will be the method of the class first declared using @extension.