From 3f9d5688b76914469894b6049c2c3590826c4987 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Wed, 16 Feb 2022 22:43:31 +0100 Subject: sanitize utf-8 support across all supported java versions; please re-test #45 after this --- .../src/main/java/at/asit/pdfover/commons/Messages.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'pdf-over-commons/src') diff --git a/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java b/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java index f881f621..36cc921d 100644 --- a/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java +++ b/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java @@ -15,6 +15,7 @@ */ package at.asit.pdfover.commons; +import java.io.UnsupportedEncodingException; // Imports import java.util.HashMap; import java.util.Locale; @@ -92,11 +93,7 @@ public class Messages { * @return the localized message */ public static String getString(String key) { - try { - return getBundle(currentLocale).getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } + return getString(key, currentLocale); } /** @@ -107,7 +104,14 @@ public class Messages { */ public static String getString(String key, Locale locale) { try { - return getBundle(locale).getString(key); + String value = getBundle(locale).getString(key); + + /* DIRTY HACK: this recognizes java 8 ("1.8") and older; these versions read .properties files as ISO-8859-1 instead of UTF-8 */ + if (System.getProperty("java.version").startsWith("1.")) + try { value = new String(value.getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) {} + + log.trace("[{}] {}: {} -> {}", new Object[]{System.getProperty("java.version"), currentLocale, key, value}); + return value; } catch (MissingResourceException e) { return '!' + key + '!'; } -- cgit v1.2.3