summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:14:49 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:14:49 +0000
commitb37e66c8906d2edb0b457505e4122f62ad681791 (patch)
tree1ddbfa678f82f977ae1e2d2060b43605c319fb3f /pdf-over-gui/src
parent4ba3799ddddb6eeb3e74760b3d90171048d8723c (diff)
downloadmocca-b37e66c8906d2edb0b457505e4122f62ad681791.tar.gz
mocca-b37e66c8906d2edb0b457505e4122f62ad681791.tar.bz2
mocca-b37e66c8906d2edb0b457505e4122f62ad681791.zip
Merge branch 'master' of git@abyss:12PDF-OVER-4.0.git
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@219 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java49
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java9
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java57
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java12
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java7
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java40
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java2
-rw-r--r--pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties1
-rw-r--r--pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties1
9 files changed, 171 insertions, 7 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java
index 1e8f899a..0c6101b9 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java
+++ b/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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java
index d612f3c9..c7e1b7b7 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java
@@ -173,8 +173,13 @@ public class PositioningComposite extends StateComposite {
.map(FileChannel.MapMode.READ_ONLY, 0, chan.size());
chan.close();
rafile.close();
-
- this.pdf = new PDFFile(buf);
+ try
+ {
+ this.pdf = new PDFFile(buf);
+ }
+ catch (IOException e) {
+ throw new IOException(Messages.getString("error.MayNotBeAPDF"), e); //$NON-NLS-1$
+ }
if (this.viewer == null) {
this.viewer = new SignaturePanel(this.pdf);
this.frame.add(this.viewer);
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java
new file mode 100644
index 00000000..fccbedc8
--- /dev/null
+++ b/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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
index d7b23e58..c5f0b930 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
+++ b/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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
index b545f400..f0b53cbf 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
+++ b/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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
index 8da0a069..801f626c 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
+++ b/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);
+ }
+ }
+
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java
index 44513806..d877cdcf 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java
@@ -101,7 +101,7 @@ public class PositioningState extends State {
log.error("Failed to display PDF document", e); //$NON-NLS-1$
ErrorDialog dialog = new ErrorDialog(
this.stateMachine.getGUIProvider().getMainShell(),
- e.getMessage(), ERROR_BUTTONS.RETRY_CANCEL);
+ e.getLocalizedMessage(), ERROR_BUTTONS.RETRY_CANCEL);
if(dialog.open() == SWT.RETRY) {
this.stateMachine.update();
} else {
diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties
index a60175fa..413e9db5 100644
--- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties
+++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages.properties
@@ -77,6 +77,7 @@ error.SignaturePanel.NoRender="Could not render page"
error.TanTooLong=Entered TAN too long
error.Unexpected=Unexpected Error
error.title=Error
+error.MayNotBeAPDF=This may not be a PDF File
exception.InvalidEmblemFile=%s is an invalid signature logo file!
exception.InvalidPort=%s is invalid: has to be a number between %d and %d
exception.PasswordTooLong=Given password is too long!
diff --git a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties
index 789880f9..c3a1d302 100644
--- a/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties
+++ b/pdf-over-gui/src/main/resources/at/asit/pdfover/gui/messages_de.properties
@@ -77,6 +77,7 @@ error.SignaturePanel.NoRender="Konnte Seite nicht darstellen"
error.TanTooLong=Eingegebener TAN zu lange
error.Unexpected=Unerwarteter Fehler
error.title=Fehler
+error.MayNotBeAPDF=Dies ist möglicherweise keine PDF Datei
exception.InvalidEmblemFile=%s ist eine ungültige Bildmarken-Datei!
exception.InvalidPort=%s ist ungültig: muss eine Nummer zwischen %d und %d sein.
exception.PasswordTooLong=Eingegebenes Passwort ist zu lange!