| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.XPathContext; |
| 11 |
import net.sf.saxon.om.NameChecker; |
| 12 |
import net.sf.saxon.om.QNameException; |
| 13 |
import net.sf.saxon.om.Sequence; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.type.BuiltInAtomicType; |
| 16 |
import net.sf.saxon.value.QNameValue; |
| 17 |
import net.sf.saxon.value.StringValue; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class QNameFn extends SystemFunction { |
| 25 |
|
| 26 |
|
| 27 |
public static QNameValue expandedQName(StringValue namespace, StringValue lexical) throws XPathException { |
| 28 |
|
| 29 |
String uri; |
| 30 |
if (namespace == null) { |
| 31 |
uri = null; |
| 32 |
} else { |
| 33 |
uri = namespace.getStringValue(); |
| 34 |
} |
| 35 |
|
| 36 |
try { |
| 37 |
final String lex = lexical.getStringValue(); |
| 38 |
final String[] parts = NameChecker.getQNameParts(lex); |
| 39 |
|
| 40 |
if (!parts[0].isEmpty() && !NameChecker.isValidNCName(parts[0])) { |
| 41 |
XPathException err = new XPathException("Malformed prefix in QName: '" + parts[0] + '\''); |
| 42 |
err.setErrorCode("FOCA0002"); |
| 43 |
throw err; |
| 44 |
} |
| 45 |
return new QNameValue(parts[0], uri, parts[1], BuiltInAtomicType.QNAME, true); |
| 46 |
} catch (QNameException e) { |
| 47 |
throw new XPathException(e.getMessage(), "FOCA0002"); |
| 48 |
} catch (XPathException err) { |
| 49 |
if (err.getErrorCodeLocalPart().equals("FORG0001")) { |
| 50 |
err.setErrorCode("FOCA0002"); |
| 51 |
} |
| 52 |
throw err; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public QNameValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 66 |
return expandedQName( |
| 67 |
(StringValue) arguments[0].head(), |
| 68 |
(StringValue) arguments[1].head() |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
public String getCompilerName() { |
| 73 |
return "QNameFnCompiler"; |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|