Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove <pre> tag from entries fetched using MathSciNet #2990

Merged
merged 2 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,8 @@ public void doPostCleanup(BibEntry entry) {
new MoveFieldCleanup("mrclass", FieldName.KEYWORDS).cleanup(entry);
new FieldFormatterCleanup("mrreviewer", new ClearFormatter()).cleanup(entry);
new FieldFormatterCleanup(FieldName.URL, new ClearFormatter()).cleanup(entry);

// Remove comments: MathSciNet prepends a <pre> html tag
entry.setCommentsBeforeEntry("");
}
}
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ public void setParsedSerialization(String parsedSerialization) {
}

public void setCommentsBeforeEntry(String parsedComments) {
this.commentsBeforeEntry = parsedComments;
// delete trailing whitespaces (between entry and text)
this.commentsBeforeEntry = REMOVE_TRAILING_WHITESPACE.matcher(parsedComments).replaceFirst("");
}

public boolean hasChanged() {
Expand Down Expand Up @@ -700,7 +701,9 @@ public boolean equals(Object o) {
return false;
}
BibEntry entry = (BibEntry) o;
return Objects.equals(type, entry.type) && Objects.equals(fields, entry.fields);
return Objects.equals(type, entry.type)
&& Objects.equals(fields, entry.fields)
&& Objects.equals(commentsBeforeEntry, entry.commentsBeforeEntry);
}

@Override
Expand Down Expand Up @@ -730,8 +733,7 @@ public BibEntry withField(String field, String value) {
* Returns user comments (arbitrary text before the entry), if they exist. If not, returns the empty String
*/
public String getUserComments() {
// delete trailing whitespaces (between entry and text) from stored serialization
return REMOVE_TRAILING_WHITESPACE.matcher(commentsBeforeEntry).replaceFirst("");
return commentsBeforeEntry;
}

public List<ParsedEntryLink> getEntryLinkList(String fieldName, BibDatabase database) {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/model/entry/CanonicalBibtexEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ private CanonicalBibtexEntry() {
*
* Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key
*/
public static String getCanonicalRepresentation(BibEntry e) {
public static String getCanonicalRepresentation(BibEntry entry) {
StringBuilder sb = new StringBuilder();

sb.append(entry.getUserComments());

// generate first line: type and bibtex key
String citeKey = e.getCiteKeyOptional().orElse("");
sb.append(String.format("@%s{%s,", e.getType().toLowerCase(Locale.US), citeKey)).append('\n');
String citeKey = entry.getCiteKeyOptional().orElse("");
sb.append(String.format("@%s{%s,", entry.getType().toLowerCase(Locale.US), citeKey)).append('\n');

// we have to introduce a new Map as fields are stored case-sensitive in JabRef (see https://github.com/koppor/jabref/issues/45).
Map<String, String> mapFieldToValue = new HashMap<>();

// determine sorted fields -- all fields lower case
SortedSet<String> sortedFields = new TreeSet<>();
for (Entry<String, String> field : e.getFieldMap().entrySet()) {
for (Entry<String, String> field : entry.getFieldMap().entrySet()) {
String fieldName = field.getKey();
String fieldValue = field.getValue();
// JabRef stores the key in the field KEY_FIELD, which must not be serialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ public void parseRecognizesEntryPrecedingComment() throws IOException {

List<BibEntry> parsed = result.getDatabase().getEntries();

BibEntry expected = new BibEntry("article").withField(BibEntry.KEY_FIELD, "test")
BibEntry expected = new BibEntry("article")
.withField(BibEntry.KEY_FIELD, "test")
.withField("author", "Ed von T@st");
expected.setCommentsBeforeEntry(comment);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@misc{,
title = {This is a test title}
}, @misc{,
}
@misc{,
title = {This is also a test title}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
% Encoding: UTF-8

@TechReport{
author = {M?ller,Rudolf and Perea,Andr?s and Wolf,Sascha},
title = {Weak Monotonicity and Bayes-Nash Incentive Compatibility},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
% Encoding: UTF-8

@TechReport{,
title = {Commercial Television and Voter Information},
url = {http://d.repec.org/n?u=RePEc:cla:levrem:784828000000000363&r=ict}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
% Encoding: UTF-8

@Article{,
author = {Federico, S. and Grillo, A. and Herzog, W.},
title = {A transversely isotropic composite with a statistical distribution of spheroidal inclusions: A geometrical approach to overall properties},
Expand Down