| 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.expr.instruct; |
| 9 | |
| 10 | import net.sf.saxon.tree.jiter.PairIterator; |
| 11 | import net.sf.saxon.lib.NamespaceConstant; |
| 12 | import net.sf.saxon.om.NamespaceResolver; |
| 13 | |
| 14 | import java.util.Iterator; |
| 15 | |
| 16 | /** |
| 17 | * A dummy namespace resolver used when validating QName-valued attributes written to |
| 18 | * the result tree. The namespace node might be created after the initial validation |
| 19 | * of the attribute, so in the first round of validation we only check the lexical form |
| 20 | * of the value, and we defer prefix checks until later. |
| 21 | */ |
| 22 | |
| 23 | public final class DummyNamespaceResolver implements NamespaceResolver { |
| 24 | |
| 25 | private final static DummyNamespaceResolver THE_INSTANCE = new DummyNamespaceResolver(); |
| 26 | |
| 27 | /** |
| 28 | * Return the singular instance of this class |
| 29 | * |
| 30 | * @return the singular instance |
| 31 | */ |
| 32 | |
| 33 | public static DummyNamespaceResolver getInstance() { |
| 34 | return THE_INSTANCE; |
| 35 | } |
| 36 | |
| 37 | private DummyNamespaceResolver() { |
| 38 | } |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * Get the namespace URI corresponding to a given prefix. |
| 43 | * |
| 44 | * @param prefix the namespace prefix |
| 45 | * @param useDefault true if the default namespace is to be used when the |
| 46 | * prefix is "" |
| 47 | * @return the uri for the namespace, or null if the prefix is not in scope |
| 48 | */ |
| 49 | |
| 50 | public String getURIForPrefix(String prefix, boolean useDefault) { |
| 51 | if (prefix.isEmpty()) { |
| 52 | return NamespaceConstant.NULL; |
| 53 | } else if ("xml".equals(prefix)) { |
| 54 | return NamespaceConstant.XML; |
| 55 | } else { |
| 56 | // this is a dummy namespace resolver, we don't actually know the URI |
| 57 | return NamespaceConstant.NULL; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get an iterator over all the prefixes declared in this namespace context. This will include |
| 63 | * the default namespace (prefix="") and the XML namespace where appropriate |
| 64 | */ |
| 65 | |
| 66 | public Iterator<String> iteratePrefixes() { |
| 67 | return new PairIterator<String>("", "xml"); |
| 68 | } |
| 69 | } |
| 70 |