diff --git a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java index 2d9d5de98e4..c62681edd42 100644 --- a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java @@ -12,12 +12,12 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.BibtexDatabaseWriter; -import net.sf.jabref.exporter.SavePreferences; -import net.sf.jabref.exporter.StringSaveSession; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.importer.fileformat.BibtexParser; import net.sf.jabref.importer.fileformat.ParseException; +import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; +import net.sf.jabref.logic.exporter.SavePreferences; +import net.sf.jabref.logic.exporter.StringSaveSession; import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.groups.GroupHierarchyType; import net.sf.jabref.logic.groups.KeywordGroup; diff --git a/src/main/java/net/sf/jabref/Globals.java b/src/main/java/net/sf/jabref/Globals.java index 7fb2cf06a5b..c51932db8db 100644 --- a/src/main/java/net/sf/jabref/Globals.java +++ b/src/main/java/net/sf/jabref/Globals.java @@ -18,9 +18,9 @@ import java.util.Optional; import net.sf.jabref.collab.FileUpdateMonitor; -import net.sf.jabref.exporter.AutoSaveManager; import net.sf.jabref.gui.GlobalFocusListener; import net.sf.jabref.gui.JabRefFrame; +import net.sf.jabref.gui.exporter.AutoSaveManager; import net.sf.jabref.gui.keyboard.KeyBindingPreferences; import net.sf.jabref.importer.ImportFormatReader; import net.sf.jabref.logic.error.StreamEavesdropper; diff --git a/src/main/java/net/sf/jabref/JabRefMain.java b/src/main/java/net/sf/jabref/JabRefMain.java index 93a4420e7e3..e825a28a917 100644 --- a/src/main/java/net/sf/jabref/JabRefMain.java +++ b/src/main/java/net/sf/jabref/JabRefMain.java @@ -20,9 +20,9 @@ import javax.swing.SwingUtilities; import net.sf.jabref.cli.ArgumentProcessor; -import net.sf.jabref.exporter.ExportFormats; import net.sf.jabref.gui.remote.JabRefMessageHandler; import net.sf.jabref.logic.CustomEntryTypesManager; +import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.net.ProxyAuthenticator; diff --git a/src/main/java/net/sf/jabref/JabRefPreferences.java b/src/main/java/net/sf/jabref/JabRefPreferences.java index 497210c35bd..79cae1b39fc 100644 --- a/src/main/java/net/sf/jabref/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/JabRefPreferences.java @@ -46,9 +46,6 @@ import javax.swing.JTable; import javax.swing.UIManager; -import net.sf.jabref.exporter.CustomExportList; -import net.sf.jabref.exporter.ExportComparator; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.external.DroppedFileHandler; import net.sf.jabref.gui.desktop.JabRefDesktop; import net.sf.jabref.gui.entryeditor.EntryEditorTabList; @@ -58,6 +55,9 @@ import net.sf.jabref.logic.autocompleter.AutoCompletePreferences; import net.sf.jabref.logic.cleanup.CleanupPreset; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; +import net.sf.jabref.logic.exporter.CustomExportList; +import net.sf.jabref.logic.exporter.ExportComparator; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; import net.sf.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index c4247fc4511..de4646a4511 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -31,9 +31,9 @@ import java.util.TreeMap; import java.util.Vector; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.config.SaveOrderConfig; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.groups.GroupTreeNode; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.labelpattern.AbstractLabelPattern; diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index 9a8b0d548bd..f8212c7d3b0 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -19,14 +19,6 @@ import net.sf.jabref.JabRefGUI; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.BibDatabaseWriter; -import net.sf.jabref.exporter.BibtexDatabaseWriter; -import net.sf.jabref.exporter.ExportFormats; -import net.sf.jabref.exporter.FileSaveSession; -import net.sf.jabref.exporter.IExportFormat; -import net.sf.jabref.exporter.SaveException; -import net.sf.jabref.exporter.SavePreferences; -import net.sf.jabref.exporter.SaveSession; import net.sf.jabref.external.AutoSetLinks; import net.sf.jabref.importer.ImportFormatReader; import net.sf.jabref.importer.ImportInspectionCommandLine; @@ -35,6 +27,14 @@ import net.sf.jabref.importer.fetcher.EntryFetcher; import net.sf.jabref.importer.fetcher.EntryFetchers; import net.sf.jabref.logic.CustomEntryTypesManager; +import net.sf.jabref.logic.exporter.BibDatabaseWriter; +import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; +import net.sf.jabref.logic.exporter.ExportFormats; +import net.sf.jabref.logic.exporter.FileSaveSession; +import net.sf.jabref.logic.exporter.IExportFormat; +import net.sf.jabref.logic.exporter.SaveException; +import net.sf.jabref.logic.exporter.SavePreferences; +import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.labelpattern.LabelPatternUtil; import net.sf.jabref.logic.logging.JabRefLogger; diff --git a/src/main/java/net/sf/jabref/cli/JabRefCLI.java b/src/main/java/net/sf/jabref/cli/JabRefCLI.java index 234b37a95f4..b7487365962 100644 --- a/src/main/java/net/sf/jabref/cli/JabRefCLI.java +++ b/src/main/java/net/sf/jabref/cli/JabRefCLI.java @@ -16,7 +16,7 @@ package net.sf.jabref.cli; import net.sf.jabref.Globals; -import net.sf.jabref.exporter.ExportFormats; +import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.l10n.Localization; import org.apache.commons.cli.CommandLine; diff --git a/src/main/java/net/sf/jabref/collab/ChangeScanner.java b/src/main/java/net/sf/jabref/collab/ChangeScanner.java index f9966dc085e..106fc148d10 100644 --- a/src/main/java/net/sf/jabref/collab/ChangeScanner.java +++ b/src/main/java/net/sf/jabref/collab/ChangeScanner.java @@ -35,17 +35,17 @@ import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.BibDatabaseWriter; -import net.sf.jabref.exporter.BibtexDatabaseWriter; -import net.sf.jabref.exporter.FileSaveSession; -import net.sf.jabref.exporter.SaveException; -import net.sf.jabref.exporter.SavePreferences; -import net.sf.jabref.exporter.SaveSession; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.importer.OpenDatabaseAction; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.bibtex.comparator.EntryComparator; +import net.sf.jabref.logic.exporter.BibDatabaseWriter; +import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; +import net.sf.jabref.logic.exporter.FileSaveSession; +import net.sf.jabref.logic.exporter.SaveException; +import net.sf.jabref.logic.exporter.SavePreferences; +import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.groups.GroupTreeNode; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.DuplicateCheck; diff --git a/src/main/java/net/sf/jabref/exporter/ExportFormats.java b/src/main/java/net/sf/jabref/exporter/ExportFormats.java deleted file mode 100644 index d0d7959183b..00000000000 --- a/src/main/java/net/sf/jabref/exporter/ExportFormats.java +++ /dev/null @@ -1,300 +0,0 @@ -/* Copyright (C) 2003-2016 JabRef contributors. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -package net.sf.jabref.exporter; - -import java.awt.event.ActionEvent; -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import javax.swing.filechooser.FileFilter; - -import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; -import net.sf.jabref.gui.JabRefFrame; -import net.sf.jabref.gui.actions.MnemonicAwareAction; -import net.sf.jabref.gui.worker.AbstractWorker; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.entry.BibEntry; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class ExportFormats { - - private static final Log LOGGER = LogFactory.getLog(ExportFormats.class); - - private static final Map EXPORT_FORMATS = new TreeMap<>(); - - // Global variable that is used for counting output entries when exporting: - public static int entryNumber; - - - public static void initAllExports() { - - ExportFormats.EXPORT_FORMATS.clear(); - - // Initialize Build-In Export Formats - ExportFormats.putFormat(new ExportFormat("HTML", "html", "html", null, ".html")); - ExportFormats.putFormat(new ExportFormat(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, ".html")); - ExportFormats.putFormat(new ExportFormat("DocBook 4.4", "docbook", "docbook", null, ".xml")); - ExportFormats.putFormat(new ExportFormat("DIN 1505", "din1505", "din1505winword", "din1505", ".rtf")); - ExportFormats.putFormat(new ExportFormat("BibTeXML", "bibtexml", "bibtexml", null, ".xml")); - ExportFormats.putFormat(new ExportFormat("BibO RDF", "bibordf", "bibordf", null, ".rdf")); - ExportFormats.putFormat(new ModsExportFormat()); - ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", ".html")); - ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML list"), - "listrefs", "listrefs", "listrefs", ".html")); - ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table (with Abstract & BibTeX)"), - "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", ".html")); - ExportFormats.putFormat(new ExportFormat("Harvard RTF", "harvard", "harvard", - "harvard", ".rtf")); - ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690rtf", "iso690RTF", "iso690rtf", ".rtf")); - ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690txt", "iso690", "iso690txt", ".txt")); - ExportFormats.putFormat(new ExportFormat("Endnote", "endnote", "EndNote", "endnote", ".txt")); - ExportFormats.putFormat(new ExportFormat("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", - "openoffice", ".csv")); - ExportFormat ef = new ExportFormat("RIS", "ris", "ris", "ris", ".ris"); - ef.setEncoding(StandardCharsets.UTF_8); - ExportFormats.putFormat(ef); - ExportFormats.putFormat(new ExportFormat("MIS Quarterly", "misq", "misq", "misq", ".rtf")); - - ExportFormats.putFormat(new OpenOfficeDocumentCreator()); - ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator()); - ExportFormats.putFormat(new MSBibExportFormat()); - ExportFormats.putFormat(new ModsExportFormat()); - - // Now add custom export formats - Map customFormats = Globals.prefs.customExports.getCustomExportFormats(); - for (IExportFormat format : customFormats.values()) { - ExportFormats.putFormat(format); - } - } - - /** - * Build a string listing of all available export formats. - * - * @param maxLineLength - * The max line length before a line break must be added. - * @param linePrefix - * If a line break is added, this prefix will be inserted at the - * beginning of the next line. - * @return The string describing available formats. - */ - public static String getConsoleExportList(int maxLineLength, int firstLineSubtr, - String linePrefix) { - StringBuilder sb = new StringBuilder(); - int lastBreak = -firstLineSubtr; - - for (String name : ExportFormats.EXPORT_FORMATS.keySet()) { - if (((sb.length() + 2 + name.length()) - lastBreak) > maxLineLength) { - sb.append(",\n"); - lastBreak = sb.length(); - sb.append(linePrefix); - } else if (sb.length() > 0) { - sb.append(", "); - } - sb.append(name); - } - - return sb.toString(); - } - - /** - * Get a Map of all export formats. - * @return A Map containing all export formats, mapped to their console names. - */ - public static Map getExportFormats() { - // It is perhaps overly paranoid to make a defensive copy in this case: - return Collections.unmodifiableMap(ExportFormats.EXPORT_FORMATS); - } - - /** - * Look up the named export format. - * - * @param consoleName - * The export name given in the JabRef console help information. - * @return The ExportFormat, or null if no exportformat with that name is - * registered. - */ - public static IExportFormat getExportFormat(String consoleName) { - return ExportFormats.EXPORT_FORMATS.get(consoleName); - } - - /** - * Create an AbstractAction for performing an export operation. - * - * @param frame - * The JabRefFrame of this JabRef instance. - * @param selectedOnly - * true indicates that only selected entries should be exported, - * false indicates that all entries should be exported. - * @return The action. - */ - public static AbstractAction getExportAction(JabRefFrame frame, boolean selectedOnly) { - - class ExportAction extends MnemonicAwareAction { - - private final JabRefFrame frame; - - private final boolean selectedOnly; - - - public ExportAction(JabRefFrame frame, boolean selectedOnly) { - this.frame = frame; - this.selectedOnly = selectedOnly; - putValue(Action.NAME, selectedOnly ? Localization.menuTitle("Export selected entries") : - Localization.menuTitle("Export")); - } - - @Override - public void actionPerformed(ActionEvent e) { - ExportFormats.initAllExports(); - JFileChooser fc = ExportFormats.createExportFileChooser( - Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); - fc.showSaveDialog(frame); - File file = fc.getSelectedFile(); - if (file == null) { - return; - } - FileFilter ff = fc.getFileFilter(); - if (ff instanceof ExportFileFilter) { - - ExportFileFilter eff = (ExportFileFilter) ff; - String path = file.getPath(); - if (!path.endsWith(eff.getExtension())) { - path = path + eff.getExtension(); - } - file = new File(path); - if (file.exists()) { - // Warn that the file exists: - if (JOptionPane.showConfirmDialog(frame, - Localization.lang("'%0' exists. Overwrite file?", file.getName()), - Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) { - return; - } - } - final IExportFormat format = eff.getExportFormat(); - List entries; - if (selectedOnly) { - // Selected entries - entries = frame.getCurrentBasePanel().getSelectedEntries(); - } else { - // All entries - entries = frame.getCurrentBasePanel().getDatabase().getEntries(); - } - - // Set the global variable for this database's file directory before exporting, - // so formatters can resolve linked files correctly. - // (This is an ugly hack!) - Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext() - .getFileDirectory(); - - // Make sure we remember which filter was used, to set - // the default for next time: - Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, format.getConsoleName()); - Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent()); - - final File finFile = file; - final List finEntries = entries; - AbstractWorker exportWorker = new AbstractWorker() { - - String errorMessage; - - - @Override - public void run() { - try { - format.performExport(frame.getCurrentBasePanel().getBibDatabaseContext(), - finFile.getPath(), - frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding(), - finEntries); - } catch (Exception ex) { - LOGGER.warn("Problem exporting", ex); - if (ex.getMessage() == null) { - errorMessage = ex.toString(); - } else { - errorMessage = ex.getMessage(); - } - } - } - - @Override - public void update() { - // No error message. Report success: - if (errorMessage == null) { - frame.output(Localization.lang("%0 export successful", format.getDisplayName())); - } - // ... or show an error dialog: - else { - frame.output(Localization.lang("Could not save file.") - + " - " + errorMessage); - // Need to warn the user that saving failed! - JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") - + "\n" + errorMessage, Localization.lang("Save database"), - JOptionPane.ERROR_MESSAGE); - } - } - }; - - // Run the export action in a background thread: - exportWorker.getWorker().run(); - // Run the update method: - exportWorker.update(); - } - } - } - - return new ExportAction(frame, selectedOnly); - } - - private static JFileChooser createExportFileChooser(String currentDir) { - String lastUsedFormat = Globals.prefs.get(JabRefPreferences.LAST_USED_EXPORT); - FileFilter defaultFilter = null; - JFileChooser fc = new JFileChooser(currentDir); - Set filters = new TreeSet<>(); - for (Map.Entry e : ExportFormats.EXPORT_FORMATS.entrySet()) { - String formatName = e.getKey(); - IExportFormat format = e.getValue(); - filters.add(format.getFileFilter()); - if (formatName.equals(lastUsedFormat)) { - defaultFilter = format.getFileFilter(); - } - } - for (FileFilter ff : filters) { - fc.addChoosableFileFilter(ff); - } - fc.setAcceptAllFileFilterUsed(false); - if (defaultFilter != null) { - fc.setFileFilter(defaultFilter); - } - return fc; - } - - private static void putFormat(IExportFormat format) { - ExportFormats.EXPORT_FORMATS.put(format.getConsoleName(), format); - } - -} diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index db900bd77cb..8e65a47c2b7 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -63,13 +63,6 @@ import net.sf.jabref.collab.FileUpdatePanel; import net.sf.jabref.event.EntryAddedEvent; import net.sf.jabref.event.EntryChangedEvent; -import net.sf.jabref.exporter.BibtexDatabaseWriter; -import net.sf.jabref.exporter.ExportToClipboardAction; -import net.sf.jabref.exporter.FileSaveSession; -import net.sf.jabref.exporter.SaveDatabaseAction; -import net.sf.jabref.exporter.SaveException; -import net.sf.jabref.exporter.SavePreferences; -import net.sf.jabref.exporter.SaveSession; import net.sf.jabref.external.AttachFileAction; import net.sf.jabref.external.ExternalFileMenuItem; import net.sf.jabref.external.ExternalFileType; @@ -83,6 +76,8 @@ import net.sf.jabref.gui.actions.CleanupAction; import net.sf.jabref.gui.desktop.JabRefDesktop; import net.sf.jabref.gui.entryeditor.EntryEditor; +import net.sf.jabref.gui.exporter.ExportToClipboardAction; +import net.sf.jabref.gui.exporter.SaveDatabaseAction; import net.sf.jabref.gui.fieldeditors.FieldEditor; import net.sf.jabref.gui.groups.GroupAddRemoveDialog; import net.sf.jabref.gui.groups.GroupSelector; @@ -117,6 +112,11 @@ import net.sf.jabref.logic.autocompleter.AutoCompleter; import net.sf.jabref.logic.autocompleter.AutoCompleterFactory; import net.sf.jabref.logic.autocompleter.ContentAutoCompleters; +import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; +import net.sf.jabref.logic.exporter.FileSaveSession; +import net.sf.jabref.logic.exporter.SaveException; +import net.sf.jabref.logic.exporter.SavePreferences; +import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Encodings; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.labelpattern.LabelPatternUtil; diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index 6b43f4ef296..4645e65ddcf 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -74,11 +74,6 @@ import net.sf.jabref.HighlightMatchingGroupPreferences; import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.JabRefPreferences; -import net.sf.jabref.exporter.AutoSaveManager; -import net.sf.jabref.exporter.ExportCustomizationDialog; -import net.sf.jabref.exporter.ExportFormats; -import net.sf.jabref.exporter.SaveAllAction; -import net.sf.jabref.exporter.SaveDatabaseAction; import net.sf.jabref.external.ExternalFileTypeEditor; import net.sf.jabref.external.push.PushToApplicationButton; import net.sf.jabref.external.push.PushToApplications; @@ -96,6 +91,11 @@ import net.sf.jabref.gui.actions.SearchForUpdateAction; import net.sf.jabref.gui.actions.SortTabsAction; import net.sf.jabref.gui.dbproperties.DatabasePropertiesDialog; +import net.sf.jabref.gui.exporter.AutoSaveManager; +import net.sf.jabref.gui.exporter.ExportAction; +import net.sf.jabref.gui.exporter.ExportCustomizationDialog; +import net.sf.jabref.gui.exporter.SaveAllAction; +import net.sf.jabref.gui.exporter.SaveDatabaseAction; import net.sf.jabref.gui.groups.EntryTableTransferHandler; import net.sf.jabref.gui.groups.GroupSelector; import net.sf.jabref.gui.help.AboutAction; @@ -239,8 +239,8 @@ public class JabRefFrame extends JFrame implements OutputPrinter { private final AbstractAction saveSelectedAsPlain = new GeneralAction(Actions.SAVE_SELECTED_AS_PLAIN, Localization.menuTitle("Save selected as plain BibTeX..."), Localization.lang("Save selected as plain BibTeX...")); - private final AbstractAction exportAll = ExportFormats.getExportAction(this, false); - private final AbstractAction exportSelected = ExportFormats.getExportAction(this, true); + private final AbstractAction exportAll = ExportAction.getExportAction(this, false); + private final AbstractAction exportSelected = ExportAction.getExportAction(this, true); private final AbstractAction importCurrent = ImportFormats.getImportAction(this, false); private final AbstractAction importNew = ImportFormats.getImportAction(this, true); public final AbstractAction nextTab = new ChangeTabAction(true); diff --git a/src/main/java/net/sf/jabref/gui/PreviewPanel.java b/src/main/java/net/sf/jabref/gui/PreviewPanel.java index 0868f26f648..a5e326a5815 100644 --- a/src/main/java/net/sf/jabref/gui/PreviewPanel.java +++ b/src/main/java/net/sf/jabref/gui/PreviewPanel.java @@ -51,10 +51,10 @@ import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.event.FieldChangedEvent; -import net.sf.jabref.exporter.ExportFormats; import net.sf.jabref.gui.desktop.JabRefDesktop; import net.sf.jabref.gui.fieldeditors.PreviewPanelTransferHandler; import net.sf.jabref.gui.keyboard.KeyBinding; +import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutHelper; diff --git a/src/main/java/net/sf/jabref/gui/cleanup/CleanupActionsListModel.java b/src/main/java/net/sf/jabref/gui/cleanup/CleanupActionsListModel.java index ecdd75297f0..280d508b911 100644 --- a/src/main/java/net/sf/jabref/gui/cleanup/CleanupActionsListModel.java +++ b/src/main/java/net/sf/jabref/gui/cleanup/CleanupActionsListModel.java @@ -8,8 +8,8 @@ import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; public class CleanupActionsListModel implements ListModel { diff --git a/src/main/java/net/sf/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java b/src/main/java/net/sf/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java index f1fcee95994..defbadce4de 100644 --- a/src/main/java/net/sf/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java +++ b/src/main/java/net/sf/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java @@ -41,8 +41,8 @@ import javax.swing.event.ListDataListener; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.formatter.Formatter; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; diff --git a/src/main/java/net/sf/jabref/gui/dbproperties/DatabasePropertiesDialog.java b/src/main/java/net/sf/jabref/gui/dbproperties/DatabasePropertiesDialog.java index c96900b7bd3..4128bb4b587 100644 --- a/src/main/java/net/sf/jabref/gui/dbproperties/DatabasePropertiesDialog.java +++ b/src/main/java/net/sf/jabref/gui/dbproperties/DatabasePropertiesDialog.java @@ -38,13 +38,13 @@ import net.sf.jabref.Globals; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.SaveOrderConfigDisplay; import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.gui.cleanup.FieldFormatterCleanupsPanel; import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.logic.config.SaveOrderConfig; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.l10n.Encodings; import net.sf.jabref.logic.l10n.Localization; diff --git a/src/main/java/net/sf/jabref/exporter/AutoSaveManager.java b/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java similarity index 93% rename from src/main/java/net/sf/jabref/exporter/AutoSaveManager.java rename to src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java index 6e62c22d6da..a94d78e063f 100644 --- a/src/main/java/net/sf/jabref/exporter/AutoSaveManager.java +++ b/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.io.File; import java.util.Timer; @@ -23,6 +23,12 @@ import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; +import net.sf.jabref.logic.exporter.BibDatabaseWriter; +import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; +import net.sf.jabref.logic.exporter.FileSaveSession; +import net.sf.jabref.logic.exporter.SaveException; +import net.sf.jabref.logic.exporter.SavePreferences; +import net.sf.jabref.logic.exporter.SaveSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/exporter/CustomExportDialog.java b/src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/CustomExportDialog.java rename to src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java index 489a69af8c8..f68817af2f2 100644 --- a/src/main/java/net/sf/jabref/exporter/CustomExportDialog.java +++ b/src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.awt.BorderLayout; import java.awt.GridBagConstraints; diff --git a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java new file mode 100644 index 00000000000..6686265d035 --- /dev/null +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java @@ -0,0 +1,184 @@ +package net.sf.jabref.gui.exporter; + +import java.awt.event.ActionEvent; +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileFilter; + +import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.gui.JabRefFrame; +import net.sf.jabref.gui.actions.MnemonicAwareAction; +import net.sf.jabref.gui.worker.AbstractWorker; +import net.sf.jabref.logic.exporter.ExportFormats; +import net.sf.jabref.logic.exporter.IExportFormat; +import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.model.entry.BibEntry; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ExportAction { + + private static final Log LOGGER = LogFactory.getLog(ExportAction.class); + + + /** + * Create an AbstractAction for performing an export operation. + * + * @param frame + * The JabRefFrame of this JabRef instance. + * @param selectedOnly + * true indicates that only selected entries should be exported, + * false indicates that all entries should be exported. + * @return The action. + */ + public static AbstractAction getExportAction(JabRefFrame frame, boolean selectedOnly) { + + class InternalExportAction extends MnemonicAwareAction { + + private final JabRefFrame frame; + + private final boolean selectedOnly; + + + public InternalExportAction(JabRefFrame frame, boolean selectedOnly) { + this.frame = frame; + this.selectedOnly = selectedOnly; + putValue(Action.NAME, selectedOnly ? Localization.menuTitle("Export selected entries") : Localization + .menuTitle("Export")); + } + + @Override + public void actionPerformed(ActionEvent e) { + ExportFormats.initAllExports(); + JFileChooser fc = ExportAction + .createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); + fc.showSaveDialog(frame); + File file = fc.getSelectedFile(); + if (file == null) { + return; + } + FileFilter ff = fc.getFileFilter(); + if (ff instanceof ExportFileFilter) { + + ExportFileFilter eff = (ExportFileFilter) ff; + String path = file.getPath(); + if (!path.endsWith(eff.getExtension())) { + path = path + eff.getExtension(); + } + file = new File(path); + if (file.exists()) { + // Warn that the file exists: + if (JOptionPane.showConfirmDialog(frame, + Localization.lang("'%0' exists. Overwrite file?", file.getName()), + Localization.lang("Export"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) { + return; + } + } + final IExportFormat format = eff.getExportFormat(); + List entries; + if (selectedOnly) { + // Selected entries + entries = frame.getCurrentBasePanel().getSelectedEntries(); + } else { + // All entries + entries = frame.getCurrentBasePanel().getDatabase().getEntries(); + } + + // Set the global variable for this database's file directory before exporting, + // so formatters can resolve linked files correctly. + // (This is an ugly hack!) + Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext() + .getFileDirectory(); + + // Make sure we remember which filter was used, to set + // the default for next time: + Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, format.getConsoleName()); + Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent()); + + final File finFile = file; + final List finEntries = entries; + AbstractWorker exportWorker = new AbstractWorker() { + + String errorMessage; + + + @Override + public void run() { + try { + format.performExport(frame.getCurrentBasePanel().getBibDatabaseContext(), + finFile.getPath(), + frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding(), + finEntries); + } catch (Exception ex) { + LOGGER.warn("Problem exporting", ex); + if (ex.getMessage() == null) { + errorMessage = ex.toString(); + } else { + errorMessage = ex.getMessage(); + } + } + } + + @Override + public void update() { + // No error message. Report success: + if (errorMessage == null) { + frame.output(Localization.lang("%0 export successful", format.getDisplayName())); + } + // ... or show an error dialog: + else { + frame.output(Localization.lang("Could not save file.") + " - " + errorMessage); + // Need to warn the user that saving failed! + JOptionPane.showMessageDialog(frame, + Localization.lang("Could not save file.") + "\n" + errorMessage, + Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); + } + } + }; + + // Run the export action in a background thread: + exportWorker.getWorker().run(); + // Run the update method: + exportWorker.update(); + } + } + } + + return new InternalExportAction(frame, selectedOnly); + } + + private static JFileChooser createExportFileChooser(String currentDir) { + String lastUsedFormat = Globals.prefs.get(JabRefPreferences.LAST_USED_EXPORT); + FileFilter defaultFilter = null; + JFileChooser fc = new JFileChooser(currentDir); + Set filters = new TreeSet<>(); + for (Map.Entry e : ExportFormats.getExportFormats().entrySet()) { + String formatName = e.getKey(); + IExportFormat format = e.getValue(); + ExportFileFilter exportFileFilter = new ExportFileFilter(format); + filters.add(exportFileFilter); + if (formatName.equals(lastUsedFormat)) { + defaultFilter = exportFileFilter; + } + } + for (FileFilter ff : filters) { + fc.addChoosableFileFilter(ff); + } + fc.setAcceptAllFileFilterUsed(false); + if (defaultFilter != null) { + fc.setFileFilter(defaultFilter); + } + return fc; + } + +} diff --git a/src/main/java/net/sf/jabref/exporter/ExportCustomizationDialog.java b/src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/ExportCustomizationDialog.java rename to src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java index f9a0edc299d..38ba30fbe58 100644 --- a/src/main/java/net/sf/jabref/exporter/ExportCustomizationDialog.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.awt.BorderLayout; import java.awt.Dimension; diff --git a/src/main/java/net/sf/jabref/exporter/ExportFileFilter.java b/src/main/java/net/sf/jabref/gui/exporter/ExportFileFilter.java similarity index 88% rename from src/main/java/net/sf/jabref/exporter/ExportFileFilter.java rename to src/main/java/net/sf/jabref/gui/exporter/ExportFileFilter.java index fd7d576f48e..6361316c699 100644 --- a/src/main/java/net/sf/jabref/exporter/ExportFileFilter.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportFileFilter.java @@ -13,26 +13,28 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.io.File; import javax.swing.filechooser.FileFilter; +import net.sf.jabref.logic.exporter.IExportFormat; + /** * File filter that lets the user choose export format while choosing file to * export to. Contains a reference to the ExportFormat in question. */ -class ExportFileFilter extends FileFilter implements Comparable { +public class ExportFileFilter extends FileFilter implements Comparable { private final IExportFormat format; private final String extension; private final String name; - public ExportFileFilter(IExportFormat format, String extension) { + public ExportFileFilter(IExportFormat format) { this.format = format; - this.extension = extension; + this.extension = format.getExtension(); this.name = format.getDisplayName() + " (*" + extension + ')'; } diff --git a/src/main/java/net/sf/jabref/exporter/ExportToClipboardAction.java b/src/main/java/net/sf/jabref/gui/exporter/ExportToClipboardAction.java similarity index 97% rename from src/main/java/net/sf/jabref/exporter/ExportToClipboardAction.java rename to src/main/java/net/sf/jabref/gui/exporter/ExportToClipboardAction.java index b3585157b48..fe950b8bc7e 100644 --- a/src/main/java/net/sf/jabref/exporter/ExportToClipboardAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportToClipboardAction.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.awt.Toolkit; import java.awt.datatransfer.ClipboardOwner; @@ -35,6 +35,8 @@ import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.worker.AbstractWorker; +import net.sf.jabref.logic.exporter.ExportFormats; +import net.sf.jabref.logic.exporter.IExportFormat; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; diff --git a/src/main/java/net/sf/jabref/exporter/RtfSelection.java b/src/main/java/net/sf/jabref/gui/exporter/RtfSelection.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/RtfSelection.java rename to src/main/java/net/sf/jabref/gui/exporter/RtfSelection.java index f4a6512c606..8306860b279 100644 --- a/src/main/java/net/sf/jabref/exporter/RtfSelection.java +++ b/src/main/java/net/sf/jabref/gui/exporter/RtfSelection.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; diff --git a/src/main/java/net/sf/jabref/exporter/SaveAllAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveAllAction.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/SaveAllAction.java rename to src/main/java/net/sf/jabref/gui/exporter/SaveAllAction.java index 84b83cc52b1..4394d5e92e5 100644 --- a/src/main/java/net/sf/jabref/exporter/SaveAllAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveAllAction.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.awt.event.ActionEvent; diff --git a/src/main/java/net/sf/jabref/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/SaveDatabaseAction.java rename to src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index f7245aebcd9..fb4f516716b 100644 --- a/src/main/java/net/sf/jabref/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -14,7 +14,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.gui.exporter; import java.io.File; import java.io.IOException; @@ -37,6 +37,11 @@ import net.sf.jabref.gui.worker.AbstractWorker; import net.sf.jabref.gui.worker.CallBack; import net.sf.jabref.gui.worker.Worker; +import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; +import net.sf.jabref.logic.exporter.FileSaveSession; +import net.sf.jabref.logic.exporter.SaveException; +import net.sf.jabref.logic.exporter.SavePreferences; +import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Encodings; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.io.FileBasedLock; diff --git a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java index 84d9f5bd31f..7cf910aa5cb 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java @@ -41,12 +41,12 @@ import net.sf.jabref.JabRefPreferences; import net.sf.jabref.JabRefPreferencesFilter; import net.sf.jabref.JabRefPreferencesFilterDialog; -import net.sf.jabref.exporter.ExportFormats; import net.sf.jabref.gui.FileDialogs; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.keyboard.KeyBinder; import net.sf.jabref.gui.maintable.MainTable; +import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.l10n.Localization; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/net/sf/jabref/importer/AutosaveStartupPrompter.java b/src/main/java/net/sf/jabref/importer/AutosaveStartupPrompter.java index e3c678fc365..a74e0ecb9a0 100644 --- a/src/main/java/net/sf/jabref/importer/AutosaveStartupPrompter.java +++ b/src/main/java/net/sf/jabref/importer/AutosaveStartupPrompter.java @@ -26,10 +26,10 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; -import net.sf.jabref.exporter.AutoSaveManager; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.ParserResultWarningDialog; +import net.sf.jabref.gui.exporter.AutoSaveManager; import net.sf.jabref.logic.l10n.Localization; /** diff --git a/src/main/java/net/sf/jabref/importer/OpenDatabaseAction.java b/src/main/java/net/sf/jabref/importer/OpenDatabaseAction.java index 4777284a30e..5c73a0c625b 100644 --- a/src/main/java/net/sf/jabref/importer/OpenDatabaseAction.java +++ b/src/main/java/net/sf/jabref/importer/OpenDatabaseAction.java @@ -36,13 +36,13 @@ import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.AutoSaveManager; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.FileDialogs; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.ParserResultWarningDialog; import net.sf.jabref.gui.actions.MnemonicAwareAction; +import net.sf.jabref.gui.exporter.AutoSaveManager; import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.importer.fileformat.BibtexImporter; diff --git a/src/main/java/net/sf/jabref/logic/cleanup/CleanupPreset.java b/src/main/java/net/sf/jabref/logic/cleanup/CleanupPreset.java index b0ed7b6fa3d..e90c3f1c32b 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/CleanupPreset.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/CleanupPreset.java @@ -20,7 +20,7 @@ import java.util.Set; import net.sf.jabref.JabRefPreferences; -import net.sf.jabref.exporter.FieldFormatterCleanups; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; public class CleanupPreset { diff --git a/src/main/java/net/sf/jabref/exporter/BibDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/BibDatabaseWriter.java rename to src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java index 0b06ee4bb41..f8d74d2f606 100644 --- a/src/main/java/net/sf/jabref/exporter/BibDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java @@ -14,8 +14,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.IOException; import java.nio.charset.Charset; diff --git a/src/main/java/net/sf/jabref/exporter/BibtexDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/BibtexDatabaseWriter.java rename to src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java index abd599c977a..1141323cf3b 100644 --- a/src/main/java/net/sf/jabref/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.IOException; import java.io.Writer; diff --git a/src/main/java/net/sf/jabref/exporter/CustomExportList.java b/src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/CustomExportList.java rename to src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java index ba0091b1c85..f4af48464b3 100644 --- a/src/main/java/net/sf/jabref/exporter/CustomExportList.java +++ b/src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.util.Comparator; import java.util.List; diff --git a/src/main/java/net/sf/jabref/exporter/ExportComparator.java b/src/main/java/net/sf/jabref/logic/exporter/ExportComparator.java similarity index 96% rename from src/main/java/net/sf/jabref/exporter/ExportComparator.java rename to src/main/java/net/sf/jabref/logic/exporter/ExportComparator.java index 46830f0c5b2..ed4082ee816 100644 --- a/src/main/java/net/sf/jabref/exporter/ExportComparator.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportComparator.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.util.Comparator; import java.util.List; diff --git a/src/main/java/net/sf/jabref/exporter/ExportFormat.java b/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java similarity index 96% rename from src/main/java/net/sf/jabref/exporter/ExportFormat.java rename to src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java index 97475878f7e..4cb6ba4a357 100644 --- a/src/main/java/net/sf/jabref/exporter/ExportFormat.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.File; import java.io.FileNotFoundException; @@ -31,8 +31,6 @@ import java.util.Map; import java.util.Objects; -import javax.swing.filechooser.FileFilter; - import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; import net.sf.jabref.logic.layout.Layout; @@ -55,7 +53,6 @@ public class ExportFormat implements IExportFormat { private Charset encoding; // If this value is set, it will be used to override // the default encoding for the getCurrentBasePanel. - private FileFilter fileFilter; private boolean customExport; private static final String LAYOUT_PREFIX = "/resource/layout/"; @@ -123,6 +120,14 @@ public void setEncoding(Charset encoding) { this.encoding = encoding; } + /** + * @see IExportFormat#getExtension() + */ + @Override + public String getExtension() { + return extension; + } + /** * This method should return a reader from which the given layout file can * be read. @@ -177,7 +182,7 @@ private Reader getReader(String filename) throws IOException { * @throws IOException if a problem occurred while trying to write to {@code writer} * or read from required resources. * @throws Exception if any other error occurred during export. - * @see net.sf.jabref.exporter.IExportFormat#performExport(BibDatabaseContext, String, Charset, List) + * @see net.sf.jabref.logic.exporter.IExportFormat#performExport(BibDatabaseContext, String, Charset, List) */ @Override public void performExport(final BibDatabaseContext databaseContext, final String file, @@ -359,17 +364,6 @@ private static Map readFormatterFile(String lfFileName) { return formatters; } - /** - * @see net.sf.jabref.exporter.IExportFormat#getFileFilter() - */ - @Override - public FileFilter getFileFilter() { - if (fileFilter == null) { - fileFilter = new ExportFileFilter(this, extension); - } - return fileFilter; - } - public void finalizeSaveSession(final SaveSession ss, Path file) throws SaveException, IOException { ss.getWriter().flush(); ss.getWriter().close(); diff --git a/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java b/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java new file mode 100644 index 00000000000..f5b1de8a3ea --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java @@ -0,0 +1,130 @@ +/* Copyright (C) 2003-2016 JabRef contributors. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +package net.sf.jabref.logic.exporter; + +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; + +import net.sf.jabref.Globals; +import net.sf.jabref.logic.l10n.Localization; + +public class ExportFormats { + + private static final Map EXPORT_FORMATS = new TreeMap<>(); + + // Global variable that is used for counting output entries when exporting: + public static int entryNumber; + + + public static void initAllExports() { + + ExportFormats.EXPORT_FORMATS.clear(); + + // Initialize Build-In Export Formats + ExportFormats.putFormat(new ExportFormat("HTML", "html", "html", null, ".html")); + ExportFormats.putFormat(new ExportFormat(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, ".html")); + ExportFormats.putFormat(new ExportFormat("DocBook 4.4", "docbook", "docbook", null, ".xml")); + ExportFormats.putFormat(new ExportFormat("DIN 1505", "din1505", "din1505winword", "din1505", ".rtf")); + ExportFormats.putFormat(new ExportFormat("BibTeXML", "bibtexml", "bibtexml", null, ".xml")); + ExportFormats.putFormat(new ExportFormat("BibO RDF", "bibordf", "bibordf", null, ".rdf")); + ExportFormats.putFormat(new ModsExportFormat()); + ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", ".html")); + ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML list"), + "listrefs", "listrefs", "listrefs", ".html")); + ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table (with Abstract & BibTeX)"), + "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", ".html")); + ExportFormats.putFormat(new ExportFormat("Harvard RTF", "harvard", "harvard", + "harvard", ".rtf")); + ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690rtf", "iso690RTF", "iso690rtf", ".rtf")); + ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690txt", "iso690", "iso690txt", ".txt")); + ExportFormats.putFormat(new ExportFormat("Endnote", "endnote", "EndNote", "endnote", ".txt")); + ExportFormats.putFormat(new ExportFormat("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", + "openoffice", ".csv")); + ExportFormat ef = new ExportFormat("RIS", "ris", "ris", "ris", ".ris"); + ef.setEncoding(StandardCharsets.UTF_8); + ExportFormats.putFormat(ef); + ExportFormats.putFormat(new ExportFormat("MIS Quarterly", "misq", "misq", "misq", ".rtf")); + + ExportFormats.putFormat(new OpenOfficeDocumentCreator()); + ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator()); + ExportFormats.putFormat(new MSBibExportFormat()); + ExportFormats.putFormat(new ModsExportFormat()); + + // Now add custom export formats + Map customFormats = Globals.prefs.customExports.getCustomExportFormats(); + for (IExportFormat format : customFormats.values()) { + ExportFormats.putFormat(format); + } + } + + /** + * Build a string listing of all available export formats. + * + * @param maxLineLength + * The max line length before a line break must be added. + * @param linePrefix + * If a line break is added, this prefix will be inserted at the + * beginning of the next line. + * @return The string describing available formats. + */ + public static String getConsoleExportList(int maxLineLength, int firstLineSubtr, + String linePrefix) { + StringBuilder sb = new StringBuilder(); + int lastBreak = -firstLineSubtr; + + for (String name : ExportFormats.EXPORT_FORMATS.keySet()) { + if (((sb.length() + 2 + name.length()) - lastBreak) > maxLineLength) { + sb.append(",\n"); + lastBreak = sb.length(); + sb.append(linePrefix); + } else if (sb.length() > 0) { + sb.append(", "); + } + sb.append(name); + } + + return sb.toString(); + } + + /** + * Get a Map of all export formats. + * @return A Map containing all export formats, mapped to their console names. + */ + public static Map getExportFormats() { + // It is perhaps overly paranoid to make a defensive copy in this case: + return Collections.unmodifiableMap(ExportFormats.EXPORT_FORMATS); + } + + /** + * Look up the named export format. + * + * @param consoleName + * The export name given in the JabRef console help information. + * @return The ExportFormat, or null if no exportformat with that name is + * registered. + */ + public static IExportFormat getExportFormat(String consoleName) { + return ExportFormats.EXPORT_FORMATS.get(consoleName); + } + + + private static void putFormat(IExportFormat format) { + ExportFormats.EXPORT_FORMATS.put(format.getConsoleName(), format); + } + +} diff --git a/src/main/java/net/sf/jabref/exporter/FieldFormatterCleanups.java b/src/main/java/net/sf/jabref/logic/exporter/FieldFormatterCleanups.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/FieldFormatterCleanups.java rename to src/main/java/net/sf/jabref/logic/exporter/FieldFormatterCleanups.java index dcb44ddc88c..2b18076d37e 100644 --- a/src/main/java/net/sf/jabref/exporter/FieldFormatterCleanups.java +++ b/src/main/java/net/sf/jabref/logic/exporter/FieldFormatterCleanups.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/net/sf/jabref/exporter/FileSaveSession.java b/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/FileSaveSession.java rename to src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java index 9530b6fbe04..eee1a54b91a 100644 --- a/src/main/java/net/sf/jabref/exporter/FileSaveSession.java +++ b/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -54,7 +54,7 @@ public class FileSaveSession extends SaveSession { private static final String TEMP_PREFIX = "jabref"; private static final String TEMP_SUFFIX = "save.bib"; private final boolean useLockFile; - private Path temporaryFile; + private final Path temporaryFile; public FileSaveSession(Charset encoding, boolean backup) throws SaveException { this(encoding, backup, createTemporaryFile()); diff --git a/src/main/java/net/sf/jabref/exporter/IExportFormat.java b/src/main/java/net/sf/jabref/logic/exporter/IExportFormat.java similarity index 92% rename from src/main/java/net/sf/jabref/exporter/IExportFormat.java rename to src/main/java/net/sf/jabref/logic/exporter/IExportFormat.java index 98e19f73b67..ced4d983a94 100644 --- a/src/main/java/net/sf/jabref/exporter/IExportFormat.java +++ b/src/main/java/net/sf/jabref/logic/exporter/IExportFormat.java @@ -13,14 +13,12 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.nio.charset.Charset; import java.nio.file.Path; import java.util.List; -import javax.swing.filechooser.FileFilter; - import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.model.entry.BibEntry; @@ -37,10 +35,7 @@ public interface IExportFormat { */ String getDisplayName(); - /** - * A file filter that accepts filetypes that this exporter would create. - */ - FileFilter getFileFilter(); + String getExtension(); /** * Perform the export. diff --git a/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java b/src/main/java/net/sf/jabref/logic/exporter/MSBibExportFormat.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java rename to src/main/java/net/sf/jabref/logic/exporter/MSBibExportFormat.java index f33852aec1b..ee17ff813ad 100644 --- a/src/main/java/net/sf/jabref/exporter/MSBibExportFormat.java +++ b/src/main/java/net/sf/jabref/logic/exporter/MSBibExportFormat.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.IOException; import java.nio.charset.Charset; diff --git a/src/main/java/net/sf/jabref/exporter/ModsExportFormat.java b/src/main/java/net/sf/jabref/logic/exporter/ModsExportFormat.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/ModsExportFormat.java rename to src/main/java/net/sf/jabref/logic/exporter/ModsExportFormat.java index b43f079a622..04308883bdb 100644 --- a/src/main/java/net/sf/jabref/exporter/ModsExportFormat.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ModsExportFormat.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.IOException; import java.nio.charset.Charset; diff --git a/src/main/java/net/sf/jabref/exporter/OOCalcDatabase.java b/src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/OOCalcDatabase.java rename to src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java index 9c4a34ead00..be761efcf0f 100644 --- a/src/main/java/net/sf/jabref/exporter/OOCalcDatabase.java +++ b/src/main/java/net/sf/jabref/logic/exporter/OOCalcDatabase.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/net/sf/jabref/exporter/OpenDocumentRepresentation.java b/src/main/java/net/sf/jabref/logic/exporter/OpenDocumentRepresentation.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/OpenDocumentRepresentation.java rename to src/main/java/net/sf/jabref/logic/exporter/OpenDocumentRepresentation.java index b03e6daa0b1..2cd3c68b5c2 100644 --- a/src/main/java/net/sf/jabref/exporter/OpenDocumentRepresentation.java +++ b/src/main/java/net/sf/jabref/logic/exporter/OpenDocumentRepresentation.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/net/sf/jabref/exporter/OpenDocumentSpreadsheetCreator.java b/src/main/java/net/sf/jabref/logic/exporter/OpenDocumentSpreadsheetCreator.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/OpenDocumentSpreadsheetCreator.java rename to src/main/java/net/sf/jabref/logic/exporter/OpenDocumentSpreadsheetCreator.java index 56960af0bbe..62e4a25df21 100644 --- a/src/main/java/net/sf/jabref/exporter/OpenDocumentSpreadsheetCreator.java +++ b/src/main/java/net/sf/jabref/logic/exporter/OpenDocumentSpreadsheetCreator.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; diff --git a/src/main/java/net/sf/jabref/exporter/OpenOfficeDocumentCreator.java b/src/main/java/net/sf/jabref/logic/exporter/OpenOfficeDocumentCreator.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/OpenOfficeDocumentCreator.java rename to src/main/java/net/sf/jabref/logic/exporter/OpenOfficeDocumentCreator.java index 2a104480d3b..ce0668a30c6 100644 --- a/src/main/java/net/sf/jabref/exporter/OpenOfficeDocumentCreator.java +++ b/src/main/java/net/sf/jabref/logic/exporter/OpenOfficeDocumentCreator.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; diff --git a/src/main/java/net/sf/jabref/exporter/SaveException.java b/src/main/java/net/sf/jabref/logic/exporter/SaveException.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/SaveException.java rename to src/main/java/net/sf/jabref/logic/exporter/SaveException.java index c2597d6c55d..0c4d6143a43 100644 --- a/src/main/java/net/sf/jabref/exporter/SaveException.java +++ b/src/main/java/net/sf/jabref/logic/exporter/SaveException.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; diff --git a/src/main/java/net/sf/jabref/exporter/SavePreferences.java b/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java similarity index 99% rename from src/main/java/net/sf/jabref/exporter/SavePreferences.java rename to src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java index 5230f1953b9..0d0b52db800 100644 --- a/src/main/java/net/sf/jabref/exporter/SavePreferences.java +++ b/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.nio.charset.Charset; diff --git a/src/main/java/net/sf/jabref/exporter/SaveSession.java b/src/main/java/net/sf/jabref/logic/exporter/SaveSession.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/SaveSession.java rename to src/main/java/net/sf/jabref/logic/exporter/SaveSession.java index 57898db111d..6b95ac4e907 100644 --- a/src/main/java/net/sf/jabref/exporter/SaveSession.java +++ b/src/main/java/net/sf/jabref/logic/exporter/SaveSession.java @@ -15,7 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.nio.charset.Charset; import java.nio.file.Path; diff --git a/src/main/java/net/sf/jabref/exporter/StringSaveSession.java b/src/main/java/net/sf/jabref/logic/exporter/StringSaveSession.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/StringSaveSession.java rename to src/main/java/net/sf/jabref/logic/exporter/StringSaveSession.java index 3fec5c30f30..fbdc4d9a4f2 100644 --- a/src/main/java/net/sf/jabref/exporter/StringSaveSession.java +++ b/src/main/java/net/sf/jabref/logic/exporter/StringSaveSession.java @@ -15,7 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/main/java/net/sf/jabref/exporter/VerifyingWriter.java b/src/main/java/net/sf/jabref/logic/exporter/VerifyingWriter.java similarity index 98% rename from src/main/java/net/sf/jabref/exporter/VerifyingWriter.java rename to src/main/java/net/sf/jabref/logic/exporter/VerifyingWriter.java index 8a40ccd7244..4f636e345ab 100644 --- a/src/main/java/net/sf/jabref/exporter/VerifyingWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/VerifyingWriter.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.IOException; import java.io.OutputStream; diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java index 905b2ad6e15..c0cbba8d536 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java @@ -40,7 +40,7 @@ public class GroupTreeNode extends TreeNode { * * @param group the group underlying this node */ - private GroupTreeNode(AbstractGroup group) { + public GroupTreeNode(AbstractGroup group) { super(GroupTreeNode.class); setGroup(group); } @@ -85,7 +85,7 @@ public Optional setGroup(AbstractGroup newGroup, boolean sho if (shouldKeepPreviousAssignments && newGroup.supportsAdd()) { List entriesMatchedByOldGroup = entriesInDatabase.stream().filter(oldGroup::isMatch) .collect(Collectors.toList()); - if (oldGroup instanceof ExplicitGroup && newGroup instanceof ExplicitGroup) { + if ((oldGroup instanceof ExplicitGroup) && (newGroup instanceof ExplicitGroup)) { // Rename of explicit group, so remove old group assignment oldGroup.remove(entriesMatchedByOldGroup); } @@ -170,7 +170,7 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (o == null || getClass() != o.getClass()) { + if ((o == null) || (getClass() != o.getClass())) { return false; } GroupTreeNode that = (GroupTreeNode) o; diff --git a/src/main/java/net/sf/jabref/logic/layout/format/Number.java b/src/main/java/net/sf/jabref/logic/layout/format/Number.java index 238eb50b070..71f8998cde2 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/Number.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/Number.java @@ -15,7 +15,7 @@ */ package net.sf.jabref.logic.layout.format; -import net.sf.jabref.exporter.ExportFormats; +import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.layout.ParamLayoutFormatter; /** diff --git a/src/main/java/net/sf/jabref/sql/exporter/DatabaseExporter.java b/src/main/java/net/sf/jabref/sql/exporter/DatabaseExporter.java index 24cc5990faa..644ccdf0423 100644 --- a/src/main/java/net/sf/jabref/sql/exporter/DatabaseExporter.java +++ b/src/main/java/net/sf/jabref/sql/exporter/DatabaseExporter.java @@ -30,9 +30,9 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; -import net.sf.jabref.exporter.BibDatabaseWriter; -import net.sf.jabref.exporter.SavePreferences; import net.sf.jabref.gui.JabRefFrame; +import net.sf.jabref.logic.exporter.BibDatabaseWriter; +import net.sf.jabref.logic.exporter.SavePreferences; import net.sf.jabref.logic.groups.AbstractGroup; import net.sf.jabref.logic.groups.AllEntriesGroup; import net.sf.jabref.logic.groups.ExplicitGroup; diff --git a/src/test/java/net/sf/jabref/MetaDataTest.java b/src/test/java/net/sf/jabref/MetaDataTest.java index 81fb660887d..a0c7d9450b5 100644 --- a/src/test/java/net/sf/jabref/MetaDataTest.java +++ b/src/test/java/net/sf/jabref/MetaDataTest.java @@ -4,8 +4,8 @@ import java.util.Map; import java.util.TreeMap; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.formatter.casechanger.LowerCaseFormatter; import org.junit.Before; diff --git a/src/test/java/net/sf/jabref/cleanup/CleanupActionsListModelTest.java b/src/test/java/net/sf/jabref/cleanup/CleanupActionsListModelTest.java index 9252e726c9a..d15e7ab4d42 100644 --- a/src/test/java/net/sf/jabref/cleanup/CleanupActionsListModelTest.java +++ b/src/test/java/net/sf/jabref/cleanup/CleanupActionsListModelTest.java @@ -8,9 +8,9 @@ import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.gui.cleanup.CleanupActionsListModel; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.formatter.bibtexfields.ClearFormatter; import org.junit.Test; diff --git a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java index adc87ca2342..29b0fef3e8f 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java @@ -14,10 +14,10 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; -import net.sf.jabref.exporter.FieldFormatterCleanups; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.cleanup.FieldFormatterCleanup; import net.sf.jabref.logic.config.SaveOrderConfig; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.formatter.casechanger.LowerCaseFormatter; import net.sf.jabref.logic.groups.AllEntriesGroup; import net.sf.jabref.logic.groups.ExplicitGroup; diff --git a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java index 25a6eed16a4..30bc897ee92 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java @@ -11,7 +11,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; -import net.sf.jabref.exporter.FieldFormatterCleanups; +import net.sf.jabref.logic.exporter.FieldFormatterCleanups; import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; import net.sf.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; diff --git a/src/test/java/net/sf/jabref/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java similarity index 99% rename from src/test/java/net/sf/jabref/exporter/BibtexDatabaseWriterTest.java rename to src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index e9cd0d57662..f5cce9ba6c6 100644 --- a/src/test/java/net/sf/jabref/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -1,6 +1,5 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; -import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; @@ -49,7 +48,7 @@ public class BibtexDatabaseWriterTest { private BibDatabaseContext bibtexContext; @Before - public void setUp() throws SaveException, IOException { + public void setUp() { Globals.prefs = JabRefPreferences.getInstance(); // Write to a string instead of to a file diff --git a/src/test/java/net/sf/jabref/exporter/ExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java similarity index 98% rename from src/test/java/net/sf/jabref/exporter/ExportFormatTest.java rename to src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java index 17c1d0d3636..56c0a013715 100644 --- a/src/test/java/net/sf/jabref/exporter/ExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.File; import java.nio.charset.Charset; diff --git a/src/test/java/net/sf/jabref/exporter/FieldFormatterCleanupsTest.java b/src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java similarity index 99% rename from src/test/java/net/sf/jabref/exporter/FieldFormatterCleanupsTest.java rename to src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java index f1d7a861754..16122e70dda 100644 --- a/src/test/java/net/sf/jabref/exporter/FieldFormatterCleanupsTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/FieldFormatterCleanupsTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.util.Arrays; import java.util.Collections; diff --git a/src/test/java/net/sf/jabref/exporter/HtmlExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java similarity index 98% rename from src/test/java/net/sf/jabref/exporter/HtmlExportFormatTest.java rename to src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java index d72385d23c0..14749370112 100644 --- a/src/test/java/net/sf/jabref/exporter/HtmlExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.File; import java.nio.charset.Charset; diff --git a/src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java b/src/test/java/net/sf/jabref/logic/exporter/MSBibExportFormatTestFiles.java similarity index 97% rename from src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java rename to src/test/java/net/sf/jabref/logic/exporter/MSBibExportFormatTestFiles.java index c113d6190f3..b9ce27ac87f 100644 --- a/src/test/java/net/sf/jabref/exporter/MSBibExportFormatTestFiles.java +++ b/src/test/java/net/sf/jabref/logic/exporter/MSBibExportFormatTestFiles.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.File; import java.io.IOException; @@ -42,7 +42,7 @@ public class MSBibExportFormatTestFiles { public MSBibExportFormat msBibExportFormat; public BibtexImporter testImporter; - public static final String PATH_TO_FILE = "src/test/resources/net/sf/jabref/exporter/"; + public static final String PATH_TO_FILE = "src/test/resources/net/sf/jabref/logic/exporter/"; @Parameter public String filename; diff --git a/src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/MsBibExportFormatTest.java similarity index 97% rename from src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java rename to src/test/java/net/sf/jabref/logic/exporter/MsBibExportFormatTest.java index ffecbf00c36..977541ffc1a 100644 --- a/src/test/java/net/sf/jabref/exporter/MsBibExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/MsBibExportFormatTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.exporter; +package net.sf.jabref.logic.exporter; import java.io.File; import java.io.IOException; diff --git a/src/test/java/net/sf/jabref/logic/openoffice/CitationEntryTest.java b/src/test/java/net/sf/jabref/logic/openoffice/CitationEntryTest.java index 36faf50d22b..4f4c53cfe3e 100644 --- a/src/test/java/net/sf/jabref/logic/openoffice/CitationEntryTest.java +++ b/src/test/java/net/sf/jabref/logic/openoffice/CitationEntryTest.java @@ -80,7 +80,6 @@ public void testCitationEntryCompareTo() { CitationEntry citationEntry1 = new CitationEntry("RefMark", "Context", "Info"); CitationEntry citationEntry2 = new CitationEntry("RefMark2", "Context", "Info"); CitationEntry citationEntry3 = new CitationEntry("RefMark", "Other Context", "Other Info"); - assertEquals(0, citationEntry1.compareTo(citationEntry1)); assertEquals(0, citationEntry1.compareTo(citationEntry3)); assertEquals(-1, citationEntry1.compareTo(citationEntry2)); assertEquals(1, citationEntry2.compareTo(citationEntry1)); diff --git a/src/test/java/net/sf/jabref/model/entry/AuthorListTest.java b/src/test/java/net/sf/jabref/model/entry/AuthorListTest.java index 859e2ce84a6..67fb4020593 100644 --- a/src/test/java/net/sf/jabref/model/entry/AuthorListTest.java +++ b/src/test/java/net/sf/jabref/model/entry/AuthorListTest.java @@ -31,8 +31,8 @@ public void testFixAuthorNatbib() { public void testGetAuthorList() { // Test caching in authorCache. AuthorList al = AuthorList.parse("John Smith"); - Assert.assertTrue(al == AuthorList.parse("John Smith")); - Assert.assertFalse(al == AuthorList.parse("Smith")); + Assert.assertEquals(al, AuthorList.parse("John Smith")); + Assert.assertFalse(al.equals(AuthorList.parse("Smith"))); } @SuppressWarnings("unused") diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest1.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest1.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest1.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest1.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest1.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest1.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest1.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest1.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest2.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest2.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest2.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest2.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest2.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest3.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest3.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest3.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest3.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest3.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest3.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest3.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest3.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest4.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest4.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest4.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest4.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest4.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest5.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest5.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest5.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest5.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest5.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest5.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest5.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest5.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest6.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest6.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest6.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest6.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest6.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest6.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatTest6.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatTest6.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatUmlauts.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatUmlauts.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatUmlauts.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibExportFormatUmlauts.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibExportFormatUmlauts.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibLCID.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibLCID.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibLCID.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibLCID.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibLCID.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibLCID.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibLCID.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibLCID.xml diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibShorttitle.bib b/src/test/resources/net/sf/jabref/logic/exporter/MsBibShorttitle.bib similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibShorttitle.bib rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibShorttitle.bib diff --git a/src/test/resources/net/sf/jabref/exporter/MsBibShorttitle.xml b/src/test/resources/net/sf/jabref/logic/exporter/MsBibShorttitle.xml similarity index 100% rename from src/test/resources/net/sf/jabref/exporter/MsBibShorttitle.xml rename to src/test/resources/net/sf/jabref/logic/exporter/MsBibShorttitle.xml