Example usage for java.text ParseException toString

List of usage examples for java.text ParseException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.silverpeas.components.projectmanager.model.ProjectManagerDAO.java

public static Date dbDate2Date(String dbDate, String fieldName) throws SQLException {
    Date date = null;/*from  ww w .  ja  va 2  s.c  om*/
    try {
        // the date format used in database to represent a date
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
        date = formatter.parse(dbDate);
    } catch (ParseException e) {
        throw new SQLException(
                "ProjectManagerDAO : dbDate2Date(" + fieldName + ") : format unknown " + e.toString(), e);
    }
    return date;
}

From source file:eionet.cr.util.Util.java

/**
 *
 * @param str//from  ww w. j  a  va 2s.  c  o  m
 * @param datePattern
 * @return
 */
public static java.util.Date stringToDate(String str, String datePattern) {

    if (str == null || str.trim().length() == 0) {
        return null;
    }

    SimpleDateFormat formatter = new SimpleDateFormat(datePattern);
    try {
        return formatter.parse(str);
    } catch (ParseException e) {
        throw new CRRuntimeException("Failed to convert the given string to java.util.Date: " + e.toString(),
                e);
    }
}

From source file:org.encuestame.utils.json.JsonDateDeserializer.java

public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    try {// ww  w  .j av  a2s.  co  m
        log.debug("json parse:{ " + jp.getText());
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
        return sdf.parse(jp.getText());
    } catch (ParseException e) {
        throw new IOException("Error parsing Twitter date format: " + e.toString());
    }
}

From source file:us.mn.state.health.lims.common.util.validator.DateValidator.java

/** 
  * <p>Checks if the field is a valid date.  The pattern is used with 
  * <code>java.text.SimpleDateFormat</code>.  If strict is true, then the 
  * length will be checked so '2/12/1999' will not pass validation with 
  * the format 'MM/dd/yyyy' because the month isn't two digits. 
  * The setLenient method is set to <code>false</code> for all.</p> 
  * /*  www.j a  va2s .  c o  m*/
  * @param value The value validation is being performed on. 
  * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. 
  * @param strict Whether or not to have an exact match of the datePattern. 
 */
public boolean isValid(String value, String datePattern, boolean strict) {
    if (value == null || datePattern == null || datePattern.length() <= 0) {
        return false;
    }
    //System.out.println("value & datePattern " + value + " " + datePattern);
    SimpleDateFormat formatter = new SimpleDateFormat(datePattern);
    formatter.setLenient(false);
    try {
        formatter.parse(value);
    } catch (ParseException e) {
        //bugzilla 2154
        LogEvent.logError("DateValidator", "isValid()", e.toString());
        return false;
    }
    if (strict && (datePattern.length() != value.length())) {
        return false;
    }
    return true;
}

From source file:us.mn.state.health.lims.common.util.validator.DateValidator.java

/** 
 * &lt;p&gt;Checks if the field is a valid date.  The &lt;code&gt;Locale&lt;/code&gt; is 
 * used with &lt;code&gt;java.text.DateFormat&lt;/code&gt;.  The setLenient method 
 * is set to &lt;code&gt;false&lt;/code&gt; for all.&lt;/p&gt; 
 * /*from w  ww .j  a v  a  2  s  .  c  om*/
 * @param value The value validation is being performed on. 
 * @param locale The locale to use for the date format, defaults to the default 
 * system default if null. 
*/
public boolean isValid(String value, Locale locale) {
    if (value == null) {
        return false;
    }
    //System.out.println("value & locale " + value + " " + locale);

    DateFormat formatter = null;
    if (locale != null) {
        formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    } else {
        formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    }
    formatter.setLenient(false);
    try {
        formatter.parse(value);
    } catch (ParseException e) {
        //bugzilla 2154
        LogEvent.logError("DateValidator", "isValid()", e.toString());
        return false;
    }
    return true;
}

From source file:org.sakaiproject.importer.impl.translators.Bb6AnnouncementTranslator.java

