css4j 3.9.1 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 CSSStyleSheetFactory interface. There are three implementations of that interface:

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 AbstractCSSStyleSheet.parseStyleSheet(source) method.

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.

Packages
Package
Description
Basic classes and interfaces used by documents.
User agent classes.
This package provide an implementation of the Document Object Model (DOM) Level 3 Core Specification that can be used for XML or HTML documents, albeit with a few deviations from the specification.
Interfaces and classes related to W3C's Geometry Interfaces Module.
This package and its subpackages provide an implementation of the CSS Object Model API.
NSAC: a non-standard revision to W3C's SAC api.
Implementation classes for the CSS Object Model API.
Classes related to CSS parsing.
Implementations of CSS property values.
Utility classes that could be used in your CSS projects.