Tomas Jelinek has uploaded a new change for review.

Change subject: webadmin: "No message" is displayed in Japanese environment
......................................................................

webadmin: "No message" is displayed in Japanese environment

New/Edit VM dialog -> fill a japanese chars into the description
field. An error dialog with message "No message" will be displayed.

The problem was, that the ErrorTranslator expected, that when a message
is in form: "$AAA b" is a variable $AAA with value "b". Than it expected
that the ${AAA} in other messages can be replaced by "b". The problem
was, that the decision, if the specific message is a variable declaration
or a message was decided in a following way:
- if the string starts with "$" character, than it is a variable declaration
- it is a message otherwise

The problem with this is, that when a message looks like "${AAA} b"
than it is considered to be a variable declaration, even it is a message
with reference to the declaration.

Fixed by enriching this decision if somethin is a variable declaratition to
the following:
- if the string starts with "$" but it is does not start with something like
"${some string}" it is a variable
- it is a message otherwise

Change-Id: I04b32be4cf4c05873bcf9643dd5b9acb3695a54a
Signed-off-by: Tomas Jelinek <tjeli...@redhat.com>
---
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ErrorTranslator.java
A 
frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/ErrorTranslatorTest.java
2 files changed, 47 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/9818/1

diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ErrorTranslator.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ErrorTranslator.java
index b2fd3f6..75a9f52 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ErrorTranslator.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/ErrorTranslator.java
@@ -12,6 +12,11 @@
 import com.google.gwt.regexp.shared.RegExp;
 
 public class ErrorTranslator {
+
+    private static final String VARIABLE_PATTERN = "\\$\\{\\w*\\}*";
+
+    private static final RegExp STARTS_WITH_VARIABLE = RegExp.compile("^" + 
VARIABLE_PATTERN, "i"); //$NON-NLS-1$ //$NON-NLS-2$
+
     private ConstantsWithLookup errors;
 
     public ErrorTranslator() {
@@ -125,7 +130,7 @@
         Map<String, String> variables = new HashMap<String, String>();
 
         for (String currentMessage : translatedMessages) {
-            if (currentMessage.startsWith("$")) { //$NON-NLS-1$
+            if (isVariableDeclaration(currentMessage)) {
                 addVariable(currentMessage, variables);
             } else {
                 translatedErrors.add(currentMessage);
@@ -155,7 +160,7 @@
     private String resolveMessage(String message, Map<String, String> 
variables) {
         String returnValue = message;
 
-        RegExp regex = RegExp.compile("\\$\\{\\w*\\}*", "gi"); //$NON-NLS-1$ 
//$NON-NLS-2$
+        RegExp regex = RegExp.compile(VARIABLE_PATTERN, "gi"); //$NON-NLS-1$ 
//$NON-NLS-2$
 
         int fromIndex = 0;
         int length = message.length();
@@ -190,4 +195,13 @@
     private final boolean isDynamicVariable(String strMessage) {
         return strMessage.startsWith("$"); //$NON-NLS-1$
     }
+
+    /**
+     * Returns true if and only if the param starts with $ but is not a 
variable reference (e.g. is not ${something})
+     */
+    boolean isVariableDeclaration(String msg) {
+        boolean startsAsVariable = msg.startsWith("$"); //$NON-NLS-1$
+        boolean isVariableReference = STARTS_WITH_VARIABLE.test(msg);
+        return startsAsVariable && !isVariableReference;
+    }
 }
diff --git 
a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/ErrorTranslatorTest.java
 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/ErrorTranslatorTest.java
new file mode 100644
index 0000000..2370c0f
--- /dev/null
+++ 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/ErrorTranslatorTest.java
@@ -0,0 +1,31 @@
+package org.ovirt.engine.ui.frontend;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+public class ErrorTranslatorTest {
+
+    private ErrorTranslator translator = new ErrorTranslator();
+
+    @Test
+    public void isVariableDeclaration_yes() {
+        assertTrue(translator.isVariableDeclaration("$x aaa"));
+    }
+
+    @Test
+    public void isVariableDeclaration_referenceToVariable() {
+        assertFalse(translator.isVariableDeclaration("${x} aaa"));
+    }
+
+    @Test
+    public void isVariableDeclaration_declarationContainsVariableReference() {
+        assertTrue(translator.isVariableDeclaration("$x aaa ${a}"));
+    }
+
+    @Test
+    public void isVariableDeclaration_variableReferenceContainsDeclaration() {
+        assertFalse(translator.isVariableDeclaration("${a} aaa $x"));
+    }
+}


--
To view, visit http://gerrit.ovirt.org/9818
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I04b32be4cf4c05873bcf9643dd5b9acb3695a54a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tomas Jelinek <tjeli...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to