Package info.informatica.doc.dom4j

Built on top of the DOM4J package, provides XHTML parsing with built-in support for CSS style sheets.

See:
          Description

Interface Summary
DOM4JCSSErrorHandler CSS Error handler for DOM4J.
 

Class Summary
CachedTableCellElement Cached table cell element.
CachedTableElement Cached table element.
CachedTableRowElement Cached table row element.
CSSStylableElement An element that is stylable with CSS.
DocumentFormatter Builds the formatting structure for DOM4J documents.
DOM4JCSSStyleDeclaration Style declaration for DOM4J.
DOM4JCSSStyleSheet CSS Style Sheet for DOM4J.
DOM4JUserAgent<C> User Agent based on DOM4J document trees.
DummyErrorHandler CSS dummy error handler.
Log4jErrorHandler Log4j error handler.
TableCellElement Table cell element.
TableElement Table element.
TableRowElement Table row element.
XHTMLDocument XHTML-specific implementation of a DOM4J Document.
XHTMLDocumentFactory DocumentFactory for CSS-styled XHTML documents.
XHTMLElement An XHTML element.
 

Package info.informatica.doc.dom4j Description

Built on top of the DOM4J package, provides XHTML parsing with built-in support for CSS style sheets.

DOM4J is an XML DOM-like software package with better support for Java language constructs, like Collections. See http://dom4j.sourceforge.net/ for more information.

This implementation integrates DOM4J with the CSS DOM implementation found in the info.informatica.doc.style.css package and subpackages.

Short example

This is the easiest way to use this package:

   Reader re = ...  [reader for XHTML document]
   InputSource source = new InputSource(re);
   SAXReader reader = new SAXReader(XHTMLDocumentFactory.getInstance());
   reader.setEntityResolver(new DefaultEntityResolver());
   Document document = reader.read(source);
   

And once you got the element you want style for (see, for example, the DOM4J Guide), just get it:

   CSSStyleDeclaration style = ((CSSStylableElement)element).getComputedStyle();
   String propertyValue = style.getPropertyValue("display");
   

Non-standard interfaces

The CSSStyleDeclaration interface may be hard to use, however, so you may want to access the more specialized interface CSS2ComputedProperties.

For complete access to this API, first configure the style declaration with a style database according to the target display device, for example:

   ((StyleDatabaseAware)style).setStyleDatabase(new Java2DStyleDatabase());
   
or, alternatively, set the style database at the XHTMLDocumentFactory with the setStyleDatabase method (recommended).

Then, you just have to cast the style declaration with the CSS2ComputedProperties interface and use it, for example:

   Color color = Java2DStyleDatabase.getAWTColor(((CSS2ComputedProperties)style).getColor());
   
Read the documentation of the individual classes for information on additional capabilities, like caching or the use of customized style sheets.

Default style sheet and user preferences

CSS4J uses a default user-agent style sheet as the basis for style computations, although you can set a different one with the setUserAgentStyleSheet method in XHTMLDocumentFactory. User preferences can be specified with the setUserStyleSheet method.

Formatting structure

The DocumentFormatter class can be used to build a formatting structure from the DOM4J document tree. You get the root box, and then can recurse the contained boxes. For each box, you can obtain the computed properties using the getComputedStyle method. Note that this class is experimental and likely to have bugs.



Copyright © 2011 informatica.info. All Rights Reserved.