use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunEnvironment method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (!context.getSubject().hasDbaRole()) {
final String txt = "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to call this function.";
logger.error(txt);
return Sequence.EMPTY_SEQUENCE;
}
if (isCalledAs("available-environment-variables")) {
final Sequence result = new ValueSequence();
final Map<String, String> env = context.getEnvironmentVariables();
for (final String key : env.keySet()) {
result.add(new StringValue(key));
}
return result;
} else {
if (args[0].isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
final String parameter = args[0].itemAt(0).getStringValue();
final String value = context.getEnvironmentVariables().get(parameter);
if (value == null) {
return Sequence.EMPTY_SEQUENCE;
}
return new StringValue(value);
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunIRIToURI 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 (contextItem != null) {
contextSequence = contextItem.toSequence();
}
Sequence result;
final Sequence seq = getArgument(0).eval(contextSequence);
if (seq.isEmpty()) {
result = StringValue.EMPTY_STRING;
} else {
String value;
value = URIUtils.iriToURI(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 FunInScopePrefixes 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 Map<String, String> prefixes = collectPrefixes(context, (NodeValue) args[0].itemAt(0));
final ValueSequence result = new ValueSequence();
for (final String prefix : prefixes.keySet()) {
// The predefined namespaces (e.g. "exist" for temporary nodes) could have been removed from the static context
if (!(context.getURIForPrefix(prefix) == null && ("exist".equals(prefix) || "xs".equals(prefix) || "xsi".equals(prefix) || "wdt".equals(prefix) || "fn".equals(prefix) || "local".equals(prefix)))) {
result.add(new StringValue(prefix));
}
}
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 RangeIndexConfigAttributeCondition method find.
@Override
public boolean find(Predicate predicate) {
final Expression inner = this.getInnerExpression(predicate);
Operator operator;
Expression lhe;
Expression rhe;
// get the type of the expression inside the predicate and determine right and left hand arguments
if (inner instanceof GeneralComparison) {
final GeneralComparison comparison = (GeneralComparison) inner;
operator = RangeQueryRewriter.getOperator(inner);
lhe = comparison.getLeft();
rhe = comparison.getRight();
} else if (inner instanceof InternalFunctionCall) {
// calls to matches() will not have been rewritten to a comparison, so check for function call
final Function func = ((InternalFunctionCall) inner).getFunction();
if (func.isCalledAs("matches")) {
operator = Operator.MATCH;
lhe = func.getArgument(0);
rhe = func.getArgument(1);
lhe = unwrapSubExpression(lhe);
rhe = unwrapSubExpression(rhe);
} else {
// predicate expression cannot be parsed as condition
return false;
}
} else {
// predicate expression cannot be parsed as condition
return false;
}
// find the attribute name and value pair from the predicate to check against
// first assume attribute is on the left and value is on the right
LocationStep testStep = findLocationStep(lhe);
AtomicValue testValue = findAtomicValue(rhe);
switch(this.operator) {
case EQ:
case NE:
// check the other way around
if (testStep == null && testValue == null) {
testStep = findLocationStep(rhe);
testValue = findAtomicValue(lhe);
}
case GT:
case LT:
case GE:
case LE:
// but the operator has to be inverted
if (testStep == null && testValue == null) {
testStep = findLocationStep(rhe);
testValue = findAtomicValue(lhe);
operator = invertOrdinalOperator(operator);
}
}
if (testStep != null && testValue != null) {
final QName qname = testStep.getTest().getName();
Comparable foundValue;
Comparable requiredValue;
boolean valueTypeMatches;
try {
if (this.numericComparison) {
valueTypeMatches = testValue instanceof NumericValue;
requiredValue = this.numericValue;
foundValue = testValue.toJavaObject(Double.class);
} else {
valueTypeMatches = testValue instanceof StringValue;
if (this.caseSensitive) {
requiredValue = this.getLowercaseValue();
foundValue = testValue.getStringValue().toLowerCase();
} else {
requiredValue = this.value;
foundValue = testValue.getStringValue();
}
}
if (qname.getNameType() == ElementValue.ATTRIBUTE && operator.equals(this.operator) && qname.equals(this.attribute) && valueTypeMatches && foundValue.equals(requiredValue)) {
return true;
}
} catch (XPathException e) {
RangeIndex.LOG.error("Value conversion error when testing predicate for condition, value: {}", testValue.toString());
RangeIndex.LOG.error(e);
}
}
return false;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class AttributeConstructor method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.xquery.StaticContext, org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
final StringBuilder buf = new StringBuilder();
for (final Object next : contents) {
if (next instanceof Expression) {
evalEnclosedExpr(((Expression) next).eval(contextSequence, contextItem), buf);
} else {
buf.append(next);
}
}
// TODO : include that tricky attribute normalization here
final StringValue result = new StringValue(buf.toString());
// result.expand();
return result;
}
Aggregations