This CSS implementation can be used with either the
DOM4J API or the
regular W3C DOM API.
Using it from DOM4J (through the classes in the dom4j
package) is much easier, however. The classes in that package will
give you access to the style sheet of an XHTML document as soon as
you parse it.
If you choose the DOM way instead of DOM4J, you have to retrieve the embedded and linked CSS style sheets yourself, merge it with a default sheet, and then use the resulting style sheet to get the style declaration for the elements. In the future, helper classes may be available to simplify this task.
By default, computed styles only take into account generic styles that are
common to all media. If you want to target a specific medium, you have to use
the setTargetMedium() method of the document's style sheet, that
in DOM4J can be accessed with the XHTMLDocument.getStyleSheet()
method.
CSS4J offers you more than an implementation of the W3C CSS OM API, as it brings you closer to the actual style formatting for a particular device, through the use of concepts like the style database. With the information provided by the style database, the CSS4J-specific interfaces automatically let you take into account the particular formatting for the target device, including the page size or the available fonts.
For example, if your style declaration for the font family of an element reads "Helvetica, Arial", and you happen to have only the second one available, on retrieving the font with the enhanced interface you will get the correct result, "Arial".
Read the descriptions of the individual packages for more information on the use of CSS4J. The package also has a number of unit tests that are useful as examples.