Skip to content

Commit

Permalink
Check integrity edition check implemented (#1914)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jürgen Lange authored and tobiasdiez committed Sep 5, 2016
1 parent 5dcc05a commit 6bc8ffc
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1813](https://github.com/JabRef/jabref/issues/1813) Import/Export preferences dialog default directory set to working directory
- [#1897](https://github.com/JabRef/jabref/issues/1897) Implemented integrity check for `year` field: Last four nonpunctuation characters should be numerals
- Address in MS-Office 2007 xml format is now imported as `location`

- [#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)

### Fixed
- Fixed selecting an entry out of multiple duplicates
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/net/sf/jabref/logic/integrity/EditionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.sf.jabref.logic.integrity;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import net.sf.jabref.BibDatabaseContext;
import net.sf.jabref.logic.integrity.IntegrityCheck.Checker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

public class EditionChecker implements Checker {

private static final Predicate<String> FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate();
private static final Predicate<String> ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9]+)$")
.asPredicate();

private final BibDatabaseContext bibDatabaseContextEdition;


public EditionChecker(BibDatabaseContext bibDatabaseContext) {
this.bibDatabaseContextEdition = Objects.requireNonNull(bibDatabaseContext);
}

/**
* Checks, if field contains only an integer or a literal (BibLaTeX mode)
* Checks, if the first letter is capitalized (BibTeX mode)
* BibLaTex:
* The edition of a printed publication. This must be an integer, not an ordinal.
* It is also possible to give the edition as a literal string, for example "Third, revised and expanded edition".
* Official bibtex spec:
* The edition of a book-for example, "Second".
* This should be an ordinal, and should have the first letter capitalized.
*/
@Override
public List<IntegrityMessage> check(BibEntry entry) {
Optional<String> value = entry.getField(FieldName.EDITION);
if (!value.isPresent()) {
return Collections.emptyList();
}

//BibLaTeX
if (bibDatabaseContextEdition.isBiblatexMode() && !ONLY_NUMERALS_OR_LITERALS.test(value.get().trim())) {
return Collections.singletonList(new IntegrityMessage(
Localization.lang("should contain an integer or a literal"), entry, FieldName.EDITION));
}

//BibTeX
if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.get().trim())) {
return Collections.singletonList(new IntegrityMessage(
Localization.lang("should have the first letter capitalized"), entry, FieldName.EDITION));
}

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private List<IntegrityMessage> checkBibtexEntry(BibEntry entry) {

result.addAll(new BracketChecker(FieldName.TITLE).check(entry));
result.addAll(new YearChecker().check(entry));
result.addAll(new EditionChecker(bibDatabaseContext).check(entry));
result.addAll(new UrlChecker().check(entry));
result.addAll(new FileChecker(bibDatabaseContext, fileDirectoryPreferences).check(entry));
result.addAll(new TypeChecker().check(entry));
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2490,3 +2490,6 @@ last_four_nonpunctuation_characters_should_be_numerals=Die letzten vier Nichtint
Remember_password?=Passwort_merken?

shared=geteilt

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2306,3 +2306,5 @@ Look_up_full_text_documents=Look_up_full_text_documents
You_are_about_to_look_up_full_text_documents_for_%0_entries.=You_are_about_to_look_up_full_text_documents_for_%0_entries.
last_four_nonpunctuation_characters_should_be_numerals=last_four_nonpunctuation_characters_should_be_numerals
shared=shared
should_contain_an_integer_or_a_literal=should_contain_an_integer_or_a_literal
should_have_the_first_letter_capitalized=should_have_the_first_letter_capitalized
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1726,3 +1726,5 @@ last_four_nonpunctuation_characters_should_be_numerals=Les_4_derniers_caractère
Remember_password?=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,10 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

Remember_password?=Kom_ihåg_lösenord?

shared=delad

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,9 @@ Look_up_full_text_documents=Tam_netin_belgeri_ara
You_are_about_to_look_up_full_text_documents_for_%0_entries.=%0_adet_girdi_için_tam_metin_belgeleri_aramak_üzeresiniz.

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,9 @@ Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=

last_four_nonpunctuation_characters_should_be_numerals=

should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=
Remember_password?=

shared=
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ public void testYearChecks() {
assertWrong(createContext("year", "1986a(){},.;!?<>%&$"));
}

@Test
public void testEditionChecks() {
assertCorrect(withMode(createContext("edition", "Second"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "Third"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "second"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "2"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "2"), BibDatabaseMode.BIBLATEX));
assertCorrect(withMode(createContext("edition", "10"), BibDatabaseMode.BIBLATEX));
assertCorrect(
withMode(createContext("edition", "Third, revised and expanded edition"), BibDatabaseMode.BIBLATEX));
assertWrong(withMode(createContext("edition", "2nd"), BibDatabaseMode.BIBLATEX));
}

@Test
public void testBracketChecks() {
assertCorrect(createContext("title", "x"));
Expand Down

0 comments on commit 6bc8ffc

Please sign in to comment.