java/dictionary-generator/src/cz/frantovo/telco/dictionary/MappedNamespaceContext.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 22 Jun 2020 21:59:38 +0200
changeset 151 a9f1ba451247
parent 47 b87ea854d920
permissions -rw-r--r--
fix license version: GNU GPLv3, GNU FDLv1.3
franta-hg@15
     1
/**
franta-hg@15
     2
 * Free Telco Dictionary
franta-hg@15
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@15
     4
 *
franta-hg@15
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@15
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@151
     7
 * the Free Software Foundation, version 3 of the License.
franta-hg@15
     8
 *
franta-hg@15
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@15
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@15
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@15
    12
 * GNU General Public License for more details.
franta-hg@15
    13
 *
franta-hg@15
    14
 * You should have received a copy of the GNU General Public License
franta-hg@15
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@15
    16
 */
franta-hg@15
    17
package cz.frantovo.telco.dictionary;
franta-hg@15
    18
franta-hg@15
    19
import static cz.frantovo.telco.dictionary.Functions.*;
franta-hg@15
    20
import java.util.Iterator;
franta-hg@15
    21
import java.util.Map;
franta-hg@15
    22
import java.util.Map.Entry;
franta-hg@15
    23
import javax.xml.namespace.NamespaceContext;
franta-hg@15
    24
franta-hg@15
    25
/**
franta-hg@15
    26
 *
franta-hg@15
    27
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@15
    28
 */
franta-hg@15
    29
public class MappedNamespaceContext implements NamespaceContext {
franta-hg@15
    30
franta-hg@15
    31
	/**
franta-hg@15
    32
	 * maps prexix to namespace URI
franta-hg@15
    33
	 */
franta-hg@15
    34
	private Map<String, String> prefixMap;
franta-hg@15
    35
franta-hg@15
    36
	public MappedNamespaceContext(Map<String, String> prefixMap) {
franta-hg@15
    37
		this.prefixMap = prefixMap;
franta-hg@15
    38
	}
franta-hg@15
    39
franta-hg@15
    40
	@Override
franta-hg@15
    41
	public String getNamespaceURI(String prefix) {
franta-hg@15
    42
		return prefixMap.get(prefix);
franta-hg@15
    43
	}
franta-hg@15
    44
franta-hg@15
    45
	@Override
franta-hg@15
    46
	public String getPrefix(String xmlns) {
franta-hg@15
    47
		for (Entry<String, String> e : prefixMap.entrySet()) {
franta-hg@15
    48
			if (equalz(xmlns, e.getValue())) {
franta-hg@15
    49
				return e.getKey();
franta-hg@15
    50
			}
franta-hg@15
    51
		}
franta-hg@15
    52
		return null;
franta-hg@15
    53
	}
franta-hg@15
    54
franta-hg@15
    55
	@Override
franta-hg@47
    56
	public Iterator<String> getPrefixes(String xmlns) {
franta-hg@18
    57
		return getKeysForValue(prefixMap, xmlns).iterator();
franta-hg@15
    58
	}
franta-hg@15
    59
}