Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Browse files Browse the repository at this point in the history
* upstream/master:
  Add oaDOI fulltext fetcher (#3581)
  Refactor export code to fix #3576 (#3578)
  Fix #3359: Automatically remove colon and apostrophe from key pattern (#3506)
  • Loading branch information
Siedlerchr committed Jan 2, 2018
2 parents e71181a + b246b9c commit d3daaa6
Show file tree
Hide file tree
Showing 133 changed files with 1,427 additions and 1,434 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- We added [oaDOI](https://oadoi.org/) as a fulltext provider, so that JabRef is now able to provide fulltexts for more than 90 million open-access articles.


### Fixed
- We fixed the missing dot in the name of an exported file. [#3576](https://github.com/JabRef/jabref/issues/3576)

### Removed
- We removed the Look and Feels from jgoodies, because these are not compatible with Java 9
Expand Down Expand Up @@ -126,6 +128,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where fetched entries from the ACM fetcher could not be imported. [#3500](https://github.com/JabRef/jabref/issues/3500)
- We fixed an issue where custom data in combobox fields in the entry editor was not saved. [#3538](https://github.com/JabRef/jabref/issues/3538)
- We fixed an issue where automatically found files were not added with a relative paths when the bib file is in the same directory as the files. [#3476](https://github.com/JabRef/jabref/issues/3476)
- We improved the key generator to remove certain illegal characters such as colons or apostrophes. [#3359](https://github.com/JabRef/jabref/issues/3359)


## [4.0] - 2017-10-04
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileUpdateMonitor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class Globals {
* Manager for the state of the GUI.
*/
public static StateManager stateManager = new StateManager();
public static ExporterFactory exportFactory;
// Key binding preferences
private static KeyBindingRepository keyBindingRepository;
// Background tasks
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref;

import java.net.Authenticator;
import java.util.Map;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
Expand All @@ -13,13 +12,10 @@

import org.jabref.cli.ArgumentProcessor;
import org.jabref.gui.remote.JabRefMessageHandler;
import org.jabref.logic.exporter.ExportFormat;
import org.jabref.logic.exporter.ExportFormats;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.net.ProxyAuthenticator;
import org.jabref.logic.net.ProxyPreferences;
import org.jabref.logic.net.ProxyRegisterer;
Expand Down Expand Up @@ -147,12 +143,7 @@ private static void start(String[] args) {
Globals.prefs.getXMPPreferences());
EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX),
preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs
.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
Globals.exportFactory = ExporterFactory.create(Globals.prefs, Globals.journalAbbreviationLoader);

// Initialize protected terms loader
Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences());
Expand Down
48 changes: 20 additions & 28 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
import org.jabref.gui.externalfiles.AutoSetLinks;
import org.jabref.gui.importer.fetcher.EntryFetcher;
import org.jabref.gui.importer.fetcher.EntryFetchers;
import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.ExportFormat;
import org.jabref.logic.exporter.ExportFormats;
import org.jabref.logic.exporter.Exporter;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.exporter.FileSaveSession;
import org.jabref.logic.exporter.IExportFormat;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.exporter.SaveSession;
import org.jabref.logic.exporter.TemplateExporter;
import org.jabref.logic.importer.ImportException;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.importer.OpenDatabase;
Expand All @@ -47,7 +47,6 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.metadata.MetaData;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.SearchPreferences;

Expand Down Expand Up @@ -250,7 +249,7 @@ private boolean exportMatches(List<ParserResult> loaded) {
formatName = data[2];
break;
case 2:
//default ExportFormat: HTML table (with Abstract & BibTeX)
//default exporter: HTML table (with Abstract & BibTeX)
formatName = "tablerefsabsbib";
break;
default:
Expand All @@ -261,14 +260,14 @@ private boolean exportMatches(List<ParserResult> loaded) {
}

//export new database
IExportFormat format = ExportFormats.getExportFormat(formatName);
if (format == null) {
Optional<Exporter> exporter = Globals.exportFactory.getExporterByName(formatName);
if (!exporter.isPresent()) {
System.err.println(Localization.lang("Unknown export format") + ": " + formatName);
} else {
// We have an ExportFormat instance:
// We have an TemplateExporter instance:
try {
System.out.println(Localization.lang("Exporting") + ": " + data[1]);
format.performExport(databaseContext, data[1],
exporter.get().export(databaseContext, Paths.get(data[1]),
databaseContext.getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()),
matches);
} catch (Exception ex) {
Expand Down Expand Up @@ -438,18 +437,17 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
Globals.prefs.fileDirForDatabase = databaseContext
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
System.out.println(Localization.lang("Exporting") + ": " + data[0]);
IExportFormat format = ExportFormats.getExportFormat(data[1]);
if (format == null) {
Optional<Exporter> exporter = Globals.exportFactory.getExporterByName(data[1]);
if (!exporter.isPresent()) {
System.err.println(Localization.lang("Unknown export format") + ": " + data[1]);
} else {
// We have an ExportFormat instance:
// We have an exporter:
try {
format.performExport(pr.getDatabaseContext(), data[0],
exporter.get().export(pr.getDatabaseContext(), Paths.get(data[0]),
pr.getDatabaseContext().getMetaData().getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()),
pr.getDatabaseContext().getDatabase().getEntries());
} catch (Exception ex) {

System.err.println(Localization.lang("Could not export file") + " '" + data[0] + "': "
+ Throwables.getStackTraceAsString(ex));
}
Expand All @@ -463,12 +461,12 @@ private void importPreferences() {
Globals.prefs.importPreferences(cli.getPreferencesImport());
EntryTypes.loadCustomEntryTypes(Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBTEX),
Globals.prefs.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Map<String, TemplateExporter> customExporters = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs
.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
Globals.exportFactory = ExporterFactory.create(customExporters, layoutPreferences, savePreferences);
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
}
Expand Down Expand Up @@ -509,17 +507,11 @@ private void regenerateBibtexKeys(List<ParserResult> loaded) {
for (ParserResult parserResult : loaded) {
BibDatabase database = parserResult.getDatabase();

MetaData metaData = parserResult.getMetaData();
if (metaData != null) {
LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata"));
for (BibEntry entry : database.getEntries()) {
// try to make a new label
BibtexKeyPatternUtil.makeAndSetLabel(
metaData.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
database, entry, Globals.prefs.getBibtexKeyPatternPreferences());
}
} else {
LOGGER.info(Localization.lang("No meta data present in BIB file. Cannot regenerate BibTeX keys"));
LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata"));

BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(parserResult.getDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences());
for (BibEntry entry : database.getEntries()) {
keyGenerator.generateAndSetKey(entry);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import org.jabref.Globals;
import org.jabref.logic.exporter.ExportFormats;
import org.jabref.logic.l10n.Localization;

import org.apache.commons.cli.CommandLine;
Expand Down Expand Up @@ -246,7 +245,7 @@ public void printUsage() {
String importFormats = Globals.IMPORT_FORMAT_READER.getImportFormatList();
String importFormatsList = String.format("%s:%n%s%n", Localization.lang("Available import formats"), importFormats);

String outFormats = ExportFormats.getConsoleExportList(70, 20, "");
String outFormats = Globals.exportFactory.getExportersAsString(70, 20, "");
String outFormatsList = String.format("%s: %s%n", Localization.lang("Available export formats"), outFormats);

String footer = '\n' + importFormatsList + outFormatsList + "\nPlease report issues at https://github.com/JabRef/jabref/issues.";
Expand Down
33 changes: 12 additions & 21 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
import org.jabref.gui.worker.CitationStyleToClipboardWorker;
import org.jabref.gui.worker.MarkEntriesAction;
import org.jabref.gui.worker.SendAsEMailAction;
import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
import org.jabref.logic.citationstyle.CitationStyleCache;
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
import org.jabref.logic.exporter.BibtexDatabaseWriter;
Expand All @@ -116,13 +116,12 @@
import org.jabref.logic.layout.LayoutHelper;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.logic.search.SearchQuery;
import org.jabref.logic.util.FileExtensions;
import org.jabref.logic.util.FileType;
import org.jabref.logic.util.UpdateField;
import org.jabref.logic.util.io.FileFinder;
import org.jabref.logic.util.io.FileFinders;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.FieldChange;
import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.KeyCollisionException;
Expand All @@ -140,6 +139,7 @@
import org.jabref.model.entry.event.EntryEventSource;
import org.jabref.model.entry.specialfields.SpecialField;
import org.jabref.model.entry.specialfields.SpecialFieldValue;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreviewPreferences;

Expand Down Expand Up @@ -489,16 +489,10 @@ public void run() {

// generate the new cite keys for each entry
final NamedCompound ce = new NamedCompound(Localization.lang("Autogenerate BibTeX keys"));
AbstractBibtexKeyPattern citeKeyPattern = bibDatabaseContext.getMetaData()
.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern());
BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibDatabaseContext, Globals.prefs.getBibtexKeyPatternPreferences());
for (BibEntry entry : entries) {
String oldCiteKey = entry.getCiteKeyOptional().orElse("");
BibtexKeyPatternUtil.makeAndSetLabel(citeKeyPattern, bibDatabaseContext.getDatabase(),
entry, Globals.prefs.getBibtexKeyPatternPreferences());
String newCiteKey = entry.getCiteKeyOptional().orElse("");
if (!oldCiteKey.equals(newCiteKey)) {
ce.addEdit(new UndoableKeyChange(entry, oldCiteKey, newCiteKey));
}
Optional<FieldChange> change = keyGenerator.generateAndSetKey(entry);
change.ifPresent(fieldChange -> ce.addEdit(new UndoableKeyChange(fieldChange)));
}
ce.end();

Expand Down Expand Up @@ -1754,15 +1748,12 @@ public void autoGenerateKeysBeforeSaving() {
if (Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING)) {
NamedCompound ce = new NamedCompound(Localization.lang("Autogenerate BibTeX keys"));

BibtexKeyGenerator keyGenerator = new BibtexKeyGenerator(bibDatabaseContext, Globals.prefs.getBibtexKeyPatternPreferences());
for (BibEntry bes : bibDatabaseContext.getDatabase().getEntries()) {
Optional<String> oldKey = bes.getCiteKeyOptional();
if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) {
BibtexKeyPatternUtil.makeAndSetLabel(bibDatabaseContext.getMetaData()
.getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()),
bibDatabaseContext.getDatabase(),
bes, Globals.prefs.getBibtexKeyPatternPreferences());
bes.getCiteKeyOptional().ifPresent(
newKey -> ce.addEdit(new UndoableKeyChange(bes, oldKey.orElse(""), newKey)));
if (StringUtil.isBlank(oldKey)) {
Optional<FieldChange> change = keyGenerator.generateAndSetKey(bes);
change.ifPresent(fieldChange -> ce.addEdit(new UndoableKeyChange(fieldChange)));
}
}

Expand Down Expand Up @@ -2230,8 +2221,8 @@ public SaveSelectedAction(SavePreferences.DatabaseSaveType saveType) {
@Override
public void action() throws SaveException {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withDefaultExtension(FileExtensions.BIBTEX_DB)
.addExtensionFilter(FileExtensions.BIBTEX_DB)
.withDefaultExtension(FileType.BIBTEX_DB)
.addExtensionFilter(FileType.BIBTEX_DB)
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();

DialogService ds = new FXDialogService();
Expand Down
Loading

0 comments on commit d3daaa6

Please sign in to comment.