public Importable translate(Node resourceNode, Document descriptor, String contextPath,
        String archiveBasePath) {
    // create a new generic object to return
    Announcement item = new Announcement();

    // this sets the display category of this item apparently (the one the user will see)
    item.setLegacyGroup(item.getDisplayType());

    // Dates from Bb are formatted like '2007-05-08 23:45:00 EDT'
    DateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss zzz");
    String bbid = XPathHelper.getNodeValue("/ANNOUNCEMENT/@id", descriptor);

    // populate the generic object fields
    item.setTitle(XPathHelper.getNodeValue("/ANNOUNCEMENT/TITLE/@value", descriptor));
    item.setDescription(XPathHelper.getNodeValue("/ANNOUNCEMENT/DESCRIPTION/TEXT", descriptor));

    item.setHtml(Boolean.getBoolean(XPathHelper.getNodeValue("/ANNOUNCEMENT/FLAGS/ISHTML/@value", descriptor)));
    item.setLiternalNewline(Boolean
            .getBoolean(XPathHelper.getNodeValue("/ANNOUNCEMENT/FLAGS/ISNEWLINELITERAL/@value", descriptor)));
    item.setPermanent(/*  w  w w.  j  a  va2s .c o  m*/
            Boolean.getBoolean(XPathHelper.getNodeValue("/ANNOUNCEMENT/ISPERMANENT/@value", descriptor)));

    // attempt to parse the start date
    try {
        Date d = df.parse(XPathHelper.getNodeValue("/ANNOUNCEMENT/DATES/RESTRICTSTART/@value", descriptor));
        item.setStart(d);
    } catch (ParseException e) {
        // report it but continue
        log.warn("Could not parse date startdate for " + bbid + ": " + e.toString());
    }

    // attempt to parse the end date
    try {
        Date d = df.parse(XPathHelper.getNodeValue("/ANNOUNCEMENT/DATES/RESTRICTEND/@value", descriptor));
        item.setEnd(d);
    } catch (ParseException e) {
        // report it but continue
        log.warn("Could not parse date enddate for " + bbid + ": " + e.toString());
    }

    log.info("Translation complete for BB6 announcement item:" + bbid);
    log.debug("Announcement item: " + item.toString());
    item.setLegacyGroup(Blackboard6FileParser.ANNOUNCEMENT_GROUP);
    return item;
}

From source file:org.artifactory.ui.rest.service.builds.buildsinfo.tabs.licenses.BuildLicensesService.java

@Override
public void execute(ArtifactoryRestRequest request, RestResponse response) {
    try {/*from   w  w  w. j  ava  2s . c o m*/
        String name = request.getPathParamByKey("name");
        String buildNumber = request.getPathParamByKey("number");
        String buildStarted = DateUtils.formatBuildDate(Long.parseLong(request.getPathParamByKey("date")));
        Boolean authFind = Boolean.valueOf(request.getQueryParamByKey("autoFind"));
        Build build = getBuild(name, buildNumber, buildStarted, response);
        // fetch license
        Multimap<RepoPath, ModuleLicenseModel> repoPathLicenseModuleModel = getRepoPathLicenseModuleModelMultimap(
                build, authFind);
        if (repoPathLicenseModuleModel != null && !repoPathLicenseModuleModel.isEmpty()) {
            Collection<ModuleLicenseModel> values = repoPathLicenseModuleModel.values();
            // fetch published modules
            Set<ModuleLicenseModel> publishedModules = getPublishedModulesFromModelList(values,
                    build.getModules());
            // filter published modules from licenses
            publishedModules.forEach(published -> values.remove(published));
            // fetch build license summary
            Set<String> scopes = getScopeMapping(values);
            BuildLicenseModel buildLicenseModel = new BuildLicenseModel(values, publishedModules, scopes);
            response.iModel(buildLicenseModel);
            // get scopes
        }
    } catch (ParseException e) {
        log.error(e.toString());
        response.error("error with retrieving build licenses");
        return;
    }
}

From source file:org.openhab.binding.cardio2e.internal.code.Cardio2eDateTime.java

public Date toDate() {
    Date dateTime = null;/*  w w w. ja  v a2s. c o m*/
    try {
        dateTime = CARDIO2E_DATE_TIME_FORMAT.parse(this.dateTime);
    } catch (ParseException ex) {
        logger.warn("Unknown error in parsing to Date(): '{}'", ex.toString());
    }
    return dateTime;
}

From source file:org.openhab.binding.cardio2e.internal.code.Cardio2eDateTime.java

public Calendar toCalendar() {
    Calendar dateTime = null;//  w  ww .  j  a  va2  s  . co  m
    try {
        dateTime = Calendar.getInstance();
        dateTime.setTime((Date) CARDIO2E_DATE_TIME_FORMAT.parse(this.dateTime));
    } catch (ParseException ex) {
        logger.warn("Unknown error in parsing to Calendar(): '{}'", ex.toString());
    }
    return dateTime;
}

From source file:org.artifactory.ui.rest.service.builds.buildsinfo.tabs.licenses.ChangeBuildLicenseService.java

@Override
public void execute(ArtifactoryRestRequest request, RestResponse response) {
    try {/*from  w  w w  .  j  av  a2  s . c  o m*/
        String id = request.getQueryParamByKey("id");
        String repoKey = request.getQueryParamByKey("repoKey");
        String path = request.getQueryParamByKey("path");
        String name = request.getPathParamByKey("name");
        String buildNumber = request.getPathParamByKey("number");
        String buildStarted = DateUtils.formatBuildDate(Long.parseLong(request.getPathParamByKey("date")));
        // get license-repo map
        Build build = getBuild(name, buildNumber, buildStarted, response);
        RepoPath repoPath = InternalRepoPathFactory.create(repoKey, path);
        Multimap<RepoPath, ModuleLicenseModel> repoPathLicenseMultimap = getRepoPathLicenseModuleModelMultimap(
                build);
        Map<String, LicenseInfo> currentValues = getCurrentValues(id, repoPath, repoPathLicenseMultimap);
        PreDefineValues preDefineValues = getLicenseValues(repoPath, currentValues);
        response.iModel(preDefineValues);
    } catch (ParseException e) {
        log.error(e.toString());
    }

}