Search in sources :

Example 36 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class MessageListFunctions method parseBodyTerm.

private SearchTerm parseBodyTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String pattern = ((Element) terms).getAttribute("pattern");
    if (pattern != null && !pattern.isEmpty()) {
        st = new BodyTerm(pattern);
    } else {
        throw (new XPathException(this, "Pattern attribute must be specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) BodyTerm(jakarta.mail.search.BodyTerm) SearchTerm(jakarta.mail.search.SearchTerm)

Example 37 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class MessageListFunctions method parseComparisonAttribute.

private int parseComparisonAttribute(Node terms) throws XPathException {
    int cp = ComparisonTerm.EQ;
    String comp = ((Element) terms).getAttribute("comparison");
    if (comp != null && !comp.isEmpty()) {
        if (comp.equalsIgnoreCase("eq")) {
            cp = ComparisonTerm.EQ;
        } else if (comp.equalsIgnoreCase("ge")) {
            cp = ComparisonTerm.GE;
        } else if (comp.equalsIgnoreCase("gt")) {
            cp = ComparisonTerm.GT;
        } else if (comp.equalsIgnoreCase("le")) {
            cp = ComparisonTerm.LE;
        } else if (comp.equalsIgnoreCase("lt")) {
            cp = ComparisonTerm.LT;
        } else if (comp.equalsIgnoreCase("ne")) {
            cp = ComparisonTerm.NE;
        } else {
            throw (new XPathException(this, "Invalid comparison: " + comp + ", for term with type: " + ((Element) terms).getAttribute("type")));
        }
    } else {
        throw (new XPathException(this, "comparison attribute must be specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (cp);
}
Also used : XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element)

Example 38 with XPathException

use of org.exist.xquery.XPathException 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)

Example 39 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class MessageListFunctions method parseFromTerm.

private SearchTerm parseFromTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String pattern = ((Element) terms).getAttribute("pattern");
    if (pattern != null && !pattern.isEmpty()) {
        st = new FromStringTerm(pattern);
    } else {
        throw (new XPathException(this, "Pattern attribute must be specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : FromStringTerm(jakarta.mail.search.FromStringTerm) XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) SearchTerm(jakarta.mail.search.SearchTerm)

Example 40 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class MessageListFunctions method parseRecipientTerm.

private SearchTerm parseRecipientTerm(Node terms) throws XPathException {
    SearchTerm st = null;
    String pattern = ((Element) terms).getAttribute("pattern");
    String type = ((Element) terms).getAttribute("recipientType");
    if (StringUtils.isEmpty(type)) {
        throw (new XPathException(this, "recipientType not specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    if (pattern != null && !pattern.isEmpty()) {
        Message.RecipientType rtype = null;
        if (type.equalsIgnoreCase("to")) {
            rtype = Message.RecipientType.TO;
        } else if (type.equalsIgnoreCase("cc")) {
            rtype = Message.RecipientType.CC;
        } else if (type.equalsIgnoreCase("bcc")) {
            rtype = Message.RecipientType.BCC;
        } else {
            throw (new XPathException(this, "Invalid recipientType: " + type + ", for term with type: " + ((Element) terms).getAttribute("type")));
        }
        st = new RecipientStringTerm(rtype, pattern);
    } else {
        throw (new XPathException(this, "Pattern attribute must be specified for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}
Also used : Message(jakarta.mail.Message) RecipientStringTerm(jakarta.mail.search.RecipientStringTerm) XPathException(org.exist.xquery.XPathException) Element(org.w3c.dom.Element) SearchTerm(jakarta.mail.search.SearchTerm)

Aggregations

XPathException (org.exist.xquery.XPathException)306 Sequence (org.exist.xquery.value.Sequence)86 IOException (java.io.IOException)61 SAXException (org.xml.sax.SAXException)43 StringValue (org.exist.xquery.value.StringValue)40 PermissionDeniedException (org.exist.security.PermissionDeniedException)34 NodeValue (org.exist.xquery.value.NodeValue)34 DBBroker (org.exist.storage.DBBroker)32 IntegerValue (org.exist.xquery.value.IntegerValue)32 ValueSequence (org.exist.xquery.value.ValueSequence)27 Item (org.exist.xquery.value.Item)26 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)24 EXistException (org.exist.EXistException)23 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)22 BrokerPool (org.exist.storage.BrokerPool)21 Txn (org.exist.storage.txn.Txn)21 XQueryContext (org.exist.xquery.XQueryContext)21 Element (org.w3c.dom.Element)21 XQuery (org.exist.xquery.XQuery)20