コード例 #1
0
  /**
   * given a string that denotes the properties of one or more selectors, parse further into
   * name/value pairs and call documentHandler's property callback.
   */
  private void _handlePropertiesString(SkinCSSDocumentHandler documentHandler, String properties) {
    if (properties == null) return;

    // first, parse out any comments
    Matcher matcher = _COMMENT_PATTERN.matcher(properties);
    properties = matcher.replaceAll("");
    // split into name and value (don't skip whitespace since properties like padding: 0px 5px
    // need the spaces)
    String[] property = _splitString(properties, ';', false);

    for (int i = 0; i < property.length; i++) {
      int indexOfColon = property[i].indexOf(':');
      if ((indexOfColon > -1) && (indexOfColon < property[i].length())) {
        String name = property[i].substring(0, indexOfColon);
        String value = property[i].substring(indexOfColon + 1);
        documentHandler.property(name.trim(), value.trim());
      }
    }
  }
コード例 #2
0
  public void parseCSSDocument(Reader in, SkinCSSDocumentHandler documentHandler) {

    try {
      CSSScanner scanner = new CSSScanner(in);
      documentHandler.startDocument();
      List<String> selectorList = null;

      // start scanning the document
      // return comments /* xxx */
      // return @rules, which end with ';'
      // return selectors, which end with a {
      // return properties, which end with a }
      int currentType = _nextIgnoreSpaces(scanner);

      while (currentType != CSSLexicalUnits.EOF) {
        if (currentType == CSSLexicalUnits.COMMENT)
          documentHandler.comment(scanner.getStringValue());
        else if (currentType == CSSLexicalUnits.AT_KEYWORD)
          documentHandler.atRule(scanner.getStringValue());
        else if (currentType == CSSLexicalUnits.LEFT_CURLY_BRACE) {
          documentHandler.startSelector();
          selectorList = _parseSelectorString(scanner.getStringValue());
        } else if (currentType == CSSLexicalUnits.RIGHT_CURLY_BRACE) {
          String properties = scanner.getStringValue();
          _handlePropertiesString(documentHandler, properties);
          if (selectorList == null) {
            if (_LOG.isWarning()) {
              _LOG.warning("IGNORING_PROPERTIES_WITHOUT_SELECTOR", properties);
            }
          }
          documentHandler.endSelector(selectorList);
        }
        currentType = _nextIgnoreSpaces(scanner);
      }
    } finally {
      documentHandler.endDocument();
    }
  }