Refine search
private <T extends CssNode & HasNodes> void parseInnerStylesheet( String tagName, T parent, String blockContents) { pushParent(parent); // parse the inner text InputSource s = new InputSource(); s.setCharacterStream(new StringReader(blockContents)); Parser parser = new Parser(); parser.setDocumentHandler(this); parser.setErrorHandler(errors); try { parser.parseStyleSheet(s); } catch (IOException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Unable to parse " + tagName, e); } if (currentParent.pop() != parent) { // This is a coding error throw new RuntimeException("Incorrect element popped"); } }
/** * Convert the source into a Reader. Used only by DOM Level 2 parser methods. */ private Reader getReader(InputSource source) throws IOException { if (source.getCharacterStream() != null) { return source.getCharacterStream(); } else if (source.getByteStream() != null) { // My DOM level 2 implementation doesn't use this case. if (source.getEncoding() == null) { // unknown encoding, use ASCII as default. return new InputStreamReader(source.getByteStream(), "ASCII"); } else { return new InputStreamReader(source.getByteStream(), source.getEncoding()); } } else { // systemId // @@TODO throw new CSSException("not yet implemented"); } }
/** * Creates a new LocatorImpl */ public LocatorImpl(Parser p) { if (W3CDebug) { System.err.println( "LocatorImpl::newLocator(" + p + ");"); } uri = p.source.getURI(); line = p.token.beginLine; column = p.token.beginColumn; }
/** * Return true if <code>source</code> is valid and false otherwise. * * @param source * @throws IOException */ private void checkInputSource(InputSource source) throws IOException { Reader reader = source.getCharacterStream(); InputStream stream = source.getByteStream(); if (reader == null && stream == null) throw new IOException( "CharacterStream or ByteStream cannot be null for the InputSource."); }
public CSSStyleDeclaration parseStyleDeclaration(Reader reader) throws IOException { InputSource source = new InputSource(); source.setCharacterStream(reader); return parseStyleDeclaration(source); }
/** * Parse a CSS rule. * * @exception CSSException Any CSS exception, possibly * wrapping another exception. * @exception java.io.IOException An IO exception from the parser, * possibly from a byte stream or character stream * supplied by the application. */ public void parseRule(String source) throws CSSException, IOException { parser.parseRule(new InputSource(new StringReader(source))); }
final InputSource is = new InputSource(new StringReader(cssText)); final CSSOMParser parser = new CSSOMParser(); final CSSRule r = parser.parseRule(is);
.getUrl().toExternalForm(); final String styleAttribute = jsElement_.getDomNodeOrDie().getAttribute("style"); final InputSource source = new InputSource(new StringReader(styleAttribute)); source.setURI(uri); final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); try { styleDeclaration_ = parser.parseStyleDeclaration(source);
public void setMediaText(final String mediaText) { final InputSource source = new InputSource(new StringReader(mediaText)); try { final CSSOMParser parser = new CSSOMParser(); final SACMediaList sml = parser.parseMedia(source); media_ = new MediaListImpl(sml); } catch (final IOException e) { // TODO handle exception } }
public void setCssText(final String cssText) throws DOMException { try { final InputSource is = new InputSource(new StringReader(cssText)); final CSSOMParser parser = new CSSOMParser(); final CSSValueImpl v2 = (CSSValueImpl) parser.parsePropertyValue(is); value_ = v2.value_; setUserDataMap(v2.getUserDataMap()); } catch (final Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
public void setCssText(final String cssText) throws DOMException { try { final InputSource is = new InputSource(new StringReader(cssText)); final CSSOMParser parser = new CSSOMParser(); properties_.clear(); parser.parseStyleDeclaration(this, is); } catch (final Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
private CSSStyleDeclarationImpl mergeStyle( CSSStyleDeclarationImpl parentStyle, String parentStyleValue, String styleValue) { CSSStyleDeclarationImpl currentStyle = new CSSStyleDeclarationImpl(); if (parentStyle == null) { try { this.cssParser.parseStyleDeclaration(currentStyle, new InputSource(new StringReader(parentStyleValue))); } catch (Exception e) { return parentStyle; } } else { currentStyle.setProperties(parentStyle.getProperties()); } try { this.cssParser.parseStyleDeclaration(currentStyle, new InputSource( new StringReader(styleValue))); } catch (Exception e) { return parentStyle; } return currentStyle; }
public void setSelectorText(final String selectorText) throws DOMException { final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { final InputSource is = new InputSource(new StringReader(selectorText)); final CSSOMParser parser = new CSSOMParser(); selectors_ = parser.parseSelectors(is); } catch (final CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (final IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
private void init() { if (style != null) { String styleContent = style.getValue().getText(); if (styleContent != null && !styleContent.isEmpty()) { InputSource source = new InputSource(new StringReader(styleContent)); CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(new ParserErrorHandler()); try { styleSheet = parser.parseStyleSheet(source, null, null); cssFormat = new CSSFormat().setRgbAsHex(true); CSSRuleList rules = styleSheet.getCssRules(); for (int i = 0; i < rules.getLength(); i++) { final CSSRule rule = rules.item(i); if (rule instanceof CSSStyleRuleImpl) { styleRuleMap.put(((CSSStyleRuleImpl) rule).getSelectorText(), (CSSStyleRuleImpl) rule); } } } catch (IOException e) { e.printStackTrace(); } } } }
public StyleSheet parseStyleSheet(InputStream stream) throws IOException { InputSource source = new InputSource(); source.setByteStream(stream); return parseStyleSheet(source); }
if (source.getCharacterStream() != null) { return new Generic_CharStream(source.getCharacterStream(), 1, 1); } else if (source.getByteStream() == null) { source.setByteStream(new URL(source.getURI()).openStream()); } catch (Exception e) { try { source.setByteStream(new FileInputStream(source.getURI())); } catch (IOException ex) { throw new CSSException("invalid url ?"); InputStream input = source.getByteStream(); char c = ' '; source.setByteStream(input); if (source.getEncoding() != null) { if (!encoding.equals(source.getEncoding())) { throw new CSSException("invalid encoding information."); source.setEncoding(encoding); source.setCharacterStream(new InputStreamReader(source.getByteStream(), Encoding.getJavaEncoding(encoding))); return new Generic_CharStream(source.getCharacterStream(), 1, 1);
private CharStream getCharStream(final InputSource source) throws IOException { if (source.getCharacterStream() != null) { return new CssCharStream(source.getCharacterStream(), 1, 1); } if (source.getByteStream() != null) { final InputStreamReader reader; final String encoding = source.getEncoding(); 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 (source.getURI() != null) { final InputStreamReader reader = new InputStreamReader(new URL(source.getURI()).openStream()); return new CssCharStream(reader, 1, 1); } return null; }
@Override public InputSource resolve(String identifier) { // identifier should not have .scss, fileName should String ext = ".scss"; if (identifier.endsWith(".css")) { ext = ".css"; } String fileName = identifier; if (identifier.endsWith(ext)) { identifier = identifier.substring(0, identifier.length() - ext.length()); } else { fileName = fileName + ext; } try { InputStream is = new FileInputStream(fileName); InputSource source = new InputSource(); source.setByteStream(is); source.setURI(fileName); return source; } catch (FileNotFoundException e) { // not found, try something else return null; } }
break; Path p = new Path(source.getURI()); IPath trim = p.removeLastSegments(1); InputSource tempStream = new InputSource(); tempStream.setURI(url.toString()); tempStream.setByteStream(stream); parseImport = true; styleSheet = (CSSStyleSheet) this.parseStyleSheet(tempStream);
StyleSheet parse( InputStream inputStream, String uri, ResourceLoader loader ) throws CSSException, IOException { InputSource source = new InputSource(); source.setByteStream( inputStream ); source.setEncoding( CSS_ENCODING ); source.setURI( uri ); parser.setConditionFactory( new ConditionFactoryImpl( this ) ); parser.setSelectorFactory( new SelectorFactoryImpl( this ) ); DocumentHandlerImpl documentHandler = new DocumentHandlerImpl( this, loader ); parser.setDocumentHandler( documentHandler ); parser.setErrorHandler( new ErrorHandlerImpl( this ) ); // TODO [rst] Batik parser throws ParseException try { parser.parseStyleSheet( source ); } catch( ParseException e ) { throw new CSSException( e ); } return documentHandler.getStyleSheet(); }