Example usage for java.text ParseException getMessage

List of usage examples for java.text ParseException getMessage

Introduction

In this page you can find the example usage for java.text ParseException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.monash.merc.util.DMUtil.java

public static Date formatYMDDate(final String dateStr) {
    Date date = null;/*from w  w w  .j ava 2s  .  c o  m*/
    DateFormat df = new SimpleDateFormat(DATE_YYYYMMDD_FORMAT);
    try {
        date = df.parse(dateStr);
    } catch (ParseException e) {
        throw new DMException(e.getMessage());
    }
    return date;
}

From source file:org.eclipse.sw360.datahandler.common.SW360Utils.java

/**
 * Tries to parse a given date in format "yyyy-MM-dd HH:mm:ss" to a Date, returns null if it fails
 * @param date in format "yyyy-MM-dd HH:mm:ss"
 * @return Date/*from   ww  w.  j  av  a 2s .  co  m*/
 */
public static Date getDateFromTimeString(String date) {
    try {
        return new SimpleDateFormat(FORMAT_DATE_TIME).parse(date);
    } catch (ParseException e) {
        log.error(e.getMessage(), e);
        return null;
    }
}

From source file:net.sourcewalker.garanbot.api.Item.java

/**
 * Tries to create a Item object from the provided JSON string.
 * //from  w  ww . j a  va  2  s.  co m
 * @param content
 *            JSON content as String.
 * @param lastModified
 *            Value of last-modified-header if available or
 *            <code>null</code> if current device time should be used.
 * @return Item object
 * @throws ClientException
 *             If the provided JSON is not valid.
 */
public static Item fromJSON(String content, String lastModified) throws ClientException {
    try {
        JSONObject object = (JSONObject) new JSONTokener(content).nextValue();
        Item result = new Item(Item.UNKNOWN_ID);
        result.setName(object.getString("name"));
        result.setManufacturer(object.getString("manufacturer"));
        result.setItemType(object.getString("itemType"));
        result.setVendor(object.getString("vendor"));
        result.setLocation(object.getString("location"));
        result.setNotes(object.getString("notes"));
        result.setHasPicture(object.getBoolean("hasPicture"));
        result.setVisibility(ItemVisibility.parseInt(object.getInt("visibility")));
        result.setPurchaseDate(parseDate(object.getString("purchaseDate")));
        result.setEndOfWarranty(parseDate(object.getString("endOfWarranty")));
        if (lastModified == null) {
            result.setLastModified(new Date());
        } else {
            try {
                result.setLastModified(ApiConstants.HTTP_DATE_FORMAT.parse(lastModified));
            } catch (ParseException e) {
                throw new ClientException("Error parsing Last-Modified header: " + e.getMessage(), e);
            }
        }
        result.setServerId(object.getInt("id"));
        return result;
    } catch (JSONException e) {
        throw new ClientException("Error parsing Item: " + e.getMessage(), e);
    }
}

From source file:com.qmetry.qaf.automation.util.StringUtil.java

/**
 * Convert date string from one format to another format.
 * <p>//from  w  w w  .  j  av  a2  s . co m
 * <b>Example:</b>
 * <ul>
 * <li><code>
 * formatDate("2012-01-11",
    "yyy-MM-dd", "MMM d, yyyy"))
 * </code> will retrun "Jan 11, 2012"</li>
 * <li>formatDate("2012-01-11T05:38:00+0530", {@link #BPM_DATETIME_FORMAT},
 * {@link #GI_DATETIME_FORMAT})) will retrun "Jan 11, 2012 05:38 AM"</li>
 * </ul>
 * </p>
 * 
 * @param dateStr
 *            : date string to be formated
 * @param formatFrom
 *            : format of the given date string
 * @param formatTo
 *            : String expected format
 * @return date string in expected format
 */
public static String getFormatedDate(String dateString, String formatFrom, String formatTo) {
    SimpleDateFormat aformat = new SimpleDateFormat(formatFrom);
    SimpleDateFormat eformat = new SimpleDateFormat(formatTo);
    Date d;
    try {
        d = aformat.parse(dateString);
    } catch (ParseException e) {
        throw new RuntimeException(e.getMessage());
    }
    return eformat.format(d);
}

