⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sacparser.java

📁 cssparser -- CSS 的语法解析器。采用java语言编写。可用在服务端生成页面。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Generated By:JavaCC: Do not edit this line. SACParser.java */package com.steadystate.css.parser;import java.io.*;import java.net.*;import java.util.*;import org.w3c.css.sac.*;import com.steadystate.css.parser.selectors.*;/** * @author David Schweinsberg * @version $Release$ */public class SACParser implements Parser, SACParserConstants {    private InputSource _source = null;    private Locale _locale = null;    private DocumentHandler _docHandler = null;    private ErrorHandler _errHandler = null;    private SelectorFactory _selectorFactory = new SelectorFactoryImpl();    private ConditionFactory _conditionFactory = new ConditionFactoryImpl();    private boolean _quiet = true;    public SACParser() {        this((CharStream) null);    }    public void setLocale(Locale locale) throws CSSException {        _locale = locale;        // TODO: Search for requested locale        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);    }    public void setDocumentHandler(DocumentHandler handler) {        _docHandler = handler;    }    public void setSelectorFactory(SelectorFactory selectorFactory) {        _selectorFactory = selectorFactory;    }    public void setConditionFactory(ConditionFactory conditionFactory) {        _conditionFactory = conditionFactory;    }    public void setErrorHandler(ErrorHandler handler) {        _errHandler = handler;    }    public void parseStyleSheet(InputSource source)            throws CSSException, IOException {        _source = source;        ReInit(getCharStream(source));        try {            styleSheet();        } catch (ParseException e) {            throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e);        }    }    public void parseStyleSheet(String uri) throws CSSException, IOException {        parseStyleSheet(new InputSource(uri));    }    public void parseStyleDeclaration(InputSource source)            throws CSSException, IOException {        _source = source;        ReInit(getCharStream(source));        try {            styleDeclaration();        } catch (ParseException e) {            throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e);        }    }    public void parseRule(InputSource source) throws CSSException, IOException {        _source = source;        ReInit(getCharStream(source));        try {            styleSheetRuleSingle();        } catch (ParseException e) {            throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e);        }    }    public String getParserVersion() {        return "http://www.w3.org/TR/REC-CSS2";    }    public SelectorList parseSelectors(InputSource source)            throws CSSException, IOException {        _source = source;        ReInit(getCharStream(source));        SelectorList sl = null;        try {            sl = selectorList();        } catch (ParseException e) {            throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e);        }        return sl;    }    public LexicalUnit parsePropertyValue(InputSource source)            throws CSSException, IOException {        _source = source;        ReInit(getCharStream(source));        LexicalUnit lu = null;        try {            lu = expr();        } catch (ParseException e) {            throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e);        }        return lu;    }    public boolean parsePriority(InputSource source)            throws CSSException, IOException {        _source = source;        ReInit(getCharStream(source));        boolean b = false;        try {            b = prio();        } catch (ParseException e) {            throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e);        }        return b;    }    private CharStream getCharStream(InputSource source)            throws CSSException, IOException {        if (source.getCharacterStream() != null) {                return new ASCII_CharStream(source.getCharacterStream(), 1, 1);            } else {            // TODO: Handle other sources            return null;        }    }    private Locator getLocator() {        return null;    }//// stylesheet//  : [ CHARSET_SYM S* STRING S* ';' ]?//      [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*//      [ [ ruleset | media | page | font_face ] [S|CDO|CDC]* ]*//  ;//  final public void styleSheet() throws ParseException {    try {          _docHandler.startDocument(_source);      styleSheetRuleList();      jj_consume_token(0);    } finally {        _docHandler.endDocument(_source);    }  }  final public void styleSheetRuleList() throws ParseException {    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case CHARSET_SYM:      charsetRule();      break;    default:      jj_la1[0] = jj_gen;      ;    }    label_1:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case S:      case CDO:      case CDC:        ;        break;      default:        jj_la1[1] = jj_gen;        break label_1;      }      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case S:        jj_consume_token(S);        break;      case CDO:        jj_consume_token(CDO);        break;      case CDC:        jj_consume_token(CDC);        break;      default:        jj_la1[2] = jj_gen;        jj_consume_token(-1);        throw new ParseException();      }    }    label_2:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case IMPORT_SYM:        ;        break;      default:        jj_la1[3] = jj_gen;        break label_2;      }      importRule();      label_3:      while (true) {        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case S:        case CDO:        case CDC:          ;          break;        default:          jj_la1[4] = jj_gen;          break label_3;        }        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case S:          jj_consume_token(S);          break;        case CDO:          jj_consume_token(CDO);          break;        case CDC:          jj_consume_token(CDC);          break;        default:          jj_la1[5] = jj_gen;          jj_consume_token(-1);          throw new ParseException();        }      }    }    label_4:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case DOT:      case COLON:      case ASTERISK:      case LSQUARE:      case HASH:      case PAGE_SYM:      case MEDIA_SYM:      case FONT_FACE_SYM:      case ATKEYWORD:      case IDENT:        ;        break;      default:        jj_la1[6] = jj_gen;        break label_4;      }      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case DOT:      case COLON:      case ASTERISK:      case LSQUARE:      case HASH:      case IDENT:        styleRule();        break;      case MEDIA_SYM:        mediaRule();        break;      case PAGE_SYM:        pageRule();        break;      case FONT_FACE_SYM:        fontFaceRule();        break;      case ATKEYWORD:        unknownRule();        break;      default:        jj_la1[7] = jj_gen;        jj_consume_token(-1);        throw new ParseException();      }      label_5:      while (true) {        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case S:        case CDO:        case CDC:          ;          break;        default:          jj_la1[8] = jj_gen;          break label_5;        }        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case S:          jj_consume_token(S);          break;        case CDO:          jj_consume_token(CDO);          break;        case CDC:          jj_consume_token(CDC);          break;        default:          jj_la1[9] = jj_gen;          jj_consume_token(-1);          throw new ParseException();        }      }    }  }//// This is used by ASTStyleSheet.insertRule to parse a single rule//  final public void styleSheetRuleSingle() throws ParseException {    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case CHARSET_SYM:      charsetRule();      break;    case IMPORT_SYM:      importRule();      break;    case DOT:    case COLON:    case ASTERISK:    case LSQUARE:    case HASH:    case IDENT:      styleRule();      break;    case MEDIA_SYM:      mediaRule();      break;    case PAGE_SYM:      pageRule();      break;    case FONT_FACE_SYM:      fontFaceRule();      break;    case ATKEYWORD:      unknownRule();      break;    default:      jj_la1[10] = jj_gen;      jj_consume_token(-1);      throw new ParseException();    }  }  final public void charsetRule() throws ParseException {  Token t;    jj_consume_token(CHARSET_SYM);    label_6:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case S:        ;        break;      default:        jj_la1[11] = jj_gen;        break label_6;      }      jj_consume_token(S);    }    t = jj_consume_token(STRING);    label_7:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case S:        ;        break;      default:        jj_la1[12] = jj_gen;        break label_7;      }      jj_consume_token(S);    }    jj_consume_token(SEMICOLON);  }  final public void unknownRule() throws ParseException {    Token t;    String s;    t = jj_consume_token(ATKEYWORD);        s = skip();        _docHandler.ignorableAtRule(s);  }//// import//   : IMPORT_SYM S*//     [STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S*//   ;//  final public void importRule() throws ParseException {    Token t;    String s;    SACMediaListImpl ml = new SACMediaListImpl();    jj_consume_token(IMPORT_SYM);    label_8:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case S:        ;        break;      default:        jj_la1[13] = jj_gen;        break label_8;      }      jj_consume_token(S);    }    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case STRING:      t = jj_consume_token(STRING);      break;    case URI:      t = jj_consume_token(URI);      break;    default:      jj_la1[14] = jj_gen;      jj_consume_token(-1);      throw new ParseException();    }    label_9:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case S:        ;        break;      default:        jj_la1[15] = jj_gen;        break label_9;      }      jj_consume_token(S);    }    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case IDENT:      mediaList(ml);      break;    default:      jj_la1[16] = jj_gen;      ;    }    jj_consume_token(SEMICOLON);        _docHandler.importStyle(unescape(t.image), ml, null);  }//// media//   : MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S*//   ;//  final public void mediaRule() throws ParseException {    boolean start = false;    SACMediaListImpl ml = new SACMediaListImpl();    try {      jj_consume_token(MEDIA_SYM);      label_10:      while (true) {        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case S:          ;          break;        default:          jj_la1[17] = jj_gen;          break label_10;        }        jj_consume_token(S);      }      mediaList(ml);            start = true;            _docHandler.startMedia(ml);      jj_consume_token(LBRACE);      label_11:      while (true) {        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case S:          ;          break;        default:          jj_la1[18] = jj_gen;          break label_11;        }        jj_consume_token(S);      }      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case DOT:      case COLON:      case ASTERISK:      case LSQUARE:      case HASH:      case PAGE_SYM:      case ATKEYWORD:      case IDENT:        mediaRuleList();        break;      default:        jj_la1[19] = jj_gen;        ;      }      jj_consume_token(RBRACE);    } finally {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -