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


Java CSSVisitor类代码示例

本文整理汇总了Java中com.helger.css.decl.visit.CSSVisitor的典型用法代码示例。如果您正苦于以下问题:Java CSSVisitor类的具体用法?Java CSSVisitor怎么用?Java CSSVisitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CSSVisitor类属于com.helger.css.decl.visit包,在下文中一共展示了CSSVisitor类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFromStyleAttributeWithVisitor

import com.helger.css.decl.visit.CSSVisitor; //导入依赖的package包/类
public static void readFromStyleAttributeWithVisitor ()
{
  final String sStyle = "color:red; background:fixed !important";
  final CSSDeclarationList aDeclList = CSSReaderDeclarationList.readFromString (sStyle, ECSSVersion.CSS30);
  if (aDeclList == null)
    throw new IllegalStateException ("Failed to parse CSS: " + sStyle);
  // Create a custom visitor
  final ICSSVisitor aVisitor = new DefaultCSSVisitor ()
  {
    @Override
    public void onDeclaration (@Nonnull final CSSDeclaration aDeclaration)
    {
      System.out.println (aDeclaration.getProperty () +
                          ": " +
                          aDeclaration.getExpression ().getAsCSSString (new CSSWriterSettings (ECSSVersion.CSS30)) +
                          (aDeclaration.isImportant () ? " (important)" : " (not important)"));
    }
  };
  CSSVisitor.visitAllDeclarations (aDeclList, aVisitor);
}
 
开发者ID:phax,项目名称:ph-css,代码行数:21,代码来源:WikiVisitFromHtml.java

示例2: readAllSelectors

import com.helger.css.decl.visit.CSSVisitor; //导入依赖的package包/类
public void readAllSelectors ()
{
  final String sStyle = "blockquote p,\r\n" +
                        "blockquote ul,\r\n" +
                        "blockquote ol {\r\n" +
                        "  line-height:normal;\r\n" +
                        "  font-style:italic;\r\n" +
                        "}\r\n" +
                        "\r\n" +
                        "a { color:#FFEA6F; }\r\n" +
                        "\r\n" +
                        "a:hover { text-decoration:none; }\r\n" +
                        "\r\n" +
                        "img { border:none; }";
  final CascadingStyleSheet aCSS = CSSReader.readFromString (sStyle, ECSSVersion.CSS30);
  final ICommonsList <String> aAllSelectors = new CommonsArrayList <> ();
  CSSVisitor.visitCSS (aCSS, new DefaultCSSVisitor ()
  {
    @Override
    public void onStyleRuleSelector (@Nonnull final CSSSelector aSelector)
    {
      aAllSelectors.add (aSelector.getAsCSSString (new CSSWriterSettings (ECSSVersion.CSS30)));
    }
  });
  System.out.println (aAllSelectors);
}
 
开发者ID:phax,项目名称:ph-css,代码行数:27,代码来源:WikiVisitSelectors.java

示例3: parse

import com.helger.css.decl.visit.CSSVisitor; //导入依赖的package包/类
@Override
public void parse(File cssFile) throws CssParsingException {
    final CascadingStyleSheet data = CSSReader.readFromFile(cssFile, CCharset.CHARSET_UTF_8_OBJ, ECSSVersion.CSS30);
    if (data == null) {
        throw new CssParsingException();
    }
    CSSVisitor.visitCSS(data, new CssVisitor());
}
 
开发者ID:acharpen,项目名称:mocss,代码行数:9,代码来源:Css3Parser.java

示例4: readFromStyleAttributeWithAPI

import com.helger.css.decl.visit.CSSVisitor; //导入依赖的package包/类
public void readFromStyleAttributeWithAPI ()
{
  final String sStyle = "@import 'foobar.css';\n" +
                        "div{background:fixed url(a.gif) !important;}\n" +
                        "span { background-image:url('/my/folder/b.gif');}";
  final CascadingStyleSheet aCSS = CSSReader.readFromString (sStyle, ECSSVersion.CSS30);
  CSSVisitor.visitCSSUrl (aCSS, new DefaultCSSUrlVisitor ()
  {
    // Called for each import
    @Override
    public void onImport (@Nonnull final CSSImportRule aImportRule)
    {
      System.out.println ("Import: " +
                          aImportRule.getLocationString () +
                          " - " +
                          getSourceLocationString (aImportRule.getSourceLocation ()));
    }

    // Call for URLs outside of URLs
    @Override
    public void onUrlDeclaration (@Nullable final ICSSTopLevelRule aTopLevelRule,
                                  @Nonnull final CSSDeclaration aDeclaration,
                                  @Nonnull final CSSExpressionMemberTermURI aURITerm)
    {
      System.out.println (aDeclaration.getProperty () +
                          " - references: " +
                          aURITerm.getURIString () +
                          " - " +
                          getSourceLocationString (aURITerm.getSourceLocation ()));
    }
  });
}
 
