";
+ String myText = "" + JS_HIGHLIGHT_FUNCTION + "
" + text + "
";
previewView.getEngine().setJavaScriptEnabled(true);
previewView.getEngine().loadContent(myText);
diff --git a/src/main/java/org/jabref/gui/util/BindingsHelper.java b/src/main/java/org/jabref/gui/util/BindingsHelper.java
index f594c680607..a64c6a73f7f 100644
--- a/src/main/java/org/jabref/gui/util/BindingsHelper.java
+++ b/src/main/java/org/jabref/gui/util/BindingsHelper.java
@@ -24,6 +24,7 @@
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.PreboundBinding;
+import org.fxmisc.easybind.Subscription;
/**
* Helper methods for javafx binding.
@@ -43,12 +44,13 @@ public static
BooleanBinding all(ObservableList source, Predicate pred
return Bindings.createBooleanBinding(() -> !source.isEmpty() && source.stream().allMatch(predicate), source);
}
- public static void includePseudoClassWhen(Node node, PseudoClass pseudoClass, ObservableValue extends Boolean> condition) {
+ public static Subscription includePseudoClassWhen(Node node, PseudoClass pseudoClass, ObservableValue extends Boolean> condition) {
Consumer changePseudoClass = value -> node.pseudoClassStateChanged(pseudoClass, value);
- EasyBind.subscribe(condition, changePseudoClass);
+ Subscription subscription = EasyBind.subscribe(condition, changePseudoClass);
// Put the pseudo class there depending on the current value
changePseudoClass.accept(condition.getValue());
+ return subscription;
}
/**
diff --git a/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java b/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
index c0ce703dee0..72188027e8a 100644
--- a/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
+++ b/src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
@@ -1,6 +1,8 @@
package org.jabref.gui.util;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
@@ -20,6 +22,8 @@
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.model.strings.StringUtil;
+import org.fxmisc.easybind.Subscription;
+
/**
* Constructs a {@link ListCell} based on the view model of the row and a bunch of specified converter methods.
*
@@ -144,10 +148,16 @@ public ListCell call(ListView param) {
return new ListCell() {
+ List subscriptions = new ArrayList<>();
+
@Override
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
+ // Remove previous subscriptions
+ subscriptions.forEach(Subscription::unsubscribe);
+ subscriptions.clear();
+
T viewModel = getItem();
if (empty || (viewModel == null)) {
setText(null);
@@ -190,10 +200,10 @@ protected void updateItem(T item, boolean empty) {
}
for (Map.Entry>> pseudoClassWithCondition : pseudoClasses.entrySet()) {
ObservableValue condition = pseudoClassWithCondition.getValue().call(viewModel);
- BindingsHelper.includePseudoClassWhen(this, pseudoClassWithCondition.getKey(), condition);
+ Subscription subscription = BindingsHelper.includePseudoClassWhen(this, pseudoClassWithCondition.getKey(), condition);
+ subscriptions.add(subscription);
}
}
- getListView().refresh();
}
};
}
diff --git a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
index f1ebe894836..05285948ccd 100644
--- a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
+++ b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
@@ -7,6 +7,7 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
+import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
@@ -147,6 +148,11 @@ public static List discoverCitationStyles() {
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
Path path = fs.getPath(STYLES_ROOT);
STYLES.addAll(discoverCitationStylesInPath(path));
+ } catch (FileSystemAlreadyExistsException e) {
+ try (FileSystem fs = FileSystems.getFileSystem(uri)) {
+ Path path = fs.getPath(STYLES_ROOT);
+ STYLES.addAll(discoverCitationStylesInPath(path));
+ }
}
} else {
STYLES.addAll(discoverCitationStylesInPath(Paths.get(uri)));
diff --git a/src/main/java/org/jabref/logic/importer/FulltextFetchers.java b/src/main/java/org/jabref/logic/importer/FulltextFetchers.java
index 4ba2cb69b63..52f2dcbd8d6 100644
--- a/src/main/java/org/jabref/logic/importer/FulltextFetchers.java
+++ b/src/main/java/org/jabref/logic/importer/FulltextFetchers.java
@@ -3,11 +3,12 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
@@ -34,7 +35,7 @@ public class FulltextFetchers {
// Timeout in seconds
private static final int FETCHER_TIMEOUT = 10;
- private final List finders = new ArrayList<>();
+ private final Set finders = new HashSet<>();
private final Predicate isPDF = url -> {
try {
@@ -49,7 +50,7 @@ public FulltextFetchers(ImportFormatPreferences importFormatPreferences) {
this(WebFetchers.getFullTextFetchers(importFormatPreferences));
}
- FulltextFetchers(List fetcher) {
+ FulltextFetchers(Set fetcher) {
finders.addAll(fetcher);
}
@@ -108,7 +109,7 @@ private Callable> getCallable(BibEntry entry, FulltextFe
};
}
- private List>> getCallables(BibEntry entry, List fetchers) {
+ private List>> getCallables(BibEntry entry, Set fetchers) {
return fetchers.stream()
.map(f -> getCallable(entry, f))
.collect(Collectors.toList());
diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java
index 604cd750541..66319f5e6b4 100644
--- a/src/main/java/org/jabref/logic/importer/WebFetchers.java
+++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java
@@ -1,9 +1,11 @@
package org.jabref.logic.importer;
-import java.util.ArrayList;
import java.util.Comparator;
-import java.util.List;
+import java.util.HashSet;
import java.util.Optional;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.jabref.logic.importer.fetcher.ACMPortalFetcher;
import org.jabref.logic.importer.fetcher.ACS;
@@ -76,66 +78,77 @@ public static Optional> getIdFetcherForField(Fie
return Optional.empty();
}
- public static List getSearchBasedFetchers(ImportFormatPreferences importFormatPreferences) {
- ArrayList list = new ArrayList<>();
- list.add(new ArXiv(importFormatPreferences));
- list.add(new INSPIREFetcher(importFormatPreferences));
- list.add(new GvkFetcher());
- list.add(new MedlineFetcher());
- list.add(new AstrophysicsDataSystem(importFormatPreferences));
- list.add(new MathSciNet(importFormatPreferences));
- list.add(new ZbMATH(importFormatPreferences));
- list.add(new ACMPortalFetcher(importFormatPreferences));
- list.add(new GoogleScholar(importFormatPreferences));
- list.add(new DBLPFetcher(importFormatPreferences));
- list.add(new SpringerFetcher());
- list.add(new CrossRef());
- list.add(new CiteSeer());
- list.add(new DOAJFetcher(importFormatPreferences));
- list.add(new IEEE(importFormatPreferences));
- list.sort(Comparator.comparing(WebFetcher::getName));
- return list;
+ /**
+ * @return sorted set containing search based fetchers
+ */
+ public static SortedSet getSearchBasedFetchers(ImportFormatPreferences importFormatPreferences) {
+ SortedSet set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
+ set.add(new ArXiv(importFormatPreferences));
+ set.add(new INSPIREFetcher(importFormatPreferences));
+ set.add(new GvkFetcher());
+ set.add(new MedlineFetcher());
+ set.add(new AstrophysicsDataSystem(importFormatPreferences));
+ set.add(new MathSciNet(importFormatPreferences));
+ set.add(new ZbMATH(importFormatPreferences));
+ set.add(new ACMPortalFetcher(importFormatPreferences));
+ set.add(new GoogleScholar(importFormatPreferences));
+ set.add(new DBLPFetcher(importFormatPreferences));
+ set.add(new SpringerFetcher());
+ set.add(new CrossRef());
+ set.add(new CiteSeer());
+ set.add(new DOAJFetcher(importFormatPreferences));
+ set.add(new IEEE(importFormatPreferences));
+ return set;
}
- public static List getIdBasedFetchers(ImportFormatPreferences importFormatPreferences) {
- ArrayList list = new ArrayList<>();
- list.add(new ArXiv(importFormatPreferences));
- list.add(new AstrophysicsDataSystem(importFormatPreferences));
- list.add(new IsbnFetcher(importFormatPreferences));
- list.add(new DiVA(importFormatPreferences));
- list.add(new DoiFetcher(importFormatPreferences));
- list.add(new MedlineFetcher());
- list.add(new TitleFetcher(importFormatPreferences));
- list.add(new MathSciNet(importFormatPreferences));
- list.add(new CrossRef());
- list.add(new LibraryOfCongress(importFormatPreferences));
- list.add(new IacrEprintFetcher(importFormatPreferences));
- list.add(new RfcFetcher(importFormatPreferences));
- list.sort(Comparator.comparing(WebFetcher::getName));
- return list;
+ /**
+ * @return sorted set containing id based fetchers
+ */
+ public static SortedSet getIdBasedFetchers(ImportFormatPreferences importFormatPreferences) {
+ SortedSet set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
+ set.add(new ArXiv(importFormatPreferences));
+ set.add(new AstrophysicsDataSystem(importFormatPreferences));
+ set.add(new IsbnFetcher(importFormatPreferences));
+ set.add(new DiVA(importFormatPreferences));
+ set.add(new DoiFetcher(importFormatPreferences));
+ set.add(new MedlineFetcher());
+ set.add(new TitleFetcher(importFormatPreferences));
+ set.add(new MathSciNet(importFormatPreferences));
+ set.add(new CrossRef());
+ set.add(new LibraryOfCongress(importFormatPreferences));
+ set.add(new IacrEprintFetcher(importFormatPreferences));
+ set.add(new RfcFetcher(importFormatPreferences));
+ return set;
}
- public static List getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences) {
- ArrayList list = new ArrayList<>();
- list.add(new AstrophysicsDataSystem(importFormatPreferences));
- list.add(new DoiFetcher(importFormatPreferences));
- list.add(new IsbnFetcher(importFormatPreferences));
- list.add(new MathSciNet(importFormatPreferences));
- list.add(new CrossRef());
- list.sort(Comparator.comparing(WebFetcher::getName));
- return list;
+ /**
+ * @return sorted set containing entry based fetchers
+ */
+ public static SortedSet getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences) {
+ SortedSet set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
+ set.add(new AstrophysicsDataSystem(importFormatPreferences));
+ set.add(new DoiFetcher(importFormatPreferences));
+ set.add(new IsbnFetcher(importFormatPreferences));
+ set.add(new MathSciNet(importFormatPreferences));
+ set.add(new CrossRef());
+ return set;
}
- public static List getIdFetchers(ImportFormatPreferences importFormatPreferences) {
- ArrayList list = new ArrayList<>();
- list.add(new CrossRef());
- list.add(new ArXiv(importFormatPreferences));
- list.sort(Comparator.comparing(WebFetcher::getName));
- return list;
+ /**
+ * @return sorted set containing id fetchers
+ */
+ public static SortedSet getIdFetchers(ImportFormatPreferences importFormatPreferences) {
+ SortedSet set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
+ set.add(new CrossRef());
+ set.add(new ArXiv(importFormatPreferences));
+ return set;
}
- public static List getFullTextFetchers(ImportFormatPreferences importFormatPreferences) {
- List fetchers = new ArrayList<>();
+ /**
+ * @return set containing fulltext fetchers
+ */
+ public static Set getFullTextFetchers(ImportFormatPreferences importFormatPreferences) {
+ Set fetchers = new HashSet<>();
// Original
fetchers.add(new DoiResolution());
// Publishers
diff --git a/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java b/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java
index b42252ac914..6b2156047ee 100644
--- a/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java
+++ b/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java
@@ -122,6 +122,7 @@ public class OOBibStyle implements Comparable {
private File styleFile;
private long styleFileModificationTime = Long.MIN_VALUE;
private String localCopy;
+ private boolean isDefaultLayoutPresent;
public OOBibStyle(File styleFile, LayoutFormatterPreferences prefs,
Charset encoding) throws IOException {
this.prefs = Objects.requireNonNull(prefs);
@@ -321,13 +322,11 @@ private void readFormatFile(Reader in) throws IOException {
}
}
-
// Set validity boolean based on whether we found anything interesting
// in the file:
- if (mode != BibStyleMode.NONE) {
+ if ((mode != BibStyleMode.NONE) && isDefaultLayoutPresent) {
valid = true;
}
-
}
/**
@@ -350,11 +349,11 @@ private void handleStructureLine(String line) {
int index = line.indexOf('=');
if ((index > 0) && (index < (line.length() - 1))) {
String formatString = line.substring(index + 1);
- boolean setDefault = line.substring(0, index).equals(OOBibStyle.DEFAULT_MARK);
+ isDefaultLayoutPresent = line.substring(0, index).equals(OOBibStyle.DEFAULT_MARK);
EntryType type = EntryTypeFactory.parse(line.substring(0, index));
try {
Layout layout = new LayoutHelper(new StringReader(formatString), this.prefs).getLayoutFromText();
- if (setDefault) {
+ if (isDefaultLayoutPresent) {
defaultBibLayout = layout;
} else {
bibLayout.put(type, layout);
diff --git a/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java b/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java
index 1f3cc1a5f6d..986165ad0ee 100644
--- a/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java
+++ b/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java
@@ -3,8 +3,8 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Arrays;
import java.util.Optional;
+import java.util.Set;
import org.jabref.logic.importer.fetcher.TrustLevel;
import org.jabref.model.entry.BibEntry;
@@ -34,8 +34,7 @@ public void tearDown() {
public void acceptPdfUrls() throws MalformedURLException {
URL pdfUrl = new URL("http://docs.oasis-open.org/wsbpel/2.0/OS/wsbpel-v2.0-OS.pdf");
FulltextFetcher finder = (e) -> Optional.of(pdfUrl);
- FulltextFetchers fetcher = new FulltextFetchers(Arrays.asList(finder));
-
+ FulltextFetchers fetcher = new FulltextFetchers(Set.of(finder));
assertEquals(Optional.of(pdfUrl), fetcher.findFullTextPDF(entry));
}
@@ -43,7 +42,7 @@ public void acceptPdfUrls() throws MalformedURLException {
public void rejectNonPdfUrls() throws MalformedURLException {
URL pdfUrl = new URL("https://github.com/JabRef/jabref/blob/master/README.md");
FulltextFetcher finder = (e) -> Optional.of(pdfUrl);
- FulltextFetchers fetcher = new FulltextFetchers(Arrays.asList(finder));
+ FulltextFetchers fetcher = new FulltextFetchers(Set.of(finder));
assertEquals(Optional.empty(), fetcher.findFullTextPDF(entry));
}
@@ -52,7 +51,7 @@ public void rejectNonPdfUrls() throws MalformedURLException {
public void noTrustLevel() throws MalformedURLException {
URL pdfUrl = new URL("http://docs.oasis-open.org/wsbpel/2.0/OS/wsbpel-v2.0-OS.pdf");
FulltextFetcher finder = (e) -> Optional.of(pdfUrl);
- FulltextFetchers fetcher = new FulltextFetchers(Arrays.asList(finder));
+ FulltextFetchers fetcher = new FulltextFetchers(Set.of(finder));
assertEquals(Optional.of(pdfUrl), fetcher.findFullTextPDF(entry));
}
@@ -69,7 +68,7 @@ public void higherTrustLevelWins() throws MalformedURLException, IOException, Fe
when(finderHigh.findFullText(entry)).thenReturn(Optional.of(highUrl));
when(finderLow.findFullText(entry)).thenReturn(Optional.of(lowUrl));
- FulltextFetchers fetcher = new FulltextFetchers(Arrays.asList(finderLow, finderHigh));
+ FulltextFetchers fetcher = new FulltextFetchers(Set.of(finderLow, finderHigh));
assertEquals(Optional.of(highUrl), fetcher.findFullTextPDF(entry));
}
diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java
index 58b2e3b15fd..b5d93a2be54 100644
--- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java
+++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java
@@ -1,6 +1,6 @@
package org.jabref.logic.importer;
-import java.util.List;
+import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
@@ -31,7 +31,7 @@ void setUp() throws Exception {
@Test
void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exception {
- List idFetchers = WebFetchers.getIdBasedFetchers(importFormatPreferences);
+ Set idFetchers = WebFetchers.getIdBasedFetchers(importFormatPreferences);
try (ScanResult scanResult = classGraph.scan()) {
@@ -50,7 +50,7 @@ void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exce
@Test
void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher() throws Exception {
- List idFetchers = WebFetchers.getEntryBasedFetchers(importFormatPreferences);
+ Set idFetchers = WebFetchers.getEntryBasedFetchers(importFormatPreferences);
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(EntryBasedFetcher.class.getCanonicalName());
@@ -64,7 +64,7 @@ void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher() throw
@Test
void getSearchBasedFetchersReturnsAllFetcherDerivingFromSearchBasedFetcher() throws Exception {
- List searchBasedFetchers = WebFetchers.getSearchBasedFetchers(importFormatPreferences);
+ Set searchBasedFetchers = WebFetchers.getSearchBasedFetchers(importFormatPreferences);
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(SearchBasedFetcher.class.getCanonicalName());
Set> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
@@ -76,7 +76,7 @@ void getSearchBasedFetchersReturnsAllFetcherDerivingFromSearchBasedFetcher() thr
@Test
void getFullTextFetchersReturnsAllFetcherDerivingFromFullTextFetcher() throws Exception {
- List fullTextFetchers = WebFetchers.getFullTextFetchers(importFormatPreferences);
+ Set fullTextFetchers = WebFetchers.getFullTextFetchers(importFormatPreferences);
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(FulltextFetcher.class.getCanonicalName());
@@ -87,7 +87,7 @@ void getFullTextFetchersReturnsAllFetcherDerivingFromFullTextFetcher() throws Ex
@Test
void getIdFetchersReturnsAllFetcherDerivingFromIdFetcher() throws Exception {
- List idFetchers = WebFetchers.getIdFetchers(importFormatPreferences);
+ Set idFetchers = WebFetchers.getIdFetchers(importFormatPreferences);
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(IdFetcher.class.getCanonicalName());
@@ -98,7 +98,7 @@ void getIdFetchersReturnsAllFetcherDerivingFromIdFetcher() throws Exception {
}
}
- private Set extends Class>> getClasses(List> objects) {
+ private Set extends Class>> getClasses(Collection> objects) {
return objects.stream().map(Object::getClass).collect(Collectors.toSet());
}
}
diff --git a/src/test/java/org/jabref/logic/importer/fetcher/FulltextFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/FulltextFetcherTest.java
index 20e70601800..183e011a84b 100644
--- a/src/test/java/org/jabref/logic/importer/fetcher/FulltextFetcherTest.java
+++ b/src/test/java/org/jabref/logic/importer/fetcher/FulltextFetcherTest.java
@@ -1,7 +1,7 @@
package org.jabref.logic.importer.fetcher;
-import java.util.List;
import java.util.Optional;
+import java.util.Set;
import org.jabref.logic.importer.FulltextFetcher;
import org.jabref.logic.importer.ImportFormatPreferences;
@@ -18,7 +18,7 @@
class FulltextFetcherTest {
@SuppressWarnings("unused")
- private static List fetcherProvider() {
+ private static Set fetcherProvider() {
return WebFetchers.getFullTextFetchers(mock(ImportFormatPreferences.class));
}