private void checkIdentPosition(CSSName cssName, IdentValue firstIdent, IdentValue secondIdent) { if (firstIdent == IdentValue.TOP || firstIdent == IdentValue.BOTTOM || secondIdent == IdentValue.LEFT || secondIdent == IdentValue.RIGHT) { throw new CSSParseException("Invalid combination of keywords in " + cssName, -1); } }
public String getMessage() { if (_genericMessage != null) { return _genericMessage + " at line " + (_line+1) + "."; } else { String found = _found == null ? "end of file" : _found.getExternalName(); return "Found " + found + " where " + descr(_expected) + " was expected at line " + (_line+1) + "."; } }
private void error(CSSParseException e, String what, boolean rethrowEOF) { if (! e.isCallerNotified()) { String message = e.getMessage() + " Skipping " + what + "."; _errorHandler.error(_URI, message); } e.setCallerNotified(true); if (e.isEOF() && rethrowEOF) { throw e; } }
public PropertyValue parsePropertyValue(CSSName cssName, int origin, String expr) { _URI = cssName + " property value"; try { reset(new StringReader(expr)); List values = expr( cssName == CSSName.FONT_FAMILY || cssName == CSSName.FONT_SHORTHAND || cssName == CSSName.FS_PDF_FONT_ENCODING); PropertyBuilder builder = CSSName.getPropertyBuilder(cssName); List props; try { props = builder.buildDeclarations(cssName, values, origin, false); } catch (CSSParseException e) { e.setLine(getCurrentLine()); throw e; } if (props.size() != 1) { throw new CSSParseException( "Builder created " + props.size() + "properties, expected 1", getCurrentLine()); } PropertyDeclaration decl = (PropertyDeclaration)props.get(0); return (PropertyValue)decl.getValue(); } catch (IOException e) { // "Shouldn't" happen throw new RuntimeException(e.getMessage(), e); } catch (CSSParseException e) { error(e, "property value", false); return null; } }
if (t != Token.TK_SEMICOLON) { push(t); throw new CSSParseException(t, Token.TK_SEMICOLON, getCurrentLine()); throw new CSSParseException(t, Token.TK_STRING, getCurrentLine()); case Token.IMPORT_SYM: next(); error(new CSSParseException("@import not allowed here", getCurrentLine()), "@import rule", true); recover(false, false); case Token.NAMESPACE_SYM: next(); error(new CSSParseException("@namespace not allowed here", getCurrentLine()), "@namespace rule", true); recover(false, false); case Token.AT_RULE: next(); error(new CSSParseException( "Invalid at-rule", getCurrentLine()), "at-rule", true); recover(false, false); if (! e.isCallerNotified()) { error(e, "stylesheet", false);
} else { push(t); throw new CSSParseException(t, Token.TK_IDENT, getCurrentLine()); selector.addNthChildCondition(number.toString()); } catch (CSSParseException e) { e.setLine(getCurrentLine()); push(t); throw e; throw new CSSParseException(f + " is not a valid function in this context", getCurrentLine()); throw new CSSParseException(t, Token.TK_RPAREN, getCurrentLine());
protected void checkValueCount(CSSName cssName, int min, int max, int found) { if (! (found >= min && found <= max)) { throw new CSSParseException("Found " + found + " value(s) for " + cssName + " when between " + min + " and " + max + " value(s) were expected", -1); } }
throw new CSSParseException( t, new Token[] { Token.TK_SEMICOLON, Token.TK_RBRACE }, cssName, values, ruleset.getOrigin(), important, !inFontFace)); } catch (CSSParseException e) { e.setLine(getCurrentLine()); error(e, "declaration", true); throw new CSSParseException(t, Token.TK_COLON, getCurrentLine()); throw new CSSParseException(t, Token.TK_IDENT, getCurrentLine());
protected void checkValueCount(CSSName cssName, int expected, int found) { if (expected != found) { throw new CSSParseException("Found " + found + " value(s) for " + cssName + " when " + expected + " value(s) were expected", -1); } }
protected void checkValidity(CSSName cssName, BitSet validValues, IdentValue value) { if (! validValues.get(value.FS_ID)) { throw new CSSParseException("Ident " + value + " is an invalid or unsupported value for " + cssName, -1); } }
protected void checkLengthType(CSSName cssName, CSSPrimitiveValue value) { if (! isLength(value)) { throw new CSSParseException("Value for " + cssName + " must be a length", -1); } }
protected void checkInheritAllowed(CSSPrimitiveValue value, boolean inheritAllowed) { if (value.getCssValueType() == CSSPrimitiveValue.CSS_INHERIT && ! inheritAllowed) { throw new CSSParseException("Invalid use of inherit", -1); } }
protected void checkIdentType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_IDENT) { throw new CSSParseException("Value for " + cssName + " must be an identifier", -1); } }
protected void checkIdentOrURIType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_URI) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a URI", -1); } }
protected void checkIdentOrString(CSSName cssName, CSSPrimitiveValue value) { short type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_STRING && type != CSSPrimitiveValue.CSS_IDENT) { throw new CSSParseException("Value for " + cssName + " must be an identifier or string", -1); } }
protected void checkIdentOrColorType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_RGBCOLOR) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a color", -1); } }
protected void checkIdentOrNumberType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_NUMBER) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a length", -1); } }
protected void checkNumberType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_NUMBER) { throw new CSSParseException("Value for " + cssName + " must be a number", -1); } }
protected void checkStringType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_STRING) { throw new CSSParseException("Value for " + cssName + " must be a string", -1); } }
private FSCMYKColor createCMYKColorFromFunction(List params) { if (params.size() != 4) { throw new CSSParseException( "The cmyk() function must have exactly four parameters", getCurrentLine()); } float[] colorComponents = new float[4]; for (int i = 0; i < params.size(); i++) { colorComponents[i] = parseCMYKColorComponent((PropertyValue)params.get(i), (i+1)); //Warning on the truncation? } return new FSCMYKColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]); }