コード例 #1
0
  @Nonnull
  private CSSImportRule _createImportRule(@Nonnull final CSSNode aNode) {
    _expectNodeType(aNode, ECSSNodeType.IMPORTRULE);
    final int nChildCount = aNode.jjtGetNumChildren();
    if (nChildCount > 2)
      _throwUnexpectedChildrenCount(
          aNode, "Expected at last 2 children but got " + nChildCount + "!");

    CSSURI aImportURI = null;
    int nCurrentIndex = 0;
    if (nChildCount > 0) {
      final CSSNode aURINode = aNode.jjtGetChild(0);
      if (ECSSNodeType.URL.isNode(aURINode, m_eVersion)) {
        aImportURI = new CSSURI(aURINode.getText());
        aImportURI.setSourceLocation(aURINode.getSourceLocation());
        ++nCurrentIndex;
      } else if (!ECSSNodeType.MEDIALIST.isNode(aURINode, m_eVersion))
        throw new IllegalStateException(
            "Expected an URI or MEDIALIST node but got "
                + ECSSNodeType.getNodeName(aURINode, m_eVersion));
    }

    if (aImportURI == null) {
      // No URI child node present, so the location is printed directly
      // E.g. @import "abc.css"
      aImportURI = new CSSURI(CSSParseHelper.extractStringValue(aNode.getText()));
    }

    // Import rule
    final CSSImportRule ret = new CSSImportRule(aImportURI);
    ret.setSourceLocation(aNode.getSourceLocation());
    if (nChildCount > nCurrentIndex) {
      // We have a media query present!
      final CSSNode aMediaListNode = aNode.jjtGetChild(nCurrentIndex);
      if (ECSSNodeType.MEDIALIST.isNode(aMediaListNode, m_eVersion)) {
        for (final CSSNode aMediaQueryNode : aMediaListNode) {
          ret.addMediaQuery(_createMediaQuery(aMediaQueryNode));
        }
        ++nCurrentIndex;
      } else
        s_aLogger.error(
            "Expected an MEDIALIST node but got "
                + ECSSNodeType.getNodeName(aMediaListNode, m_eVersion));
    }

    if (nCurrentIndex < nChildCount)
      s_aLogger.error("Import statement has children which are unhandled.");
    return ret;
  }
コード例 #2
0
 @Nonnull
 private CSSMediaRule _createMediaRule(@Nonnull final CSSNode aNode) {
   _expectNodeType(aNode, ECSSNodeType.MEDIARULE);
   final CSSMediaRule ret = new CSSMediaRule();
   ret.setSourceLocation(aNode.getSourceLocation());
   for (final CSSNode aChildNode : aNode) {
     if (ECSSNodeType.MEDIALIST.isNode(aChildNode, m_eVersion)) {
       for (final CSSNode aMediaListChildNode : aChildNode)
         ret.addMediaQuery(_createMediaQuery(aMediaListChildNode));
     } else if (ECSSNodeType.STYLERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createStyleRule(aChildNode));
     else if (ECSSNodeType.MEDIARULE.isNode(aChildNode, m_eVersion)) {
       // Nested media rules are OK!
       ret.addRule(_createMediaRule(aChildNode));
     } else if (ECSSNodeType.PAGERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createPageRule(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.isErrorNode(aChildNode, m_eVersion))
       s_aLogger.error(
           "Unsupported media-rule child: " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
   }
   return ret;
 }