DependencyResolver.java 1.51 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xmp.schema.rng.parser.sax;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class DependencyResolver
implements EntityResolver {
    private String baseDir;
    private List<String> otherDir;

    public DependencyResolver(String baseDir, List<String> otherDir) {
        this.baseDir = baseDir;
        this.otherDir = otherDir;
    }

    @Override
    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
        InputSource s;
        if (this.baseDir != null && (s = this.getInputSource(this.baseDir, systemId)) != null) {
            return s;
        }
        if (this.otherDir != null) {
            for (String dir : this.otherDir) {
                InputSource s2 = this.getInputSource(dir, systemId);
                if (s2 == null) continue;
                return s2;
            }
        }
        return new InputSource(systemId);
    }

    private InputSource getInputSource(String dir, String systemId) {
        String path = dir + systemId;
        try {
            URL url = new URL(path);
            InputSource is = new InputSource(url.openStream());
            return is;
        }
        catch (IOException e) {
            return null;
        }
    }
}