All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.daisy.dotify.common.xml.EntityResolverCache Maven / Gradle / Ivy

The newest version!
package org.daisy.dotify.common.xml;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 * Provides an entity resolver with cache
 * @author Joel Håkansson
 *
 */
public class EntityResolverCache implements EntityResolver {
	
	private final URLCache cache;
	
	/**
	 * Creates a new entity resolver with cache
	 */
	public EntityResolverCache() {
		cache = new URLCache();
	}

	@Override
	public InputSource resolveEntity(String publicId, String systemId)
			throws SAXException, IOException {
		try {
			URL url = new URI(systemId).toURL();
			InputSource is = new InputSource(cache.openStream(url));
			is.setPublicId(publicId);
			is.setSystemId(systemId);
			return is;
		} catch (URISyntaxException e) {
			return null;
		} catch (IOException e) {
			return null;
		}
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy