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

se.mtm.dotify.addons.MergeLinegroupsProcessor Maven / Gradle / Ivy

package se.mtm.dotify.addons;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.daisy.dotify.api.tasks.AnnotatedFile;
import org.daisy.dotify.api.tasks.DefaultAnnotatedFile;
import org.daisy.dotify.api.tasks.ExpandingTask;
import org.daisy.dotify.api.tasks.InternalTask;
import org.daisy.dotify.api.tasks.InternalTaskException;
import org.daisy.dotify.common.xml.XMLInfo;
import org.daisy.dotify.common.xml.XMLTools;
import org.daisy.dotify.common.xml.XMLToolsException;
import org.daisy.dotify.tasks.tools.XsltTask;

class MergeLinegroupsProcessor extends ExpandingTask {
	private final Map xsltParams;

	MergeLinegroupsProcessor(Map xsltParams) {
		super("MTM linegroups");
		this.xsltParams = xsltParams;
	}

	@Override
	public List resolve(File input) throws InternalTaskException {
		return resolve(new DefaultAnnotatedFile.Builder(input).build());
	}

	@Override
	public List resolve(AnnotatedFile input) throws InternalTaskException {
		ArrayList ret = new ArrayList<>();
		try {
			XMLInfo peekResult = XMLTools.parseXML(input.getFile(), true);
			String rootNS = peekResult.getUri();
			String rootElement = peekResult.getLocalName();
			if ("dtbook".equals(rootElement) && "http://www.daisy.org/z3986/2005/dtbook/".equals(rootNS)) {
				ret.addAll(getDtbookTasks(xsltParams));
			}
		} catch (XMLToolsException e) {
			throw new InternalTaskException("XMLToolsException while reading input", e);
		}
		return ret;	
	}
	
	static List getDtbookTasks(Map parameters) {
		ArrayList ret = new ArrayList<>();
		ret.add(new XsltTask("Merge linegroups", MergeLinegroupsProcessor.class.getResource("resource-files/linegroup.xsl"), parameters));
		return ret;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy