Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions exist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ throws PermissionDeniedException, EXistException, XPathException
)
{
if (orderempty)
throw new XPathException(prolog_AST_in, ErrorCodes.XQST0065, "Ordering mode already declared.");
throw new XPathException(prolog_AST_in, ErrorCodes.XQST0069, "Empty order declaration already declared.");
orderempty = true;
}
)
Expand Down Expand Up @@ -454,7 +454,7 @@ throws PermissionDeniedException, EXistException, XPathException
{
// ignored
if (construction)
throw new XPathException(prolog_AST_in, ErrorCodes.XQST0069, "Construction already declared.");
throw new XPathException(prolog_AST_in, ErrorCodes.XQST0067, "Construction already declared.");
construction = true;
}
)
Expand Down Expand Up @@ -734,25 +734,15 @@ throws PermissionDeniedException, EXistException, XPathException
targetURI:STRING_LITERAL
( uriList [uriList] )?
{
if ("".equals(targetURI.getText()) && nsPrefix != null) {
throw new XPathException(s, ErrorCodes.XQST0057, "A schema without target namespace (zero-length string target namespace) may not bind a namespace prefix: " + nsPrefix);
}
if (nsPrefix != null) {
if (declaredNamespaces.get(nsPrefix) != null)
throw new XPathException(s, ErrorCodes.XQST0033, "Prolog contains " +
"multiple declarations for namespace prefix: " + nsPrefix);
declaredNamespaces.put(nsPrefix, targetURI.getText());
}
try {
context.declareNamespace(nsPrefix, targetURI.getText());
staticContext.declareNamespace(nsPrefix, targetURI.getText());
// We currently do nothing with eventual location hints. /ljo
} catch(XPathException xpe) {
xpe.prependMessage("err:XQST0059: Error found while loading schema " + nsPrefix + ": ");
throw xpe;
if (s != null) {
throw new XPathException(s, ErrorCodes.XQST0009, "The eXist-db XQuery implementation does not support the Schema Import Feature.");
}
// We ought to do this for now until Dannes can say it works. /ljo
//throw new XPathException(s, ErrorCodes.XQST0009, "The eXist-db XQuery implementation does not support the Schema Import Feature quite yet.");
}
)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
try {
qn = QName.parse(context, nameSeq.getStringValue(), null);
} catch (final QName.IllegalQNameException e) {
throw new XPathException(this, ErrorCodes.XPTY0004, "'" + nameSeq.getStringValue() + "' is not a valid attribute name");
throw new XPathException(this, ErrorCodes.XQDY0074, "'" + nameSeq.getStringValue() + "' is not a valid attribute name");
}

//Not in the specs but... makes sense
if(!XMLNames.isName(qn.getLocalPart()))
{throw new XPathException(this, ErrorCodes.XPTY0004, "'" + qn.getLocalPart() + "' is not a valid attribute name");}
{throw new XPathException(this, ErrorCodes.XQDY0074, "'" + qn.getLocalPart() + "' is not a valid attribute name");}

if ("xmlns".equals(qn.getLocalPart()) && qn.getNamespaceURI().isEmpty())
{throw new XPathException(this, ErrorCodes.XQDY0044, "'" + qn.getLocalPart() + "' is not a valid attribute name");}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
try {
attrQName = QName.parse(context, constructor.getQName(), XMLConstants.NULL_NS_URI);
} catch (final QName.IllegalQNameException e) {
throw new XPathException(this, ErrorCodes.XPTY0004, "'" + constructor.getQName() + "' is not a valid attribute name");
throw new XPathException(this, ErrorCodes.XQDY0074, "'" + constructor.getQName() + "' is not a valid attribute name");
}

