Search in sources :

Example 1 with ReceivedDateTerm

use of jakarta.mail.search.ReceivedDateTerm in project exist by eXist-db.

the class MessageListFunctions method parseReceivedDateTerm.

private SearchTerm parseReceivedDateTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String value = ((Element) terms).getAttribute("date");
    String format = ((Element) terms).getAttribute("format");
    if (StringUtils.isEmpty(value)) {
        throw (new XPathException(this, "value not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    if (StringUtils.isEmpty(format)) {
        throw (new XPathException(this, "format not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    int cp = parseComparisonAttribute(terms);
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = sdf.parse(value);
        st = new ReceivedDateTerm(cp, date);
    } catch (ParseException pe) {
        throw (new XPathException(this, "Cannot parse date value: " + value + ", using format: " + format + ", for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) ReceivedDateTerm(jakarta.mail.search.ReceivedDateTerm) ParseException(java.text.ParseException) SearchTerm(jakarta.mail.search.SearchTerm) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ReceivedDateTerm (jakarta.mail.search.ReceivedDateTerm)1 SearchTerm (jakarta.mail.search.SearchTerm)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 XPathException (org.exist.xquery.XPathException)1 Element (org.w3c.dom.Element)1