Ejemplo n.º 1
0
  /** Parse a CSS style attribute. */
  public void parseStyleAttribute(
      final Reader reader, String systemID, final CssErrorHandler err, final CssContentHandler doc)
      throws IOException, CssException {
    CssTokenIterator iter = scan(reader, systemID, err);
    doc.startDocument();
    while (iter.hasNext()) {
      CssToken tk = iter.next();

      if (MATCH_SEMI.apply(tk)) {
        continue; // starting with ';' is allowed, Issue 238
      }
      try {

        CssDeclaration decl = handleDeclaration(tk, iter, doc, err, true);
        if (decl != null) {
          doc.declaration(decl);
        } else {
          // #handleDeclaration has issued errors
          return;
        }
      } catch (PrematureEOFException te) {
        // The subroutines report premature EOF to ErrHandler
        // on occurrence; if the listener rethrows it will
        // be a CssException so we don't catch it here.
        break;
      }
    }
    doc.endDocument();
  }
Ejemplo n.º 2
0
  /** Parse a CSS document. */
  public void parse(
      final Reader reader,
      final String systemID,
      final CssErrorHandler err,
      final CssContentHandler doc)
      throws IOException, CssException {

    CssTokenIterator iter = scan(reader, systemID, err);

    doc.startDocument();

    while (iter.hasNext(FILTER_S_CMNT_CDO_CDC)) {
      CssToken tk = iter.next(FILTER_S_CMNT_CDO_CDC);
      try {

        if (tk.type == CssToken.Type.ATKEYWORD) {
          handleAtRule(tk, iter, doc, err);
          if (debug) {
            checkArgument(MATCH_SEMI_CLOSEBRACE.apply(iter.last));
          }
        } else {
          handleRuleSet(tk, iter, doc, err);
          if (debug) {
            checkArgument(MATCH_CLOSEBRACE.apply(iter.last));
          }
        }

      } catch (PrematureEOFException te) {
        // The subroutines report premature EOF to ErrHandler
        // on occurrence; if the listener rethrows it will
        // be a CssException so we don't catch it here.
        break;
      }
    }

    doc.endDocument();
  }