Crappy Java Package of the WeekIntro
Recently, I employed myself as a Java developer. Mostly out of curiosity and to try out something different ('new' would probably be the wrong word here). So the first thought when someone hears Java is most likely Enterprise. There really is not much anything else (Android is a completely different story). And considering that it's so widely used for such a long time, with so many detailed specs you would expect an abundance of good software libraries. Yeah, right...Part I: RichFaces, SAC and CSSParser
When developing on the web sooner or later you'll need some way to process CSS files. "Simple API for CSS" - sounds great! It's modeled after SAX, not my favorite way to process data, but ok.
So RichFaces uses that for their ECSS - CSS, but you can embed expressions inside properties. Well, we have SCSS and LESS for some time now, but I assume that when they started the version 4 rewrite it wasn't availble yet.
But then comes the SAC implementation: CSSParser. It advertises itself as a CSS2 parser... ok, so let's try parsing:
/* some stuff */
Well, that's not CSS2 stricly speaking, but even old browsers don't have trouble parsing it and just ignore the parts they don't understand - that's how CSS is meant to work. It turns out CSSParser does exactly that - it ignored the whole rule (not raised an error, ignored
). Not very useful for a processing tool.
But maybe it's a bug. So I check for the latest version: mine is 0.9.5, repo has 0.9.7 (released this year) and the release notes say it now uses a CSS2.1 parser by default. Silly me I just didn't use the right parser, right?
Sadly, the @font-face rule was removed from CSS2.1 spec (it's now a part of CSS3), so the people implementing the parser decided to ignore
that rule from now on. How useful (not to mention backwards compatible).
Thus, I'm left with a choice between a parser that ignores properties starting with "-" and a one that ignores @font-face.
I don't really believe anyone would seriously consider any of this a feature. If I wanted a CSS validator I would use a one. A CSS processing tool should handle as much as possible and, for sanity's sake, never silently ignore anything! My hope now rests in http://code.google.com/p/phloc-css/