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?
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:
See the full specification here.