1、代码4package org.hibernate.c3p0.internal;package com.steadystate.css.parser;import com.steadystate.css.parser.selectors.ConditionFactoryImpl;import com.steadystate.css.parser.selectors.SelectorFactoryImpl;import com.steadystate.css.sac.DocumentHandlerExt;import java.io.IOException;import java.io.Input
2、StreamReader;import .URL;import java.nio.charset.Charset;import java.text.MessageFormat;import java.util.Locale;import java.util.MissingResourceException;import java.util.ResourceBundle;import org.w3c.css.sac.CSSParseException;import org.w3c.css.sac.ConditionFactory;import org.w3c.css.sac.DocumentHa
3、ndler;import org.w3c.css.sac.ErrorHandler;import org.w3c.css.sac.InputSource;import org.w3c.css.sac.LexicalUnit;import org.w3c.css.sac.Locator;import org.w3c.css.sac.Parser;import org.w3c.css.sac.SACMediaList;import org.w3c.css.sac.Selector;import org.w3c.css.sac.SelectorFactory;import org.w3c.css.s
4、ac.SelectorList;abstract class AbstractSACParser implements Parser private DocumentHandler documentHandler_; private ErrorHandler errorHandler_; private InputSource source_; private Locale locale_; private SelectorFactory selectorFactory_; private ConditionFactory conditionFactory_; private Resource
5、Bundle sacParserMessages_; private static final String NUM_CHARS = 0123456789.; protected abstract Token getToken(); protected DocumentHandler getDocumentHandler() if (this.documentHandler_ = null) setDocumentHandler(new HandlerBase(); return this.documentHandler_; public void setDocumentHandler(Doc
6、umentHandler handler) this.documentHandler_ = handler; protected ErrorHandler getErrorHandler() if (this.errorHandler_ = null) setErrorHandler(new HandlerBase(); return this.errorHandler_; public void setErrorHandler(ErrorHandler eh) this.errorHandler_ = eh; protected InputSource getInputSource() re
7、turn this.source_; public void setLocale(Locale locale) if (this.locale_ != locale) this.sacParserMessages_ = null; this.locale_ = locale; protected Locale getLocale() if (this.locale_ = null) setLocale(Locale.getDefault(); return this.locale_; protected SelectorFactory getSelectorFactory() if (this
8、.selectorFactory_ = null) this.selectorFactory_ = new SelectorFactoryImpl(); return this.selectorFactory_; public void setSelectorFactory(SelectorFactory selectorFactory) this.selectorFactory_ = selectorFactory; protected ConditionFactory getConditionFactory() if (this.conditionFactory_ = null) this
9、.conditionFactory_ = new ConditionFactoryImpl(); return this.conditionFactory_; public void setConditionFactory(ConditionFactory conditionFactory) this.conditionFactory_ = conditionFactory; protected ResourceBundle getSACParserMessages() if (this.sacParserMessages_ = null) try this.sacParserMessages
10、_ = ResourceBundle.getBundle(com.steadystate.css.parser.SACParserMessages, getLocale(); catch (MissingResourceException e) e.printStackTrace(); return this.sacParserMessages_; public Locator getLocator() return createLocator(getToken(); protected Locator createLocator(Token t) return new LocatorImpl
11、(getInputSource().getURI(), t = null ? 0 : t.beginLine, t = null ? 0 : t.beginColumn); protected String add_escapes(String str) StringBuilder sb = new StringBuilder(); if (ch ) String s = 0000 + Integer.toString(ch, 16); sb.append(u + s.substring(s.length() - 4, s.length(); else sb.append(ch); break
12、; return sb.toString(); protected CSSParseException toCSSParseException(String key, ParseException e) String messagePattern1 = getSACParserMessages().getString(invalidExpectingOne); String messagePattern2 = getSACParserMessages().getString(invalidExpectingMore); int maxSize = 0; StringBuilder expect
13、ed = new StringBuilder(); for (int i = 0; i e.expectedTokenSequences.length; i+) if (maxSize e.expectedTokenSequencesi.length) maxSize = e.expectedTokenSequencesi.length; for (int j = 0; j e.expectedTokenSequencesi.length; j+) expected.append(e.tokenImagee.expectedTokenSequencesij); if (i e.expected
14、TokenSequences.length - 1) expected.append(, ); StringBuilder invalid = new StringBuilder(); Token tok = e.currentToken.next; for (int i = 0; i maxSize; i+) if (i != 0) invalid.append( ); if (tok.kind = 0) invalid.append(e.tokenImage0); break; invalid.append(add_escapes(tok.image); tok = tok.next; S
15、tring s = null; try s = getSACParserMessages().getString(key); catch (MissingResourceException ex) s = key; StringBuilder message = new StringBuilder(s); message.append( (); if (e.expectedTokenSequences.length = 1) message.append(MessageFormat.format(messagePattern1, new Object invalid, expected );
16、else message.append(MessageFormat.format(messagePattern2, new Object invalid, expected ); message.append(); return new CSSParseException(message.toString(), getInputSource().getURI(), e.currentToken.next.beginLine, e.currentToken.next.beginColumn); protected CSSParseException toCSSParseException(Tok
17、enMgrError e) String messagePattern = getSACParserMessages().getString(tokenMgrError); return new CSSParseException(messagePattern, getInputSource().getURI(), 1, 1); protected CSSParseException toCSSParseException(String messageKey, Object msgParams, Locator locator) String messagePattern = getSACPa
18、rserMessages().getString(messageKey); return new CSSParseException(MessageFormat.format(messagePattern, msgParams), locator); protected CSSParseException createSkipWarning(String key, CSSParseException e) String s = null; try s = getSACParserMessages().getString(key); catch (MissingResourceException
19、 ex) s = key; return new CSSParseException(s, e.getURI(), e.getLineNumber(), e.getColumnNumber(); public void parseStyleSheet(InputSource source) throws IOException this.source_ = source; ReInit(getCharStream(source); try styleSheet(); catch (ParseException e) getErrorHandler().error(toCSSParseExcep
20、tion(invalidStyleSheet, e); catch (TokenMgrError e) getErrorHandler().error(toCSSParseException(e); catch (CSSParseException e) getErrorHandler().error(e); public void parseStyleSheet(String uri) throws IOException parseStyleSheet(new InputSource(uri); public void parseStyleDeclaration(InputSource s
21、ource) throws IOException this.source_ = source; ReInit(getCharStream(source); try styleDeclaration(); catch (ParseException e) getErrorHandler().error(toCSSParseException(invalidStyleDeclaration, e); catch (TokenMgrError e) getErrorHandler().error(toCSSParseException(e); catch (CSSParseException e)
22、 getErrorHandler().error(e); public void parseRule(InputSource source) throws IOException this.source_ = source; ReInit(getCharStream(source); try styleSheetRuleSingle(); catch (ParseException e) getErrorHandler().error(toCSSParseException(invalidRule, e); catch (TokenMgrError e) getErrorHandler().e
23、rror(toCSSParseException(e); catch (CSSParseException e) getErrorHandler().error(e); public SelectorList parseSelectors(InputSource source) throws IOException this.source_ = source; ReInit(getCharStream(source); SelectorList sl = null; try sl = parseSelectorsInternal(); catch (ParseException e) getE
24、rrorHandler().error(toCSSParseException(invalidSelectorList, e); catch (TokenMgrError e) getErrorHandler().error(toCSSParseException(e); catch (CSSParseException e) getErrorHandler().error(e); return sl; public LexicalUnit parsePropertyValue(InputSource source) throws IOException this.source_ = sour
25、ce; ReInit(getCharStream(source); LexicalUnit lu = null; try lu = expr(); catch (ParseException e) getErrorHandler().error(toCSSParseException(invalidExpr, e); catch (TokenMgrError e) getErrorHandler().error(toCSSParseException(e); catch (CSSParseException e) getErrorHandler().error(e); return lu; p
26、ublic boolean parsePriority(InputSource source) throws IOException this.source_ = source; ReInit(getCharStream(source); boolean b = false; try b = prio(); catch (ParseException e) getErrorHandler().error(toCSSParseException(invalidPrio, e); catch (TokenMgrError e) getErrorHandler().error(toCSSParseE
27、xception(e); catch (CSSParseException e) getErrorHandler().error(e); return b; public SACMediaList parseMedia(InputSource source) throws IOException this.source_ = source; ReInit(getCharStream(source); SACMediaListImpl ml = new SACMediaListImpl(); try mediaList(ml); catch (ParseException e) getError
28、Handler().error(toCSSParseException(invalidMediaList, e); catch (TokenMgrError e) getErrorHandler().error(toCSSParseException(e); catch (CSSParseException e) getErrorHandler().error(e); return ml; private CharStream getCharStream(InputSource source) throws IOException if (source.getCharacterStream()
29、 != null) return new CssCharStream(source.getCharacterStream(), 1, 1); if (source.getByteStream() != null) String encoding = source.getEncoding(); InputStreamReader reader; InputStreamReader reader; if (encoding = null) | (encoding.length() 1) reader = new InputStreamReader(source.getByteStream(), Charset.defaultCharset(); else reader = new InputStreamReader(source.getByteStream(), encoding); return new CssCharStream(reader, 1, 1); if (
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1