A few days ago, I released version 0.4.0 of the CSS4J project. CSS4J is
a BSD-licensed implementation of the W3C CSS Object Model API, providing
such support to the DOM4J API (limited support for "official" XML DOM is
also present).
The home page for the project is:
http://informatica.info/projects/css/
and the Release Notes at:
http://informatica.info/projects/css/RELEASE_NOTES.TXT
Please read the Javadoc summaries to see how the API can be used. The
synopsis of its use is the following:
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);
Then, you can retrieve the body elements and do:
CSSStyleDeclaration style =
((CSSStylableElement)element).getComputedStyle();
String propertyValue = style.getPropertyValue("display");
And finally, if you want to get the full power of CSS4J, use a "style
database" according to the target device (two are provided, one for
Java2D and another for iText). This would set a style database for Java2D:
((StyleDatabaseAware)style).setStyleDatabase(new Java2DStyleDatabase());
With a style database you can use at full the CSS4J's
CSS2ComputedProperties interface, which is more handy for Java than the
W3C API. For example:
Color color =
((CSS2ComputedProperties)style).getAWTColor(((CSS2ComputedProperties)style).getColor());
Do not forget that this is still a 0.4.0 version: test it, and if you
find a bug please notify me.
Hope you find the code useful.
Regards,
Carlos Amengual
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev