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:org.karndo.piracy.Scraper.java

/**
 * //from   ww w  . j a  v  a 2s  . co m
 * @param url
 * @param io
 * @return 
 */
public LinkedList<PiracyEvent> parse_piracy_data(String url, InputOutput io) throws IOException {

    //use the private method in this class to get the data
    String data = get_piracy_data(url);
    System.out.println(data);

    //strip everything before "icons"
    String temp = StringUtils.strip(data,
            "head.ready(function() {fabrikMap45 = new FbGoogleMapViz('table_map', {\"icons\":[");
    temp = "\"" + temp;

    //after stripping the first section, the data can be split using the
    //'curly brackets'
    String[] events = StringUtils.split(temp, "{");
    LinkedList<PiracyEvent> events_list = new LinkedList<PiracyEvent>();

    //some parameters for holding data from the event strings 
    PiracyEvent event1 = null;
    double longitude = 0.0;
    double latitude = 0.0;
    String attack_id = "";
    String vessel_type = "";
    String status = "";
    Date date = null;

    for (String str : events) {
        try {

            //Strip out the latitude and longitude
            String lat1 = StringUtils.strip(StringUtils.substringBetween(str, "\"0\":", ","), "\"");
            String long1 = StringUtils.strip(StringUtils.substringBetween(str, "\"1\":", ","), "\"");
            //parse the values into doubles
            latitude = Double.parseDouble(lat1);
            longitude = Double.parseDouble(long1);
            //strip out the attack id.
            attack_id = StringUtils.strip(StringUtils.substringBetween(str, "\"2\":", "<br \\/>"),
                    "\"Attack ID:");
            //strip out the date
            String date_str = StringUtils.strip(StringUtils.substringBetween(str, "Date:", "<br"), "Date:");
            // TODO change this to a GMT time-format
            date = DateUtils.parseDate(StringUtils.trim(date_str), "yyyy-MM-dd");
            //strip out the Vessel type
            vessel_type = StringUtils.strip(StringUtils.substringBetween(str, "Vessel:", "<br \\/>"),
                    "Vessel:");
            //strip out the status
            status = StringUtils.strip(StringUtils.substringBetween(str, "Status:", "<br \\/>"), "Status:");

            //create a piracy event
            event1 = new PiracyEvent(latitude, longitude, attack_id, date, StringUtils.trim(status),
                    StringUtils.trim(vessel_type));
            events_list.add(event1);

            //print to the supplied InputOutput from the main window
            io.getOut().println(event1);
        } catch (ParseException ex) {
            System.err.println("A parse exception occurred parsing the date");
            System.err.println(ex.getMessage());
        } finally {

        }
    }

    return events_list;
}

From source file:org.dspace.app.xmlui.aspect.statisticsElasticSearch.ReportGenerator.java

public Date tryParse(String dateString) {
    if (dateString == null || dateString.length() == 0) {
        return null;
    }// ww w .  j av a  2 s. c  o  m

    for (String formatString : formatStrings) {
        try {
            return new SimpleDateFormat(formatString).parse(dateString);
        } catch (ParseException e) {
            log.error("ReportGenerator couldn't parse date: " + dateString + ", with pattern of: "
                    + formatString + " with error message:" + e.getMessage());
        }
    }
    return null;
}

From source file:tasly.greathealth.oms.web.mock.rest.resource.TaslyOrderProducerMockTestResource.java

