Related to issue 19778.Added utility methods.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Wed, 01 Feb 2012 12:29:11 +0100
changeset 15649 3e99736167dc
parent 15648 0e1375b72b2c
child 15650 fc7a5c96f230
Related to issue 19778.Added utility methods.
src/org/openbravo/erpCommon/utility/Utility.java
--- a/src/org/openbravo/erpCommon/utility/Utility.java	Wed Feb 29 13:05:53 2012 +0100
+++ b/src/org/openbravo/erpCommon/utility/Utility.java	Wed Feb 01 12:29:11 2012 +0100
@@ -68,6 +68,8 @@
 import org.openbravo.base.provider.OBConfigFileProvider;
 import org.openbravo.base.secureApp.OrgTree;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
@@ -88,6 +90,7 @@
 import org.openbravo.model.ad.ui.Window;
 import org.openbravo.model.ad.utility.Image;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.uiTranslation.TranslationHandler;
 import org.openbravo.utils.FileUtility;
 import org.openbravo.utils.FormatUtilities;
@@ -312,6 +315,25 @@
   }
 
   /**
+   * Returns an String with the date in the <i>dateFormat.java</i> format defined in
+   * Openbravo.properties
+   * 
+   * @see #formatDate(Date, String)
+   * 
+   * @param date
+   *          Date to be formatted.
+   * @param pattern
+   *          Format expected for the output.
+   * @return String formatted.
+   */
+  public static String formatDate(Date date) {
+    final String pattern = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("dateFormat.java");
+    final SimpleDateFormat dateFormatter = new SimpleDateFormat(pattern);
+    return dateFormatter.format(date);
+  }
+
+  /**
    * Returns an String with the date in the specified format
    * 
    * @param date
@@ -346,6 +368,25 @@
   }
 
   /**
+   * Translate the given code into some message from the application dictionary. It searches first
+   * in AD_Message table and if there are not matchings then in AD_Element table.
+   * 
+   * It uses DalConnectionProvider to get the ConnectionProvider and the context's language to
+   * translate the message.
+   * 
+   * @see Utility#messageBD(ConnectionProvider, String, String, boolean)
+   * 
+   * @param strCode
+   *          String with the search key to search.
+   * @return String with the translated message.
+   */
+  public static String messageBD(String strCode) {
+    String language = OBContext.getOBContext().getLanguage().getLanguage();
+    ConnectionProvider conn = new DalConnectionProvider(false);
+    return messageBD(conn, strCode, language);
+  }
+
+  /**
    * @see Utility#messageBD(ConnectionProvider, String, String, boolean)
    */
   public static String messageBD(ConnectionProvider conn, String strCode, String strLanguage) {
@@ -1072,6 +1113,19 @@
   /**
    * Parse the text searching @ parameters to translate.
    * 
+   * @param text
+   *          String with the text to translate.
+   * @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(), vars, null, language, text);
+  }
+
+  /**
+   * Parse the text searching @ parameters to translate.
+   * 
    * @param conn
    *          Handler for the database connection.
    * @param vars