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:com.basetechnology.s0.agentserver.notification.NotificationInstance.java

static public NotificationInstance fromJson(AgentInstance agentInstance, JSONObject notificationInstanceJson)
        throws AgentServerException, SymbolException {
    // TODO: Whether empty fields should be null of empty strings
    String definitionName = notificationInstanceJson.optString("definition", "");
    if (definitionName == null)
        throw new AgentServerException("Missing notification 'definition' name");
    if (definitionName.trim().length() == 0)
        throw new AgentServerException("Empty notification 'definition' name");
    NotificationDefinition definition = agentInstance.agentDefinition.notifications.get(definitionName);
    if (definition == null)
        throw new AgentServerException("Undefined notification 'definition' name: " + definitionName);

    // Parse the detail values
    MapValue details = null;/*  w  w  w  .ja v a  2  s.  c  om*/
    String invalidDetailNames = "";
    SymbolManager symbolManager = new SymbolManager();
    SymbolTable symbolTable = symbolManager.getSymbolTable("details");
    JSONObject detailsJson = null;
    if (notificationInstanceJson.has("details")) {
        // Parse the detail values
        detailsJson = notificationInstanceJson.optJSONObject("details");
        List<FieldValue> detailFieldValues = new ArrayList<FieldValue>();
        for (Iterator<String> it = detailsJson.keys(); it.hasNext();) {
            String key = it.next();
            if (!definition.detail.containsKey(key))
                invalidDetailNames += (invalidDetailNames.length() > 0 ? ", " : "") + key;
            detailFieldValues.add(new FieldValue(key, Value.toValueNode(detailsJson.opt(key))));
        }
        details = new MapValue(ObjectTypeNode.one, (List<Value>) (Object) detailFieldValues);

        // Validate that they are all valid agent definition notification detail fields
        if (invalidDetailNames.length() > 0)
            throw new AgentServerException("Detail names for notification '" + definitionName
                    + "' instance for agent instance " + agentInstance.name
                    + " are not defined for the notification definition: " + invalidDetailNames);
    }

    boolean pending = notificationInstanceJson.optBoolean("pending");

    String response = notificationInstanceJson.optString("response", "");

    String responseChoice = notificationInstanceJson.optString("response_choice", "");

    long timeout = notificationInstanceJson.optLong("timeout", -1);

    String comment = notificationInstanceJson.optString("comment", "");

    String timeNotifiedString = notificationInstanceJson.optString("time_notified", null);
    long timeNotified = -1;
    try {
        timeNotified = timeNotifiedString != null ? DateUtils.parseRfcString(timeNotifiedString) : -1;
    } catch (ParseException e) {
        throw new AgentServerException(
                "Unable to parse notification time ('" + timeNotifiedString + "') - " + e.getMessage());
    }

    String timeResponseString = notificationInstanceJson.optString("time_response", null);
    long timeResponse = -1;
    try {
        timeResponse = timeResponseString != null ? DateUtils.parseRfcString(timeResponseString) : -1;
    } catch (ParseException e) {
        throw new AgentServerException("Unable to parse notification response time ('" + timeResponseString
                + "') - " + e.getMessage());
    }

    // Validate keys
    JsonUtils.validateKeys(notificationInstanceJson, "Notification Instance",
            new ArrayList<String>(Arrays.asList("name", "details", "response", "response_choice", "comment",
                    "timeout", "time_notified", "time_response")));

    return new NotificationInstance(agentInstance, definition, details, pending, response, responseChoice,
            comment, timeout, timeNotified, timeResponse);
}

From source file:org.crazydog.util.spring.NumberUtils.java

/**
 * Parse the given text into a number instance of the given target class,
 * using the given NumberFormat. Trims the input {@code String}
 * before attempting to parse the number.
 *
 * @param text         the text to convert
 * @param targetClass  the target class to parse into
 * @param numberFormat the NumberFormat to use for parsing (if {@code null},
 *                     this method falls back to {@code parseNumber(String, Class)})
 * @return the parsed number/*from   w  ww  .j a  v  a 2  s. co  m*/
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see NumberFormat#parse
 * @see #convertNumberToTargetClass
 * @see #parseNumber(String, Class)
 */
