Exemplo n.º 1
0
  /**
   * @param node
   * @param rootNode
   */
  private void addNode(IParseNode node) {
    CSSNode cssNode = (CSSNode) node;
    short type = cssNode.getNodeType();

    switch (type) {
      case ICSSNodeTypes.RULE:
        pushFormatterRuleNode((CSSRuleNode) cssNode);
        break;
      case ICSSNodeTypes.PAGE:
        pushFormatterPageNode((CSSPageNode) cssNode);
        break;
      case ICSSNodeTypes.FONTFACE:
        pushFormatterFontFaceNode((CSSFontFaceNode) cssNode);
        break;
      case ICSSNodeTypes.MEDIA:
        pushFormatterMediaNode((CSSMediaNode) cssNode);
        break;
      case ICSSNodeTypes.AT_RULE:
      case ICSSNodeTypes.CHAR_SET:
      case ICSSNodeTypes.NAMESPACE:
      case ICSSNodeTypes.IMPORT:
        // Custom at-rule and import nodes currently fall under the same formatting case. This may
        // need to
        // change once the parser returns the url part as a textnode
        pushAtRuleNode(cssNode);
        break;
      default:
        break;
    }
  }
Exemplo n.º 2
0
  // This is a temporary fix for custom at-rules. When the parser adds support to return the ruleID,
  // this will need to
  // be changed
  private void pushAtRuleNode(CSSNode atRuleNode) {

    int length = document.getLength();
    int selectorStartingOffset = atRuleNode.getStartingOffset();
    int selectEndingOffset = atRuleNode.getEndingOffset();

    // Locate first white space after the @rule
    while (selectorStartingOffset < length) {
      if (Character.isWhitespace(document.charAt(selectorStartingOffset))) {
        break;
      }
      selectorStartingOffset++;
    }
    // Find the starting offset for the selector
    selectorStartingOffset = getBeginWithoutWhiteSpaces(selectorStartingOffset, document);

    // Find the end offset for the selector
    while (selectEndingOffset >= selectorStartingOffset) {
      if (!Character.isWhitespace(document.charAt(selectEndingOffset - 1))) {
        break;
      }
      selectEndingOffset--;
    }
    // Push an At-Node to control the lines separators.
    FormatterCSSAtRuleNode atNode = new FormatterCSSAtRuleNode(document);
    atNode.setBegin(
        createTextNode(document, atRuleNode.getStartingOffset(), selectorStartingOffset));
    push(atNode);
    checkedPop(atNode, -1);

    // We use a selector node for now, we may want to create a new formatter node type for rule id
    FormatterBlockWithBeginNode formatterSelectorNode =
        new FormatterCSSSelectorNode(document, false, false);
    formatterSelectorNode.setBegin(
        createTextNode(
            document,
            getBeginWithoutWhiteSpaces(selectorStartingOffset, document),
            getEndWithoutWhiteSpaces(selectEndingOffset, document) + 1));
    push(formatterSelectorNode);

    findAndPushPunctuationNode(TypePunctuation.SEMICOLON, selectEndingOffset, false);

    checkedPop(formatterSelectorNode, -1);
  }