private static MyfacesConfig createAndInitializeMyFacesConfig()

in impl/src/main/java/org/apache/myfaces/config/webparameters/MyfacesConfig.java [932:1350]


    private static MyfacesConfig createAndInitializeMyFacesConfig(ExternalContext extCtx)
    {
        MyfacesConfig cfg = new MyfacesConfig();

        try
        {
            cfg.projectStage = ProjectStage.valueOf(getString(extCtx, ProjectStage.PROJECT_STAGE_PARAM_NAME, null));
        }
        catch (Exception e)
        {
            // ignore, it's logged in ApplicationImpl
        }
        if (cfg.projectStage == null)
        {
            cfg.projectStage = ProjectStage.Production;
        }

        cfg.renderClearJavascriptOnButton = getBoolean(extCtx, RENDER_CLEAR_JAVASCRIPT_FOR_BUTTON,
                RENDER_CLEAR_JAVASCRIPT_FOR_BUTTON_DEFAULT);

        cfg.renderViewStateId = getBoolean(extCtx, RENDER_VIEWSTATE_ID,
                RENDER_VIEWSTATE_ID_DEFAULT);
        
        cfg.strictXhtmlLinks = getBoolean(extCtx, STRICT_XHTML_LINKS,
                STRICT_XHTML_LINKS_DEFAULT);
        
        cfg.configRefreshPeriod = getLong(extCtx, CONFIG_REFRESH_PERIOD,
                CONFIG_REFRESH_PERIOD_DEFAULT);

        String refreshTransientBuildOnPSS = getString(extCtx, REFRESH_TRANSIENT_BUILD_ON_PSS, 
                REFRESH_TRANSIENT_BUILD_ON_PSS_DEFAULT);
        if (refreshTransientBuildOnPSS == null)
        {
            cfg.refreshTransientBuildOnPSS = false;
            cfg.refreshTransientBuildOnPSSAuto = false;
        }
        else if ("auto".equalsIgnoreCase(refreshTransientBuildOnPSS))
        {
            cfg.refreshTransientBuildOnPSS = true;
            cfg.refreshTransientBuildOnPSSAuto = true;
        }
        else if (refreshTransientBuildOnPSS.equalsIgnoreCase("true") || 
                refreshTransientBuildOnPSS.equalsIgnoreCase("on") || 
                refreshTransientBuildOnPSS.equalsIgnoreCase("yes"))
        {
            cfg.refreshTransientBuildOnPSS = true;
            cfg.refreshTransientBuildOnPSSAuto = false;
        }
        else
        {
            cfg.refreshTransientBuildOnPSS = false;
            cfg.refreshTransientBuildOnPSSAuto = false;
        }
        
        cfg.refreshTransientBuildOnPSSPreserveState = getBoolean(extCtx, REFRESH_TRANSIENT_BUILD_ON_PSS_PRESERVE_STATE,
                REFRESH_TRANSIENT_BUILD_ON_PSS_PRESERVE_STATE_DEFAULT);
        
        cfg.validateXML = getBoolean(extCtx, VALIDATE_XML, 
                VALIDATE_XML_DEFAULT);
        
        cfg.wrapScriptContentWithXmlCommentTag = getBoolean(extCtx, WRAP_SCRIPT_CONTENT_WITH_XML_COMMENT_TAG, 
                WRAP_SCRIPT_CONTENT_WITH_XML_COMMENT_TAG_DEFAULT);
        
        cfg.debugPhaseListenerEnabled = getBoolean(extCtx, DEBUG_PHASE_LISTENER,
                DEBUG_PHASE_LISTENER_DEFAULT);
                
        cfg.strictJsf2CCELResolver = getBoolean(extCtx, STRICT_JSF_2_CC_EL_RESOLVER,
                STRICT_JSF_2_CC_EL_RESOLVER_DEFAULT);
        
        cfg.defaultResponseWriterContentTypeMode = getString(extCtx, DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE,
                DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT);

        cfg.viewUniqueIdsCacheEnabled = getBoolean(extCtx, VIEW_UNIQUE_IDS_CACHE_ENABLED,
                VIEW_UNIQUE_IDS_CACHE_ENABLED_DEFAULT);

        cfg.componentUniqueIdsCacheSize = getInt(extCtx, COMPONENT_UNIQUE_IDS_CACHE_SIZE, 
                COMPONENT_UNIQUE_IDS_CACHE_SIZE_DEFAULT);

        cfg.strictJsf2ViewNotFound = getBoolean(extCtx, STRICT_JSF_2_VIEW_NOT_FOUND,
                STRICT_JSF_2_VIEW_NOT_FOUND_DEFAULT);
        
        cfg.earlyFlushEnabled = getBoolean(extCtx, EARLY_FLUSH_ENABLED,
                EARLY_FLUSH_ENABLED_DEFAULT);
        if (cfg.projectStage != ProjectStage.Production)
        {
            cfg.earlyFlushEnabled = false;
        }

        cfg.strictJsf2FaceletsCompatibility = getBoolean(extCtx, STRICT_JSF_2_FACELETS_COMPATIBILITY, 
                STRICT_JSF_2_FACELETS_COMPATIBILITY_DEFAULT);
        
        cfg.renderFormViewStateAtBegin = getBoolean(extCtx, RENDER_FORM_VIEW_STATE_AT_BEGIN,
                RENDER_FORM_VIEW_STATE_AT_BEGIN_DEFAULT);
        
        cfg.flashScopeDisabled = getBoolean(extCtx, FLASH_SCOPE_DISABLED,
                FLASH_SCOPE_DISABLED_DEFAULT);
        
        cfg.strictJsf2AllowSlashLibraryName = getBoolean(extCtx, STRICT_JSF_2_ALLOW_SLASH_LIBRARY_NAME,
                STRICT_JSF_2_ALLOW_SLASH_LIBRARY_NAME_DEFAULT);
        
        try
        {
            cfg.numberOfSequentialViewsInSession = getInt(extCtx, NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION,
                    NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_DEFAULT);
            if (cfg.numberOfSequentialViewsInSession == null
                    || cfg.numberOfSequentialViewsInSession < 0)
            {
                Logger.getLogger(MyfacesConfig.class.getName()).severe(
                        "Configured value for " + NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION
                          + " is not valid, must be an value >= 0, using default value ("
                          + NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_DEFAULT);
                cfg.numberOfSequentialViewsInSession = NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_DEFAULT;
            }
        }
        catch (Throwable e)
        {
            Logger.getLogger(MyfacesConfig.class.getName()).log(Level.SEVERE, "Error determining the value for "
                   + NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION
                   + ", expected an integer value > 0, using default value ("
                   + NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_DEFAULT + "): " + e.getMessage(), e);
        }        
        try
        {
            cfg.numberOfViewsInSession = getInt(extCtx, NUMBER_OF_VIEWS_IN_SESSION,
                    NUMBER_OF_VIEWS_IN_SESSION_DEFAULT);
            if (cfg.numberOfViewsInSession == null || cfg.numberOfViewsInSession <= 0)
            {
                Logger.getLogger(MyfacesConfig.class.getName()).severe(
                        "Configured value for " + NUMBER_OF_VIEWS_IN_SESSION
                          + " is not valid, must be an value > 0, using default value ("
                          + NUMBER_OF_VIEWS_IN_SESSION_DEFAULT);
                cfg.numberOfViewsInSession = NUMBER_OF_VIEWS_IN_SESSION_DEFAULT;
            }
        }
        catch (Throwable e)
        {
            Logger.getLogger(MyfacesConfig.class.getName()).log(Level.SEVERE, "Error determining the value for "
                   + NUMBER_OF_VIEWS_IN_SESSION
                   + ", expected an integer value > 0, using default value ("
                   + NUMBER_OF_VIEWS_IN_SESSION_DEFAULT + "): " + e.getMessage(), e);
        }

        int numberOfFlashTokensInSessionDefault;
        if (cfg.numberOfSequentialViewsInSession != null && cfg.numberOfSequentialViewsInSession > 0)
        {
            numberOfFlashTokensInSessionDefault = (cfg.numberOfViewsInSession
                    / cfg.numberOfSequentialViewsInSession) + 1;
        }
        else
        {
            numberOfFlashTokensInSessionDefault = cfg.numberOfViewsInSession + 1;
        }

        cfg.numberOfFlashTokensInSession = getInt(extCtx, NUMBER_OF_FLASH_TOKENS_IN_SESSION,
                numberOfFlashTokensInSessionDefault);

        cfg.numberOfClientWindows = getInt(extCtx,
                ClientWindow.NUMBER_OF_CLIENT_WINDOWS_PARAM_NAME, 
                10);
                        
        cfg.supportEL3ImportHandler = getBoolean(extCtx, SUPPORT_EL_3_IMPORT_HANDLER, 
                SUPPORT_EL_3_IMPORT_HANDLER_DEFAULT); 

        cfg.strictJsf2OriginHeaderAppPath = getBoolean(extCtx, STRICT_JSF_2_ORIGIN_HEADER_APP_PATH, 
                STRICT_JSF_2_ORIGIN_HEADER_APP_PATH_DEFAULT);

        cfg.resourceBufferSize = getInt(extCtx, RESOURCE_BUFFER_SIZE, 
                RESOURCE_BUFFER_SIZE_DEFAULT);
        
        cfg.useCdiForAnnotationScanning = getBoolean(extCtx, USE_CDI_FOR_ANNOTATION_SCANNING,
                USE_CDI_FOR_ANNOTATION_SCANNING_DEFAULT);
        
        cfg.resourceHandlerCacheEnabled = getBoolean(extCtx, RESOURCE_HANDLER_CACHE_ENABLED,
                RESOURCE_HANDLER_CACHE_ENABLED_DEFAULT);
        if (cfg.projectStage != ProjectStage.Production)
        {
            cfg.resourceHandlerCacheEnabled = false;
        }
        
        cfg.resourceHandlerCacheSize = getInt(extCtx, RESOURCE_HANDLER_CACHE_SIZE,
                RESOURCE_HANDLER_CACHE_SIZE_DEFAULT);
        
        cfg.scanPackages = getString(extCtx, SCAN_PACKAGES,
                null);
        
        String websocketEndpointPort = extCtx.getInitParameter(WEBSOCKET_ENDPOINT_PORT);
        if (websocketEndpointPort != null && !websocketEndpointPort.isEmpty())
        {
            cfg.websocketEndpointPort = Integer.valueOf(websocketEndpointPort);
        }
        
        cfg.websocketMaxIdleTimeout = getLong(extCtx, WEBSOCKET_MAX_IDLE_TIMEOUT,
                WEBSOCKET_MAX_IDLE_TIMEOUT_DEFAULT);
        
        cfg.randomKeyInWebsocketSessionToken = getString(extCtx, RANDOM_KEY_IN_WEBSOCKET_SESSION_TOKEN,
                RANDOM_KEY_IN_WEBSOCKET_SESSION_TOKEN_DEFAULT);
        
        cfg.clientViewStateTimeout = getLong(extCtx, CLIENT_VIEW_STATE_TIMEOUT,
                CLIENT_VIEW_STATE_TIMEOUT_DEFAULT);
        if (cfg.clientViewStateTimeout < 0L)
        {
            cfg.clientViewStateTimeout = 0L;
        }
        
        cfg.randomKeyInViewStateSessionToken = getString(extCtx, RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN,
                RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_DEFAULT);
        
        cfg.randomKeyInViewStateSessionTokenLength = getInt(extCtx, RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH,
                RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_DEFAULT);
        
        cfg.randomKeyInViewStateSessionTokenSecureRandomClass = getString(extCtx,
                RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS,
                null);
        
        cfg.randomKeyInViewStateSessionTokenSecureRandomProvider = getString(extCtx,
                RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER,
                null);
        
        cfg.randomKeyInViewStateSessionTokenSecureRandomAlgorithm = getString(extCtx,
                RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITHM,
                RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITHM_DEFAULT);
        
        cfg.randomKeyInCsrfSessionToken = getString(extCtx, RANDOM_KEY_IN_CSRF_SESSION_TOKEN,
                RANDOM_KEY_IN_CSRF_SESSION_TOKEN_DEFAULT);
        
        cfg.serializeStateInSession = getBoolean(extCtx, StateManager.SERIALIZE_SERVER_STATE_PARAM_NAME,
                false);
        
        cfg.compressStateInSession = getBoolean(extCtx, COMPRESS_STATE_IN_SESSION,
                COMPRESS_STATE_IN_SESSION_DEFAULT);
        
        cfg.useFlashScopePurgeViewsInSession = getBoolean(extCtx, USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION,
                USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION_DEFAULT);

        cfg.autocompleteOffViewState = getBoolean(extCtx, AUTOCOMPLETE_OFF_VIEW_STATE,
                AUTOCOMPLETE_OFF_VIEW_STATE_DEFAULT);
        
        cfg.resourceMaxTimeExpires = getLong(extCtx, RESOURCE_MAX_TIME_EXPIRES,
                RESOURCE_MAX_TIME_EXPIRES_DEFAULT);
        
        cfg.lazyLoadConfigObjects = getBoolean(extCtx, LAZY_LOAD_CONFIG_OBJECTS,
                LAZY_LOAD_CONFIG_OBJECTS_DEFAULT);
        
        cfg.elResolverComparator = getString(extCtx, EL_RESOLVER_COMPARATOR,
                null);
        
        cfg.elResolverPredicate = getString(extCtx, EL_RESOLVER_PREDICATE,
                null);
        
        cfg.viewIdExistsCacheEnabled = getBoolean(extCtx, VIEWID_EXISTS_CACHE_ENABLED,
                VIEWID_EXISTS_CACHE_ENABLED_DEFAULT);
        if (cfg.projectStage == ProjectStage.Development)
        {
            cfg.viewIdExistsCacheEnabled = false;
        }
        
        cfg.viewIdProtectedCacheEnabled = getBoolean(extCtx, VIEWID_PROTECTED_CACHE_ENABLED,
                VIEWID_PROTECTED_CACHE_ENABLED_DEFAULT);
        if (cfg.projectStage == ProjectStage.Development)
        {
            cfg.viewIdProtectedCacheEnabled = false;
        }

        cfg.viewIdDeriveCacheEnabled = getBoolean(extCtx, VIEWID_DERIVE_CACHE_ENABLED,
                VIEWID_DERIVE_CACHE_ENABLED_DEFAULT);
        if (cfg.projectStage == ProjectStage.Development)
        {
            cfg.viewIdDeriveCacheEnabled = false;
        }
        
        cfg.viewIdCacheSize = getInt(extCtx, VIEWID_CACHE_SIZE,
                VIEWID_CACHE_SIZE_DEFAULT);

        cfg.beanBeforeJsfValidation = getBoolean(extCtx, BEAN_BEFORE_JSF_VALIDATION,
                BEAN_BEFORE_JSF_VALIDATION_DEFAULT);
        
        cfg.facesInitPlugins = getString(extCtx, FACES_INIT_PLUGINS,
                null);
        
        cfg.initializeSkipJarFacesConfigScan = getBoolean(extCtx, INITIALIZE_SKIP_JAR_FACES_CONFIG_SCAN,
                INITIALIZE_SKIP_JAR_FACES_CONFIG_SCAN_DEFAULT);
        
        cfg.expressionFactory = getString(extCtx, EXPRESSION_FACTORY,
                null);
        
        cfg.checkIdProductionMode = getString(extCtx, CHECK_ID_PRODUCTION_MODE,
                CHECK_ID_PRODUCTION_MODE_DEFAULT);
        
        // Per spec section 11.1.3, the default value for the partial state saving feature needs
        // to be true if 2.0, false otherwise.
        // lets ignore this on 3.x
        cfg.partialStateSaving = getBoolean(extCtx, StateManager.PARTIAL_STATE_SAVING_PARAM_NAME,
                true);
        
        if (cfg.partialStateSaving == false)
        {
            Logger.getLogger(MyfacesConfig.class.getName()).warning(
                "The configuration 'jakarta.faces.PARTIAL_STATE_SAVING' is deprecated " +
                    "as of Faces 4.1");
        }

        cfg.fullStateSavingViewIds = StringUtils.splitShortString(
                getString(extCtx, StateManager.FULL_STATE_SAVING_VIEW_IDS_PARAM_NAME, null),
                ',');

        if (cfg.fullStateSavingViewIds.length > 0)
        {
            Logger.getLogger(MyfacesConfig.class.getName()).warning(
                "The configuration 'jakarta.faces.FULL_STATE_SAVING_VIEW_IDS' is deprecated " +
                    "as of Faces 4.1");
        }
        
        cfg.faceletsBufferSize = getInt(extCtx, ViewHandler.FACELETS_BUFFER_SIZE_PARAM_NAME,
                1024);
        
        cfg.markInitialStateWhenApplyBuildView = getBoolean(extCtx, MARK_INITIAL_STATE_WHEN_APPLY_BUILD_VIEW,
                MARK_INITIAL_STATE_WHEN_APPLY_BUILD_VIEW_DEFAULT);

        cfg.viewSuffix = StringUtils.splitShortString(
                getString(extCtx, ViewHandler.FACELETS_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_FACELETS_SUFFIX),
                ' ');
        
        cfg.faceletsViewMappings = StringUtils.splitShortString(
                getString(extCtx, ViewHandler.FACELETS_VIEW_MAPPINGS_PARAM_NAME, null),
                ';');
        
        cfg.faceletsViewSuffix = getString(extCtx, ViewHandler.FACELETS_SUFFIX_PARAM_NAME,
                ViewHandler.DEFAULT_FACELETS_SUFFIX);
        
        String elExpressionCacheMode = getString(extCtx, CACHE_EL_EXPRESSIONS,
                CACHE_EL_EXPRESSIONS_DEFAULT);    
        cfg.elExpressionCacheMode = Enum.valueOf(ELExpressionCacheMode.class, elExpressionCacheMode); 
 
        cfg.wrapTagExceptionsAsContextAware = getBoolean(extCtx, WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE,
                WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE_DEFAULT);
        
        cfg.resourceCacheLastModified = getBoolean(extCtx, RESOURCE_CACHE_LAST_MODIFIED,
                RESOURCE_CACHE_LAST_MODIFIED_DEFAULT);
        if (cfg.projectStage == ProjectStage.Development)
        {
            cfg.resourceCacheLastModified = false;
        }
        
        String logWebContextParams = getString(extCtx, LOG_WEB_CONTEXT_PARAMS,
                LOG_WEB_CONTEXT_PARAMS_DEFAULT);    

        switch(logWebContextParams)
        {
            case "dev-only": 
                if(cfg.projectStage == ProjectStage.Development)
                {
                    cfg.logWebContextParams = true;
                }
                else
                {
                    cfg.logWebContextParams = false;
                }
                break;
            case "true":
                if(cfg.projectStage == ProjectStage.Production || cfg.projectStage == ProjectStage.Development)
                {
                    cfg.logWebContextParams = true;
                }
                else
                {
                    cfg.logWebContextParams = false;
                }
                break;
            default: 
                cfg.logWebContextParams = false;
        }
        
        cfg.websocketMaxConnections = getInt(extCtx, WEBSOCKET_MAX_CONNECTIONS,
                WEBSOCKET_MAX_CONNECTIONS_DEFAULT);

        cfg.renderClientBehaviorScriptsAsString = getBoolean(extCtx, RENDER_CLIENTBEHAVIOR_SCRIPTS_AS_STRING,
                RENDER_CLIENTBEHAVIOR_SCRIPTS_AS_STRING_DEFAULT);

        cfg.alwaysForceSessionCreation = getBoolean(extCtx, ALWAYS_FORCE_SESSION_CREATION,
                ALWAYS_FORCE_SESSION_CREATION_DEFAULT);
        
        String resourceBundleControl = getString(extCtx, RESOURCE_BUNDLE_CONTROL, null);
        if (StringUtils.isNotBlank(resourceBundleControl))
        {
            cfg.resourceBundleControl = (ResourceBundle.Control) ClassUtils.newInstance(resourceBundleControl);
        }
        
        cfg.automaticExtensionlessMapping = getBoolean(extCtx, FacesServlet.AUTOMATIC_EXTENSIONLESS_MAPPING_PARAM_NAME,
                AUTOMATIC_EXTENSIONLESS_MAPPING_DEFAULT);

        cfg.elResolverTracing = getBoolean(extCtx, EL_RESOLVER_TRACING,
                EL_RESOLVER_TRACING_DEFAULT);
        
        if (cfg.projectStage == ProjectStage.Production)
        {
            cfg.faceletsRefreshPeriod = getLong(extCtx,
                    ViewHandler.FACELETS_REFRESH_PERIOD_PARAM_NAME,
                    -1);
        }
        else
        {
            cfg.faceletsRefreshPeriod = getLong(extCtx,
                    ViewHandler.FACELETS_REFRESH_PERIOD_PARAM_NAME,
                    0);
        }

        String[] exceptionTypesToIgnoreInLogging = StringUtils.splitShortString(
                getString(extCtx, EXCEPTION_TYPES_TO_IGNORE_IN_LOGGING, ""),
                ',');
        for (String exceptionTypeToIgnoreInLogging : exceptionTypesToIgnoreInLogging)
        {
            if (StringUtils.isNotBlank(exceptionTypeToIgnoreInLogging))
            {
                cfg.exceptionTypesToIgnoreInLogging.add(exceptionTypeToIgnoreInLogging);
            }
        }
        
        return cfg;
    }