From source file:com.flexive.core.timer.FxQuartz.java

/**
 * Parses a Cron String and throws an exception
 * if it cannot be parsed/*from   w  w w . j a va 2 s.co  m*/
 *
 * @param cronString  Cron String
 * @since 3.1.2
 * @throws com.flexive.shared.exceptions.FxInvalidParameterException on errors
 */
public static void parseCronString(String cronString) throws FxInvalidParameterException {
    try {
        new CronExpression(cronString);
    } catch (ParseException e) {
        throw new FxInvalidParameterException("cronString", "ex.scripting.schedule.parameter.cronString",
                cronString, e.getMessage());
    }
}

From source file:com.basetechnology.s0.agentserver.AgentState.java

static public AgentState fromJson(JSONObject stateJson, SymbolManager symbolManager)
        throws AgentServerException, SymbolException, ParseException {
    // Parse the timestamp
    long time = 0;
    try {/*  www. j  a  v  a  2s .c om*/
        time = DateUtils.parseIsoString(stateJson.optString("time"));
    } catch (ParseException e) {
        throw new AgentServerException("Error parsing timestamp for agent state ('"
                + stateJson.optString("time") + "'): " + e.getMessage());
    }

    // Parse parameter values
    SymbolValues parameters = null;
    if (stateJson.has("parameters"))
        parameters = SymbolValues.fromJson(symbolManager.getSymbolTable("parameters"),
                stateJson.optJSONObject("parameters"));
    else
        parameters = new SymbolValues();

    // Parse input values
    SymbolValues inputs = null;
    if (stateJson.has("inputs"))
        inputs = SymbolValues.fromJson(symbolManager.getSymbolTable("inputs"),
                stateJson.optJSONObject("inputs"));
    else
        inputs = new SymbolValues();

    /*
        // Parse input values
        SymbolValues events = null;
        if (stateJson.has("events"))
          events = SymbolValues.fromJson(symbolManager.getSymbolTable("events"), stateJson.optJSONObject("events"));
        else
          events = new SymbolValues();
    */

    // Parse memory values
    SymbolValues memory = null;
    if (stateJson.has("memory"))
        memory = SymbolValues.fromJson(symbolManager.getSymbolTable("memory"),
                stateJson.optJSONObject("memory"));
    else
        memory = new SymbolValues();

    // Parse output values
    SymbolValues outputs = null;
    if (stateJson.has("outputs"))
        outputs = SymbolValues.fromJson(symbolManager.getSymbolTable("outputs"),
                stateJson.optJSONObject("outputs"));
    else
        outputs = new SymbolValues();

    // Parse exception history
    List<ExceptionInfo> exceptions = new ArrayList<ExceptionInfo>();
    if (stateJson.has("exceptions")) {
        JSONArray exceptionsJson = stateJson.optJSONArray("exceptions");
        int numExceptions = exceptionsJson.length();
        for (int i = 0; i < numExceptions; i++)
            exceptions.add(ExceptionInfo.fromJson(exceptionsJson.optJSONObject(i)));
    }

    String lde = stateJson.optString("last_dismissed_exception");
    long lastDismissedException = lde == null || lde.length() == 0 ? 0 : DateUtils.parseRfcString(lde);

    // Parse notifications
    ListMap<String, NotificationInstance> notifications = null;
    if (stateJson.has("notifications")) {
        notifications = new ListMap<String, NotificationInstance>();
        JSONArray notificationsJson = stateJson.optJSONArray("notifications");
        int numNotifications = notificationsJson.length();
        for (int i = 0; i < numNotifications; i++) {
            NotificationInstance notificationInstance = NotificationInstance.fromJson(null,
                    notificationsJson.optJSONObject(i));
            notifications.put(notificationInstance.definition.name, notificationInstance);
        }
    }

    // Parse notification history
    NotificationHistory notificationHistory = null;
    if (stateJson.has("notification_history")) {
        JSONArray notificationsJson = stateJson.optJSONArray("notification_history");
        notificationHistory = NotificationHistory.fromJson(null, notificationsJson);
    }

    // Validate keys
    JsonUtils.validateKeys(stateJson, "Agent state",
            new ArrayList<String>(Arrays.asList("time", "parameters", "inputs", "memory", "outputs",
                    "exceptions", "last_dismissed_exception", "notifications", "notification_history")));

    // Generate the agent state object
    AgentState newState = new AgentState(time, symbolManager, parameters, inputs, memory, outputs, exceptions,
            lastDismissedException, notifications, notificationHistory);

    // Return the agent state object
    return newState;
}

