summaryrefslogtreecommitdiff
path: root/trunk/pdf-over-gui/src/main
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2012-11-07 09:56:51 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2012-11-07 10:02:55 +0100
commitfd2a1aacd3841b84dcad14346aa7ce1715607ad0 (patch)
tree223c8cb3c1e9c9a35a91591c77aa2cbce45ae513 /trunk/pdf-over-gui/src/main
parent8337fbfeb4b58a7ecebd0f32d22b2bbab2c93ce8 (diff)
downloadpdf-over-fd2a1aacd3841b84dcad14346aa7ce1715607ad0.tar.gz
pdf-over-fd2a1aacd3841b84dcad14346aa7ce1715607ad0.tar.bz2
pdf-over-fd2a1aacd3841b84dcad14346aa7ce1715607ad0.zip
+ added locale config parameter
Diffstat (limited to 'trunk/pdf-over-gui/src/main')
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java49
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java57
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java12
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java7
-rw-r--r--trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java40
5 files changed, 161 insertions, 4 deletions
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java
index 1e8f899a..0c6101b9 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java
@@ -16,29 +16,72 @@
package at.asit.pdfover.gui;
// Imports
+import java.util.HashMap;
+import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Localizes string messages for PDFOver GUI
*/
public class Messages {
+
+ /**
+ * SFL4J Logger instance
+ **/
+ static final Logger log = LoggerFactory.getLogger(Messages.class);
+
private static final String BUNDLE_NAME = "at.asit.pdfover.gui.messages"; //$NON-NLS-1$
- private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
- .getBundle(BUNDLE_NAME);
+ private static HashMap<Locale, ResourceBundle> bundles = new HashMap<Locale, ResourceBundle>();
+
+ //private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ // .getBundle(BUNDLE_NAME);
+ private static Locale currentLocale = Locale.getDefault();
+
private Messages() {
}
/**
+ * Sets the currently used locals
+ * @param locale
+ */
+ public static void setLocale(Locale locale) {
+ currentLocale = locale;
+ }
+
+ private static ResourceBundle getBundle() {
+ if(!bundles.containsKey(currentLocale)) {
+ ResourceBundle tmp = null;
+ try {
+ tmp = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
+ } catch(Exception e) {
+ log.error("NO RESOURCE BUNDLE FOR " + currentLocale.toString(), e); //$NON-NLS-1$
+ tmp = ResourceBundle.getBundle(BUNDLE_NAME);
+ }
+ if(tmp == null) {
+ log.error("NO RESOURCE BUNDLE FOR " + currentLocale.toString()); //$NON-NLS-1$
+ tmp = ResourceBundle.getBundle(BUNDLE_NAME);
+ }
+ bundles.put(currentLocale, tmp);
+ return tmp;
+ }
+ return bundles.get(currentLocale);
+ }
+
+ /**
* Gets the localized message
* @param key
* @return the localized message
*/
public static String getString(String key) {
try {
- return RESOURCE_BUNDLE.getString(key);
+ return getBundle().getString(key);
+ //return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java
new file mode 100644
index 00000000..fccbedc8
--- /dev/null
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.utils;
+
+// Imports
+import java.util.Locale;
+
+/**
+ *
+ */
+public class LocaleSerializer {
+
+ /**
+ * Parse a locale from a string
+ * @param localeString the string
+ * @return the locale
+ */
+ public static Locale parseFromString(String localeString) {
+
+ if(localeString == null || localeString.isEmpty()) {
+ return null;
+ }
+
+ Locale targetLocal = null;
+ Locale[] locale = Locale.getAvailableLocales();
+ for(int i = 0; i < locale.length; i++) {
+ if(locale[i].toString().equals(localeString)) {
+ targetLocal = locale[i];
+ break;
+ }
+ }
+ return targetLocal;
+ }
+
+ /**
+ * creates a parseable string for a locale
+ * @param locale the locale
+ * @return the parseable string
+ */
+ public static String getParseableString(Locale locale) {
+ return locale.toString();
+ }
+
+}
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
index d7b23e58..c5f0b930 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
@@ -16,6 +16,7 @@
package at.asit.pdfover.gui.workflow;
import java.io.IOException;
+import java.util.Locale;
import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.SignaturePosition;
@@ -74,6 +75,11 @@ public interface ConfigManipulator {
public static final String EMBLEM_CONFIG = "EMBLEM"; //$NON-NLS-1$
/**
+ * The locale config parameter
+ */
+ public static final String LOCALE_CONFIG = "LOCALE"; //$NON-NLS-1$
+
+ /**
* The proxy host config parameter
*/
public static final String PROXY_HOST_CONFIG = "PROXY_HOST"; //$NON-NLS-1$
@@ -163,4 +169,10 @@ public interface ConfigManipulator {
* @throws IOException
*/
public void saveCurrentConfiguration() throws IOException;
+
+ /**
+ * Sets the locale to be used!
+ * @param locale the locale
+ */
+ public void setLocale(Locale locale);
}
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
index b545f400..f0b53cbf 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
@@ -17,6 +17,7 @@ package at.asit.pdfover.gui.workflow;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Locale;
import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.SignaturePosition;
@@ -110,6 +111,12 @@ public interface ConfigProvider {
public String getSigantureNote();
/**
+ * Gets the configured locale
+ * @return the configured locale
+ */
+ public Locale getConfigLocale();
+
+ /**
* Loads the current configuration to the current configuration file
* @param configSource
* @throws IOException
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
index 8da0a069..801f626c 100644
--- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
+++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
@@ -28,6 +28,8 @@ import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.gui.Messages;
+import at.asit.pdfover.gui.utils.LocaleSerializer;
import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.SignaturePosition;
@@ -64,6 +66,8 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator {
private String defaultPassword = STRING_EMPTY;
+ private Locale locale = Locale.getDefault();
+
private String emblem = STRING_EMPTY;
private String proxyHost = STRING_EMPTY;
@@ -362,6 +366,11 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator {
props.setProperty(SIGNATURE_PLACEHOLDER_TRANSPARENCY_CONFIG,
Integer.toString(this.getPlaceholderTransparency()));
+ Locale configLocale = this.getConfigLocale();
+ if(configLocale != null) {
+ props.setProperty(LOCALE_CONFIG, LocaleSerializer.getParseableString(configLocale));
+ }
+
SignaturePosition pos = this.getDefaultSignaturePosition();
if (pos == null) {
@@ -416,9 +425,16 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator {
this.setDefaultOutputFolder(config
.getProperty(ConfigManipulator.OUTPUT_FOLDER_CONFIG));
+ String localString = config.getProperty(ConfigManipulator.LOCALE_CONFIG);
+
+ Locale targetLocal = LocaleSerializer.parseFromString(localString);
+ if(targetLocal != null) {
+ this.setLocale(targetLocal);
+ }
+
String bku = config
.getProperty(ConfigManipulator.MOBILE_BKU_URL_CONFIG);
-
+
if (bku != null && !bku.equals("")) { //$NON-NLS-1$
this.mobileBKU = bku;
}
@@ -550,4 +566,26 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator {
}
}
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getConfigLocale()
+ */
+ @Override
+ public Locale getConfigLocale() {
+ return this.locale;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigManipulator#setLocale(java.util.Locale)
+ */
+ @Override
+ public void setLocale(Locale locale) {
+ if(locale == null) {
+ this.locale = Locale.getDefault();
+ } else {
+ this.locale = locale;
+ Locale.setDefault(locale);
+ Messages.setLocale(locale);
+ }
+ }
+
}