use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class EchoFunction method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
// is argument the empty sequence?
if (args[0].isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
// iterate through the argument sequence and echo each item
ValueSequence result = new ValueSequence();
for (SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
String str = i.nextItem().getStringValue();
result.add(new StringValue("echo: " + str));
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class ExampleFunctions method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
switch(getName().getLocalPart()) {
case FS_HELLO_WORLD_NAME:
return sayHello(Optional.of(new StringValue("World")));
case FS_SAY_HELLO_NAME:
final Optional<StringValue> name = args[0].isEmpty() ? Optional.empty() : Optional.of((StringValue) args[0].itemAt(0));
return sayHello(name);
case FS_ADD_NAME:
final IntegerValue a = (IntegerValue) args[0].itemAt(0);
final IntegerValue b = (IntegerValue) args[1].itemAt(0);
return add(a, b);
default:
throw new XPathException(this, "No function: " + getName() + "#" + getSignature().getArgumentCount());
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class InstallFunction method getBinaryDoc.
private LockedDocument getBinaryDoc(final String path) throws XPathException {
try {
final XmldbURI uri = XmldbURI.createInternal(path);
final LockedDocument lockedDoc = context.getBroker().getXMLResource(uri, LockMode.READ_LOCK);
if (lockedDoc == null) {
throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not .xar resource", new StringValue(path));
} else if (lockedDoc.getDocument().getResourceType() != DocumentImpl.BINARY_FILE) {
lockedDoc.close();
throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not a valid .xar, it's not a binary resource", new StringValue(path));
}
return lockedDoc;
} catch (PermissionDeniedException e) {
throw new XPathException(this, EXPathErrorCode.EXPDY003, e.getMessage(), new StringValue(path), e);
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class XQueryTrigger method getScript.
private CompiledXQuery getScript(boolean isBefore, DBBroker broker, Txn transaction, XmldbURI src) throws TriggerException {
// get the query
final Source query = getQuerySource(broker);
if (query == null) {
return null;
}
// avoid infinite recursion by allowing just one trigger per thread
if (isBefore && !TriggerStatePerThread.verifyUniqueTriggerPerThreadBeforePrepare(this, src)) {
return null;
} else if (!isBefore && !TriggerStatePerThread.verifyUniqueTriggerPerThreadBeforeFinish(this, src)) {
return null;
}
TriggerStatePerThread.setTransaction(transaction);
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
if (query instanceof DBSource) {
context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + ((DBSource) query).getDocumentPath().removeLastSegment().toString());
}
CompiledXQuery compiledQuery;
try {
// compile the XQuery
compiledQuery = service.compile(context, query);
// declare user defined parameters as external variables
for (Object o : userDefinedVariables.keySet()) {
final String varName = (String) o;
final String varValue = userDefinedVariables.getProperty(varName);
context.declareVariable(bindingPrefix + varName, new StringValue(varValue));
}
// reset & prepareForExecution for execution
compiledQuery.reset();
context.getWatchDog().reset();
// do any preparation before execution
context.prepareForExecution();
return compiledQuery;
} catch (final XPathException | IOException | PermissionDeniedException e) {
LOG.warn(e.getMessage(), e);
TriggerStatePerThread.setTriggerRunningState(TriggerStatePerThread.NO_TRIGGER_RUNNING, this, null);
TriggerStatePerThread.setTransaction(null);
throw new TriggerException(PREPARE_EXCEPTION_MESSAGE, e);
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunIdRef method getIdRef.
private void getIdRef(NodeSet result, DocumentSet docs, String id) throws XPathException {
final NodeSet attribs = context.getBroker().getValueIndex().find(context.getWatchDog(), Comparison.EQ, docs, null, -1, null, new StringValue(id, Type.IDREF));
for (final NodeProxy n : attribs) {
n.setNodeType(Node.ATTRIBUTE_NODE);
result.add(n);
}
}
Aggregations