From source file:com.alibaba.dubbo.monitor.simple.SimpleMonitorService.java

private static void createChart(String key, String service, String method, String date, String[] types,
        Map<String, long[]> data, double[] summary, String path) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
    DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
    TimeSeriesCollection xydataset = new TimeSeriesCollection();
    for (int i = 0; i < types.length; i++) {
        String type = types[i];//from  w  w  w  .j av  a  2 s.c o m
        TimeSeries timeseries = new TimeSeries(type);
        for (Map.Entry<String, long[]> entry : data.entrySet()) {
            try {
                timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
            } catch (ParseException e) {
                logger.error(e.getMessage(), e);
            }
        }
        xydataset.addSeries(timeseries);
    }
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
            "max: " + numberFormat.format(summary[0])
                    + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "") + " avg: "
                    + numberFormat.format(summary[2])
                    + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""),
            toDisplayService(service) + "  " + method + "  " + toDisplayDate(date), key, xydataset, true, true,
            false);
    jfreechart.setBackgroundPaint(Color.WHITE);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.GRAY);
    xyplot.setRangeGridlinePaint(Color.GRAY);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    BufferedImage image = jfreechart.createBufferedImage(600, 300);
    try {
        if (logger.isInfoEnabled()) {
            logger.info("write chart: " + path);
        }
        File methodChartFile = new File(path);
        File methodChartDir = methodChartFile.getParentFile();
        if (methodChartDir != null && !methodChartDir.exists()) {
            methodChartDir.mkdirs();
        }
        FileOutputStream output = new FileOutputStream(methodChartFile);
        try {
            ImageIO.write(image, "png", output);
            output.flush();
        } finally {
            output.close();
        }
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
    }
}

From source file:com.amazon.s3.util.XpathUtils.java

/**
 * Evaluates the specified XPath expression and returns the result as a
 * Date. Assumes that the node's text is formatted as an ISO 8601 date, as
 * specified by xs:dateTime./*from w ww  .j  a va  2  s. c  o m*/
 *
 * @param expression
 *            The XPath expression to evaluate.
 * @param node
 *            The node to run the expression on.
 *
 * @return The Date result.
 *
 * @throws XPathExpressionException
 *             If there was a problem processing the specified XPath
 *             expression.
 */
public static Date asDate(String expression, Node node) throws XPathExpressionException {
    String dateString = evaluateAsString(expression, node);
    if (isEmptyString(dateString))
        return null;

    try {
        return dateUtils.parseIso8601Date(dateString);
    } catch (ParseException e) {
        Log.e(TAG, "Unable to parse date '" + dateString + "':  " + e.getMessage(), e);
        return null;
    }
}

From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java

/**
 * Return compatible class for typedValue based on untypedValueClass 
 * //from ww  w .j a  va2  s.  c  om
 * @param untypedValueClass
 * @param typedValue
 * @return
 */
