use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class RenameFunction 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()) && !(args[2].isEmpty())) {
String dn = args[1].getStringValue();
String newDN = args[2].getStringValue();
try {
long ctxID = ((IntegerValue) args[0].itemAt(0)).getLong();
DirContext ctx = (DirContext) JNDIModule.retrieveJNDIContext(context, ctxID);
if (ctx == null) {
logger.error("jndi:rename() - Invalid JNDI context handle provided: {}", ctxID);
} else {
ctx.rename(dn, newDN);
}
} catch (NamingException ne) {
logger.error("jndi:rename() Rename failed for dn [{}], new dn [{}]: ", dn, newDN, ne);
throw (new XPathException(this, "jndi:rename() Rename failed for dn [" + dn + "], new dn [" + newDN + "]: " + ne));
}
}
return (Sequence.EMPTY_SEQUENCE);
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class MailFolderFunctions method getMailFolder.
private Sequence getMailFolder(Sequence[] args, Sequence contextSequence) throws XPathException {
Folder folder;
// was a store handle specified?
if (args[0].isEmpty() || args[1].isEmpty()) {
throw (new XPathException(this, "Store handle and/or folder name not specified"));
}
// get the Store
long storeHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
Store store = MailModule.retrieveStore(context, storeHandle);
if (store == null) {
throw (new XPathException(this, "Invalid Store handle specified"));
}
// get the Folder Name
String name = args[1].getStringValue();
try {
folder = store.getFolder(name);
folder.open(Folder.READ_WRITE);
} catch (MessagingException me) {
throw (new XPathException(this, "Failed to open mail folder", me));
}
return (new IntegerValue(MailModule.storeFolder(context, folder)));
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class DeleteFunction 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:delete() - Invalid JNDI context handle provided: {}", ctxID);
} else {
ctx.destroySubcontext(dn);
}
} catch (NamingException ne) {
logger.error("jndi:delete() Delete failed for dn [{}]: ", dn, ne);
throw (new XPathException(this, "jndi:delete() Delete failed for dn [" + dn + "]: ", ne));
}
}
return (Sequence.EMPTY_SEQUENCE);
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class IndexKeyDocuments method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final NodeSet nodes = args[0].toNodeSet();
final DocumentSet docs = nodes.getDocumentSet();
if (this.getArgumentCount() == 3) {
final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[2].itemAt(0).getStringValue());
// IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[2].itemAt(0).getStringValue()).getWorker();
if (indexWorker == null) {
throw new XPathException(this, "Unknown index: " + args[2].itemAt(0).getStringValue());
}
final Map<String, Object> hints = new HashMap<>();
if (indexWorker instanceof OrderedValuesIndex) {
hints.put(OrderedValuesIndex.START_VALUE, args[1]);
} else {
logger.warn("{} isn't an instance of org.exist.indexing.OrderedIndexWorker. Start value '{}' ignored.", indexWorker.getClass().getName(), args[1]);
}
final Occurrences[] occur = indexWorker.scanIndex(context, docs, nodes, hints);
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getDocuments());
}
} else {
final ValueOccurrences[] occur = context.getBroker().getValueIndex().scanIndexKeys(docs, nodes, (Indexable) args[1]);
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getDocuments());
}
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.xquery.value.IntegerValue in project exist by eXist-db.
the class IndexKeyOccurrences method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final NodeSet nodes = args[0].toNodeSet();
final DocumentSet docs = nodes.getDocumentSet();
if (this.getArgumentCount() == 3) {
final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[2].itemAt(0).getStringValue());
// IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[2].itemAt(0).getStringValue()).getWorker();
if (indexWorker == null) {
throw new XPathException(this, "Unknown index: " + args[2].itemAt(0).getStringValue());
}
final Map<String, Object> hints = new HashMap<>();
if (indexWorker instanceof OrderedValuesIndex) {
hints.put(OrderedValuesIndex.START_VALUE, args[1]);
} else {
logger.warn("{} isn't an instance of org.exist.indexing.OrderedIndexWorker. Start value '{}' ignored.", indexWorker.getClass().getName(), args[1]);
}
final Occurrences[] occur = indexWorker.scanIndex(context, docs, nodes, hints);
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getOccurrences());
}
} else {
ValueOccurrences[] occur = context.getBroker().getValueIndex().scanIndexKeys(docs, nodes, (Indexable) (args[1].itemAt(0)));
if (occur.length == 0) {
occur = context.getBroker().getValueIndex().scanIndexKeys(docs, nodes, null, (Indexable) (args[1].itemAt(0)));
}
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getOccurrences());
}
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
Aggregations