Search in sources :

Example 1 with FunctionSignature

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

the class InspectFunction method eval.

@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
    final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
    final FunctionSignature sig = ref.getSignature();
    try {
        context.pushDocumentContext();
        final MemTreeBuilder builder = context.getDocumentBuilder();
        final int nodeNr = InspectFunctionHelper.generateDocs(sig, null, builder);
        return builder.getDocument().getNode(nodeNr);
    } finally {
        context.popDocumentContext();
    }
}
Also used : MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) FunctionReference(org.exist.xquery.value.FunctionReference) FunctionSignature(org.exist.xquery.FunctionSignature)

Example 2 with FunctionSignature

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

the class AbstractExtractFunction method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    this.contextSequence = contextSequence;
    if (args[0].isEmpty())
        return Sequence.EMPTY_SEQUENCE;
    // get the entry-filter function and check its types
    if (!(args[1].itemAt(0) instanceof FunctionReference))
        throw new XPathException("No entry-filter function provided.");
    entryFilterFunction = (FunctionReference) args[1].itemAt(0);
    FunctionSignature entryFilterFunctionSig = entryFilterFunction.getSignature();
    if (entryFilterFunctionSig.getArgumentCount() < 3)
        throw new XPathException("entry-filter function must take at least 3 arguments.");
    filterParam = args[2];
    // get the entry-data function and check its types
    if (!(args[3].itemAt(0) instanceof FunctionReference))
        throw new XPathException("No entry-data function provided.");
    entryDataFunction = (FunctionReference) args[3].itemAt(0);
    FunctionSignature entryDataFunctionSig = entryDataFunction.getSignature();
    if (entryDataFunctionSig.getArgumentCount() < 3)
        throw new XPathException("entry-data function must take at least 3 arguments");
    storeParam = args[4];
    try {
        final Charset encoding;
        if ((args.length >= 6) && !args[5].isEmpty()) {
            encoding = Charset.forName(args[5].getStringValue());
        } else {
            encoding = StandardCharsets.UTF_8;
        }
        BinaryValue compressedData = ((BinaryValue) args[0].itemAt(0));
        return processCompressedData(compressedData, encoding);
    } catch (final UnsupportedCharsetException | XMLDBException e) {
        throw new XPathException(this, e.getMessage(), e);
    } finally {
        entryDataFunction.close();
        entryFilterFunction.close();
    }
}
Also used : XPathException(org.exist.xquery.XPathException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Charset(java.nio.charset.Charset) XMLDBException(org.xmldb.api.base.XMLDBException) FunctionSignature(org.exist.xquery.FunctionSignature)

Example 3 with FunctionSignature

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

the class AdaptiveWriter method writeFunctionItem.

private void writeFunctionItem(final FunctionReference item) throws XPathException, SAXException {
    final FunctionReference ref = item;
    final FunctionSignature signature = ref.getSignature();
    final QName fn = signature.getName();
    final String name;
    if (fn == InlineFunction.INLINE_FUNCTION_QNAME) {
        name = "(anonymous-function)";
    } else {
        switch(fn.getNamespaceURI()) {
            case Namespaces.XPATH_FUNCTIONS_NS:
                name = "fn:" + fn.getLocalPart();
                break;
            case Namespaces.XPATH_FUNCTIONS_MATH_NS:
                name = MathModule.PREFIX + ':' + fn.getLocalPart();
                break;
            case MapModule.NAMESPACE_URI:
                name = MapModule.PREFIX + ':' + fn.getLocalPart();
                break;
            case ArrayModule.NAMESPACE_URI:
                name = ArrayModule.PREFIX + ':' + fn.getLocalPart();
                break;
            case Namespaces.SCHEMA_NS:
                name = "xs:" + fn.getLocalPart();
                break;
            default:
                name = "Q{" + fn.getNamespaceURI() + '}' + fn.getLocalPart();
                break;
        }
    }
    writeText(name + '#' + signature.getArgumentCount());
}
Also used : QName(org.exist.dom.QName) FunctionSignature(org.exist.xquery.FunctionSignature)

Aggregations

FunctionSignature (org.exist.xquery.FunctionSignature)3 Charset (java.nio.charset.Charset)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 QName (org.exist.dom.QName)1 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)1 XPathException (org.exist.xquery.XPathException)1 FunctionReference (org.exist.xquery.value.FunctionReference)1 XMLDBException (org.xmldb.api.base.XMLDBException)1