Search in sources :

Example 1 with XSAnyURI

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

the class FnBaseUri method getBaseUri.

/*
	 * Helper function for base-uri support
	 */
public static ResultSequence getBaseUri(Item att) {
    ResultBuffer rs = new ResultBuffer();
    XSAnyURI baseUri = null;
    if (att instanceof NodeType) {
        NodeType node = (NodeType) att;
        Node domNode = node.node_value();
        String buri = domNode.getBaseURI();
        if (buri != null) {
            baseUri = new XSAnyURI(buri);
        } else {
            baseUri = new XSAnyURI("null");
        }
    }
    if (baseUri != null) {
        rs.add(baseUri);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node)

Example 2 with XSAnyURI

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

the class Function method convert_argument.

// convert argument according to section 3.1.5 of xpath 2.0 spec
/**
 * Convert the input argument according to section 3.1.5 of specification.
 *
 * @param arg
 *            input argument.
 * @param expected
 *            Expected Sequence type.
 * @throws DynamicError
 *             Dynamic error.
 * @return Converted argument.
 */
public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected) throws DynamicError {
    ResultBuffer result = new ResultBuffer();
    // XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class())
    AnyType expected_type = expected.type();
    // expected is atomic
    if (expected_type instanceof AnyAtomicType) {
        AnyAtomicType expected_aat = (AnyAtomicType) expected_type;
        // atomize
        org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg);
        // cast untyped to expected type
        for (Iterator i = rs.iterator(); i.hasNext(); ) {
            AnyType item = (AnyType) i.next();
            if (item instanceof XSUntypedAtomic) {
                // create a new item of the expected
                // type initialized with from the string
                // value of the item
                ResultSequence converted = null;
                if (expected_aat instanceof XSString) {
                    XSString strType = new XSString(item.getStringValue());
                    converted = ResultSequenceFactory.create_new(strType);
                } else {
                    converted = ResultSequenceFactory.create_new(item);
                }
                result.concat(converted);
            } else // xs:anyURI promotion to xs:string
            if (item instanceof XSAnyURI && expected_aat instanceof XSString) {
                result.add(new XSString(item.getStringValue()));
            } else // numeric type promotion
            if (item instanceof NumericType) {
                if (expected_aat instanceof XSDouble) {
                    XSDouble doubleType = new XSDouble(item.getStringValue());
                    result.add(doubleType);
                } else {
                    result.add(item);
                }
            } else {
                result.add(item);
            }
        }
        // do sequence type matching on converted arguments
        return expected.match(result.getSequence());
    } else {
        // do sequence type matching on converted arguments
        return expected.match(arg);
    }
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 3 with XSAnyURI

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

the class FnResolveURI method resolveURI.

/**
 * Resolve-URI operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param d_context
 *            Dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:resolve-uri operation.
 */
public static ResultSequence resolveURI(Collection args, EvaluationContext ec) throws DynamicError {
    if (ec.getStaticContext().getBaseUri() == null) {
        throw DynamicError.noBaseURI();
    }
    Collection cargs = args;
    Iterator argit = cargs.iterator();
    ResultSequence relativeRS = (ResultSequence) argit.next();
    ResultSequence baseUriRS = null;
    if (argit.hasNext()) {
        baseUriRS = (ResultSequence) argit.next();
    }
    if (relativeRS.empty()) {
        return ResultBuffer.EMPTY;
    }
    Item relativeURI = relativeRS.first();
    String resolvedURI = null;
    if (baseUriRS == null) {
        resolvedURI = resolveURI(ec.getStaticContext().getBaseUri().toString(), relativeURI.getStringValue());
    } else {
        Item baseURI = baseUriRS.first();
        resolvedURI = resolveURI(baseURI.getStringValue(), relativeURI.getStringValue());
    }
    return new XSAnyURI(resolvedURI);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 4 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_18.

// Evaluates the "document-uri" function as argument to fn:concat function.
public void test_fn_document_uri_18() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-18.xq";
    String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-18.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)

Example 5 with XSAnyURI

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

the class SeqDocFuncTest method test_fn_doc_18.

// Evaluation of fn:doc used together with "is" operator and a the fn:not function.
public void test_fn_doc_18() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Functions/NodeSeqFunc/SeqDocFunc/fn-doc-18.xq";
    String resultFile = "/ExpectedTestResults/Functions/NodeSeqFunc/SeqDocFunc/fn-doc-18.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-context", 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