All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joinfaces.autoconfigure.mojarra.MojarraProperties Maven / Gradle / Ivy

There is a newer version: 5.4.1
Show newest version
/*
 * Copyright 2016-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.joinfaces.autoconfigure.mojarra;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import jakarta.el.ExpressionFactory;

import com.sun.faces.spi.InjectionProvider;
import com.sun.faces.spi.SerializationProvider;
import lombok.Data;
import org.apache.el.ExpressionFactoryImpl;
import org.joinfaces.autoconfigure.servlet.initparams.ServletContextInitParameter;
import org.joinfaces.autoconfigure.servlet.initparams.ServletContextInitParameterProperties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;

/**
 * Configuration properties of Mojarra.
 * Taken from
 * https://balusc.omnifaces.org/2015/09/what-mojarra-context-parameters-are.html
 * @author Marcelo Fernandes
 */
@Data
@ConfigurationProperties(prefix = "joinfaces.mojarra")
public class MojarraProperties implements ServletContextInitParameterProperties {

	static final String PREFIX = "com.sun.faces.";

	/**
	 * Maximum time, in seconds, that client state will be considered valid by
	 * the default StateManager/ResponseStateManager implementations. If the
	 * time between requests exceeds the configured time, a
	 * jakarta.faces.application.ViewExpiredException. will be thrown. It is
	 * important to note that if this feature is enabled, and client requests
	 * are recieved with view state produced from a previous version, the
	 * ViewExpiredException will be thrown immediately.
	 */
	@DurationUnit(ChronoUnit.SECONDS)
	@ServletContextInitParameter(PREFIX + "clientStateTimeout")
	private Duration clientStateTimeout;

	/**
	 * The size, in bytes, of the buffer that is used to write client state. It
	 * should be noted, that the buffer used is split - half is for raw bytes,
	 * the other half is for the Base64 encoded characters of said bytes. So,
	 * for example, if the default, 8192, is used, then 4096 of that is used for
	 * the bytes, and the other 4096 is used for the Base64 encoded characters.
	 */
	@DataSizeUnit(DataUnit.BYTES)
	@ServletContextInitParameter(PREFIX + "clientStateWriteBufferSize")
	private DataSize clientStateWriteBufferSize;

	/**
	 * When true, the view is compressed after it is serialized and before
	 * base64 encoded. Works with client state saving only. As of 1.2_09, this
	 * option also impacts server side state saving when
	 * com.sun.faces.serializeServerState is set to true (this has a large
	 * impact of the size of the state in the session when using this option, at
	 * the expense of more CPU of course).
	 */
	@ServletContextInitParameter(PREFIX + "compressViewState")
	private Boolean compressViewState;

	/**
	 * Since Mojarra 2.2, the client state is by default always encrypted. When
	 * true, the client state encryption is disabled.
	 * See also com.sun.faces.ClientStateSavingPassword - recommendations for actual
	 * password?
	 */
	@ServletContextInitParameter(PREFIX + "disableClientStateEncryption")
	private Boolean disableClientStateEncryption;

	/**
	 * When true, the client state will as test be unserialized before writing
	 * and any serialization exceptions will be logged aInteger with a debug
	 * path to the cause of the serialization error.
	 */
	@ServletContextInitParameter(PREFIX + "enableClientStateDebugging")
	private Boolean enableClientStateDebugging;

	/**
	 * If true, generate random server view state ids. If false, create server
	 * view state ids sequentially. This resembles closely the JSF 1.x behavior,
	 * but this is more sensitive to CSRF.
	 */
	@ServletContextInitParameter(PREFIX + "generateUniqueServerStateIds")
	private Boolean generateUniqueServerStateIds;

	/**
	 * Defines the maximum number of serialized views stored in the session.
	 * Works with server state saving only (note the implementation
	 * unintentionally has swapped the meaning, as we cannot change this without
	 * breaking what people have become used to we have updated this here). See
	 * com.sun.faces.numberOfViewsInSession vs
	 * com.sun.faces.numberOfLogicalViews for detail.
	 */
	@ServletContextInitParameter(PREFIX + "numberOfLogicalViews")
	private Integer numberOfLogicalViews;

