diff --git a/src/main/java/org/jabref/logic/openoffice/style/JStyle.java b/src/main/java/org/jabref/logic/openoffice/style/JStyle.java index 8ab93ca939c..74563d3e3d4 100644 --- a/src/main/java/org/jabref/logic/openoffice/style/JStyle.java +++ b/src/main/java/org/jabref/logic/openoffice/style/JStyle.java @@ -5,6 +5,8 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -19,6 +21,7 @@ import java.util.TreeSet; import java.util.regex.Pattern; +import org.jabref.architecture.AllowedToUseClassGetResource; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutFormatter; @@ -55,6 +58,7 @@ * 3) If the entries are not numbered, a citation marker must be produced for each entry. This * operation is performed for each JabRef BibEntry. */ +@AllowedToUseClassGetResource("Required for jstyle loading") public class JStyle implements Comparable, OOStyle { public static final String ITALIC_ET_AL = "ItalicEtAl"; @@ -160,7 +164,7 @@ public JStyle(String resourcePath, LayoutFormatterPreferences layoutPreferences, setDefaultProperties(); // we need to distinguish if it's a style from the local resources or a file on disk InputStream stream = JStyle.class.getResourceAsStream(resourcePath); - styleFile = Path.of(resourcePath); + styleFile = Path.of(resourcePath).toAbsolutePath(); fromResource = true; if (stream == null) { stream = Files.newInputStream(styleFile); @@ -274,8 +278,19 @@ public void ensureUpToDate() throws IOException { */ private void reload() throws IOException { if (styleFile != null) { - this.styleFileModificationTime = Files.getLastModifiedTime(styleFile).toMillis(); - try (InputStream stream = Files.newInputStream(styleFile)) { + Path resourcePath = styleFile; + if (fromResource) { + try { + URL resUrl = JStyle.class.getResource(path); + if (resUrl != null) { + resourcePath = Path.of(resUrl.toURI()); + } + } catch (URISyntaxException ex) { + LOGGER.error("Couldn't resolve resource path for style {}", path, ex); + } + } + this.styleFileModificationTime = Files.getLastModifiedTime(resourcePath).toMillis(); + try (InputStream stream = Files.newInputStream(resourcePath)) { initialize(stream); } }