| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.lib; |
| 9 |
|
| 10 |
import net.sf.saxon.event.CloseNotifier; |
| 11 |
import net.sf.saxon.event.PipelineConfiguration; |
| 12 |
import net.sf.saxon.event.Receiver; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.s9api.Action; |
| 15 |
import net.sf.saxon.serialize.SerializationProperties; |
| 16 |
import net.sf.saxon.trans.UncheckedXPathException; |
| 17 |
import net.sf.saxon.trans.XPathException; |
| 18 |
|
| 19 |
import javax.xml.transform.Result; |
| 20 |
import javax.xml.transform.TransformerException; |
| 21 |
import java.util.ArrayList; |
| 22 |
import java.util.List; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class OutputURIResolverWrapper implements ResultDocumentResolver { |
| 32 |
|
| 33 |
private OutputURIResolver outputURIResolver; |
| 34 |
|
| 35 |
public OutputURIResolverWrapper(OutputURIResolver resolver) { |
| 36 |
this.outputURIResolver = resolver; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public Receiver resolve( |
| 52 |
XPathContext context, String href, String baseUri, SerializationProperties properties) |
| 53 |
throws XPathException { |
| 54 |
OutputURIResolver r2 = outputURIResolver.newInstance(); |
| 55 |
|
| 56 |
try { |
| 57 |
Result result = r2.resolve(href, baseUri); |
| 58 |
Action onClose = () -> { |
| 59 |
try { |
| 60 |
r2.close(result); |
| 61 |
} catch (TransformerException te) { |
| 62 |
throw new UncheckedXPathException(XPathException.makeXPathException(te)); |
| 63 |
} |
| 64 |
}; |
| 65 |
Receiver out; |
| 66 |
if (result instanceof Receiver) { |
| 67 |
out = (Receiver)result; |
| 68 |
} else { |
| 69 |
SerializerFactory factory = context.getConfiguration().getSerializerFactory(); |
| 70 |
PipelineConfiguration pipe = context.getController().makePipelineConfiguration(); |
| 71 |
pipe.setXPathContext(context); |
| 72 |
out = factory.getReceiver(result, properties, pipe); |
| 73 |
} |
| 74 |
List<Action> actions = new ArrayList<>(); |
| 75 |
actions.add(onClose); |
| 76 |
return new CloseNotifier(out, actions); |
| 77 |
} catch (TransformerException e) { |
| 78 |
throw XPathException.makeXPathException(e); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
public OutputURIResolver getOutputURIResolver() { |
| 83 |
return outputURIResolver; |
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|