Search in sources :

Example 56 with IntegerValue

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);
}
Also used : XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) NamingException(javax.naming.NamingException) DirContext(javax.naming.directory.DirContext)

Example 57 with IntegerValue

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)));
}
Also used : XPathException(org.exist.xquery.XPathException) MessagingException(jakarta.mail.MessagingException) IntegerValue(org.exist.xquery.value.IntegerValue) Store(jakarta.mail.Store) Folder(jakarta.mail.Folder)

Example 58 with IntegerValue

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);
}
Also used : XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) NamingException(javax.naming.NamingException) DirContext(javax.naming.directory.DirContext)

Example 59 with IntegerValue

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;
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) XPathException(org.exist.xquery.XPathException) HashMap(java.util.HashMap) IntegerValue(org.exist.xquery.value.IntegerValue) ValueOccurrences(org.exist.util.ValueOccurrences) OrderedValuesIndex(org.exist.indexing.OrderedValuesIndex) Occurrences(org.exist.util.Occurrences) ValueOccurrences(org.exist.util.ValueOccurrences) Sequence(org.exist.xquery.value.Sequence) IndexWorker(org.exist.indexing.IndexWorker) DocumentSet(org.exist.dom.persistent.DocumentSet)

Example 60 with IntegerValue

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;
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) XPathException(org.exist.xquery.XPathException) HashMap(java.util.HashMap) IntegerValue(org.exist.xquery.value.IntegerValue) ValueOccurrences(org.exist.util.ValueOccurrences) OrderedValuesIndex(org.exist.indexing.OrderedValuesIndex) Occurrences(org.exist.util.Occurrences) ValueOccurrences(org.exist.util.ValueOccurrences) Sequence(org.exist.xquery.value.Sequence) IndexWorker(org.exist.indexing.IndexWorker) Indexable(org.exist.storage.Indexable) DocumentSet(org.exist.dom.persistent.DocumentSet)

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