Class Env

java.lang.Object
org.compiere.util.Env

public final class Env extends Object
System Environment and static variables.
Version:
$Id: Env.java,v 1.3 2006/07/30 00:54:36 jjanke Exp $
Author:
Jorg Janke, Teo Sarca, www.arhipac.ro
  • BF [ 1619390 ] Use default desktop browser as external browser
  • BF [ 2017987 ] Env.getContext(TAB_INFO) should NOT use global context
  • FR [ 2392044 ] Introduce Env.WINDOW_MAIN
    • Field Details

    • Constructor Details

      • Env

        public Env()
    • Method Details

      • setContextProvider

        public static void setContextProvider(ContextProvider provider)
        Deprecated.
        Parameters:
        provider -
      • addEventListener

        public static void addEventListener(IEnvEventListener listener)
        Add environment event listener
        Parameters:
        listener -
      • removeEventListener

        public static boolean removeEventListener(IEnvEventListener listener)
        Remove environment event listener
        Parameters:
        listener -
        Returns:
        boolean
      • exitEnv

        public static void exitEnv(int status)
        Exit System
        Parameters:
        status - System exit status (usually 0 for no error)
      • logout

        public static void logout()
        Logout from the system
      • reset

        public static void reset(boolean finalCall)
        Reset Cache
        Parameters:
        finalCall - true to clear everything otherwise login data remains
      • getCtx

        public static final Properties getCtx()
        Get Context
        Returns:
        Properties
      • getContextProvider

        public static ContextProvider getContextProvider()
        Get context provider
        Returns:
        context provider for current environment
      • setCtx

        public static void setCtx(Properties ctx)
        Replace the contents of the current session/process context.
        Don't use this to setup a new session/process context, use ServerContext.setCurrentInstance instead.
        Parameters:
        ctx - context
      • setContext

        public static void setContext(Properties ctx, String context, String value)
        Set Global Context to Value
        Parameters:
        ctx - context
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, String context, Timestamp value)
        Set Global Context to Value
        Parameters:
        ctx - context
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, String context, int value)
        Set Global Context to (int) Value
        Parameters:
        ctx - context
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, String context, boolean value)
        Set Global Context to Y/N Value
        Parameters:
        ctx - context
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, String context, String value)
        Set Context for Window to Value
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, String context, Timestamp value)
        Set Context for Window to Value
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, String context, int value)
        Set Context for Window to int Value
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, int TabNo, String context, int value)
        Set context value for window and tab
        Parameters:
        ctx -
        WindowNo -
        TabNo -
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, String context, boolean value)
        Set Context for Window to Y/N Value
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, int TabNo, String context, boolean value)
        Set Context for Window and tab to Y/N Value
        Parameters:
        ctx - context
        WindowNo - window no
        TabNo -
        context - context key
        value - context value
      • setContext

        public static void setContext(Properties ctx, int WindowNo, int TabNo, String context, String value)
        Set Context for Window and Tab to Value
        Parameters:
        ctx - context
        WindowNo - window no
        TabNo - tab no
        context - context key
        value - context value
      • setAutoCommit

        @Deprecated public static void setAutoCommit(Properties ctx, boolean autoCommit)
        Deprecated.
        Set Auto Commit
        Parameters:
        ctx - context
        autoCommit - auto commit (save)
      • setAutoCommit

        public static void setAutoCommit(Properties ctx, int WindowNo, boolean autoCommit)
        Set Auto Commit for Window
        Parameters:
        ctx - context
        WindowNo - window no
        autoCommit - auto commit (save)
      • setAutoNew

        @Deprecated public static void setAutoNew(Properties ctx, boolean autoNew)
        Deprecated.
        Set Auto New Record
        Parameters:
        ctx - context
        autoNew - auto new record
      • setAutoNew

        public static void setAutoNew(Properties ctx, int WindowNo, boolean autoNew)
        Set Auto New Record for Window
        Parameters:
        ctx - context
        WindowNo - window no
        autoNew - auto new record
      • setSOTrx

        public static void setSOTrx(Properties ctx, boolean isSOTrx)
        Set IsSOTrx Y/N flag
        Parameters:
        ctx - context
        isSOTrx - SO Context
      • getContext

        public static String getContext(Properties ctx, String context)
        Get global Value of Context
        Parameters:
        ctx - context
        context - context key
        Returns:
        value or ""
      • getContext

        public static String getContext(Properties ctx, int WindowNo, String context, boolean onlyWindow)
        Get Value of Context for Window. if not found global context if available and enabled
        Parameters:
        ctx - context
        WindowNo - window
        context - context key
        onlyWindow - if true, no defaults are used unless explicitly asked for
        Returns:
        value or ""
      • getContext

        public static String getContext(Properties ctx, int WindowNo, String context)
        Get Value of Context for Window.
        If not found, try global context.
        Parameters:
        ctx - context
        WindowNo - window
        context - context key
        Returns:
        value or ""
      • getContext

        public static String getContext(Properties ctx, int WindowNo, int TabNo, String context)
        Get Value of Context for Window and Tab.
        If not found, try global context.
        If TabNo is TAB_INFO, only tab's context will be checked.
        Parameters:
        ctx - context
        WindowNo - window no
        TabNo - tab no
        context - context key
        Returns:
        value or ""
      • getContext

        public static String getContext(Properties ctx, int WindowNo, int TabNo, String context, boolean onlyTab)
        Get Value of Context for Window and Tab.
        If not found, try global context.
        If TabNo is TAB_INFO, only tab's context will be checked.
        Parameters:
        ctx - context
        WindowNo - window no
        TabNo - tab no
        context - context key
        onlyTab - if true, no window value is searched
        Returns:
        value or ""
      • getContext

        public static String getContext(Properties ctx, int WindowNo, int TabNo, String context, boolean onlyTab, boolean onlyWindow)
        Get Value of Context for Window and Tab.
        If not found, try global context.
        If TabNo is TAB_INFO, only tab's context will be checked.
        Parameters:
        ctx - context
        WindowNo - window no
        TabNo - tab no
        context - context key
        onlyTab - if true, no window value is searched
        onlyWindow - if true, no global context will be searched
        Returns:
        value or ""
      • getContextAsInt

        public static int getContextAsInt(Properties ctx, String context)
        Get Context and convert it to an integer (0 if error)
        Parameters:
        ctx - context
        context - context key
        Returns:
        value
      • getContextAsInt

        public static int getContextAsInt(Properties ctx, int WindowNo, String context)
        Get Context and convert it to an integer (0 if error)
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        Returns:
        value or 0
      • getContextAsInt

        public static int getContextAsInt(Properties ctx, int WindowNo, String context, boolean onlyWindow)
        Get Context and convert it to an integer (0 if error)
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        onlyWindow - if true, do not try global context if context key not found with window
        Returns:
        value or 0
      • getContextAsInt

        public static int getContextAsInt(Properties ctx, int WindowNo, int TabNo, String context)
        Get Context and convert it to an integer (0 if error)
        Parameters:
        ctx - context
        WindowNo - window no
        TabNo - tab no
        context - context key
        Returns:
        value or 0
      • isAutoCommit

        public static boolean isAutoCommit(Properties ctx)
        Is AutoCommit
        Parameters:
        ctx - context
        Returns:
        true if auto commit
      • isAutoCommit

        public static boolean isAutoCommit(Properties ctx, int WindowNo)
        Is Window AutoCommit (if not set use default)
        Parameters:
        ctx - context
        WindowNo - window no
        Returns:
        true if auto commit
      • isAutoNew

        public static boolean isAutoNew(Properties ctx)
        Is Auto New Record
        Parameters:
        ctx - context
        Returns:
        true if auto new
      • isAutoNew

        public static boolean isAutoNew(Properties ctx, int WindowNo)
        Is Window Auto New Record (if not set use default)
        Parameters:
        ctx - context
        WindowNo - window no
        Returns:
        true if auto new record
      • isSOTrx

        public static boolean isSOTrx(Properties ctx)
        Is Sales Order Trx
        Parameters:
        ctx - context
        Returns:
        true if SO (default)
      • isSOTrx

        public static boolean isSOTrx(Properties ctx, int WindowNo)
        Is Sales Order Trx
        Parameters:
        ctx - context
        WindowNo - window no
        Returns:
        true if SO (default)
      • getContextAsDate

        public static Timestamp getContextAsDate(Properties ctx, String context)
        Get Context and convert it to Timestamp.
        If error return today's date.
        Parameters:
        ctx - context
        context - context key
        Returns:
        Timestamp
      • getContextAsDate

        public static Timestamp getContextAsDate(Properties ctx, int WindowNo, String context)
        Get Context and convert it to Timestamp.
        If error return today's date.
        Parameters:
        ctx - context
        WindowNo - window no
        context - context key
        Returns:
        Timestamp
      • getAD_Client_ID

        public static int getAD_Client_ID(Properties ctx)
        Get Login AD_Client_ID
        Parameters:
        ctx - context
        Returns:
        login AD_Client_ID
      • getAD_Org_ID

        public static int getAD_Org_ID(Properties ctx)
        Get Login AD_Org_ID
        Parameters:
        ctx - context
        Returns:
        login AD_Org_ID
      • getAD_User_ID

        public static int getAD_User_ID(Properties ctx)
        Get Login AD_User_ID
        Parameters:
        ctx - context
        Returns:
        login AD_User_ID
      • getAD_Role_ID

        public static int getAD_Role_ID(Properties ctx)
        Get Login AD_Role_ID
        Parameters:
        ctx - context
        Returns:
        login AD_Role_ID
      • getPreference

        public static String getPreference(Properties ctx, int AD_Window_ID, String context, boolean system)
        Get Preference.
                        0)      Current Setting
                        1)      Window Preference
                        2)      Global Preference
                        3)      Login settings
                        4)      Accounting settings
          
        Parameters:
        ctx - context
        AD_Window_ID - window no
        context - Entity to search
        system - System level preferences (vs. user defined)
        Returns:
        preference value
      • getPreference

        public static String getPreference(Properties ctx, int AD_Window_ID, int AD_InfoWindow, int AD_Process_ID_Of_Panel, String context)
        Get preference of process from environment context
        Parameters:
        ctx -
        AD_Window_ID -
        AD_InfoWindow -
        AD_Process_ID_Of_Panel -
        context -
        Returns:
        preference value
      • getPreference

        public static String getPreference(Properties ctx, int AD_Window_ID, int AD_InfoWindow, String context)
        Get preference of info window from environment context
        Parameters:
        ctx -
        AD_Window_ID -
        AD_InfoWindow -
        context -
        Returns:
        preference value
      • isBaseLanguage

        public static boolean isBaseLanguage(Properties ctx, String tableName)
        Check Base Language
        Parameters:
        ctx - context
        tableName - ignore
        Returns:
        true if language value in ctx is base language
      • isBaseLanguage

        public static boolean isBaseLanguage(String AD_Language, String tableName)
        Check Base Language
        Parameters:
        AD_Language - language
        tableName - ignore
        Returns:
        true if AD_Language is base language
      • isBaseLanguage

        public static boolean isBaseLanguage(Language language, String tableName)
        Check Base Language
        Parameters:
        language - language
        tableName - ignore
        Returns:
        true if language is base language
      • isBaseTranslation

        public static boolean isBaseTranslation(String tableName)
        Table is in Base Translation (AD)
        Parameters:
        tableName - table
        Returns:
        true if base trl
      • isMultiLingualDocument

        public static boolean isMultiLingualDocument(Properties ctx)
        Do we have Multi-Lingual Documents. Set in DB.loadOrgs.
        Parameters:
        ctx - context
        Returns:
        true if tenant is using multi lingual documents
      • getAD_Language

        public static String getAD_Language(Properties ctx)
        Get AD_Language value in context.
        Fall back to base language if there's no AD_Language value in context.
        Parameters:
        ctx - context
        Returns:
        AD_Language eg. en_US
      • getLanguage

        public static Language getLanguage(Properties ctx)
        Get Language from context.
        Fall back to base language if there's no language value in context.
        Parameters:
        ctx - context
        Returns:
        Language
      • getLoginLanguage

        public static Language getLoginLanguage(Properties ctx)
        Get Login Language
        Parameters:
        ctx - context
        Returns:
        Login Language
      • getLocaleLanguage

        public static Language getLocaleLanguage(Properties ctx)
        Get language from locale value in context
        Parameters:
        ctx - context
        Returns:
        Language
      • getLocale

        public static Locale getLocale(Properties ctx)
        Get locale value in context
        Parameters:
        ctx - context
        Returns:
        Locale
      • getSupportedLanguages

        public static ArrayList<String> getSupportedLanguages()
        Get list of language from AD_Message_Trl.
        Returns:
        list of supported language
      • getLoginLanguages

        public static ArrayList<String> getLoginLanguages()
        Get list of active login languages
        Returns:
        list of active login languages
      • verifyLanguage

        public static void verifyLanguage(Properties ctx, Language language)
        Verify Language. Check that language is supported by the system.
        Parameters:
        ctx - might be updated with new AD_Language
        language - language
      • getEntireContext

        public static String[] getEntireContext(Properties ctx)
        Get Context as String array with format: key == value
        Parameters:
        ctx - context
        Returns:
        context string array
      • getHeader

        public static String getHeader(Properties ctx, int WindowNo)
        Get Header info (documentno, value, name, user name, tenant name and organization name)
        Parameters:
        ctx - context
        WindowNo - window
        Returns:
        Header String
      • clearWinContext

        public static void clearWinContext(Properties ctx, int WindowNo)
        Clean up context for Window (i.e. delete it)
        Parameters:
        ctx - context
        WindowNo - window
      • clearTabContext

        public static void clearTabContext(Properties ctx, int WindowNo, int TabNo)
        Clean up context for Window Tab (i.e. delete it). Please note that this method is not clearing the tab info context (i.e. _TabInfo).
        Parameters:
        ctx - context
        WindowNo - window
        TabNo - tab
      • clearContext

        public static void clearContext(Properties ctx)
        Clean up all context (i.e. delete it)
        Parameters:
        ctx - context
      • parseContext

        public static String parseContext(Properties ctx, int WindowNo, String value, boolean onlyWindow, boolean ignoreUnparsable)
        Parse Context replaces global or Window context @tag@ with actual value.
        Parameters:
        ctx - context
        WindowNo - Number of Window
        value - Message to be parsed
        onlyWindow - if true, no defaults are used
        ignoreUnparsable - If true, just skip context variable that's not resolvable. If false, return "" if there are context variable that's not resolvable.
        Returns:
        parsed message
      • parseContext

        public static String parseContext(Properties ctx, int WindowNo, int tabNo, String value, boolean onlyTab, boolean ignoreUnparsable)
        Parse Context replaces global or Window context @tag@ with actual value.
        Parameters:
        ctx - context
        WindowNo - Number of Window
        tabNo - Number of Tab
        value - Message to be parsed
        onlyTab - if true, only value from tabNo are used
        ignoreUnparsable - If true, just skip context variable that's not resolvable. If false, return "" if there are context variable that's not resolvable.
        Returns:
        parsed message
      • parseContext

        public static String parseContext(Properties ctx, int WindowNo, String value, boolean onlyWindow)
        Parse Context replaces global or Window context @tag@ with actual value.
        Parameters:
        ctx - context
        WindowNo - Number of Window
        value - Message to be parsed
        onlyWindow - if true, no defaults are used
        Returns:
        parsed String or "" if not successful
      • parseContext

        public static String parseContext(Properties ctx, int WindowNo, int tabNo, String value, boolean onlyTab)
        Parse Context replaces global or Window context @tag@ with actual value.
        Parameters:
        ctx - context
        WindowNo - Number of Window
        tabNo - Number of Tab
        value - Message to be parsed
        onlyTab - if true, no value from tabNo are used
        Returns:
        parsed String or "" if not successful
      • parseVariable

        public static String parseVariable(String expression, PO po, String trxName, boolean keepUnparseable)
        Parse expression, replaces global or PO properties @tag@ with actual value.
        Parameters:
        expression -
        po -
        trxName -
        keepUnparseable -
        Returns:
        String
      • parseVariable

        public static String parseVariable(String expression, PO po, String trxName, boolean useColumnDateFormat, boolean useMsgForBoolean, boolean keepUnparseable)
        Parse expression, replaces global or PO properties @tag@ with actual value.
        Parameters:
        expression -
        po -
        useColumnDateFormat -
        useMsgForBoolean -
        trxName -
        keepUnparseable - true to keep original context variable tag that can't be resolved
        Returns:
        Parsed expression
      • clearWinContext

        public static void clearWinContext(int WindowNo)
        Clean up context for Window (i.e. delete it)
        Parameters:
        WindowNo - window
      • clearContext

        public static void clearContext()
        Clean up all context (i.e. delete it)
      • getImageIcon

        public static ImageIcon getImageIcon(String fileNameInImageDir)
        Get ImageIcon.
        Parameters:
        fileNameInImageDir - file name in images folder (e.g. Bean16.gif)
        Returns:
        image
      • getImageIcon2

        public static ImageIcon getImageIcon2(String fileName)
        Get ImageIcon. This method different from getImageIcon where the fileName parameter is without extension. The method will first try .gif and then .png if .gif does not exists.
        Parameters:
        fileName - file name in images folder without the extension(e.g. Bean16)
        Returns:
        image
      • startBrowser

        public static void startBrowser(String url)
        Show url in Browser
        Parameters:
        url - url
      • isMac

        public static boolean isMac()
        Do we run on Apple
        Returns:
        true if Mac
      • isWindows

        public static boolean isWindows()
        Do we run on Windows
        Returns:
        true if windows
      • sleep

        public static void sleep(int sec)
        Sleep
        Parameters:
        sec - seconds
      • getRemoteCallCtx

        @Deprecated(forRemoval=true, since="11") public static Properties getRemoteCallCtx(Properties ctx)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Prepare the context for calling remote server (for e.g, ejb), only default and global variables are pass over. It is too expensive and also can have serialization issue if every remote call to server is passing the whole client context.
        Parameters:
        ctx -
        Returns:
        Properties
      • getMWindowVO

        public static GridWindowVO getMWindowVO(int WindowNo, int AD_Window_ID, int AD_Menu_ID)
        Get Window value object model
        Parameters:
        WindowNo - Window No
        AD_Window_ID - window
        AD_Menu_ID - menu
        Returns:
        Model Window Value Object
      • getProcessUI

        public static IProcessUI getProcessUI(Properties ctx)
        Get IProcessUI instance
        Parameters:
        ctx -
        Returns:
        IProcessUI instance or null
      • getProcessInfo

        public static ProcessInfo getProcessInfo(Properties ctx)
        Get process info instance
        Parameters:
        ctx -
        Returns:
        process info instance or null
      • getStandardReportFooterTrademarkText

        public static String getStandardReportFooterTrademarkText()
        Get footer trademark text for report
        Returns:
        trademark text for standard report footer
      • getZoomWindowID

        public static int getZoomWindowID(MQuery query)
        Get zoom AD_Window_ID
        Parameters:
        query -
        Returns:
        zoom AD_Window_ID
      • getZoomWindowUU

        public static int getZoomWindowUU(int AD_Table_ID, String Record_UU)
        Get zoom AD_Window_ID
        Parameters:
        AD_Table_ID -
        Record_UU -
        Returns:
        zoom AD_Window_ID
      • getZoomWindowUU

        public static int getZoomWindowUU(int AD_Table_ID, String Record_UU, int windowNo)
        Get zoom AD_Window_ID
        Parameters:
        AD_Table_ID -
        Record_UU -
        windowNo -
        Returns:
        zoom AD_Window_ID
      • getZoomWindowID

        public static int getZoomWindowID(int AD_Table_ID, int Record_ID)
        Get zoom AD_Window_ID
        Parameters:
        AD_Table_ID -
        Record_ID -
        Returns:
        zoom AD_Window_ID
      • getZoomWindowID

        public static int getZoomWindowID(int AD_Table_ID, int Record_ID, int windowNo)
        Get zoom AD_Window_ID
        Parameters:
        AD_Table_ID -
        Record_ID -
        windowNo -
        Returns:
        zoom AD_Window_ID
      • setPredefinedVariables

        public static void setPredefinedVariables(Properties ctx, int windowNo, String predefinedVariables)
         Add in context predefined variables with prefix +, coming from menu, window or role definition.
         Predefined variables must come separated by new lines in one of the formats:
           VAR=VALUE
           VAR="VALUE"
           VAR='VALUE'
          The + prefix is not required, is added here to the defined variables.
         
        Parameters:
        ctx -
        windowNo - window number or -1 to global level
        predefinedVariables -
      • isLogMigrationScript

        public static boolean isLogMigrationScript(String tableName)
        Is log migration script for SQL statement
        Parameters:
        tableName -
        Returns:
        true if log migration script is turn on and should be used for tableName
      • isUseCentralizedId

        public static boolean isUseCentralizedId(String tableName)
        Is use centralized id from id server
        Returns:
        true if centralized id is turn on and should be used for tableName
      • isReadOnlySession

        public static boolean isReadOnlySession()
        Is read only session? Based on user preference
        Returns:
      • isGlobalVariable

        public static boolean isGlobalVariable(String variable)
        Verifies if a context variable name is global, this is, starting with: # Login $ Accounting + Role Injected
        Parameters:
        variable -
        Returns:
      • isPreference

        public static boolean isPreference(String variable)
        Verifies if a context variable name is a preference, this is, starting with: P| Preference
        Parameters:
        variable -
        Returns: