Search in sources :

Example 46 with QName

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

the class TestBugs method testNulVarNamespacePrefix.

public void testNulVarNamespacePrefix() throws Exception {
    // Bug 345326
    String xpath = "for $a in //* return $a";
    new Engine().parseExpression(xpath, new StaticContext() {

        public boolean isXPath1Compatible() {
            return false;
        }

        public StaticVariableResolver getInScopeVariables() {
            return null;
        }

        public TypeDefinition getInitialContextType() {
            return null;
        }

        public Map getFunctionLibraries() {
            return null;
        }

        public CollationProvider getCollationProvider() {
            return null;
        }

        public URI getBaseUri() {
            return null;
        }

        public ItemType getDocumentType(URI documentUri) {
            return null;
        }

        public NamespaceContext getNamespaceContext() {
            return new NamespaceContext() {

                public String getNamespaceURI(String arg0) {
                    if (arg0 == null)
                        throw new IllegalArgumentException("#fail");
                    return XMLConstants.NULL_NS_URI;
                }

                public String getPrefix(String arg0) {
                    if (arg0 == null)
                        throw new IllegalArgumentException("#fail");
                    return XMLConstants.DEFAULT_NS_PREFIX;
                }

                public Iterator getPrefixes(String arg0) {
                    if (arg0 == null)
                        throw new IllegalArgumentException("#fail");
                    return Collections.emptyList().iterator();
                }
            };
        }

        public String getDefaultNamespace() {
            return XMLConstants.NULL_NS_URI;
        }

        public String getDefaultFunctionNamespace() {
            return null;
        }

        public TypeModel getTypeModel() {
            return null;
        }

        public Function resolveFunction(QName name, int arity) {
            return null;
        }

        public TypeDefinition getCollectionType(String collectionName) {
            return null;
        }

        public TypeDefinition getDefaultCollectionType() {
            return null;
        }
    });
}
Also used : StaticVariableResolver(org.eclipse.wst.xml.xpath2.api.StaticVariableResolver) QName(javax.xml.namespace.QName) ItemType(org.eclipse.wst.xml.xpath2.api.typesystem.ItemType) TypeModel(org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) URI(java.net.URI) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition) Function(org.eclipse.wst.xml.xpath2.api.Function) NamespaceContext(javax.xml.namespace.NamespaceContext) Iterator(java.util.Iterator) CollationProvider(org.eclipse.wst.xml.xpath2.api.CollationProvider) Map(java.util.Map) Engine(org.eclipse.wst.xml.xpath2.processor.Engine) StaticContext(org.eclipse.wst.xml.xpath2.api.StaticContext)

Example 47 with QName

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

the class LocalNameFromQNameFuncTest method test_LocalNameFromQNameFunc015.

// Test function fn:local-name-from-QName. Error case - invalid parameter type (simple type).
public void test_LocalNameFromQNameFunc015() throws Exception {
    String inputFile = "/TestSources/fsx.xml";
    String xqFile = "/Queries/XQuery/Functions/QNameFunc/LocalNameFromQnameFunc/LocalNameFromQNameFunc015.xq";
    String expectedResult = "XPTY0004";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    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) 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 48 with QName

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

the class LocalNameFromQNameFuncTest method test_LocalNameFromQNameFunc016.

// Test function fn:local-name-from-QName. Error case - invalid parameter type (integer).
public void test_LocalNameFromQNameFunc016() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/QNameFunc/LocalNameFromQnameFunc/LocalNameFromQNameFunc016.xq";
    String expectedResult = "XPTY0004";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    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) 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 49 with QName

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

the class NamespaceURIFromQNameFuncTest method test_NamespaceURIFromQNameFunc015.

// Test function fn:namespace-uri-from-QName. Error case - invalid parameter type (simple type).
public void test_NamespaceURIFromQNameFunc015() throws Exception {
    String inputFile = "/TestSources/fsx.xml";
    String xqFile = "/Queries/XQuery/Functions/QNameFunc/NamespaceURIFromQNameFunc/NamespaceURIFromQNameFunc015.xq";
    String expectedResult = "XPTY0004";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    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) 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 50 with QName

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

the class DefaultEvaluator method name_test.

// XXX this routine sux
private boolean name_test(NodeType node, QName name, String type) {
    // make sure principal node kind is the same
    if (node == null) {
        return false;
    }
    if (!type.equals(node.string_type())) {
        return false;
    }
    String test_prefix = name.prefix();
    // element namespace
    if (test_prefix == null && type.equals("element")) {
        // XXX make a new copy
        name = new QName(null, name.local());
        name.set_namespace(_sc.getDefaultNamespace());
        // if we actually have a namespace, pretend we do =D
        if (name.namespace() != null && name.namespace().length() > 0)
            test_prefix = "";
    }
    QName node_name = node.node_name();
    assert node_name != null;
    // make sure namespace matches
    String node_namespace = node_name.namespace();
    String test_namespace = null;
    if (name.expanded())
        test_namespace = name.namespace();
    // name test has no prefix
    if (test_prefix == null) {
        // ok no namespace... match
        if (node_namespace == null) {
        } else {
            return false;
        }
    } else // XXX AT THIS POINT ALL PREFIXES NEED TO BE RESOLVED!
    if (!test_namespace.equals("*")) {
        // the node doesn't have a namespace... no match
        if (node_namespace == null) {
            return false;
        } else // check namespaces
        {
            if (node_namespace.equals(test_namespace)) {
            // namespace matches
            } else {
                return false;
            }
        }
    }
    // check for wildcard in localpart
    if (name.local().equals("*"))
        return true;
    // check if local part matches
    if (!name.local().equals(node_name.local())) {
        return false;
    }
    return true;
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)77 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)77 URL (java.net.URL)76 XSModel (org.apache.xerces.xs.XSModel)76 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)76 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)76 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)42 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)21 Iterator (java.util.Iterator)18 Collection (java.util.Collection)17 ArrayList (java.util.ArrayList)13 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)11 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)10 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)10 ListIterator (java.util.ListIterator)9 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)9 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)6 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)5 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)5 Schema (javax.xml.validation.Schema)4