Skip to content

Commit

Permalink
Mark OOSTyle as invalid if no defaultStyle (#5471)
Browse files Browse the repository at this point in the history
* Valid OOStyle need to inlcude a default layout

Display correct layout for article and book

Fixes  #54527

* fix semicolon

* Fix indent and rename var

* add changelog

* Update CHANGELOG.md

* Update src/main/java/org/jabref/logic/openoffice/OOBibStyle.java

Co-Authored-By: Tobias Diez <tobiasdiez@gmx.de>
  • Loading branch information
Siedlerchr and tobiasdiez committed Oct 17, 2019
1 parent aa253f8 commit 4d81884
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ We refer to [GitHub issues](/~https://github.com/JabRef/jabref/issues) by using `#
- We added a short DOI field formatter which shortens DOI to more human-readable form. [koppor#343](/~https://github.com/koppor/jabref/issues/343)
- We improved the display of group memberships by adding multiple colored bars if the entry belongs to more than one group. [#4574](/~https://github.com/JabRef/jabref/issues/4574)
- We added an option to show the preview as an extra tab in the entry editor (instead of in a split view). [#5244](/~https://github.com/JabRef/jabref/issues/5244)
- A custom Open/LibreOffice jstyle file now requires a layout line for the entry type `default` [#5452](/~https://github.com/JabRef/jabref/issues/5452)

### Fixed

Expand Down Expand Up @@ -46,6 +47,7 @@ We refer to [GitHub issues](/~https://github.com/JabRef/jabref/issues) by using `#
- We fixed some display errors in the preferences dialog and replaced some of the controls [#5033](/~https://github.com/JabRef/jabref/pull/5033) [#5047](/~https://github.com/JabRef/jabref/pull/5047) [#5062](/~https://github.com/JabRef/jabref/pull/5062) [#5141](/~https://github.com/JabRef/jabref/pull/5141) [#5185](/~https://github.com/JabRef/jabref/pull/5185) [#5265](/~https://github.com/JabRef/jabref/pull/5265) [#5315](/~https://github.com/JabRef/jabref/pull/5315) [#5360](/~https://github.com/JabRef/jabref/pull/5360)
- We fixed an exception which occurred when trying to import entries without an open library. [#5447](/~https://github.com/JabRef/jabref/issues/5447)
- After successful import of one or multiple bib entries the main table scrolls to the first imported entry [#5383](/~https://github.com/JabRef/jabref/issues/5383)
- We fixed an exception which occurred when an invalid jstyle was loaded. [#5452](/~https://github.com/JabRef/jabref/issues/5452)


### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jabref.logic.openoffice.StyleLoader;
import org.jabref.logic.util.TestEntry;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
Expand Down Expand Up @@ -118,8 +119,8 @@ private void initialize() {

EasyBind.subscribe(viewModel.selectedItemProperty(), style -> {
tvStyles.getSelectionModel().select(style);
previewArticle.setLayout(new TextBasedPreviewLayout(style.getStyle().getDefaultBibLayout()));
previewBook.setLayout(new TextBasedPreviewLayout(style.getStyle().getDefaultBibLayout()));
previewArticle.setLayout(new TextBasedPreviewLayout(style.getStyle().getReferenceFormat(StandardEntryType.Article)));
previewBook.setLayout(new TextBasedPreviewLayout(style.getStyle().getReferenceFormat(StandardEntryType.Book)));
});
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/jabref/logic/openoffice/OOBibStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class OOBibStyle implements Comparable<OOBibStyle> {
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);
Expand Down Expand Up @@ -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;
}

}

/**
Expand All @@ -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);
Expand Down

0 comments on commit 4d81884

Please sign in to comment.