1 package net.sf.jabref.export.layout.format;
3 import net.sf.jabref.export.layout.LayoutFormatter;
4 import net.sf.jabref.export.layout.ParamLayoutFormatter;
5 import net.sf.jabref.gui.FileListTableModel;
6 import net.sf.jabref.gui.FileListEntry;
7 import net.sf.jabref.Globals;
8 import net.sf.jabref.Util;
9 import net.sf.jabref.GUIGlobals;
14 * Export formatter that handles the file link list of JabRef 2.3 and later, by
15 * selecting the first file link, if any, specified by the field.
17 public class FileLink implements ParamLayoutFormatter {
19 String fileType = null;
21 public String format(String field) {
22 FileListTableModel tableModel = new FileListTableModel();
26 tableModel.setContent(field);
28 if (fileType == null) {
29 // No file type specified. Simply take the first link.
30 if (tableModel.getRowCount() > 0)
31 link = tableModel.getEntry(0).getLink();
36 // A file type is specified:
37 for (int i=0; i< tableModel.getRowCount(); i++) {
38 FileListEntry flEntry = tableModel.getEntry(i);
39 if (flEntry.getType().getName().toLowerCase().equals(fileType)) {
40 link = flEntry.getLink();
48 // Search in the standard file directory:
49 /* TODO: oops, this part is not sufficient. We need access to the
50 database's metadata in order to check if the database overrides
51 the standard file directory */
52 String dir = Globals.prefs.get(GUIGlobals.FILE_FIELD+"Directory");
53 File f = Util.expandFilename(link, new String[] { dir, "." });
56 * Stumbled over this while investigating
58 * https://sourceforge.net/tracker/index.php?func=detail&aid=1469903&group_id=92314&atid=600306
61 return f.getPath();//f.toURI().toString();
70 * This method is called if the layout file specifies an argument for this
71 * formatter. We use it as an indicator of which file type we should look for.
72 * @param arg The file type.
74 public void setArgument(String arg) {