/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE file at the root of the source
* tree and available online at
*
* https://github.com/keeps/roda
*/
package org.roda.core.plugins.plugins.conversion;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.ghost4j.GhostscriptException;
import org.roda.core.RodaCoreFactory;
import org.roda.core.data.v2.IsRODAObject;
import org.roda.core.data.v2.jobs.Report;
import org.roda.core.index.IndexService;
import org.roda.core.model.ModelService;
import org.roda.core.plugins.Plugin;
import org.roda.core.plugins.PluginException;
import org.roda.core.plugins.plugins.common.CommandConvertPlugin;
import org.roda.core.plugins.plugins.common.FileFormatUtils;
import org.roda.core.storage.StorageService;
import org.roda.core.util.CommandException;
import org.slf4j.LoggerFactory;
public class GhostScriptConvertPlugin<T extends IsRODAObject> extends CommandConvertPlugin<T> {
private static final String TOOLNAME = "ghostscriptconvert";
public GhostScriptConvertPlugin() {
super();
}
@Override
public String getName() {
return "GhostScript conversion";
}
@Override
public String getDescription() {
return "Converts files using GhostScript.";
}
@Override
public String getVersionImpl() {
try {
return GhostScriptConvertPluginUtils.getVersion();
} catch (CommandException | IOException | UnsupportedOperationException e) {
LoggerFactory.getLogger(GhostScriptConvertPlugin.class).debug("Error getting GhostScript version");
return "1.0";
}
}
@Override
public Plugin<T> cloneMe() {
return new GhostScriptConvertPlugin<>();
}
@Override
public String executePlugin(Path inputPath, Path outputPath, String fileFormat)
throws UnsupportedOperationException, IOException, CommandException {
try {
return GhostScriptConvertPluginUtils.executeGS(inputPath, outputPath, super.getCommandArguments());
} catch (GhostscriptException e) {
return null;
}
}
@Override
public List<String> getApplicableTo() {
return FileFormatUtils.getInputExtensions(TOOLNAME);
}
@Override
public List<String> getConvertableTo() {
String outputFormats = RodaCoreFactory.getRodaConfigurationAsString("core", "tools", TOOLNAME, "outputFormats");
return Arrays.asList(outputFormats.split("\\s+"));
}
@Override
public Map<String, List<String>> getPronomToExtension() {
return FileFormatUtils.getPronomToExtension(TOOLNAME);
}
@Override
public Map<String, List<String>> getMimetypeToExtension() {
return FileFormatUtils.getMimetypeToExtension(TOOLNAME);
}
@Override
public Report beforeAllExecute(IndexService index, ModelService model, StorageService storage)
throws PluginException {
// do nothing
return null;
}
@Override
public Report afterAllExecute(IndexService index, ModelService model, StorageService storage) throws PluginException {
// do nothing
return null;
}
}