Debian Codegraph @

net/sf/saxon/functions/QNameFn.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
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 * This class supports the fn:QName() function (previously named fn:expanded-QName())
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 // The QNameValue constructor does not check the prefix
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 * Evaluate the expression
58 *
59 * @param context the dynamic evaluation context
60 * @param arguments the values of the arguments, supplied as Sequences
61 * @return the result of the evaluation, in the form of a Sequence
62 * @throws net.sf.saxon.trans.XPathException
63 * if a dynamic error occurs during the evaluation of the expression
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