public static <T extends Number> T parseNumber(String text, Class<T> targetClass, NumberFormat numberFormat) {
    if (numberFormat != null) {
        org.springframework.util.Assert.notNull(text, "Text must not be null");
        org.springframework.util.Assert.notNull(targetClass, "Target class must not be null");
        DecimalFormat decimalFormat = null;
        boolean resetBigDecimal = false;
        if (numberFormat instanceof DecimalFormat) {
            decimalFormat = (DecimalFormat) numberFormat;
            if (BigDecimal.class == targetClass && !decimalFormat.isParseBigDecimal()) {
                decimalFormat.setParseBigDecimal(true);
                resetBigDecimal = true;
            }
        }
        try {
            Number number = numberFormat.parse(StringUtils.trimAllWhitespace(text));
            return convertNumberToTargetClass(number, targetClass);
        } catch (ParseException ex) {
            throw new IllegalArgumentException("Could not parse number: " + ex.getMessage());
        } finally {
            if (resetBigDecimal) {
                decimalFormat.setParseBigDecimal(false);
            }
        }
    } else {
        return parseNumber(text, targetClass);
    }
}

From source file:com.krawler.common.util.SchedulingUtilities.java

public static String getFormattedDateString(String date, String format) {
    Date d = null;/*from w w w. j ava2 s.  c  o  m*/
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    if (!StringUtil.isNullOrEmpty(format))
        sdf = new SimpleDateFormat(format);
    try {
        d = DateUtils.parseDate(date, new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" });
    } catch (ParseException e) {
        throw ServiceException.FAILURE("Date Parse Exception :: " + e.getMessage(), e);
    } finally {
        if (d != null)
            return sdf.format(d);
        else
            return date;
    }
}

From source file:net.naijatek.myalumni.util.date.DateConverterUtil.java

/**
 * This method converts a String to a date using the datePattern
 * /*from  w  ww.  j av  a2s .  c o  m*/
 * @param strDate the date to convert (in format MM/dd/yyyy)
 * @return a date object
 * 
 * @throws ParseException
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + getDatePattern());
        }

        aDate = convertStringToDate(getDatePattern(), strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        pe.printStackTrace();
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());

    }

    return aDate;
}

From source file:org.entrystore.repository.backup.BackupJob.java

synchronized public static void runBackupMaintenance(JobExecutionContext jobContext) throws Exception {
    if (interrupted) {
        return;/*  ww w.j  av  a 2  s. co m*/
    }

    log.info("Starting backup maintenance job");

    JobDataMap dataMap = jobContext.getJobDetail().getJobDataMap();
    RepositoryManagerImpl rm = (RepositoryManagerImpl) dataMap.get("rm");

    int upperLimit = (Integer) dataMap.get("upperLimit");
    int lowerLimit = (Integer) dataMap.get("lowerLimit");
    int expiresAfterDays = (Integer) dataMap.get("expiresAfterDays");

    log.info("upperlimit: " + upperLimit + ", lowerLimit: " + lowerLimit + ", expiresAfterDays: "
            + expiresAfterDays);

    String exportPath = rm.getConfiguration().getString(Settings.BACKUP_FOLDER);
    Date today = new Date();

    if (exportPath == null) {
        log.error("Unknown backup path, please check the following setting: " + Settings.BACKUP_FOLDER);
    } else {
        File backupFolder = new File(exportPath);
        DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");

        List<Date> backupFolders = new ArrayList<Date>();
        for (File file : backupFolder.listFiles()) {
            if (!file.isDirectory() || file.isHidden()) {
                log.info("Ignoring: " + file);
                continue;
            }

            try {
                Date date = formatter.parse(file.getName());
                backupFolders.add(date);
                log.info("Found backup folder: " + file);
            } catch (ParseException pe) {
                log.warn("Skipping path: " + file + ". Reason: " + pe.getMessage());
                continue;
            }
        }

        if (backupFolders.size() <= lowerLimit) {
            log.info("Lower limit not reached - backup maintenance job done with execution");
            return;
        }

        Collections.sort(backupFolders, new Comparator<Date>() {
            public int compare(Date a, Date b) {
                if (a.after(b)) {
                    return 1;
                } else if (a.before(b)) {
                    return -1;
                } else {
                    return 0;
                }
            }
        });

        if (backupFolders.size() > upperLimit) {
            int nrRemoveItems = backupFolders.size() - upperLimit;
            log.info("Upper limit is " + upperLimit + ", will delete " + nrRemoveItems + " backup folder(s)");
            for (int i = 0; i < nrRemoveItems; i++) {
                String folder = formatter.format(backupFolders.get(i));
                File f = new File(exportPath, folder);
                if (deleteDirectory(f)) {
                    backupFolders.remove(i);
                    log.info("Deleted " + f);
                } else {
                    log.info("Unable to delete " + f);
                }
            }
        }

        Date oldestDate = backupFolders.get(0);

        if (daysBetween(oldestDate, today) > expiresAfterDays) {
            for (int size = backupFolders.size(), i = 0; lowerLimit < size; size--) {
                Date d = backupFolders.get(i);
                if (daysBetween(d, today) > expiresAfterDays) {
                    String folder = formatter.format(backupFolders.get(i));
                    File f = new File(exportPath, folder);
                    if (deleteDirectory(f)) {
                        backupFolders.remove(i);
                        log.info("Deleted " + f);
                    } else {
                        log.info("Unable to delete " + f);
                    }
                } else {
                    break;
                }
            }
        }
    }

    log.info("Backup maintenance job done with execution");
}

