details:   https://code.openbravo.com/erp/devel/pi/rev/698a79b5ee76
changeset: 33080:698a79b5ee76
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Tue Nov 28 18:01:43 2017 +0100
summary:   fixes bug 37238: OBMessageUtils fails on vars retrieval if there 
isn't request

  Two main changes:
    1- Postponed the vars initialization until it is really needed.
    2- If the vars retrieval fails because there is no request then the 
exception thrown in that case is now catched and then the message is tried to 
be loaded from database.

diffstat:

 src/org/openbravo/erpCommon/utility/OBMessageUtils.java |  19 +++++++++++-----
 1 files changed, 13 insertions(+), 6 deletions(-)

diffs (52 lines):

diff -r bc62b428fd98 -r 698a79b5ee76 
src/org/openbravo/erpCommon/utility/OBMessageUtils.java
--- a/src/org/openbravo/erpCommon/utility/OBMessageUtils.java   Tue Nov 28 
17:36:39 2017 +0100
+++ b/src/org/openbravo/erpCommon/utility/OBMessageUtils.java   Tue Nov 28 
18:01:43 2017 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2012-2016 Openbravo SLU
+ * All portions are Copyright (C) 2012-2017 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -183,9 +183,8 @@
    * @return String translated.
    */
   public static String parseTranslation(String text) {
-    final VariablesSecureApp vars = 
RequestContext.get().getVariablesSecureApp();
     final String language = 
OBContext.getOBContext().getLanguage().getLanguage();
-    return parseTranslation(new DalConnectionProvider(false), vars, null, 
language, text);
+    return parseTranslation(new DalConnectionProvider(false), null, null, 
language, text);
   }
 
   /**
@@ -198,9 +197,8 @@
    * @return String translated.
    */
   public static String parseTranslation(String text, Map<String, String> map) {
-    final VariablesSecureApp vars = 
RequestContext.get().getVariablesSecureApp();
     final String language = 
OBContext.getOBContext().getLanguage().getLanguage();
-    return parseTranslation(new DalConnectionProvider(false), vars, map, 
language, text);
+    return parseTranslation(new DalConnectionProvider(false), null, map, 
language, text);
   }
 
   /**
@@ -290,7 +288,16 @@
    */
   public static String translate(ConnectionProvider conn, VariablesSecureApp 
vars, String token,
       String language) {
-    String strTranslate = vars.getSessionValue(token);
+    String strTranslate = "";
+    if (vars == null) {
+      try {
+        strTranslate = 
RequestContext.get().getVariablesSecureApp().getSessionValue(token);
+      } catch (OBException ignore) {
+        // there is no request: can't retrieve the session info
+      }
+    } else {
+      strTranslate = vars.getSessionValue(token);
+    }
     if (!strTranslate.equals("")) {
       return strTranslate;
     }

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to