private static SyntaxError mapToSyntaxError(RecognitionException cause, String text) { return new SyntaxError("Error parsing Benerator Script expression", cause, text, cause.line, cause.charPositionInLine); }
public static Boolean parseBoolean(String s, boolean acceptWhitespace) { if (s == null) return null; if (acceptWhitespace) s = s.trim(); if ("true".equalsIgnoreCase(s)) return true; else if ("false".equalsIgnoreCase(s)) return false; else throw new SyntaxError("Not a boolean value", s); }
private void assertElementName(String name, Element element) { if (!name.equals(element.getNodeName())) { String message = "Expected element <" + name + ">, but found <" + element.getNodeName() + ">"; throw new SyntaxError(message, XMLUtil.formatShort(element)); } }
protected static SyntaxError createSyntaxError(String message, Element element) { return new SyntaxError("Syntax error: " + message, XMLUtil.format(element)); }
protected static void syntaxError(String message, Element element) { throw new SyntaxError("Syntax error: " + message, XMLUtil.format(element)); }
protected static SyntaxError createSyntaxError(String message, Element element, Exception cause) { return new SyntaxError("Syntax error: " + message, cause, XMLUtil.format(element), -1, -1); }
protected static void syntaxError(String message, Element element) { throw new SyntaxError("Syntax error: " + message, XMLUtil.format(element)); }
private static SyntaxError mapToSyntaxError(RecognitionException e, String parsedText) { return new SyntaxError("Error parsing regular expression: " + e.getMessage(), parsedText, e.charPositionInLine, e.line); }
private SyntaxError mapToSyntaxError(RecognitionException e, String parsedText) { return new SyntaxError("Error parsing regular expression: " + e.getMessage(), parsedText, e.charPositionInLine, e.line); }
private static FixedWidthColumnDescriptor parseNumberPattern(String formatSpec, String nullString, Locale locale) { if (!formatSpec.startsWith("N")) throw new SyntaxError("Illegal number pattern", formatSpec); String pattern = formatSpec.substring(1); Format format = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(locale)); return new FixedWidthColumnDescriptor(null, format, nullString); }
private static void checkForSyntaxErrors(String text, String type, org.databene.regex.antlr.RegexParser parser, ParserRuleReturnScope r) { if (parser.getNumberOfSyntaxErrors() > 0) throw new SyntaxError("Illegal " + type, text, -1, -1); CommonToken stop = (CommonToken) r.stop; if (stop.getStopIndex() < StringUtil.trimRight(text).length() - 1) { if (stop.getStopIndex() == 0) throw new SyntaxError("Syntax error after " + stop.getText(), text); else throw new SyntaxError("Syntax error", text); } }
private static FixedWidthColumnDescriptor parseDatePattern(String formatSpec, String nullString, Locale locale) { if (!formatSpec.startsWith("D")) throw new SyntaxError("Illegal date/time pattern", formatSpec); String pattern = formatSpec.substring(1); Format format = new SimpleDateFormat(pattern, DateFormatSymbols.getInstance(locale)); return new FixedWidthColumnDescriptor(null, format, nullString); }
private static void checkForSyntaxErrors(String text, String type, org.databene.script.antlr.DatabeneScriptParser parser, ParserRuleReturnScope r) { if (parser.getNumberOfSyntaxErrors() > 0) throw new SyntaxError("Illegal " + type, text, -1, -1); CommonToken stop = (CommonToken) r.stop; if (stop.getStopIndex() < StringUtil.trimRight(text).length() - 1) { if (stop.getStopIndex() == 0) throw new SyntaxError("Syntax error after " + stop.getText(), text); else throw new SyntaxError("Unspecific syntax error", text); } }
private static void checkForSyntaxErrors(String text, String type, SQLParser parser, ParserRuleReturnScope r) { if (parser.getNumberOfSyntaxErrors() > 0) throw new SyntaxError("Illegal " + type, text, -1, -1); CommonToken stop = (CommonToken) r.stop; if (text != null && stop.getStopIndex() < StringUtil.trimRight(text).length() - 1) { if (stop.getStopIndex() == 0) throw new SyntaxError("Syntax error after " + stop.getText(), text); else throw new SyntaxError("Syntax error at the beginning ", text); } }
private static void checkForSyntaxErrors(String text, String type, org.databene.formats.regex.antlr.RegexParser parser, ParserRuleReturnScope r) { if (parser.getNumberOfSyntaxErrors() > 0) throw new SyntaxError("Illegal " + type, text, -1, -1); CommonToken stop = (CommonToken) r.stop; if (stop.getStopIndex() < StringUtil.trimRight(text).length() - 1) { if (stop.getStopIndex() == 0) throw new SyntaxError("Syntax error after " + stop.getText(), text); else throw new SyntaxError("Syntax error", text); } }
public <T> T parseAsBean(String row, Class<T> beanClass) { if (row.length() != rowLength) throw new SyntaxError("Row of type '" + name + "' has illegal length. " + "Expected: " + rowLength + ", found: " + row.length(), "'" + row + "'"); T bean = BeanUtil.newInstance(beanClass); ParsePosition pos = new ParsePosition(0); for (FixedWidthColumnDescriptor columnDescriptor : columnDescriptors) { int endIndex = pos.getIndex() + columnDescriptor.getWidth(); String cellContent = row.substring(pos.getIndex(), endIndex); try { Object cellObject = columnDescriptor.parse(cellContent); AnyMutator.setValue(bean, columnDescriptor.getName(), cellObject, true, true); } catch (ParseException e) { throw new SyntaxError("Error parsing column '" + columnDescriptor + "'. " + e.getMessage(), cellContent); } pos.setIndex(endIndex); } return bean; }
public Object[] parseAsArray(String row) { if (row.length() != rowLength) throw new SyntaxError("Row of type '" + name + "' has illegal length. " + "Expected: " + rowLength + ", found: " + row.length(), "'" + row + "'"); ArrayBuilder<Object> builder = new ArrayBuilder<Object>(Object.class); ParsePosition pos = new ParsePosition(0); for (int i = 0; i < columnDescriptors.length; i++) { FixedWidthColumnDescriptor columnDescriptor = columnDescriptors[i]; int endIndex = pos.getIndex() + columnDescriptor.getWidth(); String cellContent = row.substring(pos.getIndex(), endIndex); try { Object cellObject = columnDescriptor.parse(cellContent); builder.add(cellObject); } catch (ParseException e) { throw new SyntaxError("Error parsing column '" + descriptorName(columnDescriptor, i) + "'. " + e.getMessage(), cellContent); } pos.setIndex(endIndex); } return builder.toArray(); }
public static Boolean getBooleanAttribute(Element element, String attributeName, boolean required) { String stringValue = element.getAttribute(attributeName); if (StringUtil.isEmpty(stringValue) && required) throw new SyntaxError("Missing attribute '" + attributeName + "'", format(element)); return ParseUtil.parseBoolean(stringValue); }
@SuppressWarnings("null") public static void saveAsProperties(Properties properties, File file, String encoding) throws FileNotFoundException { if (properties.size() == 0) throw new IllegalArgumentException("Cannot save empty Properties"); Document document = null; for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); String[] prefixAndRemainingPath = StringUtil.splitOnFirstSeparator(key, '.'); if (document == null) document = createDocument(prefixAndRemainingPath[0]); String rootElementName = document.getDocumentElement().getNodeName(); if (!key.startsWith(rootElementName + '.')) throw new SyntaxError("Required prefix '" + rootElementName + "' not present in key", key); setProperty(prefixAndRemainingPath[1], value, document.getDocumentElement(), document); } document.setXmlStandalone(true); // needed to omit standalone="yes/no" in the XML header saveDocument(document, file, encoding); }
return new Time(format.parse(dateOrTimeSpec).getTime()); } else throw new SyntaxError("Not a supported date/time format:", dateOrTimeSpec); } catch (ParseException e) { throw new ConversionException(e);