franta-hg@15: /**
franta-hg@15: * Free Telco Dictionary
franta-hg@15: * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@15: *
franta-hg@15: * This program is free software: you can redistribute it and/or modify
franta-hg@15: * it under the terms of the GNU General Public License as published by
franta-hg@151: * the Free Software Foundation, version 3 of the License.
franta-hg@15: *
franta-hg@15: * This program is distributed in the hope that it will be useful,
franta-hg@15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@15: * GNU General Public License for more details.
franta-hg@15: *
franta-hg@15: * You should have received a copy of the GNU General Public License
franta-hg@15: * along with this program. If not, see .
franta-hg@15: */
franta-hg@15: package cz.frantovo.telco.dictionary;
franta-hg@15:
franta-hg@15: import static cz.frantovo.telco.dictionary.Functions.*;
franta-hg@15: import java.util.Iterator;
franta-hg@15: import java.util.Map;
franta-hg@15: import java.util.Map.Entry;
franta-hg@15: import javax.xml.namespace.NamespaceContext;
franta-hg@15:
franta-hg@15: /**
franta-hg@15: *
franta-hg@15: * @author Ing. František Kučera (frantovo.cz)
franta-hg@15: */
franta-hg@15: public class MappedNamespaceContext implements NamespaceContext {
franta-hg@15:
franta-hg@15: /**
franta-hg@15: * maps prexix to namespace URI
franta-hg@15: */
franta-hg@15: private Map prefixMap;
franta-hg@15:
franta-hg@15: public MappedNamespaceContext(Map prefixMap) {
franta-hg@15: this.prefixMap = prefixMap;
franta-hg@15: }
franta-hg@15:
franta-hg@15: @Override
franta-hg@15: public String getNamespaceURI(String prefix) {
franta-hg@15: return prefixMap.get(prefix);
franta-hg@15: }
franta-hg@15:
franta-hg@15: @Override
franta-hg@15: public String getPrefix(String xmlns) {
franta-hg@15: for (Entry e : prefixMap.entrySet()) {
franta-hg@15: if (equalz(xmlns, e.getValue())) {
franta-hg@15: return e.getKey();
franta-hg@15: }
franta-hg@15: }
franta-hg@15: return null;
franta-hg@15: }
franta-hg@15:
franta-hg@15: @Override
franta-hg@47: public Iterator getPrefixes(String xmlns) {
franta-hg@18: return getKeysForValue(prefixMap, xmlns).iterator();
franta-hg@15: }
franta-hg@15: }