use of org.exist.xquery.XPathException in project exist by eXist-db.
the class MessageListFunctions method parseChildSearchTerms.
private SearchTerm[] parseChildSearchTerms(Node terms) throws XPathException {
// Parent allows multiple child search terms
ArrayList<SearchTerm> st = new ArrayList<>();
NodeList children = terms.getChildNodes();
if (children.getLength() > 0) {
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
st.add(parseSearchTerms(child));
}
} else {
throw (new XPathException(this, "At least one child term is required for term with type: " + ((Element) terms).getAttribute("type")));
}
return st.toArray(new SearchTerm[0]);
}
use of org.exist.xquery.XPathException 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.XPathException 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.XPathException 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);
}
use of org.exist.xquery.XPathException in project exist by eXist-db.
the class GetScheduledJobs method eval.
/**
* evaluate the call to the xquery function, it is really the main entry point of this class.
*
* @param args arguments from the function call
* @param contextSequence the Context Sequence to operate on (not used here internally!)
*
* @return A sequence representing the result of the function call
*
* @throws XPathException DOCUMENT ME!
*
* @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
*/
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Subject user = context.getSubject();
boolean userhasDBARole = user.hasDbaRole();
StringBuilder xmlBuf = new StringBuilder();
int iJobs = 0;
List<String> groups = scheduler.getJobGroupNames();
List<ScheduledJobInfo> scheduledJobs = scheduler.getScheduledJobs();
for (String group : groups) {
if (userhasDBARole || group.equals(UserJob.JOB_GROUP)) {
xmlBuf.append("<" + SchedulerModule.PREFIX + ":group name=\"").append(group).append("\">");
for (ScheduledJobInfo scheduledJob : scheduledJobs) {
if (scheduledJob.getGroup().equals(group)) {
xmlBuf.append("<" + SchedulerModule.PREFIX + ":job name=\"").append(scheduledJob.getName()).append("\">");
xmlBuf.append("<" + SchedulerModule.PREFIX + ":trigger name=\"").append(scheduledJob.getTriggerName()).append("\">");
xmlBuf.append("<expression>");
xmlBuf.append(scheduledJob.getTriggerExpression());
xmlBuf.append("</expression>");
xmlBuf.append("<state>");
xmlBuf.append(scheduledJob.getTriggerState());
xmlBuf.append("</state>");
xmlBuf.append("<start>");
xmlBuf.append(new DateTimeValue(scheduledJob.getStartTime()));
xmlBuf.append("</start>");
xmlBuf.append("<end>");
Date endTime = scheduledJob.getEndTime();
if (endTime != null) {
xmlBuf.append(new DateTimeValue(endTime));
}
xmlBuf.append("</end>");
xmlBuf.append("<previous>");
Date previousTime = scheduledJob.getPreviousFireTime();
if (previousTime != null) {
xmlBuf.append(new DateTimeValue(scheduledJob.getPreviousFireTime()));
}
xmlBuf.append("</previous>");
xmlBuf.append("<next>");
Date nextTime = scheduledJob.getNextFireTime();
if (nextTime != null) {
xmlBuf.append(new DateTimeValue());
}
xmlBuf.append("</next>");
xmlBuf.append("<final>");
Date finalTime = scheduledJob.getFinalFireTime();
if ((endTime != null) && (finalTime != null)) {
xmlBuf.append(new DateTimeValue());
}
xmlBuf.append("</final>");
xmlBuf.append("</" + SchedulerModule.PREFIX + ":trigger>");
xmlBuf.append("</" + SchedulerModule.PREFIX + ":job>");
iJobs++;
}
}
xmlBuf.append("</" + SchedulerModule.PREFIX + ":group>");
}
}
xmlBuf.insert(0, "<" + SchedulerModule.PREFIX + ":jobs xmlns:scheduler=\"" + SchedulerModule.NAMESPACE_URI + "\" count=\"" + iJobs + "\">");
xmlBuf.append("</" + SchedulerModule.PREFIX + ":jobs>");
try {
return ModuleUtils.stringToXML(context, xmlBuf.toString());
} catch (SAXException | IOException se) {
throw new XPathException(this, se.getMessage(), se);
}
}
Aggregations