public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) {
    Log LOG = LogFactory.getLog(DataTypeHelper.class);

    if (typedValue == null) {
        return null;
    }

    if (untypedValueClass == null) {
        return typedValue;
    }

    if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) {
        return typedValue;
    }

    String strTypedValue = null;
    boolean isStringTypedValue = typedValue instanceof String;

    Number numTypedValue = null;
    boolean isNumberTypedValue = typedValue instanceof Number;

    Boolean boolTypedValue = null;
    boolean isBooleanTypedValue = typedValue instanceof Boolean;

    Date dateTypedValue = null;
    boolean isDateTypedValue = typedValue instanceof Date;

    if (isStringTypedValue) {
        strTypedValue = (String) typedValue;
    }
    if (isNumberTypedValue) {
        numTypedValue = (Number) typedValue;
    }
    if (isBooleanTypedValue) {
        boolTypedValue = (Boolean) typedValue;
    }
    if (isDateTypedValue) {
        dateTypedValue = (Date) typedValue;
    }

    Object v = null;
    if (String.class.equals(untypedValueClass)) {
        v = ObjectUtils.toString(typedValue);
    } else if (BigDecimal.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createBigDecimal(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new BigDecimal(numTypedValue.doubleValue());
        } else if (isBooleanTypedValue) {
            v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new BigDecimal(dateTypedValue.getTime());
        }
    } else if (Boolean.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = BooleanUtils.toBooleanObject(strTypedValue);
        } else if (isNumberTypedValue) {
            v = BooleanUtils.toBooleanObject(numTypedValue.intValue());
        } else if (isDateTypedValue) {
            v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime());
        }
    } else if (Byte.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = Byte.valueOf(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Byte(numTypedValue.byteValue());
        } else if (isBooleanTypedValue) {
            v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Byte((byte) dateTypedValue.getTime());
        }
    } else if (byte[].class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = strTypedValue.getBytes();
        }
    } else if (Double.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createDouble(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Double(numTypedValue.doubleValue());
        } else if (isBooleanTypedValue) {
            v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Double(dateTypedValue.getTime());
        }
    } else if (Float.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createFloat(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Float(numTypedValue.floatValue());
        } else if (isBooleanTypedValue) {
            v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Float(dateTypedValue.getTime());
        }
    } else if (Short.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createInteger(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Integer(numTypedValue.intValue());
        } else if (isBooleanTypedValue) {
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        } else if (isDateTypedValue) {
            v = new Integer((int) dateTypedValue.getTime());
        }
    } else if (Integer.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createInteger(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Integer(numTypedValue.intValue());
        } else if (isBooleanTypedValue) {
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        } else if (isDateTypedValue) {
            v = new Integer((int) dateTypedValue.getTime());
        }
    } else if (Long.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createLong(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Long(numTypedValue.longValue());
        } else if (isBooleanTypedValue) {
            v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Long(dateTypedValue.getTime());
        }
    } else if (java.sql.Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Date(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Date(dateTypedValue.getTime());
        }
    } else if (java.sql.Time.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Time(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Time(dateTypedValue.getTime());
        }
    } else if (java.sql.Timestamp.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Timestamp(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Timestamp(dateTypedValue.getTime());
        }
    } else if (Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new Date(numTypedValue.longValue());
        } else if (isStringTypedValue) {
            try {
                v = DateFormat.getDateInstance().parse(strTypedValue);
            } catch (ParseException e) {
                LOG.error("Unable to parse the date : " + strTypedValue);
                LOG.debug(e.getMessage());
            }
        }
    }
    return v;
}

From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java

public static DateTime getLowerDateTimeBound(String dateRange) throws ParseException {
    Range range = SearchExpressionUtils.parseRange(dateRange);
    if (range == null) {
        throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
    }// ww w  .  j av  a  2  s  .c om
    if (range.getLowerBoundValue() != null) {
        java.util.Date lowerRangeDate = null;
        try {
            lowerRangeDate = CoreApiServiceLocator.getDateTimeService()
                    .convertToDate(range.getLowerBoundValue());
        } catch (ParseException pe) {
            GlobalVariables.getMessageMap().putError("dateFrom", RiceKeyConstants.ERROR_CUSTOM,
                    pe.getMessage());
        }
        MutableDateTime dateTime = new MutableDateTime(lowerRangeDate);
        dateTime.setMillisOfDay(0);
        return dateTime.toDateTime();
    }
    return null;
}