List of usage examples for java.text ParseException toString
public String toString()
From source file:ru.apertum.qsystem.client.forms.FScheduleChangeDialod.java
private void saveSchedule() { schedule.setName(textFieldPlaneName.getText()); schedule.setType(radioButtonWeek.isSelected() ? 0 : 1); try {//from ww w .java 2 s .co m schedule.setTime_begin_1(c1.isSelected() ? Uses.format_HH_mm.parse(s1.getText()) : null); schedule.setTime_end_1(c1.isSelected() ? Uses.format_HH_mm.parse(e1.getText()) : null); schedule.setTime_begin_2(c2.isSelected() ? Uses.format_HH_mm.parse(s2.getText()) : null); schedule.setTime_end_2(c2.isSelected() ? Uses.format_HH_mm.parse(e2.getText()) : null); schedule.setTime_begin_3(c3.isSelected() ? Uses.format_HH_mm.parse(s3.getText()) : null); schedule.setTime_end_3(c3.isSelected() ? Uses.format_HH_mm.parse(e3.getText()) : null); schedule.setTime_begin_4(c4.isSelected() ? Uses.format_HH_mm.parse(s4.getText()) : null); schedule.setTime_end_4(c4.isSelected() ? Uses.format_HH_mm.parse(e4.getText()) : null); schedule.setTime_begin_5(c5.isSelected() ? Uses.format_HH_mm.parse(s5.getText()) : null); schedule.setTime_end_5(c5.isSelected() ? Uses.format_HH_mm.parse(e5.getText()) : null); schedule.setTime_begin_6(c6.isSelected() ? Uses.format_HH_mm.parse(s6.getText()) : null); schedule.setTime_end_6(c6.isSelected() ? Uses.format_HH_mm.parse(e6.getText()) : null); schedule.setTime_begin_7(c7.isSelected() ? Uses.format_HH_mm.parse(s7.getText()) : null); schedule.setTime_end_7(c7.isSelected() ? Uses.format_HH_mm.parse(e7.getText()) : null); schedule.setBreaks_1((QBreaks) cb1.getSelectedItem()); schedule.setBreaks_2((QBreaks) cb2.getSelectedItem()); schedule.setBreaks_3((QBreaks) cb3.getSelectedItem()); schedule.setBreaks_4((QBreaks) cb4.getSelectedItem()); schedule.setBreaks_5((QBreaks) cb5.getSelectedItem()); schedule.setBreaks_6((QBreaks) cb6.getSelectedItem()); schedule.setBreaks_7((QBreaks) cb7.getSelectedItem()); } catch (ParseException ex) { throw new ServerException(ex.toString()); } }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
private void testLocales(final String format, final boolean eraBC) throws Exception { final Calendar cal = Calendar.getInstance(GMT); cal.clear();/* w ww . ja v a2 s . c o m*/ cal.set(2003, Calendar.FEBRUARY, 10); if (eraBC) { cal.set(Calendar.ERA, GregorianCalendar.BC); } for (final Locale locale : Locale.getAvailableLocales()) { // ja_JP_JP cannot handle dates before 1868 properly if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) { continue; } final SimpleDateFormat sdf = new SimpleDateFormat(format, locale); final DateParser fdf = getInstance(format, locale); try { checkParse(locale, cal, sdf, fdf); } catch (final ParseException ex) { Assert.fail("Locale " + locale + " failed with " + format + " era " + (eraBC ? "BC" : "AD") + "\n" + trimMessage(ex.toString())); } } }
From source file:com.radicaldynamic.groupinform.services.DatabaseService.java
private void removePlaceholders(HashMap<String, JSONObject> placeholders) { final String tt = t + "removePlaceholders(): "; for (Map.Entry<String, JSONObject> entry : placeholders.entrySet()) { if (entry.getValue().optString("createdBy", null) == null || entry.getValue().optString("dateCreated", null) == null) { // Remove old style (unowned) placeholders immediately try { getDb().delete(entry.getKey(), entry.getValue().optString("_rev")); if (Collect.Log.VERBOSE) Log.v(Collect.LOGTAG, tt + "removed old-style placeholder " + entry.getKey()); } catch (Exception e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "unable to remove old-style placeholder"); e.printStackTrace();// w w w.j a v a 2 s . c om } } else if (entry.getValue().optString("createdBy") .equals(Collect.getInstance().getInformOnlineState().getDeviceId())) { // Remove placeholders owned by me immediately try { getDb().delete(entry.getKey(), entry.getValue().optString("_rev")); if (Collect.Log.VERBOSE) Log.v(Collect.LOGTAG, tt + "removed my placeholder " + entry.getKey()); } catch (Exception e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "unable to remove my placeholder"); e.printStackTrace(); } } else { // Remove placeholders owned by other people if they are stale (older than a day) SimpleDateFormat sdf = new SimpleDateFormat(Generic.DATETIME); Calendar calendar = Calendar.getInstance(); try { calendar.setTime(sdf.parse(entry.getValue().optString("dateCreated"))); if (calendar.getTimeInMillis() - Calendar.getInstance().getTimeInMillis() > TIME_24_HOURS) { try { getDb().delete(entry.getKey(), entry.getValue().optString("_rev")); if (Collect.Log.VERBOSE) Log.v(Collect.LOGTAG, tt + "removed stale placeholder " + entry.getKey()); } catch (Exception e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "unable to remove stale placeholder"); e.printStackTrace(); } } } catch (ParseException e1) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "unable to parse dateCreated: " + e1.toString()); e1.printStackTrace(); } } } }
From source file:net.ausgstecktis.DAL.OnlineProxy.java
/** * Get open times for a Heurigen.//from w w w. ja v a2s .co m * * @param heurigenId the heurigen id * @return the open dates by id * @see net.ausgstecktis.DAL.AbstractProxy#getOpenDatesById(java.lang.Integer) */ @Override public ArrayList<OpeningCalendar> getOpenDatesById(final Integer heurigenId) { final ArrayList<OpeningCalendar> calendarList = new ArrayList<OpeningCalendar>(); prepareRestClientAndCallWebServiceWithGET(RestClient.GET_CALENDAR + heurigenId.toString()); try { if (currentRestClient.getObjectJson() != null) { final JSONArray jArray = currentRestClient.getObjectJson(); for (int i = 0; i < jArray.length(); i++) { final JSONObject jsonData = jArray.getJSONObject(i); final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date start = null; Date end = null; try { end = formatter.parse(jsonData.getString(OpenTime.END_COLUMN)); start = formatter.parse(jsonData.getString(OpenTime.START_COLUMN)); } catch (final ParseException e) { e.printStackTrace(); } calendarList.add(new OpeningCalendar( NumberConverter.getIntegerValueOfString(jsonData.getString(OpeningCalendar.ID_COLUMN)), null, start, end)); } } } catch (final JSONException e) { Log.e(OnlineProxy.TAG, "Error parsing data " + e.toString()); } return calendarList; }
From source file:com.krawler.esp.servlets.importToDoTask.java
protected int storeInDB(Connection conn, JSONObject jobjT, String projectid, String appendchoice) throws ServiceException { int skipped = 0; int taskorder = 1; int skipRecord = 0; java.util.Date defaultdd = new Date(); try {//from w ww. j a va 2s . c o m if (appendchoice.equals("1")) { todolist.deleteAllToDoTask(conn, projectid); } else { taskorder = todolist.getLastTodoTaskIndex(conn, projectid); taskorder++; } com.krawler.utils.json.base.JSONArray taskArray = jobjT.getJSONArray("data"); for (int i = 0; i < taskArray.length(); i++) { try { com.krawler.utils.json.base.JSONObject temp = taskArray.getJSONObject(i); String tid = UUID.randomUUID().toString(); java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd"); String duedate = StringUtil.serverHTMLStripper(temp.getString("duedate")); if (!duedate.equals("")) { defaultdd = sdf1.parse(duedate); } else { defaultdd = sdf1.parse("1970-01-01"); } String pri = temp.getString("priority"); if (pri.equals("")) { pri = "Moderate"; } skipRecord = todolist.insertToDoTaskFromCSV(conn, temp.getString("taskname"), taskorder, temp.getInt("status"), "", tid, projectid, 2, defaultdd, true, tid, pri, temp.getString("description")); if (skipRecord == 1) { skipped += skipRecord; } else { taskorder++; } } catch (ParseException ex) { skipped++; } catch (ServiceException ex) { skipped++; } } } catch (com.krawler.utils.json.base.JSONException jE) { KrawlerLog.op.warn("Problem Storing Data In DB [importProjectPlanCSV.storeInDB()]:" + jE.toString()); throw ServiceException.FAILURE("importProjectPlanCSV.storeInDB error", jE); } catch (ServiceException ex) { KrawlerLog.op.warn("Problem Storing Data In DB [importProjectPlanCSV.storeInDB()]:" + ex.toString()); throw ServiceException.FAILURE("importProjectPlanCSV.storeInDB error", ex); } return skipped; }
From source file:org.apache.openjpa.jdbc.sql.PostgresDictionary.java
@Override public Date getDate(ResultSet rs, int column) throws SQLException { try {//w ww . j a va2 s . c o m return super.getDate(rs, column); } catch (StringIndexOutOfBoundsException sioobe) { // there is a bug in some versions of the postgres JDBC // driver such that a date with not enough numbers in it // will throw a parsing exception: this tries to work // around it. The bug only occurs when there is a trailing // millisecond missing from the end. E.g., when the date is // like: // 2066-10-19 22:08:32.83 // rather than what the driver expects: // 2066-10-19 22:08:32.830 String dateStr = rs.getString(column); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SS"); try { return fmt.parse(dateStr); } catch (ParseException pe) { throw new SQLException(pe.toString()); } } }
From source file:org.exoplatform.services.jcr.impl.core.query.sql.JCRSQLQueryBuilder.java
/** * Creates a new {@link org.apache.jackrabbit.spi.commons.query.RelationQueryNode}. * * @param parent the parent node for the created <code>RelationQueryNode</code>. * @param propertyName the property name for the relation. * @param operationType the operation type. * @param literal the literal value for the relation or * <code>null</code> if the relation does not have a * literal (e.g. IS NULL). * @return a <code>RelationQueryNode</code>. * @throws IllegalArgumentException if the literal value does not conform * to its type. E.g. a malformed String representation of a date. */// w w w . j a v a2 s . c o m private RelationQueryNode createRelationQueryNode(QueryNode parent, InternalQName propertyName, int operationType, ASTLiteral literal) throws IllegalArgumentException { RelationQueryNode node = null; try { QPath relPath = null; if (propertyName != null) { relPath = new QPath(new QPathEntry[] { new QPathEntry(propertyName, 0) }); } if (literal == null) { node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); } else if (literal.getType() == QueryConstants.TYPE_DATE) { SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN); Date date = format.parse(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setDateValue(date); } else if (literal.getType() == QueryConstants.TYPE_DOUBLE) { double d = Double.parseDouble(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setDoubleValue(d); } else if (literal.getType() == QueryConstants.TYPE_LONG) { long l = Long.parseLong(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setLongValue(l); } else if (literal.getType() == QueryConstants.TYPE_STRING) { node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setStringValue(literal.getValue()); } else if (literal.getType() == QueryConstants.TYPE_TIMESTAMP) { Calendar c = ISO8601.parse(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setDateValue(c.getTime()); } } catch (java.text.ParseException e) { throw new IllegalArgumentException(e.toString(), e); } catch (NumberFormatException e) { throw new IllegalArgumentException(e.toString(), e); } if (node == null) { throw new IllegalArgumentException("Unknown type for literal: " + literal.getType()); } return node; }
From source file:de.andreas_rueckert.trade.site.mtgox.client.MtGoxClient.java
/** * Get all the cancelled trades of the current user. * * @param currencyPair The currency pair to use. * @param userAccount The account of the user on the exchange. Null, if the default account should be used. * * @return The cancelled trades as an array of Trade objects or null if the request failed. *//*from w w w .ja v a 2 s . c o m*/ Trade[] getCancelledTrades(CurrencyPair currencyPair, TradeSiteUserAccount userAccount) { // Query the MtGox server and fetch the result as a json object. JSONObject jsonResult = authenticatedQuery( "https://" + DOMAIN + "/api/1/" + currencyPair.getCurrency().getName() + currencyPair.getPaymentCurrency().getName() + "/public/cancelledtrades", null, userAccount); if (jsonResult != null) { try { // Get the return value and convert it to a Trade array. JSONArray jsonTrades = jsonResult.getJSONArray("return"); CryptoCoinTrade[] trades = new CryptoCoinTrade[jsonTrades.size()]; try { for (int i = 0; i < jsonTrades.size(); i++) { trades[i] = new MtGoxTradeImpl(jsonTrades.getJSONObject(i), this, currencyPair); } } catch (ParseException pe) { // Cannot parse the JSON trade. System.err.println("Cannot parse JSON trade object: " + pe.toString()); return null; // Error => return null... } return trades; // Return the parsed trades. } catch (JSONException je) { System.err.println("Cannot parse trade objects: " + je.toString()); } } return null; // The query failed. }
From source file:org.apache.jackrabbit.spi.commons.query.sql.JCRSQLQueryBuilder.java
/** * Creates a new {@link org.apache.jackrabbit.spi.commons.query.RelationQueryNode}. * * @param parent the parent node for the created <code>RelationQueryNode</code>. * @param propertyName the property name for the relation. * @param operationType the operation type. * @param literal the literal value for the relation or * <code>null</code> if the relation does not have a * literal (e.g. IS NULL). * @return a <code>RelationQueryNode</code>. * @throws IllegalArgumentException if the literal value does not conform * to its type. E.g. a malformed String representation of a date. *///from w w w. j a va 2 s . com private RelationQueryNode createRelationQueryNode(QueryNode parent, Name propertyName, int operationType, ASTLiteral literal) throws IllegalArgumentException { RelationQueryNode node = null; try { Path relPath = null; if (propertyName != null) { PathBuilder builder = new PathBuilder(); builder.addLast(propertyName); relPath = builder.getPath(); } if (literal == null) { node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); } else if (literal.getType() == QueryConstants.TYPE_DATE) { SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN); Date date = format.parse(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setDateValue(date); } else if (literal.getType() == QueryConstants.TYPE_DOUBLE) { double d = Double.parseDouble(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setDoubleValue(d); } else if (literal.getType() == QueryConstants.TYPE_LONG) { long l = Long.parseLong(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setLongValue(l); } else if (literal.getType() == QueryConstants.TYPE_STRING) { node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setStringValue(literal.getValue()); } else if (literal.getType() == QueryConstants.TYPE_TIMESTAMP) { Calendar c = ISO8601.parse(literal.getValue()); node = factory.createRelationQueryNode(parent, operationType); node.setRelativePath(relPath); node.setDateValue(c.getTime()); } } catch (java.text.ParseException e) { throw new IllegalArgumentException(e.toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e.toString()); } catch (MalformedPathException e) { // path is always valid, but throw anyway throw new IllegalArgumentException(e.getMessage()); } if (node == null) { throw new IllegalArgumentException("Unknown type for literal: " + literal.getType()); } return node; }
From source file:de.andreas_rueckert.trade.site.mtgox.client.MtGoxClient.java
/** * Get a number of trades from a given URL. * * @param url The URL to fetch the trades from. * @param currencyPair The requested currency pair. * * @return The trades as an array of Trade objects or null if an error occured. *///ww w . ja va 2 s. co m private CryptoCoinTrade[] getTradesFromURL(String url, CurrencyPair currencyPair) { if (isRequestAllowed(TradeSiteRequestType.Trades)) { ArrayList<CryptoCoinTrade> trades = new ArrayList<CryptoCoinTrade>(); // System.out.println( "Fetching trades from url: " + url); String requestResult = HttpUtils.httpGet(url); if (requestResult != null) { // Request sucessful? try { // Convert the HTTP request return value to JSON to parse further. JSONObject jsonResult = JSONObject.fromObject(requestResult); // Get the result value to check for success if (!"success".equals(jsonResult.getString("result"))) { return null; // MtGox server did not return the ticker. } // Convert the result to a JSON array. JSONArray resultArray = jsonResult.getJSONArray("return"); // Iterate over the json array and convert each trade from json to a Trade object. for (int i = 0; i < resultArray.size(); i++) { JSONObject tradeObject = resultArray.getJSONObject(i); try { trades.add(new MtGoxTradeImpl(tradeObject, this, currencyPair)); // Add the new Trade object to the list. } catch (ParseException pe) { // Cannot parse the JSON trade. System.err.println("Cannot parse JSON trade object: " + pe.toString()); return null; } } CryptoCoinTrade[] tradeArray = trades.toArray(new CryptoCoinTrade[trades.size()]); // Convert the list to an array. updateLastRequest(TradeSiteRequestType.Trades); // Update the timestamp of the last request. return tradeArray; // And return the array. } catch (JSONException je) { System.err.println("Cannot parse trade object: " + je.toString()); } } return null; // An error occured. } // The request is not allowed at the moment, so throw an exception. throw new TradeDataRequestNotAllowedException("Request for trades not allowed at the moment at MtGox site"); }