Debian Codegraph @

net/sf/saxon/lib/ResultDocumentResolver.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.lib;
9
10 import net.sf.saxon.event.Receiver;
11 import net.sf.saxon.event.SequenceNormalizer;
12 import net.sf.saxon.expr.XPathContext;
13 import net.sf.saxon.serialize.SerializationProperties;
14 import net.sf.saxon.trans.SaxonErrorCode;
15 import net.sf.saxon.trans.XPathException;
16
17
18 /**
19 * The <tt>ResultDocumentResolver</tt> interface may be implemented by a user application;
20 * it is a callback that is called whenever an xsl:result-document instruction
21 * is executed.
22 * <p>There is a single method: {@link #resolve(XPathContext, String, String, SerializationProperties)}.
23 * Saxon calls this method supplying the dynamic evaluation context, together with the value of the href
24 * attribute and the output base URI for the transformation.</p>
25 * <p>The result of the callback is an application-supplied instance of the
26 * {@link Receiver} interface. Saxon will send events to this {@code Receiver},
27 * representing the <b>raw</b> results of the {@code xsl:result-document} instruction.
28 * If the application wants results in the form of a document node generated using
29 * sequence normalization, then it must include a {@link SequenceNormalizer} in the
30 * output pipeline.</p>
31 * <p>The {@code ResultDocumentResolver} is called for every {@code xsl:result-document}
32 * instruction whether or not it specifies an {@code href} attribute.</p>
33 * <p>The implementation must be thread-safe (calls to {@code xsl:result-document} may
34 * occur in several threads concurrently). The returned {@code Receiver}
35 * may be called in a different thread.</p>
36 * <p>If the application wishes to take action when the {@code xsl:result-document} instruction
37 * finishes, that is, when the results are available for use, then it should intercept the
38 * {@link Receiver#close()} call on the returned {@code Receiver}. This can be done
39 * (for example) by adding a {@link net.sf.saxon.event.CloseNotifier} to the output pipeline,
40 * or by use of the {@link SequenceNormalizer#onClose} method.</p>
41 * <p>This interface supersedes the {@link OutputURIResolver} interface provided in earlier
42 * Saxon releases. The {@code OutputURIResolver} was limited because it did not have access
43 * to the dynamic context, nor to the serialization parameters, and it did not handle
44 * raw output as required by the XSLT 3.0 specification, needed in particular to create
45 * JSON output documents.</p>
46 * @since 9.9
47 */
48
49 public interface ResultDocumentResolver {
50
51 /**
52 * Saxon calls this method when an {@code xsl:result-document} instruction
53 * with an {@code href} attribute is evaluated.
54 * <p><em>Note: it may be appropriate for the method to obtain a suitable
55 * {@code Receiver} by calling one of the static factory methods on the
56 * {@link SerializerFactory} class. A {@code SerializerFactory} can be
57 * obtained by calling {@code context.getConfiguration().getSerializerFactory()}.
58 * </em></p>
59 * @param context the dynamic evaluation context
60 * @param href the effective value of the {@code href} attribute of
61 * {@code xsl:result-document} instruction. This will be a zero-length
62 * string if the attribute is omitted.
63 * @param baseUri the base output URI of the transformation (typically, the
64 * destination of the principal output destination). This may be null
65 * if no base output URI is known. The recommended action if it is null
66 * is to use the {@code href} value alone if it is absolute URI, otherwise
67 * to raise an error ({@link SaxonErrorCode#SXRD0002}, since there
68 * is no W3C-defined code for the condition).
69 * @param properties the serialization properties defined explicitly or implicitly on the
70 * {@code xsl:result-document} instruction, together with information
71 * about character maps in the stylesheet that might be referenced.
72 * Serialization parameters can be ignored if the result document is
73 * not being serialized. However, if the serialization parameters include
74 * a validation factory, then this must not be ignored: a validator
75 * must be inserted at a suitable point in the output pipeline.
76 * @return a new instance of the {@code Receiver} class, which Saxon will then call
77 * to open the output document, and subsequently to close it. This {@code Receiver}
78 * will receive a sequence of events representing the <b>raw result</b> of the
79 * {@code xsl:result-document} instruction, as a <b>regular event sequence</b>
80 * conforming to the rules defined in {@link net.sf.saxon.event.RegularSequenceChecker}.
81 * <p>The implementation should set the {@code systemId} property of the returned
82 * {@code Receiver} to the result of resolving the supplied {@code href} against the
83 * supplied {@code baseUri}. On return from this method, Saxon will check that
84 * the {@code systemId} is non-null and that it satisfies the uniqueness conditions
85 * imposed by the XSLT specification. Specifically, it is not permitted for two
86 * calls on {@code xsl:result-document} to use the same URI, and this URI must not
87 * be read in a call on {@code doc()} or {@code document()}, either before or after
88 * executing the {@code xsl:result-document} instruction.</p>
89 * @throws XPathException if a result document cannot be opened
90 */
91
92 Receiver resolve(
93 XPathContext context, String href, String baseUri, SerializationProperties properties)
94 throws XPathException;
95
96 }
97