	/**
	 * Definies the maximum number of serialized logical views per view. Works
	 * with server state saving only (note the implementation unintentionally
	 * has swapped the meaning, as we cannot change this without breaking what
	 * people have become used to we have updated this here) See
	 * com.sun.faces.numberOfViewsInSession vs
	 * com.sun.faces.numberOfLogicalViews for detail.
	 */
	@ServletContextInitParameter(PREFIX + "numberOfViewsInSession")
	private Integer numberOfViewsInSession;

	/**
	 * If enabled the component state (not the tree) will be serialized before
	 * being stored in the session. This may be desirable for applications that
	 * may have issues with view state being sensitive to model changes after
	 * state saving which are reflected back in view state. This has since JSF
	 * 2.2 been replaced by jakarta.faces.SERIALIZE_SERVER_STATE.
	 */
	@ServletContextInitParameter(PREFIX + "serializeServerState")
	private Boolean serializeServerState;

	/**
	 * Per the renderkit doc specification, the state information for the view
	 * will be written out prior to closing the form tag. However, it may be
	 * desirable to have the state information written out after the opening
	 * form tag. If this is the case, specifiy this parameter in the web.xml
	 * with a value of false.
	 */
	@ServletContextInitParameter(PREFIX + "writeStateAtFormEnd")
	private Boolean writeStateAtFormEnd;

	/**
	 * If true, allow children of h:inputText and h:outputText to be rendered.
	 * In 1.2, they would always be rendered before the value of tag. As of 2.0,
	 * children of UIInput and UIOutput components will not be rendered by the
	 * default renderer implementations. Set this option to true if this
	 * behavior is required, but note that doing so may cause issues when using
	 * Ajax. See issue 1154 for details.
	 */
	@ServletContextInitParameter(PREFIX + "allowTextChildren")
	private Boolean allowTextChildren;

	/**
	 * If false, don't use autocomplete="off" on view state hidden input field.
	 * This attribute is by default always rendered in order to fix a Firefox
	 * related bug, but it is invalid on a hidden input field as per w3 HTML
	 * validator. So, when false, then beware of the Firefox bug which may
	 * trigger "unexpected" ViewExpiredException. See issue 1129 for details.
	 */
	@ServletContextInitParameter(PREFIX + "autoCompleteOffOnViewState")
	private Boolean autoCompleteOffOnViewState;

	/**
	 * If true, then the JavaScript rendered by h:commandLink will be compressed
	 * to reduce the amount of whitespace transmitted in the response. If false
	 * then the JavaScript will be rendered to the client in a well formatted
	 * manner.
	 */
	@ServletContextInitParameter(PREFIX + "compressJavaScript")
	private Boolean compressJavaScript;

	/**
	 * By default any characters above a certain range will be escaped as either
	 * an HTML entity or a decimal reference. This behavior is not always
	 * desirable. To allow more flexibility how content is rendered to a client,
	 * this option was introduced. Valid configuration values are: false, true,
	 * and auto with false being the default. When the option value is false,
	 * Mojarra will continue to escaped no matter the response encoding type. If
	 * the configuration value is true, Then no escaping will occur assuming
	 * that the response encoding can properly handle all characters. If the
	 * configuration option is auto then the response encoding will be checked.
	 * If the encoding is of the UTF family of encodings no unicode or html
	 * entity encoding will occur, however, if the response stream encoding is
	 * ISO-8859-1 then the ISO characters above a certain range will be encoded
	 * as HTML entities and any characters above that range will be written as
	 * decimal references.
	 */
	@ServletContextInitParameter(PREFIX + "disableUnicodeEscaping")
	private String disableUnicodeEscaping;

	/**
	 * If true, then component ID uniqueness won't be checked if ProjectStage is
	 * Production to enhance performance. See issue 2414 for details.
	 */
	@ServletContextInitParameter(PREFIX + "disableIdUniquenessCheck")
	private Boolean disableIdUniquenessCheck;

	/**
	 * If true, inlined JavaScript rendered by the HTML ResponseWriter
	 * implementation will be rendered so that the script is hidden from older
	 * browser implementations which does not recognize {@code