Search in sources :

Example 26 with IntegerValue

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

the class FunCompare method eval.

public Sequence eval(Sequence contextSequence, Item contextItem) 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);
        }
        if (contextItem != null) {
            context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
        }
    }
    final Sequence seq1 = getArgument(0).eval(contextSequence, contextItem);
    final Sequence seq2 = getArgument(1).eval(contextSequence, contextItem);
    Sequence result;
    if (seq1.isEmpty() || seq2.isEmpty()) {
        result = Sequence.EMPTY_SEQUENCE;
    } else {
        final Collator collator = getCollator(contextSequence, contextItem, 3);
        final int comparison = Collations.compare(collator, seq1.getStringValue(), seq2.getStringValue());
        if (comparison == Constants.EQUAL) {
            result = new IntegerValue(Constants.EQUAL);
        } else if (comparison < 0) {
            result = new IntegerValue(Constants.INFERIOR);
        } else {
            result = new IntegerValue(Constants.SUPERIOR);
        }
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence) Collator(com.ibm.icu.text.Collator)

Example 27 with IntegerValue

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

the class FunCount method eval.

@Override
public Sequence eval(Sequence contextSequence, final Item contextItem) 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);
        }
        if (contextItem != null) {
            context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
        }
    }
    if (contextItem != null) {
        contextSequence = contextItem.toSequence();
    }
    final Sequence result;
    if (getArgumentCount() == 0) {
        result = IntegerValue.ZERO;
    } else {
        final Sequence seq = getArgument(0).eval(contextSequence);
        result = new IntegerValue(seq.getItemCountLong());
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence)

Example 28 with IntegerValue

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

the class FunGetDurationComponent 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.length == 0 || args[0].isEmpty()) {
        result = Sequence.EMPTY_SEQUENCE;
    } else {
        final Sequence arg = args[0];
        final DurationValue duration = new DurationValue(((DurationValue) arg.itemAt(0)).getCanonicalDuration());
        if (isCalledAs("days-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.DAY));
        } else if (isCalledAs("hours-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.HOUR));
        } else if (isCalledAs("minutes-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.MINUTE));
        } else if (isCalledAs("seconds-from-duration")) {
            if (duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS) == null) {
                result = new DecimalValue(0);
            } else {
                result = new DecimalValue((BigDecimal) duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS));
            }
            if (duration.getCanonicalDuration().getSign() < 0) {
                result = ((DecimalValue) result).negate();
            }
        } else if (isCalledAs("months-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.MONTH));
        } else if (isCalledAs("years-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.YEAR));
        } else {
            logger.error("can't handle function {}", getName().getLocalPart());
            throw new Error("can't handle function " + getName().getLocalPart());
        }
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : DurationValue(org.exist.xquery.value.DurationValue) DecimalValue(org.exist.xquery.value.DecimalValue) IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence)

Example 29 with IntegerValue

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

the class FunGetDateComponent 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.length == 0 || args[0].isEmpty()) {
        result = Sequence.EMPTY_SEQUENCE;
    } else {
        final Sequence arg = args[0];
        final AbstractDateTimeValue date = (AbstractDateTimeValue) arg.itemAt(0);
        if (isCalledAs("day-from-dateTime") || isCalledAs("day-from-date")) {
            result = new IntegerValue(date.getPart(DateValue.DAY), Type.INTEGER);
        } else if (isCalledAs("month-from-dateTime") || isCalledAs("month-from-date")) {
            result = new IntegerValue(date.getPart(DateValue.MONTH), Type.INTEGER);
        } else if (isCalledAs("year-from-dateTime") || isCalledAs("year-from-date")) {
            result = new IntegerValue(date.getPart(DateValue.YEAR), Type.INTEGER);
        } else if (isCalledAs("hours-from-dateTime") || isCalledAs("hours-from-time")) {
            result = new IntegerValue(date.getPart(DateValue.HOUR), Type.INTEGER);
        } else if (isCalledAs("minutes-from-dateTime") || isCalledAs("minutes-from-time")) {
            result = new IntegerValue(date.getPart(DateValue.MINUTE), Type.INTEGER);
        } else if (isCalledAs("seconds-from-dateTime") || isCalledAs("seconds-from-time")) {
            result = new IntegerValue(date.calendar.getSecond()).convertTo(Type.DECIMAL);
            if (date.calendar.getFractionalSecond() != null) {
                result = ((DecimalValue) result).plus(new DecimalValue(date.calendar.getFractionalSecond()));
            }
        } else if (isCalledAs("timezone-from-dateTime") || isCalledAs("timezone-from-date") || isCalledAs("timezone-from-time")) {
            result = date.getTimezone();
        } else {
            logger.error("can't handle function {}", getName().getLocalPart());
            throw new Error("can't handle function " + getName().getLocalPart());
        }
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : AbstractDateTimeValue(org.exist.xquery.value.AbstractDateTimeValue) DecimalValue(org.exist.xquery.value.DecimalValue) IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence)

Example 30 with IntegerValue

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

the class XQueryDeclareContextItemTest method declareContextItemExternal.

@Test
public void declareContextItemExternal() throws EXistException, PermissionDeniedException, XPathException {
    final String query = "xquery version \"3.0\";\n" + "declare context item external; \n" + ". + 4";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final XQuery xquery = pool.getXQueryService();
    try (final DBBroker broker = pool.getBroker()) {
        final Sequence result = xquery.execute(broker, query, new IntegerValue(3));
        assertEquals(1, result.getItemCount());
        assertEquals(7, (int) result.itemAt(0).toJavaObject(int.class));
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) IntegerValue(org.exist.xquery.value.IntegerValue) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

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