| 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.Configuration; |
| 11 | import net.sf.saxon.trans.XPathException; |
| 12 | |
| 13 | /** |
| 14 | * A CollationURIResolver accepts a collation name as input, and returns |
| 15 | * a collation (represented by a {@link StringCollator} as output. A CollationURIResolver |
| 16 | * can be registered with the Configuration (or with a TransformerFactory) |
| 17 | * to resolve all collation URIs used in a stylesheet or query. |
| 18 | */ |
| 19 | public interface CollationURIResolver { |
| 20 | |
| 21 | /** |
| 22 | * Resolve a collation URI (expressed as a string in the form of an absolute URI) and return |
| 23 | * the corresponding collation. |
| 24 | * |
| 25 | * @param collationURI the collation URI as written in the query or stylesheet, after resolving |
| 26 | * against the base URI where necessary |
| 27 | * @param config The configuration. Provided in case the collation URI resolver |
| 28 | * needs it. |
| 29 | * @return a StringCollator, representing the collation to be used. Note that although |
| 30 | * any StringCollator may be returned, functions such as contains() that need to break |
| 31 | * a string into its collation units will work only if the returned StringCollator |
| 32 | * is a {@link net.sf.saxon.lib.SubstringMatcher}. |
| 33 | * <p>If the Collation URI is not recognized, return null. |
| 34 | * Note that unlike the JAXP URIResolver, returning null does not cause the default |
| 35 | * CollationURIResolver to be invoked; if this is required, the user-written CollationURIResolver |
| 36 | * should explicitly instantiate and invoke the {@link StandardCollationURIResolver} before |
| 37 | * returning null.</p> |
| 38 | * @throws XPathException if the form of the URI is recognized, but if it is not valid, |
| 39 | * for example because it is not supported in this environment. In this case of the UCA collation, |
| 40 | * this exception is thrown when there are invalid parameters and fallback=no is specified. |
| 41 | * @since 8.5/8.9 (this interface was introduced provisionally in 8.5, and modified in 8.9 to return |
| 42 | * a StringCollator rather than a Comparator). Modified in 9.6 to accept the absolute URI of the |
| 43 | * collation, rather than the relative URI and base URI separately, and also to allow an |
| 44 | * exception to be thrown |
| 45 | */ |
| 46 | |
| 47 | public StringCollator resolve(String collationURI, Configuration config) throws XPathException; |
| 48 | } |
| 49 |