CSS4J ecosystem API
This project implements an API very similar to W3C's CSS Object Model API in the Java™ language, and also adds CSS support to the DOM4J package. It targets several different use cases, with functionalities from style sheet error detection to style computation.
Using the library
This implementation can be used in several ways: with stand-alone style sheets, with its own DOM implementation, combined with DOM4J, or by wrapping a pre-existing DOM tree.
You can play with independent style sheets created with the
createStyleSheet("title", "media") method of the
There are three implementations of that interface:
CSSDOMImplementation, the native DOM implementation.
DOMCSSStyleSheetFactoryfor the DOM Wrapper.
- If you use DOM4J (css4j-dom4j module), get it through
The document back-end is only important if you plan to use the sheets inside a document.
The resulting style sheets are empty, but you can load a style sheet with the
One of the most important functionalities in the library is the ability to compute styles for a given element. In practice, to obtain the 'computed' or 'used' values required for actual rendering a box model implementation is needed, and also device information. The library provides a simple box model that could be used, but the details of the rendering device can be more difficult.
Depending on the use case, the target device may not be the same one where the library is running (and some exact details hence not available).
To help in the computation, the library defines the
DeviceFactory interface to supply device and media-specific data (also provides
the objects required by media queries to work).
You can find more information at the Usage Guide.