franta-hg@101: /** franta-hg@101: * Alt2XML franta-hg@101: * Copyright © 2014 František Kučera (frantovo.cz) franta-hg@101: * franta-hg@101: * This program is free software: you can redistribute it and/or modify franta-hg@101: * it under the terms of the GNU General Public License as published by franta-hg@111: * the Free Software Foundation, version 3 of the License. franta-hg@101: * franta-hg@101: * This program is distributed in the hope that it will be useful, franta-hg@101: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@101: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@101: * GNU General Public License for more details. franta-hg@101: * franta-hg@101: * You should have received a copy of the GNU General Public License franta-hg@101: * along with this program. If not, see . franta-hg@101: */ franta-hg@101: package cz.frantovo.alt2xml.out.xpath; franta-hg@101: franta-hg@101: import java.util.Iterator; franta-hg@101: import javax.xml.XMLConstants; franta-hg@101: import javax.xml.namespace.NamespaceContext; franta-hg@101: import org.w3c.dom.Node; franta-hg@101: franta-hg@101: /** franta-hg@101: * franta-hg@101: * @author Ing. František Kučera (frantovo.cz) franta-hg@101: */ franta-hg@101: public class DocumentNamespaceContext implements NamespaceContext { franta-hg@101: franta-hg@101: private final Node document; franta-hg@101: franta-hg@101: public DocumentNamespaceContext(Node document) { franta-hg@101: this.document = document; franta-hg@101: } franta-hg@101: franta-hg@101: @Override franta-hg@101: public String getNamespaceURI(String prefix) { franta-hg@101: if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { franta-hg@101: return document.lookupNamespaceURI(null); franta-hg@101: } else { franta-hg@101: return document.lookupNamespaceURI(prefix); franta-hg@101: } franta-hg@101: } franta-hg@101: franta-hg@101: @Override franta-hg@101: public String getPrefix(String xmlns) { franta-hg@101: return document.lookupPrefix(xmlns); franta-hg@101: } franta-hg@101: franta-hg@101: /** franta-hg@101: * TODO: support multiple prefixes franta-hg@101: */ franta-hg@101: @Override franta-hg@101: public Iterator getPrefixes(String xmlns) { franta-hg@101: return new OneItemIterator(getPrefix(xmlns)); franta-hg@101: } franta-hg@101: }