java/alt2xml-out-xpath/src/cz/frantovo/alt2xml/out/xpath/CompoundVariableResolver.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 07 Sep 2014 01:28:07 +0200
changeset 97 a72d55ff30c9
child 111 e4900596abdb
permissions -rw-r--r--
out-xpath: optional variable resolver for environment variables – can be used together with those from command line
franta-hg@97
     1
/**
franta-hg@97
     2
 * Alt2XML
franta-hg@97
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@97
     4
 *
franta-hg@97
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@97
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@97
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@97
     8
 * (at your option) any later version.
franta-hg@97
     9
 *
franta-hg@97
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@97
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@97
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@97
    13
 * GNU General Public License for more details.
franta-hg@97
    14
 *
franta-hg@97
    15
 * You should have received a copy of the GNU General Public License
franta-hg@97
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@97
    17
 */
franta-hg@97
    18
package cz.frantovo.alt2xml.out.xpath;
franta-hg@97
    19
franta-hg@97
    20
import javax.xml.namespace.QName;
franta-hg@97
    21
import javax.xml.xpath.XPathVariableResolver;
franta-hg@97
    22
franta-hg@97
    23
/**
franta-hg@97
    24
 *
franta-hg@97
    25
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@97
    26
 */
franta-hg@97
    27
public class CompoundVariableResolver implements XPathVariableResolver {
franta-hg@97
    28
franta-hg@97
    29
	private final XPathVariableResolver[] resolvers;
franta-hg@97
    30
franta-hg@97
    31
	public CompoundVariableResolver(XPathVariableResolver... resolvers) {
franta-hg@97
    32
		this.resolvers = resolvers;
franta-hg@97
    33
	}
franta-hg@97
    34
franta-hg@97
    35
	@Override
franta-hg@97
    36
	public Object resolveVariable(QName variableName) {
franta-hg@97
    37
		for (XPathVariableResolver r : resolvers) {
franta-hg@97
    38
			Object value = r.resolveVariable(variableName);
franta-hg@97
    39
			if (value != null) {
franta-hg@97
    40
				return value;
franta-hg@97
    41
			}
franta-hg@97
    42
		}
franta-hg@97
    43
		return null;
franta-hg@97
    44
	}
franta-hg@97
    45
}