@GET
@Path("/{operation}/{status}/{startdate}/{enddate}/{pagesize}/{pageno}")
public Response getOrderProducerStatus(@PathParam("operation") final String operation,
        @PathParam("status") final String status, @PathParam("startdate") final String startdate,
        @PathParam("enddate") final String enddate, @PathParam("pagesize") final String pagesize,
        @PathParam("pageno") final String pageno) {
    LOG.info("Mock produce orders ");
    final List<String> tids = new ArrayList<>();
    {/*from   w  w w.  j av a  2 s  .c o m*/
        final SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        // final List<OrderCommand> orderCreateCommands = new ArrayList<>();
        final TradesSoldIncrementGetRequest req = new TradesSoldIncrementGetRequest();
        TradesSoldIncrementGetResponse response = null;
        try {
            req.setStatus(status);
            req.setStartModified(sf.parse(startdate));
            req.setEndModified(sf.parse(enddate));
            req.setFields(DEFAULT_MOCK_TMALL_FIELDS);
            req.setPageNo(Long.valueOf(pageno));
            req.setPageSize(Long.valueOf(pagesize));
            response = client.execute(req, defaultTmallStoreSessionkey);
            if (response.getTrades() != null) {
                final List<Trade> trades = response.getTrades();
                for (int i = trades.size() - 1; i >= 0; i--) {
                    final Trade trade = trades.get(i);
                    final String tid = String.valueOf(trade.getTid());
                    tids.add(tid);
                    final String buyerNick = trade.getBuyerNick();
                    final List<Order> orders = trade.getOrders();
                    final Order order = orders.get(0);
                    final String oid = String.valueOf(order.getOid());
                    final String payment = order.getPayment();

                    final Message message = new Message();

                    final Map<String, Object> rawMap = new HashMap<String, Object>();
                    final Map<String, Object> contentMap = new HashMap<String, Object>();
                    contentMap.put("tid", tid);
                    contentMap.put("oid", oid);
                    contentMap.put("payment", payment);
                    contentMap.put("buyer_nick", buyerNick);

                    rawMap.put("content", contentMap);
                    rawMap.put("time", String.valueOf(new Date()));

                    setRawMsg(message, rawMap);
                    message.setId(123l);

                    if ("createOrder".equalsIgnoreCase(operation)) {
                        message.setTopic("taobao_trade_TradeBuyerPay");
                        final OrderCommand command = new CreateTmallOrderCommand(this.omsOrderRetrieveService,
                                message, InnerSource.OTC);
                        OrderCommandsStorage.getInstance().addOrderCommand(ChannelSource.TMALL,
                                EventType.ORDERCREATE, command);
                    } else if ("createRefund".equalsIgnoreCase(operation)) {
                        message.setTopic("taobao_refund_RefundCreated");
                        final OrderCommand command = new CreateTmallRefundCommand(this.omsOrderRetrieveService,
                                message, InnerSource.OTC);
                        OrderCommandsStorage.getInstance().addOrderCommand(ChannelSource.TMALL,
                                EventType.REFUNDCREATE, command);
                    }
                }

                // OrderCommandsStorage.getInstance().addOrderCommands(SourceType.TMALL, EventType.ORDERCREATE,
                // orderCreateCommands);
            }
        } catch (final ParseException e) {
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        } catch (final ApiException e) {
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        } catch (final IllegalArgumentException e) {
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        } catch (final IllegalAccessException e) {
            // YTODO Auto-generated catch block
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        } catch (final InvocationTargetException e) {
            // YTODO Auto-generated catch block
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }
    return Response.ok(new JSONSerializer().serialize(tids)).build();
}

From source file:org.dd4t.core.resolvers.impl.DefaultLinkResolver.java

private String findUrlMapping(Schema schema) {
    String key = "";
    if ("id".equals(schemaKey)) {
        try {//from w  w  w .j  a  va2s.  c o  m
            TCMURI tcmUri = new TCMURI(schema.getId());
            key = String.valueOf(tcmUri.getItemId());
        } catch (ParseException e) {
            LOG.error(e.getMessage(), e);
            return null;
        }
    } else if ("title".equals(schemaKey)) {
        key = schema.getTitle();
    } else {
        // use uri as default key
        key = schema.getId();
    }

    return getSchemaToUrlMappings().get(key);
}

From source file:net.orpiske.dcd.collector.dataset.impl.MBoxDataSet.java

private Date getDate(final String strDate) {
    final int DATE_LENGTH_WITH_TZ = 37;
    final int DATE_LENGTH_WITHOUT_TZ = 31;

    String dateWithCorrectSize;/*  w w  w . jav  a  2s .  c  om*/

    if (strDate == null || strDate.isEmpty()) {
        logger.error("The input date is null, returning epoch");

        return new Date(0);
    }

    int length = strDate.trim().length();
    /*
     * DateUtils seems to fail if the length of the string
     * is bigger than expected (or I just don't know how to
     * use it properly ... TODO: research this).
     *
     * This case checks if the date is something like this:
     * Sun, 16 Feb 2014 18:44:57 -0300 (BRT)
     */
    switch (length) {
    /* This case checks if the date is something like this:
     * Sun, 1 Feb 2014 18:44:57 -0300 (BRT)
     */
    case (DATE_LENGTH_WITH_TZ - 1):
        dateWithCorrectSize = strDate.substring(0, DATE_LENGTH_WITHOUT_TZ - 1);
        break;
    /* This case checks if the date is something like this:
     * Sun, 16 Feb 2014 18:44:57 -0300 (BRT)
     */
    case DATE_LENGTH_WITH_TZ: {
        dateWithCorrectSize = strDate.substring(0, DATE_LENGTH_WITHOUT_TZ);
        break;
    }
    /* This case checks if the date is something like this:
     * Sun, 6 Feb 2014 18:44:57 -0300
     */
    case (DATE_LENGTH_WITHOUT_TZ - 1):

        /* This case checks if the date is something like this:
         * Sun, 16 Feb 2014 18:44:57 -0300
         */
    case DATE_LENGTH_WITHOUT_TZ: {
        dateWithCorrectSize = strDate;
        break;
    }
    default: {
        if (length > DATE_LENGTH_WITH_TZ) {
            logger.warn("The length of the date header is bigger than expected: " + length);
            dateWithCorrectSize = strDate.substring(0, DATE_LENGTH_WITHOUT_TZ);
        } else {
            logger.error("The input date does not seem to be in any " + "recognizable format: " + strDate);
            logger.warn("Defaulting to epoch ...");
            return new Date(0);
        }

    }
    }

    try {
        return DateUtils.parseDate(dateWithCorrectSize, "EEE, d MMM yyyy HH:mm:ss Z");
    } catch (ParseException e) {
        logger.error("Unable to parse date " + strDate + ": " + e.getMessage(), e);
        logger.warn("Defaulting to epoch ...");
        return new Date(0);
    }

}

From source file:ch.aonyx.broker.ib.api.contract.Contract.java

public Date getExpirationDate() {
    if (StringUtils.isNotEmpty(expiry)) {
        try {/*from  w w w . java  2s . c om*/
            return DateUtils.parseDate(expiry, "YYYYMM");
        } catch (final ParseException e) {
            throw new NeoIbApiClientException(ClientMessageCode.INTERNAL_ERROR, e.getMessage(), e);
        }
    }
    return null;
}

From source file:org.inftel.ssa.mobile.ui.fragments.ProjectEditFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_save:
        try {//  www  . j  a  v a 2  s. c om
            saveProject();
        } catch (ParseException e) {
            Log.w(getClass().getSimpleName(), "Fallo inesperado guardando proyecto: " + e.getMessage(), e);
        }
        // FIXME
        // getActivity().finish();
        if (mState == STATE_EDIT) {
            startActivity(new Intent(Intent.ACTION_VIEW, mContentUri));
        } else {
            startActivity(new Intent(getActivity(), ProjectListActivity.class));
        }

        return true;
    }
    return onOptionsItemSelected(item);
}

