当前位置: 首页>>代码示例>>Java>>正文


Java CSSCompiler类代码示例

本文整理汇总了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;
}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:27,代码来源:StyleAttributeHandler.java

示例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 );
    }
}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:10,代码来源:StyleNodeHandler.java

示例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;
    }
 
开发者ID:benjamarle,项目名称:typhon,代码行数:60,代码来源:TextLoader.java


注:本文中的net.nightwhistler.htmlspanner.css.CSSCompiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。