IDEMPIERE-5958: Jasper Report: ResourceBundle should use element's PrintName instead of Name (#2148)
This commit is contained in:
parent
d0d1cfb555
commit
7aa48d1856
|
@ -74,7 +74,10 @@ public final class Msg
|
||||||
private Map<String,CCache<String,String>> m_languages
|
private Map<String,CCache<String,String>> m_languages
|
||||||
= new HashMap<String, CCache<String,String>>();
|
= new HashMap<String, CCache<String,String>>();
|
||||||
|
|
||||||
private Map<String,CCache<String,String>> m_elementCache
|
private Map<String,CCache<String,String>> m_elementNameCache
|
||||||
|
= new HashMap<String,CCache<String,String>>();
|
||||||
|
|
||||||
|
private Map<String,CCache<String,String>> m_elementPrintNameCache
|
||||||
= new HashMap<String,CCache<String,String>>();
|
= new HashMap<String,CCache<String,String>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,12 +116,32 @@ public final class Msg
|
||||||
if (AD_Language == null || AD_Language.length() == 0)
|
if (AD_Language == null || AD_Language.length() == 0)
|
||||||
AD_Language = Language.getBaseAD_Language();
|
AD_Language = Language.getBaseAD_Language();
|
||||||
// Do we have the language ?
|
// Do we have the language ?
|
||||||
CCache<String,String> retValue = (CCache<String,String>)m_elementCache.get(AD_Language);
|
CCache<String,String> retValue = (CCache<String,String>)m_elementNameCache.get(AD_Language);
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
return retValue;
|
return retValue;
|
||||||
|
|
||||||
retValue = new CCache<String, String>(I_AD_Element.Table_Name, I_AD_Element.Table_Name + "|" + AD_Language, 100, 0, false, 0);
|
retValue = new CCache<String, String>(I_AD_Element.Table_Name, I_AD_Element.Table_Name + "|" + AD_Language, 100, 0, false, 0);
|
||||||
m_elementCache.put(AD_Language, retValue);
|
m_elementNameCache.put(AD_Language, retValue);
|
||||||
|
return retValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get language specific translation map for AD_Element
|
||||||
|
* @param ad_language
|
||||||
|
* @return ad_element map
|
||||||
|
*/
|
||||||
|
public synchronized CCache<String,String> getElementPrintNameMap (String ad_language)
|
||||||
|
{
|
||||||
|
String AD_Language = ad_language;
|
||||||
|
if (AD_Language == null || AD_Language.length() == 0)
|
||||||
|
AD_Language = Language.getBaseAD_Language();
|
||||||
|
// Do we have the language ?
|
||||||
|
CCache<String,String> retValue = (CCache<String,String>)m_elementPrintNameCache.get(AD_Language);
|
||||||
|
if (retValue != null)
|
||||||
|
return retValue;
|
||||||
|
|
||||||
|
retValue = new CCache<String, String>(I_AD_Element.Table_Name, I_AD_Element.Table_Name + "|" + AD_Language, 100, 0, false, 0);
|
||||||
|
m_elementPrintNameCache.put(AD_Language, retValue);
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +528,6 @@ public final class Msg
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} // getAmtInWords
|
} // getAmtInWords
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Get Translation for Element
|
* Get Translation for Element
|
||||||
* @param ad_language language
|
* @param ad_language language
|
||||||
|
@ -514,6 +536,20 @@ public final class Msg
|
||||||
* @return Name of the Column or "" if not found
|
* @return Name of the Column or "" if not found
|
||||||
*/
|
*/
|
||||||
public static String getElement (String ad_language, String ColumnName, boolean isSOTrx)
|
public static String getElement (String ad_language, String ColumnName, boolean isSOTrx)
|
||||||
|
{
|
||||||
|
return getElement(ad_language, ColumnName, isSOTrx, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Get Translation for Element
|
||||||
|
* @param ad_language language
|
||||||
|
* @param ColumnName column name
|
||||||
|
* @param isSOTrx if false PO terminology is used (if exists)
|
||||||
|
* @param isPrintName if true, will be used the PrintName instead of Name column
|
||||||
|
* @return Name/PrintName of the Column or "" if not found
|
||||||
|
*/
|
||||||
|
public static String getElement (String ad_language, String ColumnName, boolean isSOTrx, boolean isPrintName)
|
||||||
{
|
{
|
||||||
if (ColumnName == null || ColumnName.equals(""))
|
if (ColumnName == null || ColumnName.equals(""))
|
||||||
return "";
|
return "";
|
||||||
|
@ -522,7 +558,7 @@ public final class Msg
|
||||||
AD_Language = Language.getBaseAD_Language();
|
AD_Language = Language.getBaseAD_Language();
|
||||||
|
|
||||||
Msg msg = get();
|
Msg msg = get();
|
||||||
CCache<String, String> cache = msg.getElementMap(AD_Language);
|
CCache<String, String> cache = isPrintName ? msg.getElementPrintNameMap(AD_Language) : msg.getElementMap(AD_Language);
|
||||||
String key = ColumnName+"|"+isSOTrx;
|
String key = ColumnName+"|"+isSOTrx;
|
||||||
String retStr = cache.get(key);
|
String retStr = cache.get(key);
|
||||||
if (retStr != null)
|
if (retStr != null)
|
||||||
|
@ -533,13 +569,20 @@ public final class Msg
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (AD_Language == null || AD_Language.length() == 0 || Env.isBaseLanguage(AD_Language, "AD_Element"))
|
if (AD_Language == null || AD_Language.length() == 0 || Env.isBaseLanguage(AD_Language, "AD_Element")) {
|
||||||
pstmt = DB.prepareStatement("SELECT Name, PO_Name FROM AD_Element WHERE UPPER(ColumnName)=?", null);
|
StringBuilder sql = new StringBuilder("SELECT")
|
||||||
|
.append(isPrintName ? " PrintName, PO_PrintName" : " Name, PO_Name")
|
||||||
|
.append(" FROM AD_Element WHERE UPPER(ColumnName)=?");
|
||||||
|
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement("SELECT t.Name, t.PO_Name FROM AD_Element_Trl t, AD_Element e "
|
StringBuilder sql = new StringBuilder("SELECT")
|
||||||
+ "WHERE t.AD_Element_ID=e.AD_Element_ID AND UPPER(e.ColumnName)=? "
|
.append(isPrintName ? " t.PrintName, t.PO_PrintName" : " t.Name, t.PO_Name")
|
||||||
+ "AND t.AD_Language=?", null);
|
.append(" FROM AD_Element_Trl t, AD_Element e")
|
||||||
|
.append(" WHERE t.AD_Element_ID=e.AD_Element_ID AND UPPER(e.ColumnName)=?")
|
||||||
|
.append(" AND t.AD_Language=?");
|
||||||
|
pstmt = DB.prepareStatement(sql.toString(), null);
|
||||||
pstmt.setString(2, AD_Language);
|
pstmt.setString(2, AD_Language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,7 +639,6 @@ public final class Msg
|
||||||
return getElement (Env.getAD_Language(ctx), ColumnName, isSOTrx);
|
return getElement (Env.getAD_Language(ctx), ColumnName, isSOTrx);
|
||||||
} // getElement
|
} // getElement
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* "Translate" text.
|
* "Translate" text.
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
|
@ -610,6 +652,24 @@ public final class Msg
|
||||||
* @return translated text or original text if not found
|
* @return translated text or original text if not found
|
||||||
*/
|
*/
|
||||||
public static String translate(String ad_language, boolean isSOTrx, String text)
|
public static String translate(String ad_language, boolean isSOTrx, String text)
|
||||||
|
{
|
||||||
|
return translate(ad_language, isSOTrx, text, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* "Translate" text.
|
||||||
|
* <pre>{@code
|
||||||
|
* - Check AD_Message.AD_Message -> MsgText
|
||||||
|
* - Check AD_Element.ColumnName -> Name/PrintName
|
||||||
|
* }</pre>
|
||||||
|
* If checking AD_Element, the SO terminology is used.
|
||||||
|
* @param ad_language Language
|
||||||
|
* @param isSOTrx sales order context
|
||||||
|
* @param text Text - MsgText or Element Name
|
||||||
|
* @param isPrintName if true, will be used the PrintName instead of Name column
|
||||||
|
* @return translated text or original text if not found
|
||||||
|
*/
|
||||||
|
public static String translate(String ad_language, boolean isSOTrx, String text, boolean isPrintName)
|
||||||
{
|
{
|
||||||
if (text == null || text.equals(""))
|
if (text == null || text.equals(""))
|
||||||
return "";
|
return "";
|
||||||
|
@ -623,7 +683,7 @@ public final class Msg
|
||||||
return retStr;
|
return retStr;
|
||||||
|
|
||||||
// Check AD_Element
|
// Check AD_Element
|
||||||
retStr = getElement(AD_Language, text, isSOTrx);
|
retStr = getElement(AD_Language, text, isSOTrx, isPrintName);
|
||||||
if (!retStr.equals(""))
|
if (!retStr.equals(""))
|
||||||
return retStr.trim();
|
return retStr.trim();
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class MsgResourceBundle extends ResourceBundle {
|
||||||
if (overridingResourceBundle != null && overridingResourceBundle.containsKey(key)) {
|
if (overridingResourceBundle != null && overridingResourceBundle.containsKey(key)) {
|
||||||
return overridingResourceBundle.getObject(key);
|
return overridingResourceBundle.getObject(key);
|
||||||
}
|
}
|
||||||
return Msg.translate(adLanguage, isSOTrx, key);
|
return Msg.translate(adLanguage, isSOTrx, key, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,7 +85,7 @@ public class MsgResourceBundle extends ResourceBundle {
|
||||||
set = Msg.get().getMsgMap(adLanguage).keySet();
|
set = Msg.get().getMsgMap(adLanguage).keySet();
|
||||||
else
|
else
|
||||||
set.addAll(Msg.get().getMsgMap(adLanguage).keySet());
|
set.addAll(Msg.get().getMsgMap(adLanguage).keySet());
|
||||||
set.addAll(Msg.get().getElementMap(adLanguage).keySet());
|
set.addAll(Msg.get().getElementPrintNameMap(adLanguage).keySet());
|
||||||
return Collections.enumeration(set);
|
return Collections.enumeration(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue