Search in sources :

Example 66 with StringValue

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

the class FunNormalizeSpace 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();
    }
    String value = null;
    if (getSignature().getArgumentCount() == 0) {
        if (contextSequence == null) {
            throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");
        }
        value = !contextSequence.isEmpty() ? contextSequence.itemAt(0).getStringValue() : "";
    } else {
        final Sequence seq = getArgument(0).eval(contextSequence);
        if (seq == null) {
            throw new XPathException(this, ErrorCodes.XPDY0002, "Undefined context item");
        }
        if (!seq.isEmpty()) {
            value = seq.getStringValue();
        }
    }
    final Sequence result;
    if (value == null) {
        result = StringValue.EMPTY_STRING;
    } else {
        result = new StringValue(normalize(value));
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : XPathException(org.exist.xquery.XPathException) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 67 with StringValue

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

the class FunCodepointsToString 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 = StringValue.EMPTY_STRING;
    } else {
        final StringBuilder buf = new StringBuilder();
        for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
            final long next = ((NumericValue) i.nextItem()).getLong();
            if (next < 0 || next > Integer.MAX_VALUE || !XMLChar.isValid((int) next)) {
                throw new XPathException(this, ErrorCodes.FOCH0001, "Codepoint " + next + " is not a valid character.");
            }
            if (next < 65536) {
                buf.append((char) next);
            } else {
                // output a surrogate pair
                buf.append(XMLChar.highSurrogate((int) next));
                buf.append(XMLChar.lowSurrogate((int) next));
            }
        }
        result = new StringValue(buf.toString());
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : SequenceIterator(org.exist.xquery.value.SequenceIterator) XPathException(org.exist.xquery.XPathException) Sequence(org.exist.xquery.value.Sequence) NumericValue(org.exist.xquery.value.NumericValue) StringValue(org.exist.xquery.value.StringValue)

Example 68 with StringValue

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

the class FunConcat 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());
        }
    }
    if (getArgumentCount() < 2) {
        throw new XPathException(this, ErrorCodes.XPST0017, "concat() requires at least two arguments");
    }
    final StringBuilder concat = new StringBuilder();
    for (int i = 0; i < getArgumentCount(); i++) {
        concat.append(getArgument(i).eval(contextSequence, contextItem).getStringValue());
    }
    final Sequence result = new StringValue(concat.toString());
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : XPathException(org.exist.xquery.XPathException) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 69 with StringValue

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

the class FunDefaultCollation 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);
        }
    }
    final Sequence result = new StringValue(context.getDefaultCollation());
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 70 with StringValue

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

the class FunEncodeForURI 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());
        }
    }
    Sequence result;
    final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
    if (seq.isEmpty()) {
        // If $uri-part is the empty sequence, returns the zero-length string.
        result = StringValue.EMPTY_STRING;
    } else {
        String value;
        value = URIUtils.encodeForURI(seq.getStringValue());
        result = new StringValue(value);
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Aggregations

StringValue (org.exist.xquery.value.StringValue)96 Sequence (org.exist.xquery.value.Sequence)49 XPathException (org.exist.xquery.XPathException)40 ValueSequence (org.exist.xquery.value.ValueSequence)27 IOException (java.io.IOException)11 PermissionDeniedException (org.exist.security.PermissionDeniedException)10 Item (org.exist.xquery.value.Item)10 XQueryContext (org.exist.xquery.XQueryContext)8 Txn (org.exist.storage.txn.Txn)7 AnyURIValue (org.exist.xquery.value.AnyURIValue)7 QName (org.exist.dom.QName)6 LockException (org.exist.util.LockException)6 NodeValue (org.exist.xquery.value.NodeValue)6 Path (java.nio.file.Path)5 EXistException (org.exist.EXistException)5 TriggerException (org.exist.collections.triggers.TriggerException)5 DocumentImpl (org.exist.dom.persistent.DocumentImpl)5 StoredNode (org.exist.dom.persistent.StoredNode)5 NotificationService (org.exist.storage.NotificationService)5 MimeType (org.exist.util.MimeType)5