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));
}
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)));
}
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());
}
}
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);
}
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);
}
Aggregations