Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context param attributes to @FacesConfig #5328

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ffb5559
WIP
BalusC Nov 8, 2021
dee3f3c
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Jul 22, 2023
493fe5f
Merge remote-tracking branch
BalusC Jul 22, 2023
4e486bf
Continue PoC on FacesConfig annotation
BalusC Jul 22, 2023
009fbcc
Add missing STATE_SAVING_METHOD and simplified javadocs
BalusC Jul 23, 2023
7494239
Fixed compilation errors
BalusC Jul 23, 2023
a846e3a
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Jul 29, 2023
9031741
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Oct 1, 2023
041e86b
Add back state saving related params, these won't be removed in 5.0
BalusC Oct 1, 2023
c5a9c0d
Add ContextParam#isSet()/getDefaultValue()/isDefault() helpers
BalusC Oct 1, 2023
257f480
Migrate Faces spec context params from Mojarra-specific WebConfiguration
BalusC Oct 1, 2023
9109476
Fixed build error
BalusC Oct 7, 2023
6b50a77
Improved javadoc
BalusC Oct 7, 2023
106fce5
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Oct 7, 2023
ff03bdf
Migrated websocket port context param to FacesConfig.ContextParam
BalusC Oct 7, 2023
ce8bb48
Fixed ClassCastException in cases where Path is returned from context
BalusC Oct 7, 2023
82ca3f1
Turns out that webapp contracts/resources spec is broken; the spec says
BalusC Oct 7, 2023
9905d4c
Fixed javadoc errors
BalusC Oct 8, 2023
39c3f82
Mark attributes non binding
BalusC Oct 14, 2023
596906d
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Oct 14, 2023
e87d7d3
contracts/resources param can now be Path again after #5329 done
BalusC Oct 14, 2023
9cddd35
Implement support for retrieving context param value via @FacesConfig
BalusC Oct 14, 2023
99b8a6d
CDI.current() didn't work in unit tests and caused them to fail with
BalusC Oct 14, 2023
d6e3915
Fixed MockBeanManager to not return null on methods returning collection
BalusC Oct 14, 2023
7f7ada5
Revised existing occurrences where context params are obtained and
BalusC Oct 14, 2023
e37d930
Refactored Pattern#compile
BalusC Oct 14, 2023
49c597d
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Oct 15, 2023
99faa5d
Make sure that all context params are retrieved through ContextParam
BalusC Oct 15, 2023
96eaa7e
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Oct 22, 2023
7d93b58
Fixed failing tests caused by 'CDI is not available' exception due to
BalusC Oct 22, 2023
a58a656
FSS related params were deprecated in 4.1 so revert changes on them
BalusC Oct 22, 2023
8d43afd
Merge remote-tracking branch 'origin/master' into faces-config
BalusC Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions impl/src/main/java/com/sun/faces/RIConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class RIConstants {
public static final String TLV_RESOURCE_LOCATION = FACES_PREFIX + "resources.Resources";

public static final String NO_VALUE = "";
public static final String[] EMPTY_STRING_ARRAY = {};

public static final Class<?>[] EMPTY_CLASS_ARGS = new Class[0];
public static final Object[] EMPTY_METH_ARGS = new Object[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,17 @@

import static com.sun.faces.RIConstants.FACES_CONFIG_VERSION;
import static com.sun.faces.RIConstants.FACES_PREFIX;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.AutomaticExtensionlessMapping;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.FaceletsSkipComments;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.FaceletsDecorators;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.FaceletsDefaultRefreshPeriod;
import static com.sun.faces.el.ELUtils.buildFacesResolver;
import static com.sun.faces.el.FacesCompositeELResolver.ELResolverChainType.Faces;
import static com.sun.faces.facelets.util.ReflectionUtil.forName;
import static com.sun.faces.util.MessageUtils.APPLICATION_ASSOCIATE_EXISTS_ID;
import static com.sun.faces.util.MessageUtils.getExceptionMessageString;
import static com.sun.faces.util.Util.getFacesConfigXmlVersion;
import static com.sun.faces.util.Util.getFacesServletRegistration;
import static com.sun.faces.util.Util.split;
import static jakarta.faces.FactoryFinder.FACELET_CACHE_FACTORY;
import static jakarta.faces.FactoryFinder.FLOW_HANDLER_FACTORY;
import static jakarta.faces.application.ProjectStage.Development;
import static jakarta.faces.application.ProjectStage.Production;
import static jakarta.faces.application.ViewVisitOption.RETURN_AS_MINIMAL_IMPLICIT_OUTCOME;
import static java.lang.Long.parseLong;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.logging.Level.FINE;
Expand All @@ -61,7 +54,6 @@
import com.sun.faces.application.resource.ResourceManager;
import com.sun.faces.component.search.SearchExpressionHandlerImpl;
import com.sun.faces.config.ConfigManager;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.el.DemuxCompositeELResolver;
import com.sun.faces.facelets.compiler.Compiler;
import com.sun.faces.facelets.compiler.SAXCompiler;
Expand All @@ -85,6 +77,7 @@
import jakarta.el.ExpressionFactory;
import jakarta.faces.FacesException;
import jakarta.faces.FactoryFinder;
import jakarta.faces.annotation.FacesConfig.ContextParam;
import jakarta.faces.application.Application;
import jakarta.faces.application.NavigationCase;
import jakarta.faces.application.ViewHandler;
Expand Down Expand Up @@ -162,8 +155,6 @@ public class ApplicationAssociate {

private final NamedEventManager namedEventManager;

private final WebConfiguration webConfig;

private FlowHandler flowHandler;

private SearchExpressionHandler searchExpressionHandler;
Expand Down Expand Up @@ -245,7 +236,6 @@ public ApplicationAssociate(ApplicationImpl appImpl) {

navigationMap = new ConcurrentHashMap<>();
injectionProvider = (InjectionProvider) facesContext.getAttributes().get(ConfigManager.INJECTION_PROVIDER_KEY);
webConfig = WebConfiguration.getInstance(externalContext);

annotationManager = new AnnotationManager();

Expand Down Expand Up @@ -313,7 +303,7 @@ public void processEvent(SystemEvent event) {
String facesConfigVersion = getFacesConfigXmlVersion(context);
context.getExternalContext().getApplicationMap().put(FACES_CONFIG_VERSION, facesConfigVersion);

if (webConfig.isOptionEnabled(AutomaticExtensionlessMapping)) {
if (ContextParam.AUTOMATIC_EXTENSIONLESS_MAPPING.isSet(context)) {
getFacesServletRegistration(context)
.ifPresent(registration ->
viewHandler.getViews(context, "/", RETURN_AS_MINIMAL_IMPLICIT_OUTCOME)
Expand All @@ -331,9 +321,8 @@ public void initializeFacelets() {

FacesContext ctx = FacesContext.getCurrentInstance();

Map<String, Object> appMap = ctx.getExternalContext().getApplicationMap();
compiler = createCompiler(appMap, webConfig);
faceletFactory = createFaceletFactory(ctx, compiler, webConfig);
compiler = createCompiler(ctx);
faceletFactory = createFaceletFactory(ctx, compiler);
}

public long getTimeOfInstantiation() {
Expand Down Expand Up @@ -620,20 +609,10 @@ public void relateUrlToDefiningDocumentInJar(URL url, String definingDocumentId)
definingDocumentIdsToTruncatedJarUrls.put(definingDocumentId, candidate);
}

protected DefaultFaceletFactory createFaceletFactory(FacesContext context, Compiler compiler, WebConfiguration webConfig) {
protected DefaultFaceletFactory createFaceletFactory(FacesContext context, Compiler compiler) {

// refresh period
boolean isProduction = applicationImpl.getProjectStage() == Production;
String refreshPeriod;
if (webConfig.isSet(FaceletsDefaultRefreshPeriod)) {
refreshPeriod = webConfig.getOptionValue(FaceletsDefaultRefreshPeriod);
} else if (isProduction) {
refreshPeriod = "-1";
} else {
refreshPeriod = FaceletsDefaultRefreshPeriod.getDefaultValue();
}

long period = parseLong(refreshPeriod);
int period = ContextParam.FACELETS_REFRESH_PERIOD.getValue(context);

// resource resolver
DefaultResourceResolver resolver = new DefaultResourceResolver(applicationImpl.getResourceHandler());
Expand All @@ -647,35 +626,33 @@ protected DefaultFaceletFactory createFaceletFactory(FacesContext context, Compi
return toReturn;
}

protected Compiler createCompiler(Map<String, Object> appMap, WebConfiguration webConfig) {
protected Compiler createCompiler(FacesContext context) {
Compiler newCompiler = new SAXCompiler();

loadDecorators(appMap, newCompiler);
loadDecorators(context, newCompiler);

// Skip params?
newCompiler.setTrimmingComments(webConfig.isOptionEnabled(FaceletsSkipComments));
newCompiler.setTrimmingComments(ContextParam.FACELETS_SKIP_COMMENTS.isSet(context));

addTagLibraries(newCompiler);

return newCompiler;
}

protected void loadDecorators(Map<String, Object> appMap, Compiler newCompiler) {
String decoratorsParamValue = webConfig.getOptionValue(FaceletsDecorators);
protected void loadDecorators(FacesContext context, Compiler newCompiler) {
String[] decorators = ContextParam.FACELETS_DECORATORS.getValue(context);

if (decoratorsParamValue != null) {
for (String decorator : split(appMap, decoratorsParamValue.trim(), ";")) {
try {
newCompiler
.addTagDecorator((TagDecorator) forName(decorator).getDeclaredConstructor().newInstance());
for (String decorator : decorators) {
try {
newCompiler
.addTagDecorator((TagDecorator) forName(decorator).getDeclaredConstructor().newInstance());

if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "Successfully Loaded Decorator: {0}", decorator);
}
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) {
if (LOGGER.isLoggable(SEVERE)) {
LOGGER.log(SEVERE, "Error Loading Decorator: " + decorator, e);
}
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "Successfully Loaded Decorator: {0}", decorator);
}
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) {
if (LOGGER.isLoggable(SEVERE)) {
LOGGER.log(SEVERE, "Error Loading Decorator: " + decorator, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.sun.faces.application;

import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.ClientWindowMode;
import static com.sun.faces.util.Util.getCdiBeanManager;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Level.WARNING;
Expand All @@ -32,12 +31,13 @@

import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.Producer;
import jakarta.faces.annotation.FacesConfig.ContextParam;
import jakarta.faces.context.FacesContext;
import jakarta.faces.flow.Flow;
import jakarta.faces.flow.FlowHandler;
import jakarta.faces.flow.builder.FlowDefinition;

class JavaFlowLoaderHelper {
public class JavaFlowLoaderHelper {

private static final Logger LOGGER = FacesLogger.APPLICATION.getLogger();

Expand Down Expand Up @@ -70,24 +70,26 @@ synchronized void loadFlows(FacesContext context, FlowHandler flowHandler) throw
}
}

private void enableClientWindowModeIfNecessary(FacesContext context) {
WebConfiguration config = WebConfiguration.getInstance(context.getExternalContext());

String optionValue = config.getOptionValue(ClientWindowMode);
public static void enableClientWindowModeIfNecessary(FacesContext context) {
String optionValue = ContextParam.CLIENT_WINDOW_MODE.getValue(context);

boolean clientWindowNeedsEnabling = false;
if ("none".equals(optionValue)) {
clientWindowNeedsEnabling = true;

LOGGER.log(WARNING, "{0} was set to none, but Faces Flows requires {0} is enabled. Setting to ''url''.",
new Object[] { ClientWindowMode.getQualifiedName() });
new Object[] { ContextParam.CLIENT_WINDOW_MODE.getName() });

} else if (optionValue == null) {
clientWindowNeedsEnabling = true;
}

if (clientWindowNeedsEnabling) {
config.setOptionValue(ClientWindowMode, "url");
context.getExternalContext().getApplicationMap().put(JavaFlowLoaderHelper.class.getName(), Boolean.TRUE);
}
}

public static boolean isClientWindowModeForciblyEnabled(FacesContext context) {
return context.getExternalContext().getApplicationMap().get(JavaFlowLoaderHelper.class.getName()) == Boolean.TRUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.sun.faces.application.applicationimpl;

import static com.sun.faces.application.ApplicationImpl.THIS_LIBRARY;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.DateTimeConverterUsesSystemTimezone;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.RegisterConverterPropertyEditors;
import static com.sun.faces.util.Util.isEmpty;
import static com.sun.faces.util.Util.loadClass;
Expand Down Expand Up @@ -71,6 +70,7 @@
import jakarta.el.ValueExpression;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.faces.FacesException;
import jakarta.faces.annotation.FacesConfig.ContextParam;
import jakarta.faces.application.Application;
import jakarta.faces.application.Resource;
import jakarta.faces.component.UIComponent;
Expand Down Expand Up @@ -155,10 +155,11 @@ public InstanceFactory(ApplicationAssociate applicationAssociate) {
defaultValidatorIds = new LinkedHashSet<>();
behaviorMap = new ViewMemberInstanceFactoryMetadataMap<>(new ConcurrentHashMap<>());

WebConfiguration webConfig = WebConfiguration.getInstance(FacesContext.getCurrentInstance().getExternalContext());
FacesContext context = FacesContext.getCurrentInstance();
WebConfiguration webConfig = WebConfiguration.getInstance(context.getExternalContext());
registerPropertyEditors = webConfig.isOptionEnabled(RegisterConverterPropertyEditors);

passDefaultTimeZone = webConfig.isOptionEnabled(DateTimeConverterUsesSystemTimezone);
passDefaultTimeZone = ContextParam.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE.getValue(context);
if (passDefaultTimeZone) {
systemTimeZone = TimeZone.getDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@

package com.sun.faces.application.applicationimpl;

import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.JakartaFacesProjectStage;
import static jakarta.faces.application.ProjectStage.Development;
import static jakarta.faces.application.ProjectStage.Production;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;

import java.util.logging.Logger;

import com.sun.faces.application.ValidateComponentNesting;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.util.FacesLogger;

import jakarta.faces.annotation.FacesConfig.ContextParam;
import jakarta.faces.application.Application;
import jakarta.faces.application.ProjectStage;
import jakarta.faces.context.FacesContext;
Expand All @@ -45,9 +43,7 @@ public class Stage {
public ProjectStage getProjectStage(Application application) {

if (projectStage == null) {
String value = fetchProjectStageFromConfig();

setProjectStageFromValue(value, Production);
projectStage = fetchProjectStageFromConfig();

if (projectStage == Development) {
application.subscribeToEvent(PostAddToViewEvent.class, new ValidateComponentNesting());
Expand All @@ -59,38 +55,24 @@ public ProjectStage getProjectStage(Application application) {

// ----------------------------------------------------------- Private methods

private String fetchProjectStageFromConfig() {
WebConfiguration webConfig = WebConfiguration.getInstance(FacesContext.getCurrentInstance().getExternalContext());
private ProjectStage fetchProjectStageFromConfig() {
FacesContext context = FacesContext.getCurrentInstance();
WebConfiguration webConfig = WebConfiguration.getInstance(context.getExternalContext());
String value = webConfig.getEnvironmentEntry(WebConfiguration.WebEnvironmentEntry.ProjectStage);

if (value != null) {
projectStage = ProjectStage.valueOf(value);
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "ProjectStage configured via JNDI: {0}", value);
}
} else {
value = webConfig.getOptionValue(JakartaFacesProjectStage);
if (value != null && LOGGER.isLoggable(FINE)) {
projectStage = ContextParam.PROJECT_STAGE.getValue(context);
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "ProjectStage configured via servlet context init parameter: {0}", value);
}
}

return value;
}

private void setProjectStageFromValue(String value, ProjectStage defaultStage) {
if (value != null) {
try {
projectStage = ProjectStage.valueOf(value);
} catch (IllegalArgumentException iae) {
if (LOGGER.isLoggable(INFO)) {
LOGGER.log(INFO, "Unable to discern ProjectStage for value {0}.", value);
}
}
}

if (projectStage == null) {
projectStage = defaultStage;
}
return projectStage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.sun.faces.RIConstants.FLOW_IN_JAR_PREFIX;
import static com.sun.faces.config.WebConfiguration.META_INF_CONTRACTS_DIR;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.FaceletsSuffix;
import static com.sun.faces.util.Util.ensureLeadingSlash;
import static jakarta.faces.application.ResourceVisitOption.TOP_LEVEL_VIEWS_ONLY;
import static java.util.Spliterator.DISTINCT;
import static java.util.Spliterators.spliteratorUnknownSize;
Expand All @@ -34,10 +34,10 @@
import java.util.stream.Stream;

import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.util.Util;

import jakarta.faces.FacesException;
import jakarta.faces.annotation.FacesConfig.ContextParam;
import jakarta.faces.application.ResourceVisitOption;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
Expand All @@ -52,8 +52,8 @@ public class FaceletWebappResourceHelper extends ResourceHelper {

public FaceletWebappResourceHelper(WebappResourceHelper webappResourceHelper) {
this.webappResourceHelper = webappResourceHelper;
WebConfiguration webConfig = WebConfiguration.getInstance();
configuredExtensions = webConfig.getOptionValue(FaceletsSuffix, " ");
FacesContext context = FacesContext.getCurrentInstance();
configuredExtensions = new String[] { ContextParam.FACELETS_SUFFIX.getValue(context) };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.DefaultResourceMaxAge;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.ResourceBufferSize;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.ResourceExcludes;
import static com.sun.faces.util.RequestStateManager.RESOURCE_REQUEST;
import static com.sun.faces.util.Util.getFacesMapping;
import static com.sun.faces.util.Util.notNegative;
Expand Down Expand Up @@ -50,8 +49,8 @@
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.RequestStateManager;
import com.sun.faces.util.Util;

import jakarta.faces.annotation.FacesConfig.ContextParam;
import jakarta.faces.application.Resource;
import jakarta.faces.application.ResourceHandler;
import jakarta.faces.application.ResourceVisitOption;
Expand Down Expand Up @@ -80,9 +79,10 @@ public class ResourceHandlerImpl extends ResourceHandler {
public ResourceHandlerImpl() {
creationTime = System.currentTimeMillis();
webconfig = WebConfiguration.getInstance();
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext extContext = context.getExternalContext();
manager = ApplicationAssociate.getInstance(extContext).getResourceManager();
initExclusions(extContext.getApplicationMap());
initExclusions(context);
initMaxAge();
}

Expand Down Expand Up @@ -554,9 +554,8 @@ private boolean isExcluded(String resourceId) {
* <ul>
* will be used.
*/
private void initExclusions(Map<String, Object> appMap) {
String excludesParam = webconfig.getOptionValue(ResourceExcludes);
String[] patterns = Util.split(appMap, excludesParam, " ");
private void initExclusions(FacesContext context) {
String[] patterns = ContextParam.RESOURCE_EXCLUDES.getValue(context);

excludePatterns = new ArrayList<>(patterns.length);
for (String pattern : patterns) {
Expand Down
Loading
Loading