我编写了一个使用 jar cssparser-0.9.5.jar 扫描 css 文件的程序,并对其执行了一些操作
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;
}
此代码适用于所有类,但包含以“-”开头的属性的类除外
.overlay
{
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}
解析它后,在类 .overlay 的属性中出现双 ':' 错误
那么有什么想法可以解决这个问题吗?