java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/DocumentNamespaceContext.java
author František Kučera <franta-hg@frantovo.cz>
Tue, 28 Oct 2014 17:53:24 +0100
changeset 104 33b2441a6d36
parent 101 fd83cd102325
child 111 e4900596abdb
permissions -rw-r--r--
fix imports
franta-hg@101
     1
/**
franta-hg@101
     2
 * Alt2XML
franta-hg@101
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@101
     4
 *
franta-hg@101
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@101
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@101
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@101
     8
 * (at your option) any later version.
franta-hg@101
     9
 *
franta-hg@101
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@101
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@101
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@101
    13
 * GNU General Public License for more details.
franta-hg@101
    14
 *
franta-hg@101
    15
 * You should have received a copy of the GNU General Public License
franta-hg@101
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@101
    17
 */
franta-hg@101
    18
package cz.frantovo.alt2xml.out.xpath;
franta-hg@101
    19
franta-hg@101
    20
import java.util.Iterator;
franta-hg@101
    21
import javax.xml.XMLConstants;
franta-hg@101
    22
import javax.xml.namespace.NamespaceContext;
franta-hg@101
    23
import org.w3c.dom.Node;
franta-hg@101
    24
franta-hg@101
    25
/**
franta-hg@101
    26
 *
franta-hg@101
    27
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@101
    28
 */
franta-hg@101
    29
public class DocumentNamespaceContext implements NamespaceContext {
franta-hg@101
    30
franta-hg@101
    31
	private final Node document;
franta-hg@101
    32
franta-hg@101
    33
	public DocumentNamespaceContext(Node document) {
franta-hg@101
    34
		this.document = document;
franta-hg@101
    35
	}
franta-hg@101
    36
franta-hg@101
    37
	@Override
franta-hg@101
    38
	public String getNamespaceURI(String prefix) {
franta-hg@101
    39
		if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
franta-hg@101
    40
			return document.lookupNamespaceURI(null);
franta-hg@101
    41
		} else {
franta-hg@101
    42
			return document.lookupNamespaceURI(prefix);
franta-hg@101
    43
		}
franta-hg@101
    44
	}
franta-hg@101
    45
franta-hg@101
    46
	@Override
franta-hg@101
    47
	public String getPrefix(String xmlns) {
franta-hg@101
    48
		return document.lookupPrefix(xmlns);
franta-hg@101
    49
	}
franta-hg@101
    50
franta-hg@101
    51
	/**
franta-hg@101
    52
	 * TODO: support multiple prefixes
franta-hg@101
    53
	 */
franta-hg@101
    54
	@Override
franta-hg@101
    55
	public Iterator getPrefixes(String xmlns) {
franta-hg@101
    56
		return new OneItemIterator(getPrefix(xmlns));
franta-hg@101
    57
	}
franta-hg@101
    58
}