Skip to content

Commit

Permalink
Merge branch 'main' into fix-for-issue-9840
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Jun 8, 2023
2 parents 45681d9 + b4d2d51 commit 66bc727
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 16 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added drag and drop events for field 'Groups' in entry editor panel. [#569](https://github.com/koppor/jabref/issues/569)
- We added support for parsing MathML in the Medline importer. [#4273](https://github.com/JabRef/jabref/issues/4273)
- We added the ability to search for a DOI directly from 'Web Search'. [#9674](https://github.com/JabRef/jabref/issues/9674)
- We added a cleanup activity that identifies a URL in the `note` field and moves it to the `url` field. [koppor#216](https://github.com/koppor/jabref/issues/216)

### Changed

Expand Down Expand Up @@ -96,13 +97,14 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue in the preferences where custom columns could be added to the entry table with no qualifier. [#9913](https://github.com/JabRef/jabref/issues/9913)
- We fixed an issue where the encoding header in a bib file was not respected when the file contained a BOM (Byte Order Mark). [#9926](https://github.com/JabRef/jabref/issues/9926)
- We fixed an issue where cli help output for import and export format was inconsistent. [koppor#429](https://github.com/koppor/jabref/issues/429)
- We fixed an issue where no preview could be generated for some entry types and led to an exception [#9947](https://github.com/JabRef/jabref/issues/9947)
- We fixed an issue where no preview could be generated for some entry types and led to an exception. [#9947](https://github.com/JabRef/jabref/issues/9947)
- We fixed an issue where the Linux terminal working directory argument was malformed and therefore ignored upon opening a terminal [#9953](https://github.com/JabRef/jabref/issues/9953)
- We fixen an issue under Linux where under some systems the file instead of the folder was opened [#9607](https://github.com/JabRef/jabref/issues/9607)
- We fixen an issue under Linux where under some systems the file instead of the folder was opened. [#9607](https://github.com/JabRef/jabref/issues/9607)
- We fixed an issue where an Automatic Keyword Group could not be deleted in the UI. [#9778](https://github.com/JabRef/jabref/issues/9778)
- We fixed an issue where the citation key pattern `[edtrN_M]` returned the wrong editor. [#9946](https://github.com/JabRef/jabref/pull/9946)
- We fixed an issue where allow user to update the value of field in custom entry type with double-clicking it. [#9840](https://github.com/JabRef/jabref/issues/9840)
- We fixed an issue where empty grey containers would remain in the groups panel, if displaying of group item count is turned off [#9972](https://github.com/JabRef/jabref/issues/9972)
- We fixed an issue where empty grey containers would remain in the groups panel, if displaying of group item count is turned off. [#9972](https://github.com/JabRef/jabref/issues/9972)
- We fixed an issue where fetching an ISBN could lead to application freezing when the fetcher did not return any results. [#9979](https://github.com/JabRef/jabref/issues/9979)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<CheckBox fx:id="cleanUpDOI" text="%Move DOIs from note and URL field to DOI field and remove http prefix"/>
<CheckBox fx:id="cleanUpEprint"
text="%Move preprint information from 'URL' and 'journal' field to the 'eprint' field"/>
<CheckBox fx:id="cleanUpURL" text="%Move URL in note field to url field"/>
<CheckBox fx:id="cleanUpISSN" text="%Reformat ISSN"/>
<CheckBox fx:id="cleanUpUpgradeExternalLinks"/>
<CheckBox fx:id="cleanUpMovePDF"/>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CleanupPresetPanel extends VBox {
@FXML private Label cleanupRenamePDFLabel;
@FXML private CheckBox cleanUpDOI;
@FXML private CheckBox cleanUpEprint;
@FXML private CheckBox cleanUpURL;
@FXML private CheckBox cleanUpISSN;
@FXML private CheckBox cleanUpMovePDF;
@FXML private CheckBox cleanUpMakePathsRelative;
Expand Down Expand Up @@ -100,6 +101,7 @@ private void init(CleanupPreferences cleanupPreferences, FilePreferences filePre
private void updateDisplay(CleanupPreferences preset) {
cleanUpDOI.setSelected(preset.isActive(CleanupPreferences.CleanupStep.CLEAN_UP_DOI));
cleanUpEprint.setSelected(preset.isActive(CleanupPreferences.CleanupStep.CLEANUP_EPRINT));
cleanUpURL.setSelected(preset.isActive(CleanupPreferences.CleanupStep.CLEAN_UP_URL));
if (!cleanUpMovePDF.isDisabled()) {
cleanUpMovePDF.setSelected(preset.isActive(CleanupPreferences.CleanupStep.MOVE_PDF));
}
Expand Down Expand Up @@ -129,6 +131,9 @@ public CleanupPreferences getCleanupPreset() {
if (cleanUpEprint.isSelected()) {
activeJobs.add(CleanupPreferences.CleanupStep.CLEANUP_EPRINT);
}
if (cleanUpURL.isSelected()) {
activeJobs.add(CleanupPreferences.CleanupStep.CLEAN_UP_URL);
}
if (cleanUpISSN.isSelected()) {
activeJobs.add(CleanupPreferences.CleanupStep.CLEAN_UP_ISSN);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/cleanup/CleanupWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private CleanupJob toJob(CleanupPreferences.CleanupStep action) {
new DoiCleanup();
case CLEANUP_EPRINT ->
new EprintCleanup();
case CLEAN_UP_URL ->
new URLCleanup();
case MAKE_PATHS_RELATIVE ->
new RelativePathsCleanup(databaseContext, filePreferences);
case RENAME_PDF ->
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/org/jabref/logic/cleanup/URLCleanup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.jabref.logic.cleanup;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jabref.model.FieldChange;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;

/**
* Checks whether URL exists in note field, and stores it under url field.
*/
public class URLCleanup implements CleanupJob {

private static final Field NOTE_FIELD = StandardField.NOTE;
private static final Field URL_FIELD = StandardField.URL;

@Override
public List<FieldChange> cleanup(BibEntry entry) {
List<FieldChange> changes = new ArrayList<>();

String noteFieldValue = entry.getField(NOTE_FIELD).orElse(null);

/*
* The urlRegex was originally fetched from a suggested solution in
* https://stackoverflow.com/questions/28185064/python-infinite-loop-in-regex-to-match-url.
* In order to be functional, we made the necessary adjustments regarding Java
* features (mainly doubled backslashes).
*/
String urlRegex = "(?i)\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.]"
+ "[a-z]{2,4}/)(?:[^\\s()<>\\\\]+|\\(([^\\s()<>\\\\]+|(\\([^\\s()"
+ "<>\\\\]+\\)))*\\))+(?:\\(([^\\s()<>\\\\]+|(\\([^\\s()<>\\\\]+\\"
+ ")))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))";

final Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(noteFieldValue);

if (matcher.find()) {
String url = matcher.group();

// Remove the URL from the NoteFieldValue
String newNoteFieldValue = noteFieldValue
.replace(url, "")

/*
* The following regex erases unnecessary remaining
* content in note field. Explanation:
* <ul>
* <li>"(, )?": Matches an optional comma followed by a space</li>
* <li>"\\?": Matches an optional backslash</li>
* <li>"url\{\}": Matches the literal string "url{}"</li>
* </ul>
* Note that the backslashes are doubled as Java requirement
*/
.replaceAll("(, )?\\\\?url\\{\\}(, )?", "");

/*
* In case the url and note fields hold the same URL, then we just
* remove it from the note field, and no other action is performed.
*/
if (entry.hasField(URL_FIELD)) {
String urlFieldValue = entry.getField(URL_FIELD).orElse(null);
if (urlFieldValue.equals(url)) {
entry.setField(NOTE_FIELD, newNoteFieldValue).ifPresent(changes::add);
}
} else {
entry.setField(NOTE_FIELD, newNoteFieldValue).ifPresent(changes::add);
entry.setField(URL_FIELD, url).ifPresent(changes::add);
}
}
return changes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -62,22 +64,23 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
identifier = removeNewlinesAndSpacesFromIdentifier(identifier);
bibEntry = openLibraryIsbnFetcher.performSearchById(identifier);
} catch (FetcherException ex) {
LOGGER.debug("Got a fetcher exception for IBSN search", ex);
if (retryIsbnFetcher.isEmpty()) {
throw ex;
} else {
LOGGER.debug("Got a fetcher exception for IBSN search", ex);
LOGGER.debug("Try using the alternate ISBN fetchers to find an entry.");
}
} finally {
while (bibEntry.isEmpty() && retryIsbnFetcher.iterator().hasNext()) {
AbstractIsbnFetcher fetcher = retryIsbnFetcher.iterator().next();
LOGGER.debug("No entry found for ISBN=" + identifier + "; trying " + fetcher.getName() + " next.");
LOGGER.debug("Trying using the alternate ISBN fetchers to find an entry.");
// do not move the iterator in the loop as this would always return a new one and thus create and endless loop
Iterator<AbstractIsbnFetcher> iterator = retryIsbnFetcher.iterator();
while (bibEntry.isEmpty() && iterator.hasNext()) {
AbstractIsbnFetcher fetcher = iterator.next();
LOGGER.debug("No entry found for ISBN {}; trying {} next.", identifier, fetcher.getName());
bibEntry = fetcher.performSearchById(identifier);
}
}

if (bibEntry.isEmpty()) {
LOGGER.debug("Could not found a entry for ISBN=" + identifier);
LOGGER.debug("Could not found a entry for ISBN {}", identifier);
}

return bibEntry;
Expand All @@ -94,9 +97,7 @@ public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {
}

public IsbnFetcher addRetryFetcher(AbstractIsbnFetcher retryFetcher) {
if (retryFetcher == null) {
throw new IllegalArgumentException("Please provide a valid isbn fetcher.");
}
Objects.requireNonNull(retryFetcher, "Please provide a valid isbn fetcher.");
retryIsbnFetcher.add(retryFetcher);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public enum CleanupStep {
*/
CLEAN_UP_DOI,
CLEANUP_EPRINT,
CLEAN_UP_URL,
MAKE_PATHS_RELATIVE,
RENAME_PDF,
RENAME_PDF_ONLY_RELATIVE_PATHS,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ Cleanup\ entries=Cleanup entries
Automatically\ assign\ new\ entry\ to\ selected\ groups=Automatically assign new entry to selected groups
%0\ mode=%0 mode
Move\ DOIs\ from\ note\ and\ URL\ field\ to\ DOI\ field\ and\ remove\ http\ prefix=Move DOIs from note and URL field to DOI field and remove http prefix
Move\ URL\ in\ note\ field\ to\ url\ field=Move URL in note field to url field
Make\ paths\ of\ linked\ files\ relative\ (if\ possible)=Make paths of linked files relative (if possible)
Rename\ PDFs\ to\ given\ filename\ format\ pattern=Rename PDFs to given filename format pattern
Rename\ only\ PDFs\ having\ a\ relative\ path=Rename only PDFs having a relative path
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ exportFormat=Format d'exportation
Output\ file\ missing=Fichier de sortie manquant
The\ output\ option\ depends\ on\ a\ valid\ input\ option.=L'option de sortie dépend d'une option d'entrée valide.
Linked\ file\ name\ conventions=Conventions pour les noms de fichiers liés
Filename\ format\ pattern=Modèle de format de nom de fichier
Filename\ format\ pattern=Modèle de format de nom de fichier
Additional\ parameters=Paramètres additionnels
Cite\ selected\ entries\ between\ parenthesis=Citer les entrées sélectionnées entre parenthèses
Cite\ selected\ entries\ with\ in-text\ citation=Citer les entrées sélectionnées comme incluse dans le texte
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ Add\ new\ String=문자열 추가
Must\ not\ be\ empty\!=비워둘 수 없습니다\!
Open\ Help\ page=도움말 열기
Add\ new\ field\ name=새 필드 이름 추가
Field\ name\:=필드 이름\:
Field\ name\:=필드 이름\:
Field\ name\ "%0"\ already\ exists=필드 이름 "%0"이 이미 존재합니다
No\ field\ name\ selected\!=필드 이름을 선택하지 않았습니다
Remove\ field\ name=필드 이름 제거
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ This\ entry\ type\ is\ intended\ for\ sources\ such\ as\ web\ sites\ which\ are\
A\ single-volume\ work\ of\ reference\ such\ as\ an\ encyclopedia\ or\ a\ dictionary.=Неделимая работа или ссылка, как энциклопедия или словарь.
A\ technical\ report,\ research\ report,\ or\ white\ paper\ published\ by\ a\ university\ or\ some\ other\ institution.=Технический отчет, исследовательский отчет, или белая книга, выпущенная институтом или другим учреждением.
An\ entry\ set\ is\ a\ group\ of\ entries\ which\ are\ cited\ as\ a\ single\ reference\ and\ listed\ as\ a\ single\ item\ in\ the\ bibliography.=Набор записей представляет собой группу записей, которые приводятся в виде единой ссылки и перечислены в виде одного элемента в библиографии.
Supplemental\ material\ in\ a\ "Book".\ This\ type\ is\ provided\ for\ elements\ such\ as\ prefaces,\ introductions,\ forewords,\ afterwords,\ etc.\ which\ often\ have\ a\ generic\ title\ only.=Дополнительный материал в "Книге" предназначен для таких элементов, как предисловия, введения, послесловия и т.д.
Supplemental\ material\ in\ a\ "Book".\ This\ type\ is\ provided\ for\ elements\ such\ as\ prefaces,\ introductions,\ forewords,\ afterwords,\ etc.\ which\ often\ have\ a\ generic\ title\ only.=Дополнительный материал в "Книге" предназначен для таких элементов, как предисловия, введения, послесловия и т.д.
Supplemental\ material\ in\ a\ "Collection".=Дополнительные материалы в "Коллекции".
Supplemental\ material\ in\ a\ "Periodical".\ This\ type\ may\ be\ useful\ when\ referring\ to\ items\ such\ as\ regular\ columns,\ obituaries,\ letters\ to\ the\ editor,\ etc.\ which\ only\ have\ a\ generic\ title.=Дополнительные материалы в "Периодическом издании". Этот тип может быть полезен при обращении к таким элементам, как обычные колонки, некрологи, письма к редактору и т.д., которые имеют только общее название.
A\ thesis\ written\ for\ an\ educational\ institution\ to\ satisfy\ the\ requirements\ for\ a\ degree.=Тезис, написанный для учебного заведения с целью удовлетворения требований к степени.
Expand Down
Loading

0 comments on commit 66bc727

Please sign in to comment.