| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
|