本文整理汇总了Java中net.nightwhistler.htmlspanner.css.CSSCompiler类的典型用法代码示例。如果您正苦于以下问题:Java CSSCompiler类的具体用法?Java CSSCompiler怎么用?Java CSSCompiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CSSCompiler类属于net.nightwhistler.htmlspanner.css包,在下文中一共展示了CSSCompiler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseStyleFromAttribute
import net.nightwhistler.htmlspanner.css.CSSCompiler; //导入依赖的package包/类
private Style parseStyleFromAttribute(Style baseStyle, String attribute) {
Style style = baseStyle;
String[] pairs = attribute.split(";");
for ( String pair: pairs ) {
String[] keyVal = pair.split(":");
if ( keyVal.length != 2) {
Log.e("StyleAttributeHandler", "Could not parse attribute: " + attribute );
return baseStyle;
}
String key = keyVal[0].toLowerCase().trim();
String value = keyVal[1].toLowerCase().trim();
CSSCompiler.StyleUpdater updater = CSSCompiler.getStyleUpdater(key, value);
if ( updater != null ) {
style = updater.updateStyle(style, getSpanner());
}
}
return style;
}
示例2: parseCSSFromText
import net.nightwhistler.htmlspanner.css.CSSCompiler; //导入依赖的package包/类
private void parseCSSFromText( String text, SpanStack spanStack ) {
try {
for ( Rule rule: CSSParser.parse( text ) ) {
spanStack.registerCompiledRule(CSSCompiler.compile(rule, getSpanner()));
}
} catch ( Exception e ) {
Log.e( "StyleNodeHandler", "Unparseable CSS definition", e );
}
}
示例3: getCSSRules
import net.nightwhistler.htmlspanner.css.CSSCompiler; //导入依赖的package包/类
public List<CompiledRule> getCSSRules( String href ) {
if ( this.cssRules.containsKey(href) ) {
return Collections.unmodifiableList(cssRules.get(href));
}
List<CompiledRule> result = new ArrayList<>();
if ( currentBook == null ) {
return result;
}
String strippedHref = href.substring( href.lastIndexOf('/') + 1);
Resource res = null;
for ( Resource resource: this.currentBook.getResources().getAll() ) {
if ( resource.getHref().endsWith(strippedHref) ) {
res = resource;
break;
}
}
if ( res == null ) {
LOG.error("Could not find CSS resource " + strippedHref );
return new ArrayList<>();
}
StringWriter writer = new StringWriter();
try {
IOUtil.copy(res.getReader(), writer);
List<Rule> rules = CSSParser.parse(writer.toString());
LOG.debug("Parsed " + rules.size() + " raw rules.");
for ( Rule rule: rules ) {
if ( rule.getSelectors().size() == 1 && rule.getSelectors().get(0).toString().equals("@font-face")) {
handleFontLoadingRule(rule);
} else {
result.add(CSSCompiler.compile(rule, htmlSpanner));
}
}
} catch (IOException io) {
LOG.error("Error while reading resource", io);
return new ArrayList<>();
} catch (Exception e) {
LOG.error("Error reading CSS file", e);
} finally {
res.close();
}
cssRules.put(href, result);
LOG.debug("Compiled " + result.size() + " CSS rules.");
return result;
}