final String namespaceURI = attrQName.getNamespaceURI();
Expand Down Expand Up @@ -288,7 +288,7 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
try {
qn = QName.parse(context, qnitem.getStringValue());
} catch (final QName.IllegalQNameException e) {
throw new XPathException(this, ErrorCodes.XPTY0004, "'" + qnitem.getStringValue() + "' is not a valid element name");
throw new XPathException(this, ErrorCodes.XQDY0074, "'" + qnitem.getStringValue() + "' is not a valid element name");
} catch (final XPathException e) {
e.setLocation(getLine(), getColumn(), getSource());
throw e;
Expand All @@ -306,7 +306,7 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr

//Not in the specs but... makes sense
if (!XMLNames.isName(qn.getLocalPart())) {
throw new XPathException(this, ErrorCodes.XPTY0004, "'" + qnitem.getStringValue() + "' is not a valid element name");
throw new XPathException(this, ErrorCodes.XQDY0074, "'" + qnitem.getStringValue() + "' is not a valid element name");
}

// add namespace declaration nodes
Expand Down
2 changes: 2 additions & 0 deletions exist-core/src/main/java/org/exist/xquery/EnclosedExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
} catch (DOMException e) {
if (e.code == DOMException.NAMESPACE_ERR) {
throw new XPathException(this, ErrorCodes.XQDY0102, e.getMessage());
} else if (e.code == DOMException.INUSE_ATTRIBUTE_ERR) {
throw new XPathException(this, ErrorCodes.XQDY0025, e.getMessage());
} else {
throw new XPathException(this, e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ public Item itemAt(final int pos) {

@Override
public NodeSet toNodeSet() throws XPathException {
throw new XPathException(this, "Type error: the sequence cannot be converted into" +
throw new XPathException(this, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is xs:integer");
}

@Override
public MemoryNodeSet toMemNodeSet() throws XPathException {
throw new XPathException(this, "Type error: the sequence cannot be converted into" +
throw new XPathException(this, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a memory node set. Item type is xs:integer");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void checkType() throws XPathException {
}
}

throw new XPathException(getValue(),
throw new XPathException(getValue(), ErrorCodes.XPTY0004,
Messages.getMessage(Error.VAR_TYPE_MISMATCH,
toString(),
type.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,9 @@ public void declareNamespace(final String prefix, final String uri) throws XPath
}
//Forbids rebinding the *same* prefix in a *different* namespace in this *same* context
if (!nonNullUri.equals(prevURI)) {
throw new XPathException(rootExpression, ErrorCodes.XQST0033,
// XQST0066 for default element namespace redeclaration, XQST0033 for other prefixes
final ErrorCodes.ErrorCode errorCode = nonNullPrefix.isEmpty() ? ErrorCodes.XQST0066 : ErrorCodes.XQST0033;
throw new XPathException(rootExpression, errorCode,
"Cannot bind prefix '" + prefix + "' to '" + nonNullUri + "' it is already bound to '" + prevURI + "'");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
Collator collator = context.getDefaultCollator();

if (args.length > 2 && !args[2].isEmpty()) {
collator = context.getCollator(args[2].getStringValue());
collator = context.getCollator(args[2].getStringValue(), ErrorCodes.FOCH0002);
}

/* return true only if some fragment matches the trimmed token under current collation */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.exist.xquery.Constants.Comparison;
import org.exist.xquery.Constants.StringTruncationOperator;
import org.exist.xquery.Dependency;
import org.exist.xquery.ErrorCodes;
import org.exist.xquery.Function;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.Profiler;
Expand Down Expand Up @@ -129,7 +130,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
Collator collator;
if (getSignature().getArgumentCount() == 3) {
final String collation = args[2].getStringValue();
collator = context.getCollator(collation);
collator = context.getCollator(collation, ErrorCodes.FOCH0002);
} else
{collator = context.getDefaultCollator();}
result = new ValueSequence();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private Collator collator(final Sequence[] args, final int pos) throws XPathExce
return context.getDefaultCollator();
}
final String collationURI = args[pos].getStringValue();
return context.getCollator(collationURI);
return context.getCollator(collationURI, ErrorCodes.FOCH0002);
} else {
return context.getDefaultCollator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public AnyURIValue(final Expression expression, String s) throws XPathException
try {
XmldbURI.xmldbUriFor(escapedString);
} catch (final URISyntaxException ex) {
throw new XPathException(getExpression(),
throw new XPathException(getExpression(), ErrorCodes.XQST0046,
"Type error: the given string '" + s + "' cannot be cast to " + Type.getTypeName(getType()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.exist.dom.persistent.NodeProxy;
import org.exist.dom.persistent.NodeSet;
import org.exist.numbering.NodeId;
import org.exist.xquery.ErrorCodes;
import org.exist.xquery.Expression;
import org.exist.xquery.NodeTest;
import org.exist.xquery.XPathException;
Expand Down Expand Up @@ -403,7 +404,7 @@ public NodeSet toNodeSet() throws XPathException {
// }
return set;
} else {
throw new XPathException((Expression) null, "Type error: the sequence cannot be converted into" +
throw new XPathException((Expression) null, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is " + Type.getTypeName(itemType));
}
}
Expand All @@ -415,7 +416,7 @@ public MemoryNodeSet toMemNodeSet() throws XPathException {
}

if (itemType == Type.ANY_TYPE || !Type.subTypeOf(itemType, Type.NODE)) {
throw new XPathException((Expression) null, "Type error: the sequence cannot be converted into" +
throw new XPathException((Expression) null, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is " + Type.getTypeName(itemType));
}
for (final Item value : values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public NodeSet toNodeSet() throws XPathException {
}
return set;
} else {
throw new XPathException((Expression) null, "Type error: the sequence cannot be converted into" +
throw new XPathException((Expression) null, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is " + Type.getTypeName(itemType));
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ public MemoryNodeSet toMemNodeSet() throws XPathException {
return MemoryNodeSet.EMPTY;
}
if (itemType == Type.ANY_TYPE || !Type.subTypeOf(itemType, Type.NODE)) {
throw new XPathException((Expression) null, "Type error: the sequence cannot be converted into" +
throw new XPathException((Expression) null, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is " + Type.getTypeName(itemType));
}
for (int i = 0; i < count; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private static int expandCharRef(final String buf, final Expression expression)
}
return charNumber;
} catch (final NumberFormatException e) {
throw new XPathException(expression, "Unknown character reference: " + buf);
throw new XPathException(expression, ErrorCodes.XQST0090, "Unknown character reference: " + buf);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public NodeSet toNodeSet() throws XPathException {
}
return set;
} else {
throw new XPathException((Expression) null, "Type error: the sequence cannot be converted into" +
throw new XPathException((Expression) null, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is " + Type.getTypeName(itemType));
}
}
Expand All @@ -316,7 +316,7 @@ public MemoryNodeSet toMemNodeSet() throws XPathException {
return MemoryNodeSet.EMPTY;
}
if (itemType == Type.ANY_TYPE || !Type.subTypeOf(itemType, Type.NODE)) {
throw new XPathException((Expression) null, "Type error: the sequence cannot be converted into" +
throw new XPathException((Expression) null, ErrorCodes.XPTY0019, "Type error: the sequence cannot be converted into" +
" a node set. Item type is " + Type.getTypeName(itemType));
}
for (int i = 0; i <= size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void testReDeclareNamespaceEmptyPrefixFail () throws XPathException {
context.declareNamespace("", "new-default");
fail("empty prefix was rebound");
} catch (XPathException e) {
assertEquals("err:XQST0033 Cannot bind prefix '' to 'new-default' it is already bound to 'default'",
assertEquals("err:XQST0066 Cannot bind prefix '' to 'new-default' it is already bound to 'default'",
e.getMessage());
assertEquals("default", context.staticNamespaces.get(""));
}
Expand Down