summaryrefslogtreecommitdiff
path: root/pdf-over-commons/src/main/java/at/asit
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-02-16 22:43:31 +0100
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-02-16 22:43:31 +0100
commit3f9d5688b76914469894b6049c2c3590826c4987 (patch)
tree189e714bba725354bff27d5a62f92b1a71c428c7 /pdf-over-commons/src/main/java/at/asit
parent1fad1b9d59531948f5e8ac13adb16905016dbaf3 (diff)
downloadpdf-over-3f9d5688b76914469894b6049c2c3590826c4987.tar.gz
pdf-over-3f9d5688b76914469894b6049c2c3590826c4987.tar.bz2
pdf-over-3f9d5688b76914469894b6049c2c3590826c4987.zip
sanitize utf-8 support across all supported java versions; please re-test #45 after this
Diffstat (limited to 'pdf-over-commons/src/main/java/at/asit')
-rw-r--r--pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java16
1 files changed, 10 insertions, 6 deletions
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 + '!';
}