Search in sources :

Example 16 with XSAnyURI

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI in project webtools.sourceediting by eclipse.

the class FnDocumentUri method document_uri.

/**
 * Document-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:document-uri operation.
 */
public static ResultSequence document_uri(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    NodeType nt = (NodeType) arg1.first();
    if (!(nt instanceof DocType))
        return ResultBuffer.EMPTY;
    DocType dt = (DocType) nt;
    String documentURI = dt.value().getDocumentURI();
    if (documentURI != null) {
        XSAnyURI docUri = new XSAnyURI(documentURI);
        return docUri;
    }
    return ResultBuffer.EMPTY;
}
Also used : XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Collection(java.util.Collection) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 17 with XSAnyURI

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI in project webtools.sourceediting by eclipse.

the class FnNamespaceUri method namespace_uri.

/**
 * Namespace-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:namespace-uri operation.
 */
public static ResultSequence namespace_uri(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = null;
    if (cargs.isEmpty()) {
        if (context.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg1 = (AnyType) context.getContextItem();
    } else {
        // get arg
        arg1 = (ResultSequence) cargs.iterator().next();
    }
    if (arg1.empty()) {
        return new XSAnyURI("");
    }
    NodeType an = (NodeType) arg1.first();
    QName name = an.node_name();
    String sname = "";
    if (name != null)
        sname = name.namespace();
    return new XSAnyURI(sname);
}
Also used : XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Collection(java.util.Collection)

Example 18 with XSAnyURI

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI in project webtools.sourceediting by eclipse.

the class XSDouble method constructor.

/**
 * Creates a new result sequence consisting of the retrievable double number
 * in the supplied result sequence
 *
 * @param arg
 *            The result sequence from which to extract the double number.
 * @throws DynamicError
 * @return A new result sequence consisting of the double number supplied.
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    Item aat = arg.first();
    if (aat instanceof XSDuration || aat instanceof CalendarType || aat instanceof XSBase64Binary || aat instanceof XSHexBinary || aat instanceof XSAnyURI) {
        throw DynamicError.invalidType();
    }
    if (!isCastable(aat)) {
        throw DynamicError.cant_cast(null);
    }
    XSDouble d = castDouble(aat);
    if (d == null)
        throw DynamicError.cant_cast(null);
    return d;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 19 with XSAnyURI

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI in project webtools.sourceediting by eclipse.

the class XSBoolean method constructor.

/**
 * Creates a new result sequence consisting of the retrievable boolean value
 * in the supplied result sequence
 *
 * @param arg
 *            The result sequence from which to extract the boolean value.
 * @throws DynamicError
 * @return A new result sequence consisting of the boolean value supplied.
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    Item anyType = arg.first();
    if (anyType instanceof XSDuration || anyType instanceof CalendarType || anyType instanceof XSBase64Binary || anyType instanceof XSHexBinary || anyType instanceof XSAnyURI) {
        throw DynamicError.invalidType();
    }
    String str_value = anyType.getStringValue();
    if (!(isCastable(anyType, str_value))) {
        throw DynamicError.cant_cast(null);
    }
    return XSBoolean.valueOf(!isFalse(str_value));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 20 with XSAnyURI

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI in project webtools.sourceediting by eclipse.

the class DocumentURIFuncTest method test_fn_document_uri_17.

// Evaluates the "document-uri" function as argument to fn:lower-case function.
public void test_fn_document_uri_17() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-17.xq";
    String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-17.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    setVariable("input-context1", new XSAnyURI(inputFile));
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Aggregations

XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)22 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)17 URL (java.net.URL)16 XSModel (org.apache.xerces.xs.XSModel)16 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)16 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)16 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)16 Collection (java.util.Collection)4 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)4 Item (org.eclipse.wst.xml.xpath2.api.Item)3 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)3 Iterator (java.util.Iterator)2 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)2 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)2 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)1 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)1 DocType (org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)1 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)1 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)1 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)1