开发者ID:phax,项目名称:ph-css,代码行数:33,代码来源:WikiVisitUrls.java

示例5: readFromStyleAttributeWithAPI

import com.helger.css.decl.visit.CSSVisitor; //导入依赖的package包/类
public void readFromStyleAttributeWithAPI ()
{
  final String sStyle = "@import '/folder/foobar.css';\n" +
                        "div{background:fixed url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEgAACxIB0t1+/AAAAAd0SU1FB9EFBAoYMhVvMQIAAAAtSURBVHicY/z//z8DHoBH+v///yy4FDEyMjIwMDDhM3lgpaEuh7gTEzDiDxYA9HEPDF90e5YAAAAASUVORK5CYII=) !important;}\n" +
                        "span { background-image:url('/my/folder/b.gif');}";
  final CascadingStyleSheet aCSS = CSSReader.readFromString (sStyle, ECSSVersion.CSS30);
  CSSVisitor.visitCSSUrl (aCSS, new DefaultCSSUrlVisitor ()
  {
    // Called for each import
    @Override
    public void onImport (@Nonnull final CSSImportRule aImportRule)
    {
      System.out.println ("Import: " + aImportRule.getLocationString ());
    }

    // Call for URLs outside of URLs
    @Override
    public void onUrlDeclaration (@Nullable final ICSSTopLevelRule aTopLevelRule,
                                  @Nonnull final CSSDeclaration aDeclaration,
                                  @Nonnull final CSSExpressionMemberTermURI aURITerm)
    {
      final CSSURI aURI = aURITerm.getURI ();

      if (aURI.isDataURL ())
      {
        final CSSDataURL aDataURL = aURI.getAsDataURL ();
        System.out.println (aDeclaration.getProperty () +
                            " - references data URL with " +
                            aDataURL.getContentLength () +
                            " bytes of content");
      }
      else
        System.out.println (aDeclaration.getProperty () + " - references regular URL: " + aURI.getURI ());
    }
  });
}
 
开发者ID:phax,项目名称:ph-css,代码行数:37,代码来源:WikiVisitDataUrls.java

示例6: getEmbeddedResourceURLs

import com.helger.css.decl.visit.CSSVisitor; //导入依赖的package包/类
/**
 * 
 * @see
 * org.apache.jmeter.protocol.http.parser.LinkExtractorParser#getEmbeddedResourceURLs
 * (java.lang.String, byte[], java.net.URL,
 * org.apache.jmeter.protocol.http.parser.URLCollection, java.lang.String)
 */
@Override
public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] data,
        final URL baseUrl, String encoding) throws LinkExtractorParseException {
    try {
        String cssContent = new String(data, encoding);
        final CascadingStyleSheet aCSS = CSSReader.readFromStringStream(cssContent,
                    new CSSReaderSettings()
                        .setBrowserCompliantMode(true)
                        .setFallbackCharset(Charset.forName(encoding))
                        .setCSSVersion (ECSSVersion.CSS30)
                        .setCustomErrorHandler(new LoggingCSSParseErrorHandler())
                        .setCustomExceptionHandler (new CustomLoggingCSSParseExceptionCallback(baseUrl)));
        final List<URLString> list = new ArrayList<>();
        final URLCollection urlCollection = new URLCollection(list);
        if(aCSS != null) {
            CSSVisitor.visitCSSUrl(aCSS, new DefaultCSSUrlVisitor() {
                @Override
                public void onImport(final CSSImportRule importRule) {
                    String location = importRule.getLocationString();
                    if(!StringUtils.isEmpty(location)) {
                        urlCollection.addURL(location, baseUrl);
                    }
                }
                // Call for URLs outside of URLs
                @Override
                public void onUrlDeclaration(
                        final ICSSTopLevelRule aTopLevelRule,
                        final CSSDeclaration aDeclaration,
                        final CSSExpressionMemberTermURI aURITerm) {
                    // NOOP
                    // Browser fetch such urls only when CSS rule matches
                    // so we disable this code
                    //urlCollection.addURL(aURITerm.getURIString(), baseUrl);
                }
            });
        } else {
           log.warn("Failed parsing url:"+baseUrl+", got null CascadingStyleSheet");
        }
        if(log.isDebugEnabled()) {
            StringBuilder builder = new StringBuilder();
            for (Iterator<URL> iterator = urlCollection.iterator(); iterator.hasNext();) {
                URL urlString = iterator.next();
                builder.append(urlString).append(",");
            }
            log.debug("Parsed:"+baseUrl+", got:"+builder.toString());
        }
        return urlCollection.iterator();
    } catch (Exception e) {
        throw new LinkExtractorParseException(e);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:59,代码来源:CssParser.java


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