From source file:de.xwic.appkit.webbase.entityviewer.config.ColumnsConfigurationDeserializer.java

/**
 * @param str//  www  .ja  v  a2s.  co  m
 * @return
 */
private Object deserializeValue(String str) {

    if (str == null || str.trim().isEmpty() || str.startsWith(ColumnsConfigurationSerializer.NULL)) {
        return null;
    } else if (str.startsWith(ColumnsConfigurationSerializer.STRING)) {
        return str.replace(ColumnsConfigurationSerializer.STRING, "");
    } else if (str.startsWith(ColumnsConfigurationSerializer.INT)) {
        return Integer.parseInt(str.replace(ColumnsConfigurationSerializer.INT, ""));
    } else if (str.startsWith(ColumnsConfigurationSerializer.LONG)) {
        return Long.parseLong(str.replace(ColumnsConfigurationSerializer.LONG, ""));
    } else if (str.startsWith(ColumnsConfigurationSerializer.DOUBLE)) {
        return Double.parseDouble(str.replace(ColumnsConfigurationSerializer.DOUBLE, ""));
    } else if (str.startsWith(ColumnsConfigurationSerializer.BOOLEAN)) {
        return Boolean.parseBoolean(str.replace(ColumnsConfigurationSerializer.BOOLEAN, ""));
    } else if (str.startsWith(ColumnsConfigurationSerializer.DATE_TIME)) {
        try {
            return ColumnsConfigurationSerializer.SDF_DATE_TIME
                    .parse(str.replace(ColumnsConfigurationSerializer.DATE_TIME, ""));
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
            return null;
        }
    } else if (str.startsWith(ColumnsConfigurationSerializer.DATE)) {
        try {
            return ColumnsConfigurationSerializer.SDF_DATE
                    .parse(str.replace(ColumnsConfigurationSerializer.DATE, ""));
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
            return null;
        }
    } else {
        throw new IllegalArgumentException("Invalid value: " + str);
    }
}

From source file:com.neusoft.mid.clwapi.service.homePage.HomePageServiceImpl.java

/**
 * ???/*from   ww w .j a v  a 2  s  . co  m*/
 * 
 * @param uptime
 * @return
 */
// ???
private Date[] getEtag(String uptime) {
    if (StringUtils.isEmpty(uptime)) {
        logger.error("");
        throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
    }
    // ?
    String[] s = StringUtils.split(uptime, "|");
    Date[] d = new Date[s.length];

    if (s.length != 2) {
        logger.error("????[" + s.length + "]");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    for (int i = 0; i < s.length; i++) {
        s[i] = StringUtils.strip(s[i]);
        if (!s[i].equals(HttpConstant.TIME_ZERO)) {
            try {
                d[i] = TimeUtil.parseStringToDate(s[i], HttpConstant.TIME_FORMAT);
            } catch (ParseException e) {
                logger.error("?" + e.getMessage());
                throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
            }
        } else {
            s[i] = null;
        }
    }
    return d;
}

From source file:org.kuali.kra.coi.lookup.CoiDisclosureLookupableHelperServiceImpl.java

protected boolean validateDate(String dateFieldName, String dateFieldValue) {
    try {/*w  w w  .  j a v a 2s. c  om*/
        CoreApiServiceLocator.getDateTimeService().convertToSqlTimestamp(dateFieldValue);
        return true;
    } catch (ParseException e) {
        GlobalVariables.getMessageMap().putError(dateFieldName,
                KeyConstants.ERROR_PROTOCOL_SEARCH_INVALID_DATE);
        return false;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        GlobalVariables.getMessageMap().putError(dateFieldName,
                KeyConstants.ERROR_PROTOCOL_SEARCH_INVALID_DATE);
        return false;
    }
}