1 package net.sf.jabref.export;
6 import net.sf.jabref.Globals;
7 import net.sf.jabref.plugin.core.generated._JabRefPlugin.ExportFormatTemplateExtension;
10 * Class for export formats defined in plugins.
12 * Needed since resources might be loaded from a plugin-jar.
15 public class PluginBasedExportFormat extends ExportFormat {
17 public ExportFormatTemplateExtension extension;
20 * Load the plugin from the given extension. Might be null if extension
21 * could not be loaded.
26 public static PluginBasedExportFormat getFormat(
27 ExportFormatTemplateExtension extension) {
29 String consoleName = extension.getConsoleName();
30 String displayName = extension.getDisplayName();
31 String layoutFilename = extension.getLayoutFilename();
32 String fileExtension = extension.getExtension();
34 if ("".equals(fileExtension) || "".equals(displayName)
35 || "".equals(consoleName) || "".equals(layoutFilename)) {
36 Globals.logger("Could not load extension " + extension.getId());
40 return new PluginBasedExportFormat(displayName, consoleName,
41 layoutFilename, fileExtension, extension);
44 public PluginBasedExportFormat(String displayName, String consoleName,
45 String layoutFileName, String fileExtension,
46 ExportFormatTemplateExtension extension) {
47 super(displayName, consoleName, layoutFileName, null, fileExtension);
48 this.extension = extension;
52 public Reader getReader(String filename) throws IOException {
53 URL reso = extension.getDirAsUrl(filename);
57 return new InputStreamReader(reso.openStream());
58 } catch (FileNotFoundException ex) {
59 // If that didn't work, try below
64 return new FileReader(new File(filename));
65 } catch (FileNotFoundException ex) {
66 // If that did not work, throw the IOException below
68 throw new IOException(Globals.lang("Could not find layout file")
69 + ": '" + filename + "'.");