| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.resource; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Callable; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.functions.CallableFunction; |
| 13 |
import net.sf.saxon.lib.Resource; |
| 14 |
import net.sf.saxon.ma.map.DictionaryMap; |
| 15 |
import net.sf.saxon.om.GroundedValue; |
| 16 |
import net.sf.saxon.om.Item; |
| 17 |
import net.sf.saxon.type.FunctionItemType; |
| 18 |
import net.sf.saxon.type.SpecificFunctionType; |
| 19 |
import net.sf.saxon.value.SequenceType; |
| 20 |
import net.sf.saxon.value.StringValue; |
| 21 |
|
| 22 |
import java.util.Map; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class MetadataResource implements Resource { |
| 28 |
|
| 29 |
private Map<String, GroundedValue<?>> properties; |
| 30 |
private String resourceURI; |
| 31 |
private Resource content; |
| 32 |
|
| 33 |
public MetadataResource(String resourceURI, Resource content, Map<String, GroundedValue<?>> properties) { |
| 34 |
this.resourceURI = resourceURI; |
| 35 |
this.content = content; |
| 36 |
this.properties = properties; |
| 37 |
} |
| 38 |
|
| 39 |
public String getContentType() { |
| 40 |
return content.getContentType(); |
| 41 |
} |
| 42 |
|
| 43 |
public String getResourceURI() { |
| 44 |
return resourceURI; |
| 45 |
} |
| 46 |
|
| 47 |
public Item getItem(XPathContext context) { |
| 48 |
|
| 49 |
|
| 50 |
DictionaryMap map = new DictionaryMap(); |
| 51 |
|
| 52 |
|
| 53 |
for (Map.Entry<String, GroundedValue<?>> entry : properties.entrySet()) { |
| 54 |
map.initialPut(entry.getKey(), entry.getValue()); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
map.initialPut("name", StringValue.makeStringValue(resourceURI)); |
| 59 |
|
| 60 |
|
| 61 |
Callable fetcher = (context1, arguments) -> content.getItem(context1); |
| 62 |
|
| 63 |
FunctionItemType fetcherType = new SpecificFunctionType(new SequenceType[0], SequenceType.SINGLE_ITEM); |
| 64 |
CallableFunction fetcherFunction = new CallableFunction(0, fetcher, fetcherType); |
| 65 |
|
| 66 |
map.initialPut("fetch", fetcherFunction); |
| 67 |
return map; |
| 68 |
} |
| 69 |
} |
| 70 |
|