List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:com.couchbase.client.protocol.views.ViewsFetcherOperationImpl.java
private List<View> parseDesignDocumentForViews(String dn, String ddn, String json) throws ParseException { List<View> viewList = new LinkedList<View>(); try {/* w w w .j a v a 2 s . c om*/ JSONObject base = new JSONObject(json); if (base.has("error")) { return null; } if (base.has("views")) { JSONObject views = base.getJSONObject("views"); Iterator<?> itr = views.keys(); while (itr.hasNext()) { String viewname = (String) itr.next(); boolean map = views.getJSONObject(viewname).has("map"); boolean reduce = views.getJSONObject(viewname).has("reduce"); viewList.add(new View(dn, ddn, viewname, map, reduce)); } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } return viewList; }
From source file:com.couchbase.client.protocol.views.SpatialViewFetcherOperationImpl.java
private SpatialView parseDesignDocumentForView(String dn, String ddn, String viewname, String json) throws ParseException { SpatialView view = null;/*from w w w . ja v a 2s. c om*/ if (json != null) { try { JSONObject base = new JSONObject(json); if (base.has("error")) { return null; } if (base.has("spatial")) { JSONObject views = base.getJSONObject("spatial"); Iterator<?> itr = views.keys(); while (itr.hasNext()) { String curView = (String) itr.next(); if (curView.equals(viewname)) { view = new SpatialView(dn, ddn, viewname); break; } } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } } return view; }
From source file:org.mongeez.reader.FormattedJavascriptChangeSetReader.java
private List<ChangeSet> parse(Resource file) throws IOException, ParseException { List<ChangeSet> changeSets = new ArrayList<ChangeSet>(); BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream(), cs)); try {//from www. j av a 2s . com String line = reader.readLine(); parseFileHeader(file, line); ChangeSet changeSet = null; StringBuilder scriptBody = null; line = reader.readLine(); while (line != null) { ChangeSet newChangeSet = parseChangeSetStart(line); if (newChangeSet != null) { addScriptToChangeSet(changeSet, scriptBody); changeSet = newChangeSet; scriptBody = new StringBuilder(); ChangeSetReaderUtil.populateChangeSetResourceInfo(changeSet, file); changeSets.add(changeSet); } else if (scriptBody != null) { scriptBody.append(line); scriptBody.append('\n'); } else if (!line.trim().isEmpty() && !line.startsWith(LINE_COMMENT)) { throw new ParseException(file + " has content outside of a changeset. " + "To start a changeset, add a comment in the format:\n" + LINE_COMMENT + "changeset author:id", 0); } // Silently ignore whitespace-only and comment-only lines line = reader.readLine(); } addScriptToChangeSet(changeSet, scriptBody); } finally { try { reader.close(); } catch (IOException ignore) { } } return changeSets; }
From source file:org.eredlab.g4.ccl.net.ftp.parser.FTPTimestampParserImpl.java
/** * Implements the one {@link FTPTimestampParser#parseTimestamp(String) method} * in the {@link FTPTimestampParser FTPTimestampParser} interface * according to this algorithm://from www . ja va2 s.c o m * * If the recentDateFormat member has been defined, try to parse the * supplied string with that. If that parse fails, or if the recentDateFormat * member has not been defined, attempt to parse with the defaultDateFormat * member. If that fails, throw a ParseException. * * @see org.apache.commons.net.ftp.parser.FTPTimestampParser#parseTimestamp(java.lang.String) */ /* (non-Javadoc) * */ public Calendar parseTimestamp(String timestampStr) throws ParseException { Calendar now = Calendar.getInstance(); now.setTimeZone(this.getServerTimeZone()); Calendar working = Calendar.getInstance(); working.setTimeZone(this.getServerTimeZone()); ParsePosition pp = new ParsePosition(0); Date parsed = null; if (this.recentDateFormat != null) { parsed = recentDateFormat.parse(timestampStr, pp); } if (parsed != null && pp.getIndex() == timestampStr.length()) { working.setTime(parsed); working.set(Calendar.YEAR, now.get(Calendar.YEAR)); if (working.after(now)) { working.add(Calendar.YEAR, -1); } } else { pp = new ParsePosition(0); parsed = defaultDateFormat.parse(timestampStr, pp); // note, length checks are mandatory for us since // SimpleDateFormat methods will succeed if less than // full string is matched. They will also accept, // despite "leniency" setting, a two-digit number as // a valid year (e.g. 22:04 will parse as 22 A.D.) // so could mistakenly confuse an hour with a year, // if we don't insist on full length parsing. if (parsed != null && pp.getIndex() == timestampStr.length()) { working.setTime(parsed); } else { throw new ParseException("Timestamp could not be parsed with older or recent DateFormat", pp.getIndex()); } } return working; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityExcelSheetParser.java
/** * Gets field raw data value resolved by locator. * * @param locator//from w w w . j a v a 2 s . c om * activity field locator * @param cData * MS Excel document sheet representing activity object data fields * @param formattingNeeded * flag to set if value formatting is not needed * @return raw value resolved by locator, or {@code null} if value is not resolved * * @throws ParseException * if exception occurs while resolving raw data value */ @Override protected Object resolveLocatorValue(ActivityFieldLocator locator, ActivityContext cData, AtomicBoolean formattingNeeded) throws ParseException { Object val = null; String locStr = locator.getLocator(); Sheet sheet = cData.getData(); if (StringUtils.isNotEmpty(locStr)) { CellReference ref = new CellReference(locStr); boolean cellFound = false; if (ref.getRow() < 0 || ref.getCol() < 0) { throw new ParseException( StreamsResources.getStringFormatted(MsOfficeStreamConstants.RESOURCE_BUNDLE_NAME, "ActivityExcelRowParser.unresolved.cell.reference", locStr), sheet.getWorkbook().getSheetIndex(sheet)); } Row row = sheet.getRow(ref.getRow()); if (row != null) { Cell cell = row.getCell(ref.getCol()); if (cell != null) { val = getCellValue(cell); cellFound = true; } else { val = row; } } logger().log(OpLevel.TRACE, StreamsResources.getString(MsOfficeStreamConstants.RESOURCE_BUNDLE_NAME, "ActivityExcelRowParser.resolved.cell.value"), locStr, sheet.getWorkbook().getMissingCellPolicy(), toString(val)); } return val; }
From source file:org.polymap.kaps.ui.MyNumberValidator.java
public Object transform2Model(Object fieldValue) throws Exception { if (fieldValue == null) { return null; } else if (fieldValue instanceof String) { if (((String) fieldValue).isEmpty()) { return null; }//from w ww .ja v a 2 s.co m ParsePosition pp = new ParsePosition(0); Number result = nf.parse((String) fieldValue, pp); if (pp.getErrorIndex() > -1 || pp.getIndex() < ((String) fieldValue).length()) { throw new ParseException("field value: " + fieldValue + " for targetClass " + targetClass.getName(), pp.getErrorIndex()); } log.debug("value: " + fieldValue + " -> " + result.doubleValue()); // XXX check max digits if (Float.class.isAssignableFrom(targetClass)) { return Float.valueOf(result.floatValue()); } else if (Double.class.isAssignableFrom(targetClass)) { return Double.valueOf(result.doubleValue()); } else if (Integer.class.isAssignableFrom(targetClass)) { return Integer.valueOf(result.intValue()); } else if (Long.class.isAssignableFrom(targetClass)) { return Long.valueOf(result.longValue()); } else { throw new RuntimeException("Unsupported target type: " + targetClass); } } else { throw new RuntimeException("Unhandled field value type: " + fieldValue); } }
From source file:com.indoqa.lang.util.DateRangeParser.java
private static int extractPartOffset(String relativeString, int pos, String part, String unit) throws ParseException { int partOffset; try {//from w w w .ja va2 s . c om String integerDeltaPart = part.substring(0, part.indexOf(unit)); partOffset = Integer.parseInt(integerDeltaPart); } catch (NumberFormatException e) { throw new ParseException(MessageFormat.format( "No numeric offset value in relative date part >{0}< of input >{1}< at pos {2}", part, relativeString, pos), pos); } if (partOffset < 0) { throw new ParseException(MessageFormat.format( "Numeric offset value needs to be positive at relative date part >{0}< of input >{1}< at pos {2}", part, relativeString, pos), pos); } return partOffset; }
From source file:de.codesourcery.eve.skills.market.impl.EveMarketLogParser.java
public MarketLogFile parseFile(File file) throws IOException, ParseException { InventoryType type = null;/* ww w. j a va2 s. co m*/ Region region = null; final BufferedReader reader = new BufferedReader(new FileReader(file)); final List<MarketLogEntry> result = new ArrayList<MarketLogEntry>(); try { /* price,volRemaining,typeID,range,orderID ,volEntered,minVolume , bid , issued ,duration ,stationID,regionID,solarSystemID,jumps, 40.0 ,1621.0 ,37 ,32767,1235636507, 1621 , 1 ,False , 2009-08-09 16:57:34.000, 90, 60007579,10000001,30000037,6, */ String[] cols = parseLine(reader); if (cols.length == 0 || !"price".equalsIgnoreCase(cols[0])) { throw new ParseException("No or unparseable header column in file " + file.getAbsolutePath(), 0); } final Map<String, Integer> columns = new HashMap<String, Integer>(); for (int i = 0; i < cols.length; i++) { columns.put(cols[i], i); } while ((cols = parseLine(reader)).length > 0) { final MarketLogEntry entry = new MarketLogEntry(); if (type == null) { final long typeId = parseLong(readColumn(cols, "typeID", columns)); type = dataModel.getInventoryType(typeId); } if (region == null) { final long regionId = parseLong(readColumn(cols, "regionID", columns)); region = dataModel.getRegion(regionId); } entry.setRemainingVolume(parseDouble(readColumn(cols, "volRemaining", columns))); entry.setOrderId(parseLong(readColumn(cols, "orderID", columns))); entry.setPrice(parseDouble(readColumn(cols, "price", columns))); entry.setBuyOrder(parseBoolean(readColumn(cols, "bid", columns))); entry.setVolume(parseDouble(readColumn(cols, "volEntered", columns))); final Date issueDate = parseDate(readColumn(cols, "issued", columns)); entry.setIssueDate(EveDate.fromServerTime(issueDate, clock)); entry.setMinVolume(parseInt(readColumn(cols, "minVolume", columns))); result.add(entry); } } finally { reader.close(); } return new MarketLogFile(result, type, region); }
From source file:com.couchbase.client.protocol.views.ViewFetcherOperationImpl.java
private View parseDesignDocumentForView(String dn, String ddn, String viewname, String json) throws ParseException { View view = null;/* ww w . j ava 2 s. co m*/ if (json != null) { try { JSONObject base = new JSONObject(json); if (base.has("error")) { return null; } if (base.has("views")) { JSONObject views = base.getJSONObject("views"); Iterator<?> itr = views.keys(); while (itr.hasNext()) { String curView = (String) itr.next(); if (curView.equals(viewname)) { boolean map = views.getJSONObject(curView).has("map"); boolean reduce = views.getJSONObject(curView).has("reduce"); view = new View(dn, ddn, viewname, map, reduce); break; } } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } } return view; }
From source file:no.met.jtimeseries.netcdf.NetcdfChartProvider.java
NumberPhenomenon getWantedPhenomenon(String variable) throws ParseException { NumberPhenomenon phenomenon = dataModel.getPhenomenen(variable, NumberPhenomenon.class); if (phenomenon == null) throw new ParseException(variable + ": No such parameter", 0); return phenomenon; }