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

org.daisy.pipeline.braille.tex.TexHyphenatorTablePath Maven / Gradle / Ivy

package org.daisy.pipeline.braille.tex;

import java.net.URI;
import java.net.URL;
import java.util.Locale;
import java.util.Map;

import org.daisy.common.file.URLs;
import org.daisy.pipeline.braille.common.BundledResourcePath;
import org.daisy.pipeline.braille.common.Provider;
import static org.daisy.pipeline.braille.common.util.Locales.parseLocale;

public class TexHyphenatorTablePath extends BundledResourcePath implements Provider {
	
	private static final String MANIFEST = "manifest";
	
	@Override
	protected void activate(Map properties, Class context) {
		if (properties.get(UNPACK) != null)
			throw new IllegalArgumentException(UNPACK + " property not supported");
		super.activate(properties, context);
		if (properties.get(MANIFEST) != null) {
			String manifestPath = properties.get(MANIFEST).toString();
			final URL manifestURL = URLs.getResourceFromJAR(manifestPath, TexHyphenatorTablePath.class);
			if (manifestURL == null)
				throw new IllegalArgumentException("Manifest at location " + manifestPath + " could not be found");
			initProvider(manifestURL); }
	}
	
	public Iterable get(Locale locale) {
		return provider.get(locale);
	}
	
	private Provider provider = Provider.util.empty();
	
	private void initProvider(URL manifestURL) {
		provider = new Provider.util.SimpleMappingProvider(manifestURL) {
			public Locale parseKey(String locale) {
				return parseLocale(locale);
			}
			public URI parseValue(String table) {
				return canonicalize(URLs.asURI(table));
			}
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy