Ejemplo n.º 1
0
  public String process(String css) {
    CascadingStyleSheet cascadingStyleSheet =
        CSSReader.readFromString(
            css,
            CCharset.CHARSET_UTF_8_OBJ,
            ECSSVersion.CSS30,
            new DoNothingCSSParseErrorHandler());

    processRules(cascadingStyleSheet.getAllRules());

    return _cssWriter.getCSSAsString(cascadingStyleSheet);
  }
Ejemplo n.º 2
0
 @Nonnull
 public CascadingStyleSheet createCascadingStyleSheetFromNode(@Nonnull final CSSNode aNode) {
   _expectNodeType(aNode, ECSSNodeType.ROOT);
   final CascadingStyleSheet ret = new CascadingStyleSheet();
   ret.setSourceLocation(aNode.getSourceLocation());
   for (final CSSNode aChildNode : aNode) {
     if (ECSSNodeType.CHARSET.isNode(aChildNode, m_eVersion)) {
       // Ignore because this was handled when reading!
     } else if (ECSSNodeType.IMPORTRULE.isNode(aChildNode, m_eVersion))
       ret.addImportRule(_createImportRule(aChildNode));
     else if (ECSSNodeType.NAMESPACERULE.isNode(aChildNode, m_eVersion))
       ret.addNamespaceRule(_createNamespaceRule(aChildNode));
     else if (ECSSNodeType.STYLERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createStyleRule(aChildNode));
     else if (ECSSNodeType.PAGERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createPageRule(aChildNode));
     else if (ECSSNodeType.MEDIARULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createMediaRule(aChildNode));
     else if (ECSSNodeType.FONTFACERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createFontFaceRule(aChildNode));
     else if (ECSSNodeType.KEYFRAMESRULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createKeyframesRule(aChildNode));
     else if (ECSSNodeType.VIEWPORTRULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createViewportRule(aChildNode));
     else if (ECSSNodeType.SUPPORTSRULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createSupportsRule(aChildNode));
     else if (ECSSNodeType.UNKNOWNRULE.isNode(aChildNode, m_eVersion)) {
       // Unknown rule indicates either
       // 1. a parsing error
       // 2. a non-standard rule
       ret.addRule(_createUnknownRule(aChildNode));
     } else
       s_aLogger.error(
           "Unsupported child of "
               + ECSSNodeType.getNodeName(aNode, m_eVersion)
               + ": "
               + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
   }
   return ret;
 }