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;
}
});
}
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);
}
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);
}
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);
}
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;
}
Aggregations