CSS4J implements the W3C's CSS Object Model API.

See:
          Description

Packages
info.informatica.doc  
info.informatica.doc.agent  
info.informatica.doc.dom4j Built on top of the DOM4J package, provides XHTML parsing with built-in support for CSS style sheets.
info.informatica.doc.pdf.itext Helper package to render CSS as PDF with the iText package.
info.informatica.doc.structure  
info.informatica.doc.style.css This package and its subpackages provide an implementation of the CSS Object Model API.
info.informatica.doc.style.css.dom Implementation classes for the CSS Object Model API.
info.informatica.doc.style.css.j2d Infrastructure for Java2D rendering classes.
info.informatica.doc.style.css.property Implementations of CSS property names and values.
info.informatica.doc.style.css.visual Interfaces for CSS visual formatting structure.
info.informatica.doc.style.css.visual.box Implementation classes for building a CSS visual formatting structure.
info.informatica.doc.style.css.visual.container Container interfaces for the CSS visual formatting structure.
info.informatica.doc.xml.dtd DTD-related helper classes for XML parsing.

 

CSS4J implements the W3C's CSS Object Model API.

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.

Media handling

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.

Rendering with the help of CSS4J

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.