Search in sources :

Example 61 with StringValue

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

the class FunStringJoin method eval.

/* (non-Javadoc)
	 * @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 {
    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);
        }
    }
    String sep = null;
    if (getArgumentCount() == 2) {
        sep = args[1].getStringValue();
        if (sep.isEmpty()) {
            sep = null;
        }
    }
    final StringBuilder out = new StringBuilder();
    Item next;
    boolean gotOne = false;
    for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
        next = i.nextItem();
        if (gotOne && sep != null) {
            out.append(sep);
        }
        out.append(next.getStringValue());
        gotOne = true;
    }
    final Sequence result = new StringValue(out.toString());
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : Item(org.exist.xquery.value.Item) SequenceIterator(org.exist.xquery.value.SequenceIterator) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 62 with StringValue

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

the class FunSubstringAfter 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 Expression arg0 = getArgument(0);
    final Expression arg1 = getArgument(1);
    if (contextItem != null) {
        contextSequence = contextItem.toSequence();
    }
    final Sequence seq1 = arg0.eval(contextSequence);
    final Sequence seq2 = arg1.eval(contextSequence);
    String value;
    String cmp;
    Sequence result;
    if (seq1.isEmpty()) {
        value = StringValue.EMPTY_STRING.getStringValue();
    } else {
        value = seq1.getStringValue();
    }
    if (seq2.isEmpty()) {
        cmp = StringValue.EMPTY_STRING.getStringValue();
    } else {
        cmp = seq2.getStringValue();
    }
    if (cmp.isEmpty()) {
        result = new StringValue(value);
    } else {
        final Collator collator = getCollator(contextSequence, contextItem, 3);
        final int p = Collations.indexOf(collator, value, cmp);
        if (p == Constants.STRING_NOT_FOUND) {
            result = StringValue.EMPTY_STRING;
        } else {
            result = new StringValue(p + cmp.length() < value.length() ? value.substring(p + cmp.length()) : "");
        }
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : Expression(org.exist.xquery.Expression) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue) Collator(com.ibm.icu.text.Collator)

Example 63 with StringValue

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

the class QNameFunctions method eval.

/* (non-Javadoc)
	 * @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 {
    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 QNameValue value = (QNameValue) args[0].itemAt(0);
        final QName qname = value.getQName();
        if (isCalledAs("prefix-from-QName")) {
            final String prefix = qname.getPrefix();
            if (prefix == null || prefix.isEmpty()) {
                result = Sequence.EMPTY_SEQUENCE;
            } else {
                result = new StringValue(prefix, Type.NCNAME);
            }
        } else if (isCalledAs("local-name-from-QName")) {
            result = new StringValue(qname.getLocalPart(), Type.NCNAME);
        } else {
            // fn:namespace-uri-from-QName
            String uri = qname.getNamespaceURI();
            if (uri == null) {
                uri = "";
            }
            result = new AnyURIValue(uri);
        }
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : QName(org.exist.dom.QName) QNameValue(org.exist.xquery.value.QNameValue) AnyURIValue(org.exist.xquery.value.AnyURIValue) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue)

Example 64 with StringValue

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

the class FunEscapeHTMLURI 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()) {
        result = StringValue.EMPTY_STRING;
    } else {
        final String value = URIUtils.escapeHtmlURI(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)

Example 65 with StringValue

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

the class FunSubstringBefore 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 Expression arg0 = getArgument(0);
    final Expression arg1 = getArgument(1);
    if (contextItem != null) {
        contextSequence = contextItem.toSequence();
    }
    final Sequence seq1 = arg0.eval(contextSequence);
    final Sequence seq2 = arg1.eval(contextSequence);
    String value;
    String cmp;
    Sequence result;
    if (seq1.isEmpty()) {
        value = StringValue.EMPTY_STRING.getStringValue();
    } else {
        value = seq1.getStringValue();
    }
    if (seq2.isEmpty()) {
        cmp = StringValue.EMPTY_STRING.getStringValue();
    } else {
        cmp = seq2.getStringValue();
    }
    if (cmp.isEmpty()) {
        result = StringValue.EMPTY_STRING;
    } else {
        final Collator collator = getCollator(contextSequence, contextItem, 3);
        final int p = Collations.indexOf(collator, value, cmp);
        if (p == Constants.STRING_NOT_FOUND) {
            result = StringValue.EMPTY_STRING;
        } else {
            result = new StringValue(value.substring(0, p));
        }
    }
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().end(this, "", result);
    }
    return result;
}
Also used : Expression(org.exist.xquery.Expression) Sequence(org.exist.xquery.value.Sequence) StringValue(org.exist.xquery.value.StringValue) Collator(com.ibm.icu.text.Collator)

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