From source file:egovframework.oe1.utl.fcc.service.EgovNumberUtil.java

/**
 * ?? ??    ? 20081212 ??/*from   w w w . j ava2 s . c o  m*/
 * '2008-12-12'  
 * @param srcNumber
 *        - ?
 * @return String
 * @exception MyException
 * @see
 */
public static String getNumToDateCnvr(int srcNumber) {

    String pattern = null;
    String cnvrStr = null;

    String srcStr = String.valueOf(srcNumber);

    // Date ? 8? ? 14? ?
    if (srcStr.length() != 8 && srcStr.length() != 14) {
        throw new IllegalArgumentException("Invalid Number: " + srcStr + " Length=" + srcStr.trim().length());
    }

    if (srcStr.length() == 8) {

        pattern = "yyyyMMdd";

    } else if (srcStr.length() == 14) {

        pattern = "yyyyMMddhhmmss";
    }

    SimpleDateFormat dateFormatter = new SimpleDateFormat(pattern, Locale.KOREA);

    Date cnvrDate = null;

    try {
        cnvrDate = dateFormatter.parse(srcStr);

    } catch (ParseException e) {

        //log.debug(e.getMessage()); 
        log.trace(e.getMessage());
    }

    cnvrStr = String.format("%1$tY-%1$tm-%1$td", cnvrDate);

    return cnvrStr;

}

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

private static Date parseDate(String string) throws ClientException {
    try {//from w  w  w  . j a v  a2s . co m
        return JSON_DATE_FORMAT.parse(string);
    } catch (ParseException e) {
        throw new ClientException("Error parsing date: " + e.getMessage(), e);
    }
}

From source file:cn.ctyun.amazonaws.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.//w w  w .  j av a  2 s .  c  om
 *
 * @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.warn("Unable to parse date '" + dateString + "':  " + e.getMessage(), e);
        return null;
    }
}

From source file:controllers.GoogleComputeEngineApplication.java

public static WebSocket<JsonNode> gceOperations() {
    return new WebSocket<JsonNode>() {
        public void onReady(final In<JsonNode> in, final Out<JsonNode> out) {
            final ActorRef computeActor = Akka.system()
                    .actorOf(Props.create(GoogleComputeEngineConnection.class, out));

            in.onMessage(new F.Callback<JsonNode>() {
                @Override//from   ww w  . jav  a2  s . com
                public void invoke(JsonNode jsonNode) throws Throwable {
                    if (jsonNode.has("action") && "retrieve".equals(jsonNode.get("action").textValue())) {
                        Date lastOperationDate = null;
                        if (jsonNode.has("lastOperationDate")) {
                            DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
                            try {
                                lastOperationDate = format.parse(jsonNode.get("lastOperationDate").textValue());
                            } catch (ParseException e) {
                                System.out.println("Date parse error: " + e.getMessage());
                            }
                        }
                        final ActorRef computeActor = Akka.system()
                                .actorOf(Props.create(GoogleComputeEngineConnection.class, out));
                        GoogleComputeEngineService.listOperations(computeActor, lastOperationDate);
                    }
                }
            });

            in.onClose(new F.Callback0() {
                @Override
                public void invoke() throws Throwable {
                    Akka.system().stop(computeActor);
                }
            });
        }
    };
}

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

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