List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java
public static DateTime getUpperDateTimeBound(String dateRange) throws ParseException { Range range = SearchExpressionUtils.parseRange(dateRange); if (range == null) { throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange); }//from w w w .ja va2 s . c om if (range.getUpperBoundValue() != null) { java.util.Date upperRangeDate = null; try { upperRangeDate = CoreApiServiceLocator.getDateTimeService() .convertToDate(range.getUpperBoundValue()); } catch (ParseException pe) { GlobalVariables.getMessageMap().putError("dateCreated", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage()); } MutableDateTime dateTime = new MutableDateTime(upperRangeDate); // set it to the last millisecond of the day dateTime.setMillisOfDay((24 * 60 * 60 * 1000) - 1); return dateTime.toDateTime(); } return null; }
From source file:Main.java
/** * convert value to given type.//from w ww . j a v a2 s .c o m * null safe. * * @param value value for convert * @param type will converted type * @return value while converted */ public static Object convertCompatibleType(Object value, Class<?> type) { if (value == null || type == null || type.isAssignableFrom(value.getClass())) { return value; } if (value instanceof String) { String string = (String) value; if (char.class.equals(type) || Character.class.equals(type)) { if (string.length() != 1) { throw new IllegalArgumentException(String.format("CAN NOT convert String(%s) to char!" + " when convert String to char, the String MUST only 1 char.", string)); } return string.charAt(0); } else if (type.isEnum()) { return Enum.valueOf((Class<Enum>) type, string); } else if (type == BigInteger.class) { return new BigInteger(string); } else if (type == BigDecimal.class) { return new BigDecimal(string); } else if (type == Short.class || type == short.class) { return Short.valueOf(string); } else if (type == Integer.class || type == int.class) { return Integer.valueOf(string); } else if (type == Long.class || type == long.class) { return Long.valueOf(string); } else if (type == Double.class || type == double.class) { return Double.valueOf(string); } else if (type == Float.class || type == float.class) { return Float.valueOf(string); } else if (type == Byte.class || type == byte.class) { return Byte.valueOf(string); } else if (type == Boolean.class || type == boolean.class) { return Boolean.valueOf(string); } else if (type == Date.class) { try { return new SimpleDateFormat(DATE_FORMAT).parse((String) value); } catch (ParseException e) { throw new IllegalStateException("Failed to parse date " + value + " by format " + DATE_FORMAT + ", cause: " + e.getMessage(), e); } } else if (type == Class.class) { return forName((String) value); } } else if (value instanceof Number) { Number number = (Number) value; if (type == byte.class || type == Byte.class) { return number.byteValue(); } else if (type == short.class || type == Short.class) { return number.shortValue(); } else if (type == int.class || type == Integer.class) { return number.intValue(); } else if (type == long.class || type == Long.class) { return number.longValue(); } else if (type == float.class || type == Float.class) { return number.floatValue(); } else if (type == double.class || type == Double.class) { return number.doubleValue(); } else if (type == BigInteger.class) { return BigInteger.valueOf(number.longValue()); } else if (type == BigDecimal.class) { return BigDecimal.valueOf(number.doubleValue()); } else if (type == Date.class) { return new Date(number.longValue()); } } else if (value instanceof Collection) { Collection collection = (Collection) value; if (type.isArray()) { int length = collection.size(); Object array = Array.newInstance(type.getComponentType(), length); int i = 0; for (Object item : collection) { Array.set(array, i++, item); } return array; } else if (!type.isInterface()) { try { Collection result = (Collection) type.newInstance(); result.addAll(collection); return result; } catch (Throwable e) { e.printStackTrace(); } } else if (type == List.class) { return new ArrayList<>(collection); } else if (type == Set.class) { return new HashSet<>(collection); } } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) { Collection collection; if (!type.isInterface()) { try { collection = (Collection) type.newInstance(); } catch (Throwable e) { collection = new ArrayList<>(); } } else if (type == Set.class) { collection = new HashSet<>(); } else { collection = new ArrayList<>(); } int length = Array.getLength(value); for (int i = 0; i < length; i++) { collection.add(Array.get(value, i)); } return collection; } return value; }
From source file:it.geosolutions.mariss.wps.gs.DownloadProcess.java
public static String buildCQLFilterMinMaxIntervalAndGranulesBBox(/*List<String> timeList, */String minTime, String maxTime, File mosaicDir, List<String> granulesFileNames) { /*/*w w w. java2 s. c o m*/ * EXAMPLE: * time DURING 2010-01-24T09:52:32Z/2012-02-24T22:11:33Z AND (BBOX(wkb_geometry,9.887190592840616,37.981477602075785,10.310190592840616,38.38117760207579) OR BBOX(wkb_geometry,18.716863606878906,39.50822439921374,19.130563606878905,39.899624399213735)) */ GranulesManager gm = new GranulesManager(mosaicDir); Map<String, BoundingBox> bboxMap = gm.searchBoundingBoxes(granulesFileNames); // TimeParser p = new TimeParser(); // Date min = null; // Date max = null; // boolean firstIter = true; // for(String el : timeList){ // try { // Date tmpDate = p.parse(el).get(0); // if(firstIter){ // min = tmpDate; // max = tmpDate; // firstIter=false; // } // else{ // min = (tmpDate.before(min))?tmpDate:min; // max = (tmpDate.after(max))?tmpDate:max; // } // } catch (ParseException e) { // LOGGER.severe(e.getMessage()); // } // } // if(min.equals(max)){ // Calendar cla = new GregorianCalendar(); // cla.setTime(min); // cla.add(Calendar.DAY_OF_MONTH, -1); // min = cla.getTime(); // } TimeParser p = new TimeParser(); StringBuilder sb = new StringBuilder(); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date min = null; Date max = null; try { min = p.parse(minTime).get(0); max = p.parse(maxTime).get(0); } catch (ParseException e) { // TODO Auto-generated catch block LOGGER.severe(e.getMessage()); } sb.append("&CQL_FILTER="); if (min != null && max != null) { sb.append("time%20DURING%20"); sb.append(formatter.format(min)); sb.append("/"); sb.append(formatter.format(max)); LOGGER.info("Time Interval added to CQL filter"); if (!bboxMap.isEmpty()) { sb.append("%20AND%20("); sb.append(concatCqlBBOXFilters(bboxMap)); sb.append(")"); } } else { sb.append(""); LOGGER.info("The CQL filter is empty..."); } String cqlFilter = sb.toString(); LOGGER.fine("The full CQL filter is " + cqlFilter); return cqlFilter; }
From source file:org.geowebcache.util.ServletUtils.java
/** * Returns the expiration time in milliseconds from now * /* ww w .j a v a 2s . c o m*/ * @param expiresHeader * @return */ public static long parseExpiresHeader(String expiresHeader) { if (expiresHeader == null) { return -1; } long ret; synchronized (calendar) { if (ServletUtils.format == null) { ServletUtils.format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); ServletUtils.format.setTimeZone(ServletUtils.timeZone); } try { format.parse(expiresHeader); } catch (ParseException pe) { log.debug("Cannot parse " + expiresHeader + ", " + pe.getMessage()); return -1; } ret = calendar.getTimeInMillis() - System.currentTimeMillis() - localOffset; } return ret; }
From source file:org.apache.carbondata.core.util.DataTypeUtil.java
/** * Below method will be used to convert the data passed to its actual data * type// ww w . java 2 s .com * * @param data data * @param actualDataType actual data type * @return actual data after conversion */ public static Object getDataBasedOnDataType(String data, DataType actualDataType) { if (null == data || CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(data)) { return null; } try { switch (actualDataType) { case INT: if (data.isEmpty()) { return null; } return Integer.parseInt(data); case SHORT: if (data.isEmpty()) { return null; } return Short.parseShort(data); case DOUBLE: if (data.isEmpty()) { return null; } return Double.parseDouble(data); case LONG: if (data.isEmpty()) { return null; } return Long.parseLong(data); case TIMESTAMP: if (data.isEmpty()) { return null; } SimpleDateFormat parser = new SimpleDateFormat( CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT)); Date dateToStr = null; try { dateToStr = parser.parse(data); return dateToStr.getTime() * 1000; } catch (ParseException e) { LOGGER.error("Cannot convert" + data + " to Time/Long type value" + e.getMessage()); return null; } case DECIMAL: if (data.isEmpty()) { return null; } java.math.BigDecimal javaDecVal = new java.math.BigDecimal(data); scala.math.BigDecimal scalaDecVal = new scala.math.BigDecimal(javaDecVal); org.apache.spark.sql.types.Decimal decConverter = new org.apache.spark.sql.types.Decimal(); return decConverter.set(scalaDecVal); default: return UTF8String.fromString(data); } } catch (NumberFormatException ex) { LOGGER.error("Problem while converting data type" + data); return null; } }
From source file:nl.paston.bonita.importfile.Main.java
protected static CommandLine parseArguments(String[] args) { Options options = new Options(); Option serverUrl = new Option("s", Cmd.SERVER_URL.getName(), true, "URL of the Bonita BPM Server."); options.addOption(serverUrl);//w w w . jav a 2s.c o m Option applicationName = new Option("a", Cmd.APPLICATION_NAME.getName(), true, "Name of the Bonita BPM application."); options.addOption(applicationName); Option username = new Option("u", Cmd.USERNAME.getName(), true, "Username of the Bonita BPM user."); options.addOption(username); Option password = new Option("p", Cmd.PASSWORD.getName(), true, "Password of the Bonita BPM user."); options.addOption(password); Option processName = new Option("n", Cmd.PROCESS_NAME.getName(), true, "Name of the Bonita BPM Process"); options.addOption(processName); Option procesVersion = new Option("v", Cmd.PROCESS_VERSION.getName(), true, "Version of the Bonita BPM Process"); options.addOption(procesVersion); Option csvFilename = new Option("c", Cmd.CSV_FILE.getName(), true, "Filename of the CSV file."); options.addOption(csvFilename); Option help = new Option("h", Cmd.HELP.getName(), false, "Display help information."); options.addOption(help); Option talkative = new Option("t", Cmd.TALKATIVE.getName(), false, "Show talkative logging."); options.addOption(talkative); Option quiet = new Option("q", Cmd.QUIET.getName(), false, "No logging infomation in shown."); options.addOption(quiet); CommandLineParser parser = new DefaultParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException ex) { log.error(ex.getMessage()); } if (commandLine != null && !commandLine.hasOption(Cmd.HELP.getName())) { if (commandLine.hasOption(Cmd.TALKATIVE.getName())) { System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE"); } if (commandLine.hasOption(Cmd.QUIET.getName())) { System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "ERROR"); } log = LoggerFactory.getLogger(Main.class); return commandLine; } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("bonita-importfile", options); System.exit(1); } return null; }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
/** * This method converts a date in string format to java.sql.Date Format. * /*from w w w.j a v a 2 s . c o m*/ * @param sDate * @param format * @return * @throws Exception */ public static Date convertStringToDate(String sDate, String format) throws Exception { java.util.Date dateUtil = null; SimpleDateFormat dateformat = new SimpleDateFormat(format); try { dateUtil = dateformat.parse(sDate); } catch (ParseException e) { throw new Exception("Exception while parsing the date: " + e.getMessage()); } return new Date(dateUtil.getTime()); }
From source file:org.apache.lens.cube.metadata.MetastoreUtil.java
static ASTNode parseExpr(String expr) throws LensException { ParseDriver driver = new ParseDriver(); ASTNode tree;//from ww w . j ava 2 s .co m try { tree = driver.parseExpression(expr); } catch (org.apache.hadoop.hive.ql.parse.ParseException e) { throw new LensException(EXPRESSION_NOT_PARSABLE.getLensErrorInfo(), e, e.getMessage(), expr); } return ParseUtils.findRootNonNullToken(tree); }
From source file:nu.mine.kino.projects.utils.ProjectUtils.java
public static Date createDateData(File target) throws IOException { Date parseDate = null;/*from ww w. j ava 2 s .c o m*/ String string = ReadUtils.readFile(target); String FORMAT = "yyyyMMdd"; try { parseDate = DateUtils.parseDate(string, new String[] { FORMAT }); } catch (ParseException e) { System.out.println(e.getMessage()); String tmp = string.replaceAll("\n", ""); String dateStr = tmp.replaceAll("\r", ""); try { parseDate = DateUtils.parseDate(dateStr, new String[] { FORMAT }); } catch (ParseException e1) { e1.printStackTrace(); } } return parseDate; }
From source file:com.daskiworks.ghwatch.backend.NotificationStreamParser.java
public static NotificationStream parseNotificationStream(JSONArray json) throws InvalidObjectException { NotificationStream ret = new NotificationStream(); try {/* w w w . j a v a 2 s .c o m*/ for (int i = 0; i < json.length(); i++) { JSONObject notification = json.getJSONObject(i); JSONObject subject = notification.getJSONObject("subject"); JSONObject repository = notification.getJSONObject("repository"); String updatedAtStr = Utils.trimToNull(notification.getString("updated_at")); Date updatedAt = null; try { if (updatedAtStr != null) { if (updatedAtStr.endsWith("Z")) updatedAtStr = updatedAtStr.replace("Z", "GMT"); updatedAt = df.parse(updatedAtStr); } } catch (ParseException e) { Log.w(TAG, "Invalid date format for value: " + updatedAtStr); } ret.addNotification(new Notification(notification.getLong("id"), notification.getString("url"), subject.getString("title"), subject.getString("type"), subject.getString("url"), subject.getString("latest_comment_url"), repository.getString("full_name"), repository.getJSONObject("owner").getString("avatar_url"), updatedAt, notification.getString("reason"))); } } catch (Exception e) { throw new InvalidObjectException("JSON message is invalid: " + e.getMessage()); } return ret; }