My program is designed to scan css files using the jar cssparser-0.9.5.jar and perform various operations on the data.
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;
}
While the code performs well for most classes, there is an issue with classes that have properties starting with '-' such as in the following example:
.overlay
{
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}
After parsing, it generates an error due to the presence of double ':' in the .overlay class's properties. Any ideas on how to solve this problem?