001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ken.util;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.w3c.dom.ls.LSInput;
022import org.w3c.dom.ls.LSResourceResolver;
023
024/**
025 * LSResourceResolver implementation that delegates in sequence to a list of LSResourceResolvers,
026 * returning the first match. 
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public class CompoundLSResourceResolver implements LSResourceResolver {
030    private final List<LSResourceResolver> resolvers;
031
032    /**
033     * Constructs a CompoundLSResourceResolver.java.
034     * @param first
035     * @param second
036     */
037    public CompoundLSResourceResolver(LSResourceResolver first, LSResourceResolver second) {
038        this.resolvers = new ArrayList<LSResourceResolver>(2);
039        this.resolvers.add(first);
040        this.resolvers.add(second);
041    }
042
043    /**
044     * Constructs a CompoundLSResourceResolver.java.
045     * @param resolvers
046     */
047    public CompoundLSResourceResolver(List<LSResourceResolver> resolvers) {
048        this.resolvers = resolvers;
049    }
050
051    /**
052     * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
053     */
054    public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
055        for (LSResourceResolver resolver: resolvers) {
056            LSInput input = resolver.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
057            if (input != null) {
058                return input;
059            }
060        }
061        return null;
062    }
063}