List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:com.couchbase.client.protocol.views.DocsOperationImpl.java
protected ViewResponseWithDocs parseResult(String json) throws ParseException { final Collection<ViewRow> rows = new LinkedList<ViewRow>(); final Collection<RowError> errors = new LinkedList<RowError>(); if (json != null) { try {//from w ww .j a va2 s.c om JSONObject base = new JSONObject(json); if (base.has("rows")) { JSONArray ids = base.getJSONArray("rows"); for (int i = 0; i < ids.length(); i++) { JSONObject elem = ids.getJSONObject(i); String id = elem.getString("id"); String value = elem.getString("value"); if (elem.has("bbox")) { String bbox = elem.getString("bbox"); String geometry = elem.getString("geometry"); rows.add(new SpatialViewRowNoDocs(id, bbox, geometry, value)); } else { String key = elem.getString("key"); rows.add(new ViewRowNoDocs(id, key, value)); } } } if (base.has("debug_info")) { LOGGER.log(Level.INFO, "Debugging View {0}: {1}", new Object[] { getView().getURI(), json }); } if (base.has("errors")) { JSONArray ids = base.getJSONArray("errors"); for (int i = 0; i < ids.length(); i++) { JSONObject elem = ids.getJSONObject(i); String from = elem.getString("from"); String reason = elem.getString("reason"); errors.add(new RowError(from, reason)); } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } } return new ViewResponseWithDocs(rows, errors); }
From source file:com.couchbase.client.protocol.views.NoDocsOperationImpl.java
protected ViewResponseNoDocs parseResult(String json) throws ParseException { final Collection<ViewRow> rows = new LinkedList<ViewRow>(); final Collection<RowError> errors = new LinkedList<RowError>(); if (json != null) { try {//from ww w .j a v a 2s . c o m JSONObject base = new JSONObject(json); if (base.has("rows")) { JSONArray ids = base.getJSONArray("rows"); for (int i = 0; i < ids.length(); i++) { JSONObject elem = ids.getJSONObject(i); String id = elem.getString("id"); String value = elem.getString("value"); if (elem.has("bbox")) { String bbox = elem.getString("bbox"); String geometry = elem.getString("geometry"); rows.add(new SpatialViewRowNoDocs(id, bbox, geometry, value)); } else { String key = elem.getString("key"); rows.add(new ViewRowNoDocs(id, key, value)); } } } if (base.has("debug_info")) { LOGGER.log(Level.INFO, "Debugging View {0}: {1}", new Object[] { getView().getURI(), json }); } if (base.has("errors")) { JSONArray ids = base.getJSONArray("errors"); for (int i = 0; i < ids.length(); i++) { JSONObject elem = ids.getJSONObject(i); String from = elem.getString("from"); String reason = elem.getString("reason"); errors.add(new RowError(from, reason)); } } } catch (JSONException e) { throw new ParseException("Cannot read json: " + json, 0); } } return new ViewResponseNoDocs(rows, errors); }
From source file:org.unitedinternet.cosmo.calendar.query.PropertyFilter.java
/** * Construct a PropertyFilter object from a DOM Element * @param element The element.//from w w w.j a v a 2 s. c o m * @param timezone The timezone. * @throws ParseException - if something is wrong this exception is thrown. */ public PropertyFilter(Element element, VTimeZone timezone) throws ParseException { // Name must be present name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException("CALDAV:prop-filter a calendar property name (e.g., \"ATTENDEE\") is required", -1); } ElementIterator i = DomUtil.getChildren(element); int childCount = 0; while (i.hasNext()) { Element child = i.nextElement(); childCount++; // if is-not-defined is present, then nothing else can be present if (childCount > 1 && isNotDefinedFilter != null) { throw new ParseException("CALDAV:is-not-defined cannnot be present with other child" + " elements", -1); } if (ELEMENT_CALDAV_TIME_RANGE.equals(child.getLocalName())) { // Can only have one time-range or text-match if (timeRangeFilter != null) { throw new ParseException( "CALDAV:prop-filter only one time-range or text-match " + "element permitted", -1); } timeRangeFilter = new TimeRangeFilter(child, timezone); } else if (ELEMENT_CALDAV_TEXT_MATCH.equals(child.getLocalName())) { // Can only have one time-range or text-match if (textMatchFilter != null) { throw new ParseException( "CALDAV:prop-filter only one time-range or text-match element permitted", -1); } textMatchFilter = new TextMatchFilter(child); } else if (ELEMENT_CALDAV_PARAM_FILTER.equals(child.getLocalName())) { // Add to list paramFilters.add(new ParamFilter(child)); } else if (ELEMENT_CALDAV_IS_NOT_DEFINED.equals(child.getLocalName())) { if (childCount > 1) { throw new ParseException( "CALDAV:is-not-defined cannnot be present with other " + "child elements", -1); } isNotDefinedFilter = new IsNotDefinedFilter(); } else { throw new ParseException("CALDAV:prop-filter an invalid element name found", -1); } } }
From source file:edu.lternet.pasta.client.EmlUtility.java
private String emlReferenceExpander(String xslPath) throws ParseException { String xml = null;/* w w w . j a v a 2 s . c o m*/ File styleSheet = new File(xslPath); StringReader stringReader = new StringReader(this.eml); StringWriter stringWriter = new StringWriter(); StreamSource styleSource = new StreamSource(styleSheet); Result result = new StreamResult(stringWriter); Source source = new StreamSource(stringReader); try { Transformer t = TransformerFactory.newInstance().newTransformer(styleSource); t.transform(source, result); xml = stringWriter.toString(); } catch (TransformerConfigurationException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (TransformerException e) { logger.error(e.getMessage()); e.printStackTrace(); throw new ParseException("EML Parse Error: " + e.getMessage(), 0); } return xml; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityExcelRowParser.java
/** * Gets field raw data value resolved by locator. * * @param locator//from w w w. j a va 2 s. c o m * activity field locator * @param cData * MS Excel document row 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(); Row row = cData.getData(); if (StringUtils.isNotEmpty(locStr)) { int cellIndex = CellReference.convertColStringToIndex(locStr); if (cellIndex < 0) { throw new ParseException( StreamsResources.getStringFormatted(MsOfficeStreamConstants.RESOURCE_BUNDLE_NAME, "ActivityExcelRowParser.unresolved.cell.reference", locStr), row.getRowNum()); } Cell cell = row.getCell(cellIndex); boolean cellFound = false; if (cell != null) { val = getCellValue(cell); cellFound = true; } logger().log(OpLevel.TRACE, StreamsResources.getString(MsOfficeStreamConstants.RESOURCE_BUNDLE_NAME, "ActivityExcelRowParser.resolved.cell.value"), locStr, row.getSheet().getWorkbook().getMissingCellPolicy(), toString(val)); } return val; }
From source file:no.met.jtimeseries.netcdf.NetcdfChartProvider.java
Vector<NumberPhenomenon> getWantedPhenomena(Iterable<String> variables) throws ParseException { if (variables == null) variables = getVariables();//from w w w .j a v a2 s. com Vector<NumberPhenomenon> data = new Vector<NumberPhenomenon>(); for (String variable : variables) data.add(getWantedPhenomenon(variable)); if (data.isEmpty()) throw new ParseException("Unable to find requested parameters", 0); return data; }
From source file:org.unitedinternet.cosmo.calendar.ICalValueParser.java
/** * Parses the text value.//from w ww.j a va 2s . com * @throws ParseException - if something is wrong this exception is thrown. */ public void parse() throws ParseException { int nextToken = nextToken(); // log.debug("starting token: " + tokenizer); if (nextToken != ';') { return; } nextToken = nextToken(); while (nextToken != ':' && nextToken != StreamTokenizer.TT_EOF) { // log.debug("param name token: " + tokenizer); if (nextToken != StreamTokenizer.TT_WORD) { throw new ParseException("expected word, read " + tokenizer.ttype, 1); } String name = tokenizer.sval; nextToken = nextToken(); // log.debug("param = token: " + tokenizer); if (nextToken != '=') { throw new ParseException("expected =, read " + tokenizer.ttype, 1); } nextToken = nextToken(); // log.debug("param val token: " + tokenizer); if (!(nextToken == StreamTokenizer.TT_WORD || nextToken == '"')) { throw new ParseException("expected word, read " + tokenizer.ttype, 1); } String value = tokenizer.sval; // log.debug("parameter " + name + ": " + value); params.put(name, value); nextToken = nextToken(); // log.debug("post param token: " + tokenizer); if (nextToken == ':') { break; } else if (nextToken == ';') { nextToken = nextToken(); } else { throw new ParseException("expected either : or ;, read " + tokenizer.ttype, 1); } } nextToken = nextToken(); // log.debug("prop val token: " + tokenizer); if (nextToken != StreamTokenizer.TT_WORD) { throw new ParseException("expected " + StreamTokenizer.TT_WORD + ", read " + tokenizer.ttype, 1); } value = tokenizer.sval; // log.debug("property: " + value + ", params: " + params); }
From source file:com.autonomy.aci.client.util.DateTimeUtils.java
/** * Parses a string representing a date, using the supplied pattern and locale. * <p>/* w ww. jav a 2s .c o m*/ * A parse is only deemed successful if it parses the whole of the input string. If the parse pattern didn't match, a * ParseException is thrown. * @param string The date to parse, not null * @param format The date format pattern to use, see {@link java.text.SimpleDateFormat}, not null * @param locale The locale whose date format symbols should be used * @return The parsed date * @throws IllegalArgumentException If the date <tt>string</tt> or <tt>format</tt> are null * @throws ParseException If the date pattern was unsuitable */ public Date parseDate(final String string, final String format, final Locale locale) throws ParseException { LOGGER.trace("parseDate() called..."); Validate.notEmpty(string, "Date string must not be null"); Validate.notEmpty(format, "Date string format must not be null"); final SimpleDateFormat parser = new SimpleDateFormat(format, locale); final ParsePosition pos = new ParsePosition(0); final Date date = parser.parse(string, pos); if (date != null && pos.getIndex() == string.length()) { return date; } throw new ParseException("Unable to parse the date: " + string, -1); }
From source file:org.geotools.geometry.jts.spatialschema.geometry.GeometryTestParser.java
/** * Processes the root "run" node// w w w .j a v a 2s . co m * @param node * @return * @throws ParseException */ public GeometryTestContainer processRootNode(Node node) throws ParseException { if (!node.getNodeName().equalsIgnoreCase("run")) { throw new ParseException("Expected run tag, found " + node.getNodeName(), 0); } GeometryTestContainer test = new GeometryTestContainer(); Node child = node.getFirstChild(); String precisionModel = "FLOATING"; while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { String name = child.getNodeName(); if (name.equalsIgnoreCase("case")) { GeometryTestCase testCase = readTestCase(child); test.addTestCase(testCase); } else if (name.equalsIgnoreCase("precisionmodel")) { precisionModel = getPrecisionModel(child); } else { throw new ParseException("Unexpected: " + name, 0); } } child = child.getNextSibling(); } return test; }
From source file:libepg.epg.util.datetime.DateTimeFieldConverter.java
private static Map<HMS_KEY, Integer> BcdTimeToMap(byte[] hms) throws ParseException { Map<HMS_KEY, Integer> ret = new HashMap<>(); if (hms.length != 3) { throw new IndexOutOfBoundsException( "?????3????????" + " ?=" + Hex.encodeHexString(hms)); }/* w w w.j a v a 2 s .com*/ //ARIB???????????????? if (Arrays.equals(hms, UNDEFINED_BCD_TIME_BLOCK.getData())) { throw new ParseException("???????????" + " ?=" + Hex.encodeHexString(hms), 0); } Object[] parameters = null; final int hour = new BCD(hms[0]).getDecimal(); final int minute = new BCD(hms[1]).getDecimal(); final int second = new BCD(hms[2]).getDecimal(); CHECK: { final Range<Integer> HOUR_RANGE = Range.between(0, 23); if (!HOUR_RANGE.contains(hour)) { parameters = new Object[] { Hex.encodeHexString(hms), "", hour }; break CHECK; } final Range<Integer> MINUTE_AND_SECOND_RANGE = Range.between(0, 59); if (!MINUTE_AND_SECOND_RANGE.contains(minute)) { parameters = new Object[] { Hex.encodeHexString(hms), "", minute }; break CHECK; } if (!MINUTE_AND_SECOND_RANGE.contains(second)) { parameters = new Object[] { Hex.encodeHexString(hms), "", second }; break CHECK; } } if (parameters != null) { MessageFormat msg = new MessageFormat( "????????????={0} ={1} ={2}"); throw new ParseException(msg.format(parameters), 0); } if (LOG.isTraceEnabled()) { LOG.trace("hour=" + hour + " minute=" + minute + " second=" + second); } ret.put(HMS_KEY.HOUR, hour); ret.put(HMS_KEY.MINUTE, minute); ret.put(HMS_KEY.SECOND, second); return ret; }