Skip to content

Commit

Permalink
revert MYFACES-4617
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Jul 24, 2023
1 parent 7134e3a commit 5d7b826
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 89 deletions.
16 changes: 16 additions & 0 deletions api/src/main/java/jakarta/faces/annotation/FacesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import jakarta.enterprise.util.Nonbinding;
import jakarta.inject.Qualifier;

/**
Expand All @@ -33,10 +34,25 @@
@Retention(value=RetentionPolicy.RUNTIME)
public @interface FacesConfig
{
@Deprecated(forRemoval = true, since = "4.0")
@Nonbinding Version version() default Version.JSF_2_3;

@Deprecated(forRemoval = true, since = "4.0")
public static enum Version
{
JSF_2_3
}

public static final class Literal extends AnnotationLiteral<FacesConfig> implements FacesConfig
{
private static final long serialVersionUID = 1L;

public static final Literal INSTANCE = new Literal();

@Override
public Version version()
{
return Version.JSF_2_3;
}
}
}
12 changes: 12 additions & 0 deletions api/src/main/java/jakarta/faces/application/ResourceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public abstract class ResourceHandler
*/
public static final String WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME = "jakarta.faces.WEBAPP_RESOURCES_DIRECTORY";

/**
* @since 2.3
*/
@Deprecated
public static final String JSF_SCRIPT_RESOURCE_NAME = "faces.js";

/**
* @since 2.3
*/
@Deprecated
public static final String JSF_SCRIPT_LIBRARY_NAME = "jakarta.faces";

