try {
String[] parts = context.getConfiguration().getNameChecker().getQNameParts(rawName);
prefix = parts[0];
localName = parts[1];
} catch (QNameException err) {
XPathException err1 = new XPathException("Invalid attribute name: " + rawName, this);
err1.setErrorCode((isXSLT() ? "XTDE0850" : "XQDY0074"));
err1.setXPathContext(context);
throw dynamicError(this, err1, context);
}
if (rawName.toString().equals("xmlns")) {
if (namespace==null) {
XPathException err = new XPathException("Invalid attribute name: " + rawName, this);
err.setErrorCode((isXSLT() ? "XTDE0855" : "XQDY0044"));
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
}
if (prefix.equals("xmlns")) {
if (namespace==null) {
XPathException err = new XPathException("Invalid attribute name: " + rawName, this);
err.setErrorCode((isXSLT() ? "XTDE0860" : "XQDY0044"));
err.setXPathContext(context);
throw dynamicError(this, err, context);
} else {
// ignore the prefix "xmlns"
prefix = "";
}
}
} else if (nameValue instanceof QNameValue && allowNameAsQName) {
// this is allowed in XQuery
localName = ((QNameValue)nameValue).getLocalName();
uri = ((QNameValue)nameValue).getNamespaceURI();
if (uri == null) {
uri = "";
}
if (localName.equals("xmlns") && uri.length()==0) {
XPathException err = new XPathException("Invalid attribute name: xmlns", this);
err.setErrorCode("XQDY0044");
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
if ("xmlns".equals(prefix) || uri.equals("http://www.w3.org/2000/xmlns/")) {
XPathException err = new XPathException("Invalid attribute namespace: http://www.w3.org/2000/xmlns/", this);
err.setErrorCode("XQDY0044");
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
if (uri.length() == 0) {
prefix = "";
} else {
prefix = ((QNameValue)nameValue).getPrefix();
if (prefix.length()==0) {
// if (uri.equals(NamespaceConstant.XML)) {
// prefix = "xml";
// } else {
prefix = pool.suggestPrefixForURI(uri);
if (prefix == null) {
prefix = "ns0";
}
// }
}
// If the prefix is a duplicate, a different one will be substituted
}
} else {
XPathException err = new XPathException("Attribute name must be either a string or a QName", this);
err.setErrorCode("XPTY0004");
err.setIsTypeError(true);
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
if (namespace == null && uri == null) {
if (prefix.length() == 0) {
uri = "";
} else {
uri = nsContext.getURIForPrefix(prefix, false);
if (uri==null) {
XPathException err = new XPathException("Undeclared prefix in attribute name: " + prefix, this);
err.setErrorCode((isXSLT() ? "XTDE0860" : "XQDY0074"));
err.setXPathContext(context);
throw dynamicError(this, err, context);
}
}
} else {
if (uri == null) {
// generate a name using the supplied namespace URI
if (namespace instanceof StringLiteral) {
uri = ((StringLiteral)namespace).getStringValue();
} else {
uri = namespace.evaluateAsString(context).toString();
if (!AnyURIValue.isValidURI(uri)) {
XPathException de = new XPathException("The value of the namespace attribute must be a valid URI");
de.setErrorCode("XTDE0865");
de.setXPathContext(context);
de.setLocator(this);
throw de;
}
}
}
if (uri.length() == 0) {