Search in sources :

Example 1 with SentDateTerm

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

the class MessageListFunctions method parseSentDateTerm.

private SearchTerm parseSentDateTerm(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 SentDateTerm(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) SentDateTerm(jakarta.mail.search.SentDateTerm) ParseException(java.text.ParseException) SearchTerm(jakarta.mail.search.SearchTerm) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SearchTerm (jakarta.mail.search.SearchTerm)1 SentDateTerm (jakarta.mail.search.SentDateTerm)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