Skip to content

Commit 6bc8ffc

Browse files
Jürgen Langetobiasdiez
authored andcommitted
Check integrity edition check implemented (#1914)
* Check integrity edition check * Conflict in Jabref_fr * Changed order Biblatex/Bibtex condition * Create own object * Rename variable * Extract checker to own file * Improved comment * French localization: Jabref_fr: empty strings translated + removal of unused header (#1911) * Remove teamscale findings in the database package (#1577) * Check integrity edition check * Changed order Biblatex/Bibtex condition * Create own object * Rename variable * Mark some methods as deprecated in BibEntry and BibDatabase (#1913) * Mark some methods as deprecated in BibEntry and BibDatabase * Rename getResolvedFieldOrAlias * Use flatmap * Fix location field not exported correctly to office 2007 xml (#1909) * Fix location field not exported to office 2007 xml * Add some test for exporting location and address field Address in xml field is now imported as location add some javadoc * Add possibility to remember password for shared databases. (#1846) * Add possibility to remember password. - Add checkbox to the open shared database dialog - Add SharedDatabasePreferences - Add password encrypting and decrypting methods - Update localization entries - Reorganize clearing methods for Preferences * Change prefs node and add class comment. * Relativate node path for password storage. * Fix LOGGER factory. * Improve password encryption using XOR. - Use username as one operand - Add new parameter to the constructor * Extract method. * Improve exception handling. * Improve password encryption and decryption. - Use CBC and padding - Hash the key before using - Simplify conversion * Fix modifier. Fix conflicts. * Extract checker to own file * Improved comment * Translation of shared (#1919) * Add missing entries in german localization * Resolved conflicts * Some more conflicts de sv * Expressions changed
1 parent 5dcc05a commit 6bc8ffc

21 files changed

+126
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1818
- [#1813](https://github.com/JabRef/jabref/issues/1813) Import/Export preferences dialog default directory set to working directory
1919
- [#1897](https://github.com/JabRef/jabref/issues/1897) Implemented integrity check for `year` field: Last four nonpunctuation characters should be numerals
2020
- Address in MS-Office 2007 xml format is now imported as `location`
21-
21+
- [#1912](https://github.com/JabRef/jabref/issues/1912) Implemented integrity check for `edition` field: Should have the first letter capitalized (BibTeX), Should contain an integer or a literal (BibLaTeX)
2222

2323
### Fixed
2424
- Fixed selecting an entry out of multiple duplicates
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package net.sf.jabref.logic.integrity;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
import java.util.Objects;
6+
import java.util.Optional;
7+
import java.util.function.Predicate;
8+
import java.util.regex.Pattern;
9+
10+
import net.sf.jabref.BibDatabaseContext;
11+
import net.sf.jabref.logic.integrity.IntegrityCheck.Checker;
12+
import net.sf.jabref.logic.l10n.Localization;
13+
import net.sf.jabref.model.entry.BibEntry;
14+
import net.sf.jabref.model.entry.FieldName;
15+
16+
public class EditionChecker implements Checker {
17+
18+
private static final Predicate<String> FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate();
19+
private static final Predicate<String> ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9]+)$")
20+
.asPredicate();
21+
22+
private final BibDatabaseContext bibDatabaseContextEdition;
23+
24+
25+
public EditionChecker(BibDatabaseContext bibDatabaseContext) {
26+
this.bibDatabaseContextEdition = Objects.requireNonNull(bibDatabaseContext);
27+
}
28+
29+
/**
30+
* Checks, if field contains only an integer or a literal (BibLaTeX mode)
31+
* Checks, if the first letter is capitalized (BibTeX mode)
32+
* BibLaTex:
33+
* The edition of a printed publication. This must be an integer, not an ordinal.
34+
* It is also possible to give the edition as a literal string, for example "Third, revised and expanded edition".
35+
* Official bibtex spec:
36+
* The edition of a book-for example, "Second".
37+
* This should be an ordinal, and should have the first letter capitalized.
38+
*/
39+
@Override
40+
public List<IntegrityMessage> check(BibEntry entry) {
41+
Optional<String> value = entry.getField(FieldName.EDITION);
42+
if (!value.isPresent()) {
43+
return Collections.emptyList();
44+
}
45+
46+
//BibLaTeX
47+
if (bibDatabaseContextEdition.isBiblatexMode() && !ONLY_NUMERALS_OR_LITERALS.test(value.get().trim())) {
48+
return Collections.singletonList(new IntegrityMessage(
49+
Localization.lang("should contain an integer or a literal"), entry, FieldName.EDITION));
50+
}
51+
52+
//BibTeX
53+
if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.get().trim())) {
54+
return Collections.singletonList(new IntegrityMessage(
55+
Localization.lang("should have the first letter capitalized"), entry, FieldName.EDITION));
56+
}
57+
58+
return Collections.emptyList();
59+
}
60+
}

src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private List<IntegrityMessage> checkBibtexEntry(BibEntry entry) {
6666

6767
result.addAll(new BracketChecker(FieldName.TITLE).check(entry));
6868
result.addAll(new YearChecker().check(entry));
69+
result.addAll(new EditionChecker(bibDatabaseContext).check(entry));
6970
result.addAll(new UrlChecker().check(entry));
7071
result.addAll(new FileChecker(bibDatabaseContext, fileDirectoryPreferences).check(entry));
7172
result.addAll(new TypeChecker().check(entry));

src/main/resources/l10n/JabRef_da.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,9 @@ Look_up_full_text_documents=
17751775
You_are_about_to_look_up_full_text_documents_for_%0_entries.=
17761776

17771777
last_four_nonpunctuation_characters_should_be_numerals=
1778+
1779+
should_contain_an_integer_or_a_literal=
1780+
should_have_the_first_letter_capitalized=
17781781
Remember_password?=
17791782

17801783
shared=

src/main/resources/l10n/JabRef_de.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,3 +2490,6 @@ last_four_nonpunctuation_characters_should_be_numerals=Die letzten vier Nichtint
24902490
Remember_password?=Passwort_merken?
24912491

24922492
shared=geteilt
2493+
2494+
should_contain_an_integer_or_a_literal=
2495+
should_have_the_first_letter_capitalized=

src/main/resources/l10n/JabRef_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,3 +2306,5 @@ Look_up_full_text_documents=Look_up_full_text_documents
23062306
You_are_about_to_look_up_full_text_documents_for_%0_entries.=You_are_about_to_look_up_full_text_documents_for_%0_entries.
23072307
last_four_nonpunctuation_characters_should_be_numerals=last_four_nonpunctuation_characters_should_be_numerals
23082308
shared=shared
2309+
should_contain_an_integer_or_a_literal=should_contain_an_integer_or_a_literal
2310+
should_have_the_first_letter_capitalized=should_have_the_first_letter_capitalized

src/main/resources/l10n/JabRef_es.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,9 @@ Look_up_full_text_documents=
16761676
You_are_about_to_look_up_full_text_documents_for_%0_entries.=
16771677

16781678
last_four_nonpunctuation_characters_should_be_numerals=
1679+
1680+
should_contain_an_integer_or_a_literal=
1681+
should_have_the_first_letter_capitalized=
16791682
Remember_password?=
16801683

16811684
shared=

src/main/resources/l10n/JabRef_fa.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,9 @@ Look_up_full_text_documents=
24562456
You_are_about_to_look_up_full_text_documents_for_%0_entries.=
24572457

24582458
last_four_nonpunctuation_characters_should_be_numerals=
2459+
2460+
should_contain_an_integer_or_a_literal=
2461+
should_have_the_first_letter_capitalized=
24592462
Remember_password?=
24602463

24612464
shared=

src/main/resources/l10n/JabRef_fr.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,3 +1726,5 @@ last_four_nonpunctuation_characters_should_be_numerals=Les_4_derniers_caractère
17261726
Remember_password?=
17271727
17281728
shared=
1729+
should_contain_an_integer_or_a_literal=
1730+
should_have_the_first_letter_capitalized=

src/main/resources/l10n/JabRef_in.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,9 @@ Look_up_full_text_documents=
16921692
You_are_about_to_look_up_full_text_documents_for_%0_entries.=
16931693

16941694
last_four_nonpunctuation_characters_should_be_numerals=
1695+
1696+
should_contain_an_integer_or_a_literal=
1697+
should_have_the_first_letter_capitalized=
16951698
Remember_password?=
16961699

16971700
shared=

0 commit comments

Comments
 (0)