Esempio n. 1
0
  @Nonnull
  private CSSExpressionMemberTermURI _createExpressionURL(@Nonnull final CSSNode aNode) {
    _expectNodeType(aNode, ECSSNodeType.URL);

    final int nChildCount = aNode.jjtGetNumChildren();
    if (nChildCount > 0)
      _throwUnexpectedChildrenCount(aNode, "Expected 0 children but got " + nChildCount + "!");

    final CSSURI aURI = new CSSURI(aNode.getText());
    aURI.setSourceLocation(aNode.getSourceLocation());
    return new CSSExpressionMemberTermURI(aURI);
  }
Esempio n. 2
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;
  }