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