/**
* @since 4.0
*/
Expand Down
12 changes: 11 additions & 1 deletion api/src/main/java/jakarta/faces/application/ViewHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ public abstract class ViewHandler
{
public static final String CHARACTER_ENCODING_KEY = "jakarta.faces.request.charset";
public static final String DEFAULT_FACELETS_SUFFIX = ".xhtml";

@Deprecated(since = "4.0")
public static final String DEFAULT_SUFFIX = ".xhtml";

/**
* Indicate the default suffixes, separated by spaces to derive the default file URI
* used by Faces to create views and render pages.
*/
@JSFWebConfigParam(defaultValue=".xhtml", since="1.1", group="viewhandler", deprecated = true)
@Deprecated(since = "4.0")
public static final String DEFAULT_SUFFIX_PARAM_NAME = "jakarta.faces.DEFAULT_SUFFIX";

/**
* The default extension used to handle facelets pages.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
defaultEventName = "valueChange"
)
abstract class _HtmlInputFile extends UIInput implements _AccesskeyProperty,
_UniversalProperties, _DisabledProperty,
_AltProperty, _UniversalProperties, _DisabledReadonlyProperties,
_FocusBlurProperties, _ChangeProperty, _SelectProperty,
_EventProperties, _StyleProperties, _TabindexProperty, _LabelProperty,
_RoleProperty
Expand All @@ -47,6 +47,33 @@ abstract class _HtmlInputFile extends UIInput implements _AccesskeyProperty,
static public final String COMPONENT_FAMILY = "jakarta.faces.Input";
static public final String COMPONENT_TYPE = "jakarta.faces.HtmlInputFile";

/**
* HTML: The maximum number of characters allowed to be entered.
*
* @JSFProperty
* defaultValue = "Integer.MIN_VALUE"
*/
public abstract int getMaxlength();

/**
* HTML: The initial width of this control, in characters.
*
* @JSFProperty
* defaultValue = "Integer.MIN_VALUE"
*/
public abstract int getSize();

/**
* If the value of this attribute is "off", render "off" as the value of the attribute.
* This indicates that the browser should disable its autocomplete feature for this component.
* This is useful for components that perform autocompletion and do not want the browser interfering.
* If this attribute is not set or the value is "on", render nothing.
*
* @return the new autocomplete value
*/
@JSFProperty
public abstract String getAutocomplete();

/**
* Comma separated string of mime types of files to filter in client side file browse dialog.
* NOTE: this is not validated in server side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
implementz = "jakarta.faces.component.behavior.ClientBehaviorHolder",
defaultEventName = "valueChange")
abstract class _HtmlInputSecret extends UIInput implements _AccesskeyProperty,
_UniversalProperties, _FocusBlurProperties, _EventProperties,
_AltProperty, _UniversalProperties, _FocusBlurProperties, _EventProperties,
_StyleProperties, _TabindexProperty, _ChangeProperty, _SelectProperty,
_DisabledReadonlyProperties, _LabelProperty, _RoleProperty
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,9 +1704,24 @@ public Stream<String> getViewResources(FacesContext facesContext,
private Set<String> loadSuffixes(ExternalContext context)
{
Set<String> result = new HashSet<>();

String definedSuffixes = WebConfigParamUtils.getStringInitParameter(context,
ViewHandler.DEFAULT_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_SUFFIX);
StringTokenizer tokenizer;


if (definedSuffixes == null)
{
definedSuffixes = ViewHandler.DEFAULT_SUFFIX;
}

// This is a space-separated list of suffixes, so parse them out.

tokenizer = new StringTokenizer (definedSuffixes, " ");

while (tokenizer.hasMoreTokens())
{
result.add (tokenizer.nextToken());
}

String faceletSuffix = WebConfigParamUtils.getStringInitParameter(context,
ViewHandler.FACELETS_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_FACELETS_SUFFIX);

Expand All @@ -1716,6 +1731,7 @@ private Set<String> loadSuffixes(ExternalContext context)
}

String faceletViewMappings = WebConfigParamUtils.getStringInitParameter(context, FACELETS_VIEW_MAPPINGS_PARAM);

if (faceletViewMappings != null)
{
tokenizer = new StringTokenizer(faceletViewMappings, ";");
Expand Down
112 changes: 61 additions & 51 deletions impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,16 @@ else if (mapping.isExtensionMapping())
{
//See Faces 2.0 section 7.5.2
boolean founded = false;
String contextSuffix = config.getFaceletsViewSuffix();
if (viewId.endsWith(contextSuffix))
for (String contextSuffix : config.getViewSuffix())
{
builder.append(viewId, 0, viewId.indexOf(contextSuffix));
builder.append(mapping.getExtension());
founded = true;
if (viewId.endsWith(contextSuffix))
{
builder.append(viewId, 0, viewId.indexOf(contextSuffix));
builder.append(mapping.getExtension());
founded = true;
break;
}
}

if (!founded)
{
//See Faces 2.0 section 7.5.2
Expand All @@ -277,12 +279,12 @@ else if (mapping.isExtensionMapping())
else if(viewId.lastIndexOf('.') != -1 )
{
builder.append(viewId, 0, viewId.lastIndexOf('.'));
builder.append(config.getFaceletsViewSuffix());
builder.append(config.getViewSuffix()[0]);
}
else
{
builder.append(viewId);
builder.append(config.getFaceletsViewSuffix());
builder.append(config.getViewSuffix()[0]);
}
}
}
Expand Down Expand Up @@ -327,12 +329,14 @@ else if (mapping.isPrefixMapping())
private String calculateExactMapping(FacesContext context, String viewId)
{
String prefixedExactMapping = null;

if (viewId.endsWith(config.getFaceletsViewSuffix()))
for (String contextSuffix : config.getViewSuffix())
{
prefixedExactMapping = viewId.substring(0, viewId.length() - config.getFaceletsViewSuffix().length());
if (viewId.endsWith(contextSuffix))
{
prefixedExactMapping = viewId.substring(0, viewId.length() - contextSuffix.length());
break;
}
}

return prefixedExactMapping == null ? viewId : prefixedExactMapping;
}

Expand Down Expand Up @@ -400,62 +404,68 @@ protected String handleSuffixMapping(FacesContext context, String requestViewId)
StringBuilder builder = SharedStringBuilder.get(context, VIEW_HANDLER_SUPPORT_SB);

//Try to locate any resource that match with the expected id
String defaultSuffix = config.getFaceletsViewSuffix();
builder.append(requestViewId);

if (extensionPos > -1 && extensionPos > slashPos)
{
builder.replace(extensionPos, requestViewId.length(), defaultSuffix);
}
else
for (String defaultSuffix : config.getViewSuffix())
{
builder.append(defaultSuffix);
}

String candidateViewId = builder.toString();
builder.setLength(0);
builder.append(requestViewId);

if (extensionPos > -1 && extensionPos > slashPos)
{
builder.replace(extensionPos, requestViewId.length(), defaultSuffix);
}
else
{
builder.append(defaultSuffix);
}

if (config.getFaceletsViewMappings() != null && config.getFaceletsViewMappings().length > 0 )
{
for (String mapping : config.getFaceletsViewMappings())
String candidateViewId = builder.toString();
if (config.getFaceletsViewMappings() != null && config.getFaceletsViewMappings().length > 0 )
{
if (mapping.startsWith("/"))
{
continue; //skip this entry, its a prefix mapping
}
if (mapping.equals(candidateViewId))
{
return candidateViewId;
}
if (mapping.startsWith(".")) //this is a wildcard entry
for (String mapping : config.getFaceletsViewMappings())
{
builder.setLength(0); //reset/reuse the builder object
builder.append(candidateViewId);
builder.replace(candidateViewId.lastIndexOf('.'), candidateViewId.length(), mapping);
String tempViewId = builder.toString();
if (isViewExistent(context, tempViewId))
if (mapping.startsWith("/"))
{
return tempViewId;
continue; //skip this entry, its a prefix mapping
}
if (mapping.equals(candidateViewId))
{
return candidateViewId;
}
if (mapping.startsWith(".")) //this is a wildcard entry
{
builder.setLength(0); //reset/reuse the builder object
builder.append(candidateViewId);
builder.replace(candidateViewId.lastIndexOf('.'), candidateViewId.length(), mapping);
String tempViewId = builder.toString();
if (isViewExistent(context, tempViewId))
{
return tempViewId;
}
}
}
}
}

// forced facelets mappings did not match or there were no entries in faceletsViewMappings array
if (isViewExistent(context,candidateViewId))
{
return candidateViewId;
// forced facelets mappings did not match or there were no entries in faceletsViewMappings array
if (isViewExistent(context,candidateViewId))
{
return candidateViewId;
}
}

//jsp suffixes didn't match, try facelets suffix
String faceletsDefaultSuffix = config.getFaceletsViewSuffix();
if (faceletsDefaultSuffix != null)
{
if (faceletsDefaultSuffix.equals(defaultSuffix))
for (String defaultSuffix : config.getViewSuffix())
{
faceletsDefaultSuffix = null;
if (faceletsDefaultSuffix.equals(defaultSuffix))
{
faceletsDefaultSuffix = null;
break;
}
}
}

if (faceletsDefaultSuffix != null)
{
builder.setLength(0);
Expand All @@ -470,7 +480,7 @@ protected String handleSuffixMapping(FacesContext context, String requestViewId)
builder.append(faceletsDefaultSuffix);
}

candidateViewId = builder.toString();
String candidateViewId = builder.toString();
if (isViewExistent(context,candidateViewId))
{
return candidateViewId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ public class MyfacesConfig
private String[] fullStateSavingViewIds;
private int faceletsBufferSize = 1024;
private boolean markInitialStateWhenApplyBuildView = MARK_INITIAL_STATE_WHEN_APPLY_BUILD_VIEW_DEFAULT;
private String[] viewSuffix = new String[] { ViewHandler.DEFAULT_SUFFIX };
private String[] faceletsViewMappings = new String[] {};
private String faceletsViewSuffix = ViewHandler.DEFAULT_FACELETS_SUFFIX;
private ELExpressionCacheMode elExpressionCacheMode;
Expand Down Expand Up @@ -1235,6 +1236,10 @@ else if (refreshTransientBuildOnPSS.equalsIgnoreCase("true") ||
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.DEFAULT_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_SUFFIX),
' ');

cfg.faceletsViewMappings = StringUtils.splitShortString(
getString(extCtx, ViewHandler.FACELETS_VIEW_MAPPINGS_PARAM_NAME, null),
';');
Expand Down Expand Up @@ -1694,6 +1699,11 @@ public boolean isMarkInitialStateWhenApplyBuildView()
return markInitialStateWhenApplyBuildView;
}

public String[] getViewSuffix()
{
return viewSuffix;
}

public String[] getFaceletsViewMappings()
{
return faceletsViewMappings;
Expand Down
Loading

0 comments on commit 5d7b826

Please sign in to comment.