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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations