11package com .genexus .util ;
22
3+ import com .genexus .ModelContext ;
4+
35public class EnvVarReader {
46
57 static String [] m_invalidChars = { "." , "|" };
@@ -12,15 +14,30 @@ public static String getEnvironmentVar(String section, String key, String mapped
1214 }else {
1315 String prefix = ENVVAR_PREFIX ;
1416 if (section != null && !section .isEmpty () && section != "Client" ) {
15- for ( int i = 0 ; i < m_invalidChars . length ; i ++)
16- section = section . replace ( m_invalidChars [ i ], "_" ) ;
17+ section = replaceInvalidChars ( section );
18+ String realKey = key ;
1719 key = String .format ("%s%s_%s" , prefix , section .toUpperCase (), key .toUpperCase ());
20+ String envVar = System .getenv (key );
21+ if (envVar != null )
22+ return envVar ;
23+ if (ModelContext .getModelContext () != null ) {
24+ section = section .replace (replaceInvalidChars (ModelContext .getModelContext ().getPackageName () + "|" ).toUpperCase (), "" );
25+ key = String .format ("%s%s_%s" , prefix , section .toUpperCase (), realKey .toUpperCase ());
26+ }
27+ else
28+ return null ;
1829 } else
1930 key = String .format ("%s%s" , prefix , key .toUpperCase ());
2031 return System .getenv (key );
2132 }
2233 }
2334
35+ private static String replaceInvalidChars (String section ) {
36+ for (int i = 0 ; i < m_invalidChars .length ; i ++)
37+ section = section .replace (m_invalidChars [i ], "_" );
38+ return section ;
39+ }
40+
2441 public static String getEnvironmentValue (String serviceType , String serviceName , String propertyName ) {
2542 String envVarName = String .format ("%s%s_%s" , ENVVAR_PREFIX , serviceType .toUpperCase (), propertyName .toUpperCase ());
2643 String value = System .getenv (envVarName );
0 commit comments