Debian Codegraph @

net/sf/saxon/functions/DocumentUri_1.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.Controller;
11 import net.sf.saxon.expr.XPathContext;
12 import net.sf.saxon.om.*;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.type.Type;
15 import net.sf.saxon.value.AnyURIValue;
16 import net.sf.saxon.value.AtomicValue;
17
18 /**
19 * This class supports the document-uri() function
20 */
21
22 public class DocumentUri_1 extends ScalarSystemFunction {
23
24
25
26 @Override
27 public AtomicValue evaluate(Item item, XPathContext context) throws XPathException {
28 return getDocumentURI((NodeInfo)item, context);
29 }
30
31
32 public static AnyURIValue getDocumentURI(NodeInfo node, XPathContext c) {
33 if (node.getNodeKind() == Type.DOCUMENT) {
34 Object o = node.getTreeInfo().getUserData("saxon:document-uri");
35 if (o instanceof String) {
36 return o.toString().isEmpty() ? null : new AnyURIValue(o.toString());
37 }
38 final Controller controller = c.getController();
39 assert controller != null;
40 DocumentPool pool = controller.getDocumentPool();
41 String docURI = pool.getDocumentURI(node);
42 if (docURI == null) {
43 docURI = node.getSystemId();
44 }
45 if (docURI == null) {
46 return null;
47 } else if ("".equals(docURI)) {
48 return null;
49 } else {
50 return new AnyURIValue(docURI);
51 }
52 } else {
53 return null;
54 }
55 }
56
57 }
58