Search in sources :

Example 6 with IntegerValue

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

the class MailSessionFunctions method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    Properties props = new Properties();
    if (args.length == 1) {
        // try and get the session properties
        props = ParametersExtractor.parseProperties(((NodeValue) args[0].itemAt(0)).getNode());
    }
    Session session = Session.getInstance(props, null);
    return new IntegerValue(MailModule.storeSession(context, session));
}
Also used : NodeValue(org.exist.xquery.value.NodeValue) IntegerValue(org.exist.xquery.value.IntegerValue) Properties(java.util.Properties) Session(jakarta.mail.Session)

Example 7 with IntegerValue

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

the class MessageListFunctions method getMessageList.

// ***************************************************************************
// *
// *    Function Implementation Methods
// *
// ***************************************************************************/
private Sequence getMessageList(Sequence[] args, Sequence contextSequence) throws XPathException {
    Message[] msgList;
    // was a folder handle specified?
    if (args[0].isEmpty()) {
        throw (new XPathException(this, "Folder handle not specified"));
    }
    // get the Folder
    long folderHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
    Folder folder = MailModule.retrieveFolder(context, folderHandle);
    if (folder == null) {
        throw (new XPathException(this, "Invalid Folder handle specified"));
    }
    try {
        msgList = folder.getMessages();
        prefetchMessages(folder, msgList);
    } catch (MessagingException me) {
        throw (new XPathException(this, "Failed to get mail list", me));
    }
    return (new IntegerValue(MailModule.storeMessageList(context, msgList, folderHandle)));
}
Also used : Message(jakarta.mail.Message) XPathException(org.exist.xquery.XPathException) MessagingException(jakarta.mail.MessagingException) IntegerValue(org.exist.xquery.value.IntegerValue) Folder(jakarta.mail.Folder)

Example 8 with IntegerValue

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

the class ScaleFunction method eval.

/**
 * evaluate the call to the xquery scale() function,
 * it is really the main entry point of this class
 *
 * @param args		arguments from the scale() function call
 * @param contextSequence	the Context Sequence to operate on (not used here internally!)
 * @return		A sequence representing the result of the scale() function call
 *
 * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
 */
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    // was an image and a mime-type speficifed
    if (args[0].isEmpty() || args[2].isEmpty()) {
        return Sequence.EMPTY_SEQUENCE;
    }
    // get the maximum dimensions to scale to
    int maxHeight = MAXHEIGHT;
    int maxWidth = MAXWIDTH;
    if (!args[1].isEmpty()) {
        maxHeight = ((IntegerValue) args[1].itemAt(0)).getInt();
        if (args[1].hasMany())
            maxWidth = ((IntegerValue) args[1].itemAt(1)).getInt();
    }
    // get the mime-type
    String mimeType = args[2].itemAt(0).getStringValue();
    String formatName = mimeType.substring(mimeType.indexOf("/") + 1);
    // TODO currently ONLY tested for JPEG!!!
    Image image = null;
    BufferedImage bImage = null;
    try (// get the image data
    InputStream inputStream = ((BinaryValue) args[0].itemAt(0)).getInputStream()) {
        image = ImageIO.read(inputStream);
        if (image == null) {
            logger.error("Unable to read image data!");
            return Sequence.EMPTY_SEQUENCE;
        }
        // scale the image
        bImage = ImageModule.createThumb(image, maxHeight, maxWidth);
        // get the new scaled image
        try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
            ImageIO.write(bImage, formatName, os);
            // return the new scaled image data
            return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), os.toInputStream());
        }
    } catch (Exception e) {
        throw new XPathException(this, e.getMessage());
    }
}
Also used : XPathException(org.exist.xquery.XPathException) BinaryValueFromInputStream(org.exist.xquery.value.BinaryValueFromInputStream) InputStream(java.io.InputStream) IntegerValue(org.exist.xquery.value.IntegerValue) BinaryValue(org.exist.xquery.value.BinaryValue) Base64BinaryValueType(org.exist.xquery.value.Base64BinaryValueType) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) XPathException(org.exist.xquery.XPathException)

Example 9 with IntegerValue

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

the class CreateFunction method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    // Was context handle or DN specified?
    if (!(args[0].isEmpty()) && !(args[1].isEmpty())) {
        String dn = args[1].getStringValue();
        try {
            long ctxID = ((IntegerValue) args[0].itemAt(0)).getLong();
            DirContext ctx = (DirContext) JNDIModule.retrieveJNDIContext(context, ctxID);
            if (ctx == null) {
                logger.error("jndi:create() - Invalid JNDI context handle provided: {}", ctxID);
            } else {
                BasicAttributes attributes = JNDIModule.parseAttributes(args[2]);
                if (attributes.size() > 0) {
                    ctx.createSubcontext(dn, attributes);
                } else {
                    ctx.createSubcontext(dn);
                }
            }
        } catch (NamingException ne) {
            logger.error("jndi:create() Create failed for dn [{}]: ", dn, ne);
            throw (new XPathException(this, "jndi:create() Create failed for dn [" + dn + "]: " + ne));
        }
    }
    return (Sequence.EMPTY_SEQUENCE);
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) NamingException(javax.naming.NamingException) DirContext(javax.naming.directory.DirContext)

Example 10 with IntegerValue

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

the class MailFolderFunctions method closeMailFolder.

private Sequence closeMailFolder(Sequence[] args, Sequence contextSequence) throws XPathException {
    // was a folder handle specified?
    if (args[0].isEmpty()) {
        throw (new XPathException(this, "Folder handle not specified"));
    }
    boolean expunge = ((BooleanValue) args[1].itemAt(0)).effectiveBooleanValue();
    // get the Folder
    long folderHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
    Folder folder = MailModule.retrieveFolder(context, folderHandle);
    if (folder == null) {
        throw (new XPathException(this, "Invalid Folder handle specified"));
    }
    try {
        folder.close(expunge);
    } catch (MessagingException me) {
        throw (new XPathException(this, "Failed to close mail folder", me));
    } finally {
        MailModule.removeFolder(context, folderHandle);
    }
    return (Sequence.EMPTY_SEQUENCE);
}
Also used : XPathException(org.exist.xquery.XPathException) MessagingException(jakarta.mail.MessagingException) BooleanValue(org.exist.xquery.value.BooleanValue) IntegerValue(org.exist.xquery.value.IntegerValue) Folder(jakarta.mail.Folder)

Aggregations

IntegerValue (org.exist.xquery.value.IntegerValue)63 Sequence (org.exist.xquery.value.Sequence)33 XPathException (org.exist.xquery.XPathException)32 BrokerPool (org.exist.storage.BrokerPool)11 DBBroker (org.exist.storage.DBBroker)11 Test (org.junit.Test)11 Txn (org.exist.storage.txn.Txn)8 MessagingException (jakarta.mail.MessagingException)7 StringInputSource (org.exist.util.StringInputSource)7 NamingException (javax.naming.NamingException)6 DirContext (javax.naming.directory.DirContext)6 QName (org.exist.dom.QName)6 Source (org.exist.source.Source)6 StringSource (org.exist.source.StringSource)6 InputStream (java.io.InputStream)5 Map (java.util.Map)5 StringValue (org.exist.xquery.value.StringValue)5 ValueSequence (org.exist.xquery.value.ValueSequence)5 Folder (jakarta.mail.Folder)4 Image (java.awt.Image)4