W3C home > Mailing lists > Public > www-validator-css@w3.org > January 2010

Re: validate from a Java program: how to send CSS and receive results

From: Francois Daoust <fd@w3.org>
Date: Mon, 11 Jan 2010 13:23:22 +0100
Message-ID: <4B4B183A.40305@w3.org>
To: www-validator-css@w3.org
Hi Erik,

I do not think you are doing anything wrong, actually.
Your code works fine when I change the target URL to target some other 
validator.
The CSS validator must be expecting something it doesn't get, not sure 
what it is.

Depending on what you actually want to do with the results returned by 
the CSS validator, you may consider using the CSS validator directly 
within your project instead of sending an HTTP request.

Instructions to get the source code of the CSS validator are available at:
  http://jigsaw.w3.org/css-validator/DOWNLOAD.html

In particular, a JAR package of the CSS validator is available at:
  http://www.w3.org/QA/Tools/css-validator/css-validator.jar

Once your project references the JAR, all you need to do is to create an 
instance of:
  org.w3c.css.css.StyleSheetParser

... and use its "parseStyleElement" method, after having initialized an 
application context (ApplContext) with the validation settings you need 
(encoding, CSS validation level, language, ...)

You can find code that just about the same thing in the source of the 
mobileOK Checker, in the CSSUtils#getStylesheet method:
 
http://dev.w3.org/cvsweb/2007/mobileok-ref/src/org/w3c/mwi/mobileok/basic/CSSUtils.java?rev=1.29&content-type=text/x-cvsweb-markup

(Please note that some settings and classes used in those lines are 
rather specific to the mobileOK Checker, but that should give you a 
rough idea about how this can be done).

HTH,
Francois.
Received on Monday, 11 January 2010 12:23:54 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 27 June 2012 00:14:25 GMT