| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.*; |
| 11 |
import net.sf.saxon.expr.sort.DocumentOrderIterator; |
| 12 |
import net.sf.saxon.expr.sort.LocalOrderComparer; |
| 13 |
import net.sf.saxon.om.*; |
| 14 |
import net.sf.saxon.trans.KeyDefinitionSet; |
| 15 |
import net.sf.saxon.trans.KeyManager; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
import net.sf.saxon.type.Type; |
| 18 |
import net.sf.saxon.value.StringValue; |
| 19 |
|
| 20 |
|
| 21 |
public class Idref extends SystemFunction { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public int getSpecialProperties(Expression[] arguments) { |
| 31 |
int prop = StaticProperty.ORDERED_NODESET | |
| 32 |
StaticProperty.SINGLE_DOCUMENT_NODESET | |
| 33 |
StaticProperty.NO_NODES_NEWLY_CREATED; |
| 34 |
if ((getArity() == 1) || |
| 35 |
arguments[1].hasSpecialProperty(StaticProperty.CONTEXT_DOCUMENT_NODESET)) { |
| 36 |
prop |= StaticProperty.CONTEXT_DOCUMENT_NODESET; |
| 37 |
} |
| 38 |
return prop; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static SequenceIterator<NodeInfo> getIdrefMultiple(TreeInfo doc, SequenceIterator<StringValue> keys, XPathContext context) |
| 53 |
throws XPathException { |
| 54 |
IdrefMappingFunction map = new IdrefMappingFunction(); |
| 55 |
map.document = doc; |
| 56 |
map.keyContext = context; |
| 57 |
map.keyManager = context.getController().getExecutable().getTopLevelPackage().getKeyManager(); |
| 58 |
map.keySet = map.keyManager.getKeyDefinitionSet(StandardNames.getStructuredQName(StandardNames.XS_IDREFS)); |
| 59 |
SequenceIterator<? extends NodeInfo> allValues = new MappingIterator<>(keys, map); |
| 60 |
return new DocumentOrderIterator(allValues, LocalOrderComparer.getInstance()); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 73 |
NodeInfo start = arguments.length == 1 ? getContextNode(context) : (NodeInfo) arguments[1].head(); |
| 74 |
NodeInfo arg2 = start.getRoot(); |
| 75 |
if (arg2.getNodeKind() != Type.DOCUMENT) { |
| 76 |
throw new XPathException("In the idref() function," + |
| 77 |
" the tree being searched must be one whose root is a document node", "FODC0001", context); |
| 78 |
} |
| 79 |
return SequenceTool.toLazySequence(getIdrefMultiple(arg2.getTreeInfo(), arguments[0].iterate(), context)); |
| 80 |
} |
| 81 |
|
| 82 |
private static class IdrefMappingFunction implements MappingFunction<StringValue, NodeInfo> { |
| 83 |
public TreeInfo document; |
| 84 |
public XPathContext keyContext; |
| 85 |
public KeyManager keyManager; |
| 86 |
public KeyDefinitionSet keySet; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public SequenceIterator<NodeInfo> map(StringValue item) throws XPathException { |
| 93 |
return keyManager.selectByKey(keySet, document, item, keyContext); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
} |
| 98 |
|