Reputation: 149
I have written a program which scans css files using jar cssparser-0.9.5.jar and i performed some operation on it
public static Map<String, CSSStyleRule> parseCSS(String FileName) throws IOException {
Map<String, CSSStyleRule> rules = new LinkedHashMap<String, CSSStyleRule>();
InputSource inputSource = new InputSource(
new FileReader(FileName));
CSSStyleSheet styleSheet = new CSSOMParser().parseStyleSheet(
inputSource, null, null);
CSSRuleList ruleList = styleSheet.getCssRules();
for (int i = 0; i < ruleList.getLength(); i++) {
CSSRule rule = ruleList.item(i);
if (rule.getType() == CSSRule.STYLE_RULE) {
CSSStyleRule styleRule = (CSSStyleRule) rule;
rules.put(styleRule.getSelectorText(), styleRule);
}
}
return rules;
}
this code works fine for all classes except for class which contain properties which start with '-' like
.overlay
{
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}
after parsing it give error for double ':' present in class .overlay's properties
so is there any idea to solve this problem?
Upvotes: 0
Views: 321
Reputation: 18682
The code you posted is a few levels higher than where the actual problem is. The problem is in the lexical scanner. Its definition of what an identifier (IDENT) is seems to be wrong, as it can also contain hyphens and start with hyphens.
As the CSS3 syntax specification says:
In CSS3, identifiers (including element names, classes, and IDs in selectors (see [SELECT[or is this still true])) can contain only the characters [A-Za-z0-9] and ISO 10646 characters 161 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit or a hyphen followed by a digit.
See the full specification here.
Upvotes: 3