Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure importers #1207

Merged
merged 8 commits into from
May 24, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class Globals {

public static final String SELECTOR_META_PREFIX = "selector_";
public static final String PROTECTED_FLAG_META = "protectedFlag";
public static final String NONE = "_non__";

public static final String SPECIAL_COMMAND_CHARS = "\"`^~'c=";

Expand Down
60 changes: 48 additions & 12 deletions src/main/java/net/sf/jabref/JabRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,47 @@
import java.io.IOException;
import java.net.Authenticator;
import java.nio.charset.Charset;
import java.util.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Vector;
import java.util.prefs.BackingStoreException;
import javax.swing.*;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.FontUIResource;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.theme.SkyBluer;
import net.sf.jabref.bibtex.InternalBibtexFields;
import net.sf.jabref.cli.AuxCommandLine;
import net.sf.jabref.exporter.*;
import net.sf.jabref.gui.*;
import net.sf.jabref.exporter.AutoSaveManager;
import net.sf.jabref.exporter.BibDatabaseWriter;
import net.sf.jabref.exporter.ExportFormats;
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.gui.BasePanel;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.ParserResultWarningDialog;
import net.sf.jabref.gui.remote.JabRefMessageHandler;
import net.sf.jabref.gui.util.FocusRequester;
import net.sf.jabref.importer.*;
import net.sf.jabref.importer.AutosaveStartupPrompter;
import net.sf.jabref.importer.ImportFormatReader;
import net.sf.jabref.importer.ImportInspectionCommandLine;
import net.sf.jabref.importer.OpenDatabaseAction;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.importer.fetcher.EntryFetcher;
import net.sf.jabref.importer.fetcher.EntryFetchers;
import net.sf.jabref.logic.CustomEntryTypesManager;
Expand All @@ -57,6 +84,9 @@
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.util.Util;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.theme.SkyBluer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -802,14 +832,20 @@ private static Optional<ParserResult> importFile(String argument) {
if ((data.length > 1) && !"*".equals(data[1])) {
System.out.println(Localization.lang("Importing") + ": " + data[0]);
try {
List<BibEntry> entries;
ParserResult parserResult;
if (OS.WINDOWS) {
entries = Globals.IMPORT_FORMAT_READER.importFromFile(data[1], data[0], JabRef.mainFrame);
Path file = Paths.get(data[0]);
parserResult = Globals.IMPORT_FORMAT_READER.importFromFile(data[1], file);
} else {
entries = Globals.IMPORT_FORMAT_READER.importFromFile(data[1],
data[0].replace("~", System.getProperty("user.home")), JabRef.mainFrame);
Path file = Paths.get(data[0].replace("~", System.getProperty("user.home")));
parserResult = Globals.IMPORT_FORMAT_READER.importFromFile(data[1], file);
}

if(parserResult.hasWarnings()) {
mainFrame.showMessage(parserResult.getErrorMessage());
}
return Optional.of(new ParserResult(entries));

return Optional.of(parserResult);
} catch (IllegalArgumentException ex) {
System.err.println(Localization.lang("Unknown import format") + ": " + data[1]);
return Optional.empty();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/exporter/CustomExportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Collections;

import javax.swing.*;

Expand Down Expand Up @@ -93,7 +94,7 @@ public void actionPerformed(ActionEvent e) {
JButton browse = new JButton(Localization.lang("Browse"));
browse.addActionListener(e -> {
File directory = new File(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY));
String chosenStr = FileDialogs.getNewFile(parent, directory, ".layout",
String chosenStr = FileDialogs.getNewFile(parent, directory, Collections.singletonList(".layout"),
JFileChooser.OPEN_DIALOG, false);
if (chosenStr == null) {
return;
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/net/sf/jabref/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,37 @@
*/
package net.sf.jabref.exporter;

import com.jgoodies.forms.builder.FormBuilder;
import com.jgoodies.forms.layout.FormLayout;
import net.sf.jabref.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Collections;
import java.util.List;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefExecutorService;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.collab.ChangeScanner;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.collab.ChangeScanner;
import net.sf.jabref.gui.worker.CallBack;
import net.sf.jabref.gui.worker.Worker;
import net.sf.jabref.logic.l10n.Encodings;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.io.FileBasedLock;
import javax.swing.*;

import com.jgoodies.forms.builder.FormBuilder;
import com.jgoodies.forms.layout.FormLayout;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;

/**
* Action for the "Save" and "Save as" operations called from BasePanel. This class is also used for
* save operations when closing a database or quitting the applications.
Expand Down Expand Up @@ -343,8 +350,8 @@ public void saveAs() throws Throwable {
String chosenFile = null;
File f = null;
while (f == null) {
chosenFile = FileDialogs.getNewFile(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), ".bib",
JFileChooser.SAVE_DIALOG, false, null);
chosenFile = FileDialogs.getNewFile(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)),
Collections.singletonList(".bib"), JFileChooser.SAVE_DIALOG, false, null);
if (chosenFile == null) {
cancelled = true;
return; // cancelled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Collections;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
Expand Down Expand Up @@ -254,7 +255,7 @@ public void actionPerformed(ActionEvent e) {
// Nothing in the field. Go to the last file dir used:
initial = new File(Globals.prefs.get(JabRefPreferences.FILE_WORKING_DIRECTORY));
}
String chosen = FileDialogs.getNewFile(null, initial, Globals.NONE,
String chosen = FileDialogs.getNewFile(null, initial, Collections.emptyList(),
JFileChooser.OPEN_DIALOG, false);
if (chosen != null) {
File newFile = new File(chosen);
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/net/sf/jabref/external/MoveFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,32 @@
*/
package net.sf.jabref.external;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.gui.*;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.FileListEntry;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.entryeditor.EntryEditor;
import net.sf.jabref.gui.fieldeditors.FileListEditor;
import net.sf.jabref.gui.util.component.CheckBoxMessage;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.util.Util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

/**
* Action for moving or renaming a file that is linked to from an entry in JabRef.
*/
Expand Down Expand Up @@ -136,7 +143,8 @@ public void actionPerformed(ActionEvent event) {
}
chosenFile = sb.toString();
} else {
chosenFile = FileDialogs.getNewFile(frame, file, extension, JFileChooser.SAVE_DIALOG, false);
chosenFile = FileDialogs.getNewFile(frame, file, Collections.singletonList(extension),
JFileChooser.SAVE_DIALOG, false);
}
if (chosenFile == null) {
return; // cancelled
Expand Down
Loading