List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:org.level28.android.moca.json.ScheduleDeserializer.java
private static void checkChar(final char[] s, int index, char expected) throws ParseException { if (s[index] != expected) { throw new ParseException("Unexpected character", index); }//ww w. j av a 2 s.c o m }
From source file:org.azkfw.datasource.xml.XmlDatasourceBuilder.java
/** * ?// w w w . j a va 2 s .c om * * @return * @throws FileNotFoundException * @throws ParseException * @throws IOException */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Datasource build() throws FileNotFoundException, ParseException, IOException { XmlDatasource datasource = new XmlDatasource(); datasource.name = datasourceName; InputStream stream = null; try { List<XmlTable> tables = new ArrayList<XmlTable>(); for (File file : xmlFiles) { List<XmlTableEntity> tableList = null; stream = new FileInputStream(file); Digester digester = new Digester(); digester.addObjectCreate("datasource/tables", ArrayList.class); digester.addObjectCreate("datasource/tables/table", XmlTableEntity.class); digester.addSetProperties("datasource/tables/table"); digester.addSetNext("datasource/tables/table", "add"); digester.addObjectCreate("datasource/tables/table/fields", ArrayList.class); digester.addSetNext("datasource/tables/table/fields", "setFields"); digester.addObjectCreate("datasource/tables/table/fields/field", XmlFieldEntity.class); digester.addSetProperties("datasource/tables/table/fields/field"); digester.addSetNext("datasource/tables/table/fields/field", "add"); digester.addObjectCreate("datasource/tables/table/records", ArrayList.class); digester.addSetNext("datasource/tables/table/records", "setRecords"); digester.addObjectCreate("datasource/tables/table/records/record", XmlRecordEntity.class); digester.addSetNext("datasource/tables/table/records/record", "add"); digester.addObjectCreate("datasource/tables/table/records/record/data", XmlRecordDataEntity.class); digester.addSetProperties("datasource/tables/table/records/record/data"); digester.addSetNext("datasource/tables/table/records/record/data", "add"); tableList = digester.parse(stream); for (XmlTableEntity t : tableList) { XmlTable table = new XmlTable(); table.label = t.label; table.name = t.name; // Read Field List<XmlField> fields = new ArrayList<XmlField>(); for (int col = 0; col < t.fields.size(); col++) { XmlFieldEntity f = t.fields.get(col); XmlField field = readField(col, f); fields.add(field); } // Read Data List<XmlRecord> records = new ArrayList<XmlRecord>(); for (int row = 0; row < t.records.size(); row++) { XmlRecordEntity r = t.records.get(row); if (r.data.size() == fields.size()) { XmlRecord record = readData(row, r, fields); records.add(record); } else { System.out.println("Skip row(unmatch field count).[table: " + table.getName() + "; row: " + r + ";]"); } } table.fields = (List) fields; table.records = (List) records; tables.add(table); } } datasource.tables = (List) tables; } catch (SAXException ex) { throw new ParseException(ex.getMessage(), -1); } catch (IOException ex) { throw ex; } finally { if (null != stream) { try { stream.close(); } catch (Exception ex) { ex.printStackTrace(); } } } return datasource; }
From source file:org.kuali.rice.core.impl.datetime.DateTimeServiceImpl.java
protected Date parse(String dateString, String pattern) throws ParseException { if (!StringUtils.isBlank(dateString)) { DateFormat dateFormat = new SimpleDateFormat(pattern); dateFormat.setLenient(false);//from w ww. jav a 2 s .co m ParsePosition parsePosition = new ParsePosition(0); Date testDate = dateFormat.parse(dateString, parsePosition); // Ensure that the entire date String can be parsed by the current format. if (testDate == null) { throw new ParseException("The date that you provided is invalid.", parsePosition.getErrorIndex()); } else if (parsePosition.getIndex() != dateString.length()) { throw new ParseException("The date that you provided is invalid.", parsePosition.getIndex()); } // Ensure that the date's year lies between 1000 and 9999, to help prevent database-related date errors. Calendar testCalendar = Calendar.getInstance(); testCalendar.setLenient(false); testCalendar.setTime(testDate); if (testCalendar.get(Calendar.YEAR) < 1000 || testCalendar.get(Calendar.YEAR) > 9999) { throw new ParseException("The date that you provided is not between the years 1000 and 9999.", -1); } if (testCalendar.get(Calendar.YEAR) == 1970 && !pattern.contains("y".toLowerCase())) { Calendar curCalendar = Calendar.getInstance(); curCalendar.setTime(new java.util.Date()); testCalendar.set(Calendar.YEAR, curCalendar.get(Calendar.YEAR)); testDate = testCalendar.getTime(); } return testDate; } return null; }
From source file:org.pepstock.jem.ant.tasks.utilities.sort.DefaultComparator.java
/** * Creates a SingleComparator using the data extracted by message format * /*from w w w.j av a 2 s. c o m*/ * @param result result of message format * @return a single comparator to use in cascade * @throws ParseException occurs if there is any prase excption */ private SingleComparator createSingleComparator(Object[] result) throws ParseException { SingleComparator c = new SingleComparator(); // the first element of command MUST be a number // it is the FIRST char to use to compare if (result[0] instanceof Number) { Number n = (Number) result[0]; c.setStart(Math.max(n.intValue(), SingleComparator.ZERO)); } else { throw new ParseException("First parameter is not a Number", 0); } // if result has 2 elements // means could have a second element both a number or a label. if (result.length == 2) { // if Number, is the length of string to compare if (result[1] instanceof Number) { Number n = (Number) result[1]; c.setLength(Math.max(n.intValue(), SingleComparator.ZERO)); } else { // if is a string, checks if is ASC or DESC // otherwise exception String value = result[1].toString(); if (!value.equalsIgnoreCase(SingleComparator.ASC) && !value.equalsIgnoreCase(SingleComparator.DESC)) { throw new ParseException("Invalid format for sorting mode definition: must be ASC or DESC", 1); } c.setMode(value); } } else if (result.length == 3) { // if result has 3 elements // it has element 2 as number (length) if (result[1] instanceof Number) { Number n = (Number) result[1]; c.setLength(Math.max(n.intValue(), SingleComparator.ZERO)); } else { throw new ParseException("First parameter is not a Number", 1); } // and element 3 a string (mode) checks if is ASC or DESC // otherwise exception String value = result[2].toString(); if (!value.equalsIgnoreCase(SingleComparator.ASC) && !value.equalsIgnoreCase(SingleComparator.DESC)) { throw new ParseException("Invalid format for sorting mode definition: must be ASC or DESC", 2); } c.setMode(value); } else { throw new ParseException( "Invalid format for sorting definition: max length is 3 but is " + result.length, 0); } return c; }
From source file:org.opensextant.util.GeodeticUtility.java
/** * Parse coordinate from object/*from w w w . j a v a 2 s . c o m*/ * @param lat latitude * @param lon longitude * @return LatLon object * @throws ParseException if objects are not valid numbers */ public static LatLon parseLatLon(Object lat, Object lon) throws ParseException { if (lat == null || lon == null) { // incomplete data. // Caller should test throw new ParseException("Incomplete data, null lat or lon", 0); } LatLon yx = new GeoBase(); yx.setLatitude(Double.parseDouble(lat.toString())); yx.setLongitude(Double.parseDouble(lon.toString())); return yx; }
From source file:org.opentides.util.StringUtil.java
@Deprecated public static Date stringToDate(String strDate, String format) throws ParseException { SimpleDateFormat dtFormatter = new SimpleDateFormat(format); if (StringUtil.isEmpty(strDate)) throw new ParseException("Cannot convert empty string to Date.", 0); return dtFormatter.parse(strDate.trim()); }
From source file:org.azkfw.datasource.xml.XmlDatasourceBuilder.java
private XmlField readField(final int aCol, final XmlFieldEntity aField) throws ParseException { if (StringUtility.isEmpty(aField.name)) { throw new ParseException("Field name is empty.[row: 2; col: " + aCol + ";]", 2); }// ww w. j a v a 2s .c o m if (StringUtility.isEmpty(aField.type)) { throw new ParseException("Field type is empty.[row: 2; col: " + aCol + ";]", 2); } FieldType fieldType = FieldType.valueOfName(aField.type.trim()); if (FieldType.Unknown == fieldType) { throw new ParseException("Undefined type.[type: " + aField.type + "; col: " + aCol + ";]", 2); } XmlField field = new XmlField(); field.label = aField.label; field.name = aField.name; field.type = fieldType; return field; }
From source file:org.ut.biolab.medsavant.client.query.QueryViewController.java
private SearchConditionItem getItemFromXML(Element element, SearchConditionGroupItem parentGroup) throws ParseException { String name = StringEscapeUtils.unescapeXml(element.getAttribute("name")); QueryRelation qr;//w w w. ja v a2 s. com if (element.getAttribute("queryRelation").equalsIgnoreCase("OR")) { qr = QueryRelation.OR; } else if (element.getAttribute("queryRelation").equalsIgnoreCase("AND")) { qr = QueryRelation.AND; } else { throw new ParseException("Malformed input file contains invalid query relation", 0); } SearchConditionItem sci = new SearchConditionItem(name, qr, parentGroup); String encodedConditions = StringEscapeUtils.unescapeXml(element.getAttribute("encodedConditions")); if (encodedConditions != null && encodedConditions.length() > 0) { sci.setSearchConditionEncoding(encodedConditions); } //The description does not need to be unescaped. String desc = element.getAttribute("description"); if (desc != null && desc.length() > 0) { sci.setDescription(desc); } generateItemViewAndAddToGroup(sci, parentGroup); return sci; }
From source file:com.microsoft.windowsazure.messaging.Registration.java
/** * Parses an UTC date string into a Date object * @param dateString The date string to parse * @return The Date object/* w w w . jav a2 s . c om*/ * @throws java.text.ParseException */ private static Date UTCDateStringToDate(String dateString) throws ParseException { // Change Z to +00:00 to adapt the string to a format // that can be parsed in Java String s = dateString.replace("Z", "+00:00"); try { // Remove the ":" character to adapt the string to a // format that can be parsed in Java s = s.substring(0, 26) + s.substring(27); } catch (IndexOutOfBoundsException e) { throw new ParseException("The 'updated' value has an invalid format", 26); } // Parse the well-formatted date string SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ", Locale.getDefault()); dateFormat.setTimeZone(TimeZone.getDefault()); Date date = dateFormat.parse(s); return date; }
From source file:HexFormat.java
/** * Parse a hex number into a Number object. Hexadecimal numbers may be * indicated with a leading character designation of '0x'. If up to 1 byte * is parsed, returns a Byte. If more than 1 and up to 2 bytes are parsed, * return a Short. If more than 2 and up to 4 bytes are parsed, return an * Integer. If more than 4 and up to 8 bytes are parsed, return a Long. * //from ww w .j a v a 2s. c o m * @param source * a binary number * @return return an integer form of Number object if parse is successful * @exception ParseException * thrown if source is cannot be converted to a Byte, Short, * Int, or Long. * * @since 1.0 */ public Number parse(String source) throws ParseException { int startIndex = 0; Number result; ParsePosition parsePosition = new ParsePosition(startIndex); result = parse(source, parsePosition); if (result == null) { throw new ParseException("Unable to parse " + source + " using HexFormat", parsePosition.getIndex()); } return (result); }