diff --git a/impl/pom.xml b/impl/pom.xml
index edf385f07b..f158e3b057 100644
--- a/impl/pom.xml
+++ b/impl/pom.xml
@@ -39,8 +39,8 @@
EE4J Compatible Implementation for Jakarta Faces API
- 11
- 11
+ 17
+ 17${project.version}
diff --git a/impl/src/main/java/com/sun/faces/RIConstants.java b/impl/src/main/java/com/sun/faces/RIConstants.java
index cffc4e0ec5..ee8b36cac4 100644
--- a/impl/src/main/java/com/sun/faces/RIConstants.java
+++ b/impl/src/main/java/com/sun/faces/RIConstants.java
@@ -49,6 +49,7 @@ public class RIConstants {
public static final Class>[] EMPTY_CLASS_ARGS = new Class[0];
public static final Object[] EMPTY_METH_ARGS = new Object[0];
+ public static final String[][] EMPTY_STRING_MATRIX = new String[0][0];
/**
*
@@ -71,6 +72,8 @@ public class RIConstants {
public static final String PUSH_RESOURCE_URLS_KEY_NAME = FACES_PREFIX + "resourceUrls";
+ public static final String RESOURCE_NOT_FOUND = "RES_NOT_FOUND";
+
/**
* Marker used when saving the list of component adds and removes.
*/
diff --git a/impl/src/main/java/com/sun/faces/application/PropertyEditorHelper.java b/impl/src/main/java/com/sun/faces/application/PropertyEditorHelper.java
index 588dfd2b5b..2d4f87cf07 100644
--- a/impl/src/main/java/com/sun/faces/application/PropertyEditorHelper.java
+++ b/impl/src/main/java/com/sun/faces/application/PropertyEditorHelper.java
@@ -95,7 +95,7 @@ public String convertToString(Class> targetClass, Object value) {
protected UIComponent getComponent() {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
- return (UIComponent) RequestStateManager.get(context, RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME);
+ return RequestStateManager.get(context, RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME);
}
return null;
}
diff --git a/impl/src/main/java/com/sun/faces/application/resource/ClientResourceInfo.java b/impl/src/main/java/com/sun/faces/application/resource/ClientResourceInfo.java
index bfefab8701..8d82a0bd1e 100644
--- a/impl/src/main/java/com/sun/faces/application/resource/ClientResourceInfo.java
+++ b/impl/src/main/java/com/sun/faces/application/resource/ClientResourceInfo.java
@@ -187,7 +187,7 @@ public String toString() {
/**
* Create the full path to the resource. If the resource can be compressed, setup the compressedPath ivar so that the
- * path refers to the directory refereneced by the context attribute jakarta.servlet.context.tempdir.
+ * path refers to the directory referenced by the context attribute jakarta.servlet.context.tempdir.
*/
private void initPath(boolean isDevStage) {
diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java
index 6e2cffe3d1..a693c6c1c9 100644
--- a/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java
+++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java
@@ -51,12 +51,12 @@ public class ResourceCache {
/**
* The ResourceInfo cache.
*/
- private MultiKeyConcurrentHashMap
*
*
- * See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616, sec. 14 for details on the
+ * See ... RFC 2616, sec. 14 for details on the
* accept-encoding header.
*
*
@@ -416,7 +416,7 @@ protected boolean clientAcceptsCompression(FacesContext ctx) {
break;
}
if (value.contains("*") && !value.contains("*;q=0,") && !value.endsWith("*;q=0")) {
- // gzip not explictly listed, but client sent *
+ // gzip not explicitly listed, but client sent *
// meaning gzip is implicitly acceptable
// keep looping to ensure we don't come across a
// *;q=0 value.
@@ -436,7 +436,7 @@ protected boolean clientAcceptsCompression(FacesContext ctx) {
/**
*
- * Utility method to peform the necessary actions to compress content.
+ * Utility method to perform the necessary actions to compress content.
*
*
*
@@ -568,7 +568,7 @@ public int read() throws IOException {
nextRead = -1;
failedExpressionTest = false;
} else if (writingExpression) {
- if (0 < buf.size()) {
+ if ( !buf.isEmpty() ) {
i = buf.remove(0);
} else {
writingExpression = false;
diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceInfo.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceInfo.java
index 743b871deb..e80f967120 100644
--- a/impl/src/main/java/com/sun/faces/application/resource/ResourceInfo.java
+++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceInfo.java
@@ -16,6 +16,8 @@
package com.sun.faces.application.resource;
+import java.util.Objects;
+
public class ResourceInfo {
ResourceHelper helper;
@@ -29,14 +31,13 @@ public class ResourceInfo {
boolean doNotCache = false;
public ResourceInfo(LibraryInfo library, ContractInfo contract, String name, VersionInfo version) {
- this.contract = contract;
this.library = library;
- helper = library.getHelper();
- localePrefix = library.getLocalePrefix();
+ this.contract = contract;
this.name = name;
this.version = version;
- libraryName = library.getName();
-
+ this.helper = library.getHelper();
+ this.localePrefix = library.getLocalePrefix();
+ this.libraryName = library.getName();
}
public ResourceInfo(ContractInfo contract, String name, VersionInfo version, ResourceHelper helper) {
@@ -73,49 +74,23 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
- if (getClass() != obj.getClass()) {
- return false;
- }
- final ResourceInfo other = (ResourceInfo) obj;
- if (helper != other.helper && (helper == null || !helper.equals(other.helper))) {
- return false;
- }
- if (library != other.library && (library == null || !library.equals(other.library))) {
- return false;
- }
- if (libraryName == null ? other.libraryName != null : !libraryName.equals(other.libraryName)) {
+ if ( ! (obj instanceof ResourceInfo info) ) {
return false;
}
- if (localePrefix == null ? other.localePrefix != null : !localePrefix.equals(other.localePrefix)) {
- return false;
- }
- if (name == null ? other.name != null : !name.equals(other.name)) {
- return false;
- }
- if (path == null ? other.path != null : !path.equals(other.path)) {
- return false;
- }
- if (version != other.version && (version == null || !version.equals(other.version))) {
- return false;
- }
- if (doNotCache != other.doNotCache) {
- return false;
- }
- return true;
+
+ return Objects.equals(helper, info.helper) &&
+ Objects.equals(library, info.library) &&
+ Objects.equals(libraryName, info.libraryName) &&
+ Objects.equals(localePrefix, info.localePrefix) &&
+ Objects.equals(name, info.name) &&
+ Objects.equals(path, info.path) &&
+ Objects.equals(version, info.version) &&
+ doNotCache == info.doNotCache;
}
@Override
public int hashCode() {
- int hash = 7;
- hash = 17 * hash + (helper != null ? helper.hashCode() : 0);
- hash = 17 * hash + (library != null ? library.hashCode() : 0);
- hash = 17 * hash + (libraryName != null ? libraryName.hashCode() : 0);
- hash = 17 * hash + (localePrefix != null ? localePrefix.hashCode() : 0);
- hash = 17 * hash + (name != null ? name.hashCode() : 0);
- hash = 17 * hash + (path != null ? path.hashCode() : 0);
- hash = 17 * hash + (version != null ? version.hashCode() : 0);
- hash = 17 * hash + (doNotCache ? 1 : 0);
- return hash;
+ return Objects.hash(helper, library, contract, libraryName, localePrefix, name, path, version, doNotCache);
}
public boolean isDoNotCache() {
diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java
index 32e1c01ceb..2b8e2debaf 100644
--- a/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java
+++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java
@@ -62,22 +62,22 @@ public class ResourceManager {
/**
* {@link ResourceHelper} used for looking up webapp-based resources.
*/
- private WebappResourceHelper webappResourceHelper = new WebappResourceHelper();
+ private final WebappResourceHelper webappResourceHelper = new WebappResourceHelper();
/**
* {@link ResourceHelper} used for looking up webapp-based facelets resources.
*/
- private FaceletWebappResourceHelper faceletWebappResourceHelper = new FaceletWebappResourceHelper(webappResourceHelper);
+ private final FaceletWebappResourceHelper faceletWebappResourceHelper = new FaceletWebappResourceHelper(webappResourceHelper);
/**
* {@link ResourceHelper} used for looking up classpath-based resources.
*/
- private ClasspathResourceHelper classpathResourceHelper = new ClasspathResourceHelper();
+ private final ClasspathResourceHelper classpathResourceHelper = new ClasspathResourceHelper();
/**
* Cache for storing {@link ResourceInfo} instances to reduce the cost of the resource lookups.
*/
- private ResourceCache cache;
+ private final ResourceCache cache;
/**
* Patterns used to find {@link ResourceInfo} instances that may have their content compressed.
@@ -568,7 +568,7 @@ private List getResourceLibraryContracts(FacesContext context) {
// it is a resource request. look at the parameter con=.
String param = context.getExternalContext().getRequestParameterMap().get("con");
- if (!nameContainsForbiddenSequence(param) && param != null && param.trim().length() > 0) {
+ if (!nameContainsForbiddenSequence(param) && param != null && !param.trim().isEmpty()) {
return Arrays.asList(param);
}
}
@@ -610,7 +610,7 @@ private void initCompressableTypes(Map appMap) {
WebConfiguration config = WebConfiguration.getInstance();
String value = config.getOptionValue(WebConfiguration.WebContextInitParameter.CompressableMimeTypes);
- if (value != null && value.length() > 0) {
+ if (value != null && !value.isEmpty()) {
String[] values = Util.split(appMap, value, ",");
if (values != null) {
for (String s : values) {
diff --git a/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java b/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java
index 25b7c19aea..66155c5ca1 100644
--- a/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java
+++ b/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java
@@ -18,7 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -55,13 +55,13 @@ public class ComponentValidators {
* ValidatorInfo instance will be popped and thus have no impact on other
* EditableValueHolders.
*/
- private LinkedList validatorStack = null;
+ private final List validatorStack;
// ------------------------------------------------------------ Constructors
public ComponentValidators() {
- validatorStack = new LinkedList<>();
+ validatorStack = new ArrayList<>(4); // which is the usual size?
}
@@ -69,7 +69,7 @@ public ComponentValidators() {
/**
* @param context the FacesContext for the current request
- * @param createIfNull flag indicating whether or not a ComponentValidators instance should be created or
+ * @param createIfNull flag indicating whether a ComponentValidators instance should be created or
* not
* @return a ComponentValidators instance for processing a view request. If createIfNull is
* false and no ComponentValidators has been created, this method will return
@@ -102,14 +102,22 @@ public static ComponentValidators getValidators(FacesContext context, boolean cr
public static void addDefaultValidatorsToComponent(FacesContext ctx, EditableValueHolder editableValueHolder) {
if (ComponentSupport.isBuildingNewComponentTree(ctx)) {
- Set keySet = ctx.getApplication().getDefaultValidatorInfo().keySet();
- List validatorIds = new ArrayList<>(keySet.size());
+ Set defaultValidatorIds = ctx.getApplication().getDefaultValidatorInfo().keySet();
Set disabledValidatorIds = (Set) RequestStateManager.remove(ctx, RequestStateManager.DISABLED_VALIDATORS);
- for (String key : keySet) {
- if (disabledValidatorIds != null && disabledValidatorIds.contains(key)) {
- continue;
+ List validatorIds;
+
+ // if there are NO disabled validators -> use all the defined validators
+ if ( disabledValidatorIds == null || disabledValidatorIds.isEmpty() ) {
+ validatorIds = new ArrayList<>(defaultValidatorIds);
+ }
+ // otherwise only the NON disabled ones
+ else {
+ validatorIds = new ArrayList<>(defaultValidatorIds.size() - disabledValidatorIds.size() );
+ for (String key : defaultValidatorIds) {
+ if ( !disabledValidatorIds.contains(key) ) {
+ validatorIds.add(key);
+ }
}
- validatorIds.add(key);
}
addValidatorsToComponent(ctx, validatorIds, editableValueHolder, null);
@@ -128,33 +136,37 @@ public static void addDefaultValidatorsToComponent(FacesContext ctx, EditableVal
@SuppressWarnings({ "unchecked" })
public void addValidators(FacesContext ctx, EditableValueHolder editableValueHolder) {
- if (validatorStack == null || validatorStack.isEmpty()) {
+ if (validatorStack.isEmpty()) {
addDefaultValidatorsToComponent(ctx, editableValueHolder);
return;
}
Application application = ctx.getApplication();
Map defaultValidatorInfo = application.getDefaultValidatorInfo();
- Set keySet = defaultValidatorInfo.keySet();
- List validatorIds = new ArrayList<>(keySet.size());
- validatorIds.addAll(keySet);
+ // start with all the defined Validators
+ Set validatorIds = new LinkedHashSet<>(defaultValidatorInfo.keySet());
+
+ // Remove all the disabled Validators
+ Set disabledValidatorIds = (Set) RequestStateManager.remove(ctx, RequestStateManager.DISABLED_VALIDATORS);
+ if ( disabledValidatorIds != null ) {
+ validatorIds.removeAll(disabledValidatorIds);
+ }
- Set disabledIds = (Set) RequestStateManager.remove(ctx, RequestStateManager.DISABLED_VALIDATORS);
- int count = validatorStack.size();
- for (int i = count - 1; i >= 0; i--) {
+ // Add or remove a Validator (from the last one to the first one)
+ int lastIndex = validatorStack.size()-1;
+ for (int i = lastIndex; i >= 0; i--) {
ValidatorInfo info = validatorStack.get(i);
- if (!info.isEnabled() || disabledIds != null && disabledIds.contains(info.getValidatorId())) {
+ if ( !info.isEnabled() ) {
validatorIds.remove(info.getValidatorId());
- } else {
- if (!validatorIds.contains(info.getValidatorId())) {
- validatorIds.add(info.getValidatorId());
- }
+ }
+ else {
+ validatorIds.add(info.getValidatorId());
}
}
// add the validators to the EditableValueHolder.
- addValidatorsToComponent(ctx, validatorIds, editableValueHolder, validatorStack == null || validatorStack.isEmpty() ? null : validatorStack);
+ addValidatorsToComponent(ctx, validatorIds, editableValueHolder, validatorStack.isEmpty() ? null : validatorStack);
}
@@ -178,8 +190,9 @@ public void pushValidatorInfo(ValidatorInfo info) {
*/
public void popValidatorInfo() {
- if (validatorStack.size() > 0) {
- validatorStack.removeLast();
+ if ( !validatorStack.isEmpty() ) {
+ // todo: with Java 21 change to removeLast
+ validatorStack.remove( validatorStack.size()-1 );
}
}
@@ -196,8 +209,7 @@ public void popValidatorInfo() {
* @param editableValueHolder the target component to which the validators installed
* @param validatorStack current stack of ValidatorInfo instances
*/
- private static void addValidatorsToComponent(FacesContext ctx, Collection validatorIds, EditableValueHolder editableValueHolder,
- LinkedList validatorStack) {
+ private static void addValidatorsToComponent(FacesContext ctx, Collection validatorIds, EditableValueHolder editableValueHolder, List validatorStack) {
if (validatorIds == null || validatorIds.isEmpty()) {
return;
@@ -218,13 +230,13 @@ private static void addValidatorsToComponent(FacesContext ctx, Collection v = application.createValidator(id);
// work backwards up the stack of ValidatorInfo to find the
// nearest matching ValidatorInfo to apply attributes
if (validatorStack != null) {
- for (int i = validatorStack.size() - 1; i >= 0; i--) {
+ for (int i = validatorStack.size()-1; i >= 0; i--) {
ValidatorInfo info = validatorStack.get(i);
if (id.equals(info.getValidatorId())) {
info.applyAttributes(v);
@@ -232,6 +244,7 @@ private static void addValidatorsToComponent(FacesContext ctx, Collection v) {
owner.setAttributes(ctx, v);
diff --git a/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java b/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java
index af05a58d83..d52a820e7f 100644
--- a/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java
+++ b/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java
@@ -16,9 +16,12 @@
package com.sun.faces.context;
+import static java.util.Collections.emptyIterator;
+import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toSet;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -29,6 +32,7 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
import com.sun.faces.cdi.CdiExtension;
import com.sun.faces.el.ELContextImpl;
@@ -140,8 +144,8 @@ public Application getApplication() {
if (null != application) {
return application;
}
- ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
- application = aFactory.getApplication();
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ application = factory.getApplication();
assert null != application;
return application;
}
@@ -252,7 +256,7 @@ public ELContext getELContext() {
@Override
public Iterator getClientIdsWithMessages() {
assertNotReleased();
- return componentMessageLists == null ? Collections.emptyIterator() : componentMessageLists.keySet().iterator();
+ return componentMessageLists == null ? emptyIterator() : componentMessageLists.keySet().iterator();
}
/**
@@ -284,15 +288,7 @@ public List getMessageList() {
assertNotReleased();
- if (null == componentMessageLists) {
- return Collections.unmodifiableList(Collections.emptyList());
- } else {
- List messages = new ArrayList<>();
- for (List list : componentMessageLists.values()) {
- messages.addAll(list);
- }
- return Collections.unmodifiableList(messages);
- }
+ return componentMessageLists == null ? emptyList() : componentMessageLists.values().stream().flatMap(Collection::stream).toList();
}
@@ -304,11 +300,12 @@ public List getMessageList(String clientId) {
assertNotReleased();
- if (null == componentMessageLists) {
- return Collections.unmodifiableList(Collections.emptyList());
- } else {
+ if (componentMessageLists == null) {
+ return emptyList();
+ }
+ else {
List list = componentMessageLists.get(clientId);
- return Collections.unmodifiableList(list != null ? list : Collections.emptyList());
+ return list != null ? Collections.unmodifiableList(list) : emptyList();
}
}
@@ -319,14 +316,14 @@ public List getMessageList(String clientId) {
@Override
public Iterator getMessages() {
assertNotReleased();
- if (null == componentMessageLists) {
- return Collections.emptyIterator();
+ if (componentMessageLists == null) {
+ return emptyIterator();
}
- if (componentMessageLists.size() > 0) {
+ if (!componentMessageLists.isEmpty()) {
return new ComponentMessagesIterator(componentMessageLists);
} else {
- return Collections.emptyIterator();
+ return emptyIterator();
}
}
@@ -339,15 +336,12 @@ public Iterator getMessages(String clientId) {
// If no messages have been enqueued at all,
// return an empty List Iterator
- if (null == componentMessageLists) {
- return Collections.emptyIterator();
+ if (componentMessageLists == null) {
+ return emptyIterator();
}
List list = componentMessageLists.get(clientId);
- if (list == null) {
- return Collections.emptyIterator();
- }
- return list.iterator();
+ return list == null ? emptyIterator() : list.iterator();
}
/**
@@ -396,7 +390,7 @@ public ResponseStream getResponseStream() {
@Override
public void setResponseStream(ResponseStream responseStream) {
assertNotReleased();
- Util.notNull("responseStrean", responseStream);
+ Util.notNull("responseStream", responseStream);
this.responseStream = responseStream;
}
@@ -418,10 +412,13 @@ public void setViewRoot(UIViewRoot root) {
Util.notNull("root", root);
if (viewRoot != null && !viewRoot.equals(root)) {
+ // if exists, retrieve the view map
Map viewMap = viewRoot.getViewMap(false);
- if (viewMap != null) {
- viewRoot.getViewMap().clear();
- }
+
+ // if exists, clear the view map
+ if (viewMap != null) viewMap.clear();
+
+ // clear the relevant request attributes
RequestStateManager.clearAttributesOnChangeOfView(this);
}
@@ -470,7 +467,7 @@ public void addMessage(String clientId, FacesMessage message) {
}
// Add this message to our internal queue
- componentMessageLists.computeIfAbsent(clientId, k -> new ArrayList<>()).add(message);
+ componentMessageLists.computeIfAbsent(clientId, k -> new ArrayList<>(2)).add(message); // 2 messages for each component is enough on average?
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Adding Message[sourceId=" + (clientId != null ? clientId : "<>") + ",summary=" + message.getSummary() + ")");
@@ -596,7 +593,7 @@ public boolean getRenderResponse() {
@Override
public List getResourceLibraryContracts() {
assertNotReleased();
- return null == resourceLibraryContracts ? Collections.emptyList() : resourceLibraryContracts;
+ return null == resourceLibraryContracts ? emptyList() : resourceLibraryContracts;
}
@Override
diff --git a/impl/src/main/java/com/sun/faces/facelets/tag/faces/ComponentSupport.java b/impl/src/main/java/com/sun/faces/facelets/tag/faces/ComponentSupport.java
index 72efd27838..c8a73d830b 100644
--- a/impl/src/main/java/com/sun/faces/facelets/tag/faces/ComponentSupport.java
+++ b/impl/src/main/java/com/sun/faces/facelets/tag/faces/ComponentSupport.java
@@ -106,19 +106,18 @@ public static void finalizeForDeletion(UIComponent c) {
// finally remove any children marked as deleted
int sz = c.getChildCount();
if (sz > 0) {
- UIComponent cc = null;
- List cl = c.getChildren();
+ List children = c.getChildren();
while (--sz >= 0) {
- cc = (UIComponent) cl.get(sz);
- if (cc.getAttributes().containsKey(MARK_DELETED)) {
- cl.remove(sz);
+ UIComponent child = children.get(sz);
+ if (child.getAttributes().containsKey(MARK_DELETED)) {
+ children.remove(sz);
}
}
}
Map facets = c.getFacets();
// remove any facets marked as deleted
- if (facets.size() > 0) {
+ if ( !facets.isEmpty() ) {
Set> col = facets.entrySet();
UIComponent fc;
Entry curEntry;
@@ -177,12 +176,11 @@ public static Tag getTagForComponent(FacesContext context, UIComponent c) {
public static UIComponent findChild(UIComponent parent, String id) {
int sz = parent.getChildCount();
if (sz > 0) {
- UIComponent c = null;
- List cl = parent.getChildren();
+ List children = parent.getChildren();
while (--sz >= 0) {
- c = (UIComponent) cl.get(sz);
- if (id.equals(c.getId())) {
- return c;
+ UIComponent child = children.get(sz);
+ if (id.equals(child.getId())) {
+ return child;
}
}
}
@@ -238,19 +236,19 @@ public static UIComponent findChildByTagId(FacesContext context, UIComponent par
}
private static UIComponent findChildByTagIdFullStateSaving(FacesContext context, UIComponent parent, String id) {
- UIComponent c = null;
+
UIViewRoot root = context.getViewRoot();
boolean hasDynamicComponents = (null != root && root.getAttributes().containsKey(RIConstants.TREE_HAS_DYNAMIC_COMPONENTS));
- String cid = null;
+
List components;
String facetName = getFacetName(parent);
- if (null != facetName) {
- c = parent.getFacet(facetName);
+ if (facetName != null) {
+ UIComponent c = parent.getFacet(facetName);
// We will have a facet name, but no corresponding facet in the
// case of facets with composite components. In this case,
// we must do the brute force search.
- if (null != c) {
- cid = (String) c.getAttributes().get(MARK_CREATED);
+ if (c != null) {
+ String cid = (String) c.getAttributes().get(MARK_CREATED);
if (id.equals(cid)) {
return c;
}
@@ -264,10 +262,9 @@ private static UIComponent findChildByTagIdFullStateSaving(FacesContext context,
components = parent.getChildren();
}
- int len = components.size();
- for (int i = 0; i < len; i++) {
- c = components.get(i);
- cid = (String) c.getAttributes().get(MARK_CREATED);
+ for (UIComponent component : components) {
+ UIComponent c = component;
+ String cid = (String) c.getAttributes().get(MARK_CREATED);
if (id.equals(cid)) {
return c;
}
@@ -301,7 +298,7 @@ private static Map getDescendantMarkIdCache(UIComponent com
Map descendantMarkIdCache = (Map) component.getTransientStateHelper().getTransient(MARK_ID_CACHE);
if (descendantMarkIdCache == null) {
- descendantMarkIdCache = new HashMap();
+ descendantMarkIdCache = new HashMap<>();
component.getTransientStateHelper().putTransient(MARK_ID_CACHE, descendantMarkIdCache);
}
@@ -448,52 +445,51 @@ public static UIViewRoot getViewRoot(FaceletContext ctx, UIComponent parent) {
* Marks all direct children and Facets with an attribute for deletion.
*
* @see #finalizeForDeletion(UIComponent)
- * @param c UIComponent to mark
+ * @param component UIComponent to mark
*/
- public static void markForDeletion(UIComponent c) {
+ public static void markForDeletion(UIComponent component) {
// flag this component as deleted
- c.getAttributes().put(MARK_DELETED, Boolean.TRUE);
+ component.getAttributes().put(MARK_DELETED, Boolean.TRUE);
// mark all children to be deleted
- int sz = c.getChildCount();
- if (sz > 0) {
- UIComponent cc = null;
- List cl = c.getChildren();
- while (--sz >= 0) {
- cc = (UIComponent) cl.get(sz);
- if (cc.getAttributes().containsKey(MARK_CREATED)) {
- cc.getAttributes().put(MARK_DELETED, Boolean.TRUE);
+ int index = component.getChildCount();
+ if (index > 0) {
+
+ List children = component.getChildren();
+ while (--index >= 0) {
+ UIComponent child = children.get(index);
+ if (child.getAttributes().containsKey(MARK_CREATED)) {
+ child.getAttributes().put(MARK_DELETED, Boolean.TRUE);
}
}
}
// mark all facets to be deleted
- if (c.getFacets().size() > 0) {
- Set col = c.getFacets().entrySet();
- UIComponent fc;
- for (Iterator itr = col.iterator(); itr.hasNext();) {
- Map.Entry entry = (Map.Entry) itr.next();
- String facet = (String) entry.getKey();
- fc = (UIComponent) entry.getValue();
- Map attrs = fc.getAttributes();
- if (attrs.containsKey(MARK_CREATED)) {
- attrs.put(MARK_DELETED, Boolean.TRUE);
- } else if (UIComponent.COMPOSITE_FACET_NAME.equals(facet)) {
- // mark the inner pannel components to be deleted
- sz = fc.getChildCount();
- if (sz > 0) {
- UIComponent cc = null;
- List cl = fc.getChildren();
- while (--sz >= 0) {
- cc = (UIComponent) cl.get(sz);
- cc.getAttributes().put(MARK_DELETED, Boolean.TRUE);
+ if ( !component.getFacets().isEmpty() ) {
+
+ for (Entry entries : component.getFacets().entrySet()) {
+ String facetName = entries.getKey();
+ UIComponent facet = entries.getValue();
+ Map facetAttributes = facet.getAttributes();
+ if (facetAttributes.containsKey(MARK_CREATED)) {
+ facetAttributes.put(MARK_DELETED, Boolean.TRUE);
+ }
+ else if (UIComponent.COMPOSITE_FACET_NAME.equals(facetName)) {
+ // mark the inner panel components to be deleted
+ index = facet.getChildCount();
+ if (index > 0) {
+
+ List children = facet.getChildren();
+ while (--index >= 0) {
+ UIComponent child = children.get(index);
+ child.getAttributes().put(MARK_DELETED, Boolean.TRUE);
}
}
- } else if (attrs.containsKey(IMPLICIT_PANEL)) {
- List implicitPanelChildren = fc.getChildren();
- Map innerAttrs = null;
- for (UIComponent cur : implicitPanelChildren) {
- innerAttrs = cur.getAttributes();
+ }
+ else if (facetAttributes.containsKey(IMPLICIT_PANEL)) {
+ List implicitPanelChildren = facet.getChildren();
+ for (UIComponent panelChild : implicitPanelChildren) {
+ Map innerAttrs = panelChild.getAttributes();
if (innerAttrs.containsKey(MARK_CREATED)) {
innerAttrs.put(MARK_DELETED, Boolean.TRUE);
}
@@ -501,6 +497,7 @@ public static void markForDeletion(UIComponent c) {
}
}
}
+
}
public static void encodeRecursive(FacesContext context, UIComponent viewToRender) throws IOException, FacesException {
@@ -509,9 +506,9 @@ public static void encodeRecursive(FacesContext context, UIComponent viewToRende
if (viewToRender.getRendersChildren()) {
viewToRender.encodeChildren(context);
} else if (viewToRender.getChildCount() > 0) {
- Iterator kids = viewToRender.getChildren().iterator();
+ Iterator kids = viewToRender.getChildren().iterator();
while (kids.hasNext()) {
- UIComponent kid = (UIComponent) kids.next();
+ UIComponent kid = kids.next();
encodeRecursive(context, kid);
}
}
@@ -520,34 +517,33 @@ public static void encodeRecursive(FacesContext context, UIComponent viewToRende
}
public static void removeTransient(UIComponent c) {
- UIComponent d, e;
if (c.getChildCount() > 0) {
- for (Iterator itr = c.getChildren().iterator(); itr.hasNext();) {
- d = (UIComponent) itr.next();
- if (d.getFacets().size() > 0) {
- for (Iterator jtr = d.getFacets().values().iterator(); jtr.hasNext();) {
- e = (UIComponent) jtr.next();
- if (e.isTransient()) {
- jtr.remove();
+ for (Iterator children = c.getChildren().iterator(); children.hasNext();) {
+ UIComponent child = children.next();
+ if ( !child.getFacets().isEmpty() ) {
+ for (Iterator facets = child.getFacets().values().iterator(); facets.hasNext();) {
+ UIComponent facet = facets.next();
+ if (facet.isTransient()) {
+ facets.remove();
} else {
- removeTransient(e);
+ removeTransient(facet);
}
}
}
- if (d.isTransient()) {
- itr.remove();
+ if (child.isTransient()) {
+ children.remove();
} else {
- removeTransient(d);
+ removeTransient(child);
}
}
}
- if (c.getFacets().size() > 0) {
- for (Iterator itr = c.getFacets().values().iterator(); itr.hasNext();) {
- d = (UIComponent) itr.next();
- if (d.isTransient()) {
- itr.remove();
+ if ( !c.getFacets().isEmpty() ) {
+ for (Iterator facets = c.getFacets().values().iterator(); facets.hasNext();) {
+ UIComponent facet = facets.next();
+ if ( facet.isTransient() ) {
+ facets.remove();
} else {
- removeTransient(d);
+ removeTransient(facet);
}
}
}
@@ -626,11 +622,10 @@ public static void copyPassthroughAttributes(FaceletContext ctx, UIComponent c,
for (String namespace : PassThroughAttributeLibrary.NAMESPACES) {
TagAttribute[] passthroughAttrs = t.getAttributes().getAll(namespace);
- if (null != passthroughAttrs && 0 < passthroughAttrs.length) {
+ if (passthroughAttrs != null && passthroughAttrs.length > 0) {
Map componentPassthroughAttrs = c.getPassThroughAttributes(true);
- Object attrValue = null;
for (TagAttribute cur : passthroughAttrs) {
- attrValue = cur.isLiteral() ? cur.getValue(ctx) : cur.getValueExpression(ctx, Object.class);
+ Object attrValue = cur.isLiteral() ? cur.getValue(ctx) : cur.getValueExpression(ctx, Object.class);
componentPassthroughAttrs.put(cur.getLocalName(), attrValue);
}
}
diff --git a/impl/src/main/java/com/sun/faces/facelets/tag/faces/ValidatorTagHandlerDelegateImpl.java b/impl/src/main/java/com/sun/faces/facelets/tag/faces/ValidatorTagHandlerDelegateImpl.java
index 8764ba95e5..7b7acd975c 100644
--- a/impl/src/main/java/com/sun/faces/facelets/tag/faces/ValidatorTagHandlerDelegateImpl.java
+++ b/impl/src/main/java/com/sun/faces/facelets/tag/faces/ValidatorTagHandlerDelegateImpl.java
@@ -159,7 +159,7 @@ protected ComponentValidators.ValidatorInfo createValidatorInfo(FaceletContext c
// --------------------------------------------------------- Private Methods
- // Tests whether the valiator tag is wrapping other tags.
+ // Tests whether the validator tag is wrapping other tags.
private boolean isWrapping() {
// Would be nice if there was some easy way to determine whether
@@ -210,7 +210,7 @@ private void applyNested(FaceletContext ctx, UIComponent parent) {
* @param ctx FaceletContext to use
* @return a new Validator instance
*/
- private Validator createValidator(FaceletContext ctx) {
+ private Validator> createValidator(FaceletContext ctx) {
String id = owner.getValidatorId(ctx);
if (id == null) {
diff --git a/impl/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java b/impl/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
index a1bbd394cd..26debbf9b4 100644
--- a/impl/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
+++ b/impl/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
@@ -86,7 +86,7 @@ public class RenderKitUtils {
/**
*
- * The prefix to append to certain attributes when renderking XHTML Transitional content.
+ * The prefix to append to certain attributes when rendering XHTML Transitional content.
*/
private static final String XHTML_ATTR_PREFIX = "xml:";
@@ -164,9 +164,9 @@ public enum PredefinedPostbackParameter {
PARTIAL_EXECUTE_PARAM(PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME), PARTIAL_RENDER_PARAM(PartialViewContext.PARTIAL_RENDER_PARAM_NAME),
PARTIAL_RESET_VALUES_PARAM(PartialViewContext.RESET_VALUES_PARAM_NAME);
- private String name;
+ private final String name;
- private PredefinedPostbackParameter(String name) {
+ PredefinedPostbackParameter(String name) {
this.name = name;
}
@@ -300,7 +300,7 @@ public static void renderPassThruAttributes(FacesContext context, ResponseWriter
}
// Don't render behavior scripts if component is disabled
- if (null != behaviors && behaviors.size() > 0 && Util.componentIsDisabled(component)) {
+ if (null != behaviors && !behaviors.isEmpty() && Util.componentIsDisabled(component)) {
behaviors = null;
}
@@ -372,7 +372,7 @@ public static void renderOnchange(FacesContext context, UIComponent component, b
renderHandler(context, component, params, handlerName, userHandler, behaviorEventName, null, false, incExec);
}
- // Renders onclick handler for SelectRaidio and SelectCheckbox
+ // Renders onclick handler for SelectRadio and SelectCheckbox
public static void renderSelectOnclick(FacesContext context, UIComponent component, boolean incExec) throws IOException {
final String handlerName = "onclick";
@@ -513,7 +513,7 @@ public static void renderXHTMLStyleBooleanAttributes(ResponseWriter writer, UICo
continue;
}
- if (Boolean.valueOf(val.toString())) {
+ if (Boolean.parseBoolean(val.toString())) {
writer.writeAttribute(attrName, true, attrName);
}
}
@@ -533,10 +533,8 @@ public static void renderXHTMLStyleBooleanAttributes(ResponseWriter writer, UICo
* @return The content type String
*/
public static String determineContentType(String accept, String serverSupportedTypes, String preferredType) {
- String contentType = null;
-
if (null == accept || null == serverSupportedTypes) {
- return contentType;
+ return null;
}
String[][] clientContentTypes = buildTypeArrayFromString(accept);
@@ -547,10 +545,12 @@ public static String determineContentType(String accept, String serverSupportedT
// if best match exits and best match is not some wildcard,
// return best match
if (matchedInfo[0][1] != null && !matchedInfo[0][2].equals("*")) {
- contentType = matchedInfo[0][1] + CONTENT_TYPE_SUBTYPE_DELIMITER + matchedInfo[0][2];
+ String contentType = matchedInfo[0][1] + CONTENT_TYPE_SUBTYPE_DELIMITER + matchedInfo[0][2];
+ return contentType;
}
- return contentType;
+ // else return null
+ return null;
}
/**
@@ -574,7 +574,7 @@ private static boolean canBeOptimized(UIComponent component, Map Attribute inverse look up map.
// This would change the search time from O(n) to O(1).
- for (int i = 0; i < knownAttributes.length; i++) {
- Attribute attr = knownAttributes[i];
+ for (Attribute attr : knownAttributes) {
String[] events = attr.getEvents();
if (events != null && events.length > 0 && behaviorEventName.equals(events[0])) {
@@ -746,7 +745,7 @@ private static boolean isExcludedAttribute(String attributeName, List ex
}
/**
- *
+ *
* This method builds a two element array structure as follows: Example: Given the following accept string: text/html;
* level=1, text/plain; q=0.5 [0][0] 1 (quality is 1 if none specified) [0][1] "text" (type) [0][2] "html; level=1"
* (subtype) [0][3] 1 (level, if specified; null if not)
@@ -754,15 +753,15 @@ private static boolean isExcludedAttribute(String attributeName, List ex
* [1][0] .5 [1][1] "text" [1][2] "plain" [1][3] (level, if specified; null if not)
*
* The array is used for comparison purposes in the findMatch method.
- *
+ *
*
* @param accept An accept String
- * @return an two dimensional array containing content-type/quality info
+ * @return a two dimensional array containing content-type/quality info
*/
private static String[][] buildTypeArrayFromString(String accept) {
// return if empty
- if (accept == null || accept.length() == 0) {
- return new String[0][0];
+ if (Util.isEmpty(accept)) {
+ return RIConstants.EMPTY_STRING_MATRIX;
}
// some helper variables
StringBuilder typeSubType;
@@ -776,8 +775,8 @@ private static String[][] buildTypeArrayFromString(String accept) {
String[] types = Util.split(appMap, accept, CONTENT_TYPE_DELIMITER);
String[][] arrayAccept = new String[types.length][MAX_CONTENT_TYPE_PARTS];
int index = -1;
- for (int i = 0; i < types.length; i++) {
- String token = types[i].trim();
+ for (String s : types) {
+ String token = s.trim();
index += 1;
// Check to see if our accept string contains the delimiter that is used
// to add uniqueness to a type/subtype, and/or delimits a qualifier value:
@@ -804,13 +803,13 @@ private static String[][] buildTypeArrayFromString(String accept) {
quality = qualityParts[1].trim();
break;
} else {
- quality = "not set"; // to identifiy that no quality was supplied
+ quality = "not set"; // to identify that no quality was supplied
}
}
}
} else {
typeSubType = new StringBuilder(token);
- quality = "not set"; // to identifiy that no quality was supplied
+ quality = "not set"; // to identify that no quality was supplied
}
// now split type and subtype
if (typeSubType.indexOf(CONTENT_TYPE_SUBTYPE_DELIMITER) >= 0) {
@@ -839,7 +838,7 @@ private static String[][] buildTypeArrayFromString(String accept) {
quality = "0.01";
} else if (!type.equals("*") && subtype.equals("*")) {
quality = "0.02";
- } else if (type.equals("*") && subtype.length() == 0) {
+ } else if (type.equals("*") && subtype.isEmpty()) {
quality = "0.01";
} else {
quality = "1";
@@ -876,49 +875,48 @@ private static String[][] findMatch(String[][] clientContentTypes, String[][] se
double highestQFactor = 0;
// the record with the highest quality
int idx = 0;
- for (int sidx = 0, slen = serverSupportedContentTypes.length; sidx < slen; sidx++) {
+ for (String[] serverSupportedContentType : serverSupportedContentTypes) {
// get server type
- String serverType = serverSupportedContentTypes[sidx][1];
+ String serverType = serverSupportedContentType[1];
if (serverType != null) {
- for (int cidx = 0, clen = clientContentTypes.length; cidx < clen; cidx++) {
+ for (String[] clientContentType : clientContentTypes) {
// get browser type
- String browserType = clientContentTypes[cidx][1];
+ String browserType = clientContentType[1];
if (browserType != null) {
// compare them and check for wildcard
if (browserType.equalsIgnoreCase(serverType) || browserType.equals("*")) {
// types are equal or browser type is wildcard - compare subtypes
- if (clientContentTypes[cidx][2].equalsIgnoreCase(serverSupportedContentTypes[sidx][2])
- || clientContentTypes[cidx][2].equals("*")) {
+ if (clientContentType[2].equalsIgnoreCase(serverSupportedContentType[2]) || clientContentType[2].equals("*")) {
// subtypes are equal or browser subtype is wildcard
- // found match: multiplicate qualities and add to result array
+ // found match: multiplicative qualities and add to result array
// if there was a level associated, this gets higher precedence, so
// factor in the level in the calculation.
double cLevel = 0.0;
double sLevel = 0.0;
- if (clientContentTypes[cidx][3] != null) {
- cLevel = Double.parseDouble(clientContentTypes[cidx][3]) * .10;
+ if (clientContentType[3] != null) {
+ cLevel = Double.parseDouble(clientContentType[3]) * .10;
}
- if (serverSupportedContentTypes[sidx][3] != null) {
- sLevel = Double.parseDouble(serverSupportedContentTypes[sidx][3]) * .10;
+ if (serverSupportedContentType[3] != null) {
+ sLevel = Double.parseDouble(serverSupportedContentType[3]) * .10;
}
- double cQfactor = Double.parseDouble(clientContentTypes[cidx][0]) + cLevel;
- double sQfactor = Double.parseDouble(serverSupportedContentTypes[sidx][0]) + sLevel;
+ double cQfactor = Double.parseDouble(clientContentType[0]) + cLevel;
+ double sQfactor = Double.parseDouble(serverSupportedContentType[0]) + sLevel;
double resultQuality = cQfactor * sQfactor;
String[] curResult = new String[MAX_CONTENT_TYPE_PARTS];
resultList.add(curResult);
curResult[0] = String.valueOf(resultQuality);
- if (clientContentTypes[cidx][2].equals("*")) {
+ if (clientContentType[2].equals("*")) {
// browser subtype is wildcard
// return type and subtype (wildcard)
- curResult[1] = clientContentTypes[cidx][1];
- curResult[2] = clientContentTypes[cidx][2];
+ curResult[1] = clientContentType[1];
+ curResult[2] = clientContentType[2];
} else {
// return server type and subtype
- curResult[1] = serverSupportedContentTypes[sidx][1];
- curResult[2] = serverSupportedContentTypes[sidx][2];
- curResult[3] = serverSupportedContentTypes[sidx][3];
+ curResult[1] = serverSupportedContentType[1];
+ curResult[2] = serverSupportedContentType[2];
+ curResult[3] = serverSupportedContentType[3];
}
// check if this was the highest factor
if (resultQuality > highestQFactor) {
@@ -937,10 +935,8 @@ private static String[][] findMatch(String[][] clientContentTypes, String[][] se
String[][] match = new String[1][3];
if (preferredContentType.length != 0 && preferredContentType[0][0] != null) {
BigDecimal highestQual = BigDecimal.valueOf(highestQFactor);
- for (int i = 0, len = resultList.size(); i < len; i++) {
- String[] result = resultList.get(i);
- if (BigDecimal.valueOf(Double.parseDouble(result[0])).compareTo(highestQual) == 0 && result[1].equals(preferredContentType[0][1])
- && result[2].equals(preferredContentType[0][2])) {
+ for (String[] result : resultList) {
+ if (BigDecimal.valueOf(Double.parseDouble(result[0])).compareTo(highestQual) == 0 && result[1].equals(preferredContentType[0][1]) && result[2].equals(preferredContentType[0][2])) {
match[0][0] = result[0];
match[0][1] = result[1];
match[0][2] = result[2];
@@ -964,8 +960,8 @@ private static String[][] findMatch(String[][] clientContentTypes, String[][] se
* Replaces all occurrences of - with $_.
*
*
- * @param origIdentifier the original identifer that needs to be 'ECMA-ized'
- * @return an ECMA valid identifer
+ * @param origIdentifier the original identifier that needs to be 'ECMA-ized'
+ * @return an ECMA valid identifier
*/
public static String createValidECMAIdentifier(String origIdentifier) {
return origIdentifier.replace("-", "$_");
@@ -1134,7 +1130,7 @@ public static void renderHtmlErrorPage(FacesContext ctx, FacesException fe) {
// been triggered either via faces.ajax.request() or via a submitting
// behavior.
public static boolean isPartialOrBehaviorAction(FacesContext context, String clientId) {
- if (clientId == null || clientId.length() == 0) {
+ if ( Util.isEmpty(clientId) ) {
return false;
}
@@ -1196,11 +1192,7 @@ public static UIForm getForm(UIComponent component, FacesContext context) {
}
UIForm form = (UIForm) parent;
- if (form != null) {
- return form;
- }
-
- return null;
+ return form;
}
/**
@@ -1226,7 +1218,7 @@ public static String getImageSource(FacesContext context, UIComponent component,
String msg = "Illegal path, direct contract references are not allowed: " + resName;
context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
- return "RES_NOT_FOUND";
+ return RIConstants.RESOURCE_NOT_FOUND;
}
Resource res = handler.createResource(resName, libName);
@@ -1235,7 +1227,7 @@ public static String getImageSource(FacesContext context, UIComponent component,
String msg = "Unable to find resource " + (libName == null ? "" : libName + ", ") + resName;
context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
- return "RES_NOT_FOUND";
+ return RIConstants.RESOURCE_NOT_FOUND;
} else {
String requestPath = res.getRequestPath();
return context.getExternalContext().encodeResourceURL(requestPath);
@@ -1243,8 +1235,8 @@ public static String getImageSource(FacesContext context, UIComponent component,
} else {
String value = (String) component.getAttributes().get(attrName);
- if (value == null || value.length() == 0) {
- return "";
+ if ( Util.isEmpty(value) ) {
+ return RIConstants.NO_VALUE;
}
WebConfiguration webConfig = WebConfiguration.getInstance();
if (value.startsWith(webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.WebAppContractsDirectory))) {
@@ -1252,7 +1244,7 @@ public static String getImageSource(FacesContext context, UIComponent component,
String msg = "Illegal path, direct contract references are not allowed: " + value;
context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
- return "RES_NOT_FOUND";
+ return RIConstants.RESOURCE_NOT_FOUND;
}
if (handler.isResourceURL(value)) {
@@ -1304,11 +1296,11 @@ public static boolean isOutputHtml5Doctype(FacesContext context) {
// Appends a script to a faces.util.chain() call
private static void appendScriptToChain(StringBuilder builder, String script) {
- if (script == null || script.length() == 0) {
+ if ( Util.isEmpty(script) ) {
return;
}
- if (builder.length() == 0) {
+ if (builder.isEmpty()) {
builder.append("faces.util.chain(this,event,");
}
@@ -1319,7 +1311,7 @@ private static void appendScriptToChain(StringBuilder builder, String script) {
appendQuotedValue(builder, script);
}
- // Appends an name/value property pair to a JSON object. Assumes
+ // Appends a name/value property pair to a JSON object. Assumes
// object has already been opened by the caller. The value will
// be quoted (ie. wrapped in single quotes and escaped appropriately).
public static void appendProperty(StringBuilder builder, String name, Object value) {
@@ -1330,7 +1322,7 @@ public static void appendProperty(StringBuilder builder, String name, Object val
// object has already been opened by the caller.
public static void appendProperty(StringBuilder builder, String name, Object value, boolean quoteValue) {
- if (null == name || name.length() == 0) {
+ if ( Util.isEmpty(name) ) {
throw new IllegalArgumentException();
}
@@ -1347,7 +1339,7 @@ public static void appendProperty(StringBuilder builder, String name, Object val
} else if (quoteValue) {
RenderKitUtils.appendQuotedValue(builder, value.toString());
} else {
- builder.append(value.toString());
+ builder.append(value);
}
}
@@ -1386,7 +1378,7 @@ private static boolean appendBehaviorsToChain(StringBuilder builder, FacesContex
for (ClientBehavior behavior : behaviors) {
String script = behavior.getScript(bContext);
- if (script != null && script.length() > 0) {
+ if ( Util.isNotEmpty(script) ) {
appendScriptToChain(builder, script);
if (isSubmitting(behavior)) {
@@ -1438,7 +1430,7 @@ private static String getNonEmptyUserHandler(Object handlerObject) {
handler = handlerObject.toString();
handler = handler.trim();
- if (handler.length() == 0) {
+ if (handler.isEmpty()) {
handler = null;
}
}
@@ -1450,9 +1442,8 @@ private static String getNonEmptyUserHandler(Object handlerObject) {
// or null if no Behaviors are available
private static List getClientBehaviors(UIComponent component, String behaviorEventName) {
- if (component instanceof ClientBehaviorHolder) {
- ClientBehaviorHolder bHolder = (ClientBehaviorHolder) component;
- Map> behaviors = bHolder.getClientBehaviors();
+ if (component instanceof ClientBehaviorHolder holder) {
+ Map> behaviors = holder.getClientBehaviors();
if (null != behaviors) {
return behaviors.get(behaviorEventName);
}
@@ -1523,11 +1514,11 @@ private static String getChainedHandler(FacesContext context, UIComponent compon
submitting = true;
}
- if (builder.length() == 0) {
+ if (builder.isEmpty()) {
return null;
}
- builder.append(")");
+ builder.append(')');
// If we're submitting (either via a behavior, or by rendering
// a submit script), we need to return false to prevent the
@@ -1596,7 +1587,7 @@ private static void renderHandler(FacesContext context, UIComponent component, C
List behaviors = getClientBehaviors(component, behaviorEventName);
// Don't render behavior scripts if component is disabled
- if (null != behaviors && behaviors.size() > 0 && Util.componentIsDisabled(component)) {
+ if ( Util.isNotEmpty(behaviors) && Util.componentIsDisabled(component)) {
behaviors = null;
}
diff --git a/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java b/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java
index b2c2b4bf16..dbd0104df7 100644
--- a/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java
+++ b/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java
@@ -130,7 +130,7 @@ else if (writer.getContentType().equals(RIConstants.XHTML_CONTENT_TYPE)) {
RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);
String styleClass = (String) component.getAttributes().get("styleClass");
- if (styleClass != null && styleClass.length() > 0) {
+ if (styleClass != null && !styleClass.isEmpty()) {
writer.writeAttribute("class", styleClass, "styleClass");
}
@@ -172,7 +172,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
private static boolean wasClicked(FacesContext context, UIComponent component, String clientId) {
// Was our command the one that caused this submission?
- // we don' have to worry about getting the value from request parameter
+ // we don't have to worry about getting the value from request parameter
// because we just need to know if this command caused the submission. We
// can get the command name by calling currentValue. This way we can
// get around the IE bug.
diff --git a/impl/src/main/java/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java b/impl/src/main/java/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java
index 2c56873c9a..9001f435a2 100644
--- a/impl/src/main/java/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java
+++ b/impl/src/main/java/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java
@@ -533,8 +533,7 @@ protected Collection getBehaviorParameters(UICo
if (childCount > 0) {
for (UIComponent kid : command.getChildren()) {
- if (kid instanceof UIParameter) {
- UIParameter uiParam = (UIParameter) kid;
+ if (kid instanceof UIParameter uiParam) {
String name = uiParam.getName();
Object value = uiParam.getValue();
@@ -550,7 +549,7 @@ protected Collection getBehaviorParameters(UICo
}
}
- return params == null ? Collections.emptyList() : params;
+ return params == null ? Collections.emptyList() : params;
}
protected Object getValue(UIComponent component) {
@@ -701,16 +700,14 @@ protected static Map> getPassThruBehaviors(UICompon
* @param forComponent - the component to search for
*
* @return the component with the the idforComponent otheriwse null if no match is found.
+ * forComponent otherwise null if no match is found.
*/
private static UIComponent findUIComponentBelow(UIComponent startPoint, String forComponent) {
UIComponent retComp = null;
if (startPoint.getChildCount() > 0) {
List children = startPoint.getChildren();
- for (int i = 0, size = children.size(); i < size; i++) {
- UIComponent comp = children.get(i);
-
+ for (UIComponent comp : children) {
if (comp instanceof NamingContainer) {
try {
retComp = comp.findComponent(forComponent);
diff --git a/impl/src/main/java/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java b/impl/src/main/java/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java
index 838c722ae8..bdc19d12b8 100644
--- a/impl/src/main/java/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java
+++ b/impl/src/main/java/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java
@@ -21,6 +21,7 @@
import java.util.Map;
import java.util.logging.Logger;
+import com.sun.faces.RIConstants;
import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.util.FacesLogger;
@@ -166,7 +167,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
Map attributes = component.getAttributes();
String name = (String) attributes.get("name");
- if (null == name) {
+ if (name == null) {
return;
}
@@ -189,12 +190,12 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
}
Resource resource = resourceHandler.createResource(name, library);
- String resourceUrl = "RES_NOT_FOUND";
+ String resourceUrl = RIConstants.RESOURCE_NOT_FOUND;
ResponseWriter writer = context.getResponseWriter();
startExternalElement(context, writer, component);
- if (library == null && name != null && ApplicationAssociate.getInstance(context).getResourceManager().isContractsResource(name)) {
+ if (library == null && ApplicationAssociate.getInstance(context).getResourceManager().isContractsResource(name)) {
if (context.isProjectStage(ProjectStage.Development)) {
String msg = "Illegal path, direct contract references are not allowed: " + name;
context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
@@ -210,7 +211,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
} else {
resourceUrl = resource.getRequestPath();
if (query != null) {
- resourceUrl = resourceUrl + (resourceUrl.indexOf("?") > -1 ? "&" : "?") + query;
+ resourceUrl = resourceUrl + (resourceUrl.indexOf('?') > -1 ? "&" : '?') + query;
}
resourceUrl = context.getExternalContext().encodeResourceURL(resourceUrl);
}
diff --git a/impl/src/main/java/com/sun/faces/util/MultiKeyConcurrentHashMap.java b/impl/src/main/java/com/sun/faces/util/MultiKeyConcurrentHashMap.java
index 12ddae1913..bc65677666 100644
--- a/impl/src/main/java/com/sun/faces/util/MultiKeyConcurrentHashMap.java
+++ b/impl/src/main/java/com/sun/faces/util/MultiKeyConcurrentHashMap.java
@@ -16,6 +16,8 @@
package com.sun.faces.util;
+import java.io.Serial;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@@ -26,11 +28,9 @@
* single value.
*
*
- *
This Map implemenation does not support iteration through keys and/or values.
- *
- *
This Map implementation is NOT Serialziable.
- *
- *
This cannot be cast as a general Map implementation.
+ *
This Map implementation does not support iteration through keys and/or values.
+ *
This Map implementation is NOT Serializable.
+ *
This cannot be cast as a general Map implementation.
*
*/
public class MultiKeyConcurrentHashMap {
@@ -90,7 +90,7 @@ public class MultiKeyConcurrentHashMap {
/**
* The segments, each of which is a specialized hash table
*/
- final Segment[] segments;
+ final Segment[] segments;
/* ---------------- Small Utilities -------------- */
@@ -129,7 +129,6 @@ static int hash(Object x1, Object x2, Object x3, Object x4) {
* @return the segment
*/
final Segment segmentFor(int hash) {
- // noinspection unchecked
return segments[hash >>> segmentShift & segmentMask];
}
@@ -192,9 +191,7 @@ static final class Segment extends ReentrantLock {
* As a guide, all critical volatile reads and writes to the count field are marked in code comments.
*/
- /**
- *
- */
+ @Serial
private static final long serialVersionUID = -5546647604753877171L;
/**
@@ -219,7 +216,7 @@ static final class Segment extends ReentrantLock {
* The per-segment table. Declared as a raw type, casted to HashEntry on each use.
*/
@SuppressWarnings({ "NonSerializableFieldInSerializableClass" })
- volatile HashEntry[] table;
+ volatile HashEntry[] table;
/**
* The load factor for the hash table. Even though this value is same for all segments, it is replicated to avoid
@@ -237,7 +234,7 @@ static final class Segment extends ReentrantLock {
/**
* Set table to new HashEntry array. Call only while holding lock or in constructor.
*/
- void setTable(HashEntry[] newTable) {
+ void setTable(HashEntry[] newTable) {
threshold = (int) (newTable.length * loadFactor);
table = newTable;
}
@@ -246,9 +243,7 @@ void setTable(HashEntry[] newTable) {
* Return properly casted first entry of bin for given hash
*/
HashEntry getFirst(int hash) {
- HashEntry[] tab = table;
- // noinspection unchecked
- return tab[hash & tab.length - 1];
+ return table[hash & table.length - 1];
}
/**
@@ -303,11 +298,10 @@ boolean containsKey(Object key1, Object key2, Object key3, Object key4, int hash
boolean containsValue(Object value) {
if (count != 0) { // read-volatile
- HashEntry[] tab = table;
+ HashEntry[] tab = table;
int len = tab.length;
- for (int i = 0; i < len; i++) {
- for (// noinspection unchecked
- HashEntry e = tab[i]; e != null; e = e.next) {
+ for (HashEntry kvHashEntry : tab) {
+ for (HashEntry e = kvHashEntry; e != null; e = e.next) {
V v = e.value;
if (v == null) // recheck
{
@@ -370,9 +364,8 @@ V put(K key1, K key2, K key3, K key4, int hash, V value, boolean onlyIfAbsent) {
{
rehash();
}
- HashEntry[] tab = table;
+ HashEntry[] tab = table;
int index = hash & tab.length - 1;
- // noinspection unchecked
HashEntry first = tab[index];
HashEntry e = first;
while (e != null && (e.hash != hash || key1 != null && !key1.equals(e.key1) || key2 != null && !key2.equals(e.key2)
@@ -399,7 +392,7 @@ V put(K key1, K key2, K key3, K key4, int hash, V value, boolean onlyIfAbsent) {
}
void rehash() {
- HashEntry[] oldTable = table;
+ HashEntry[] oldTable = table;
int oldCapacity = oldTable.length;
if (oldCapacity >= MAXIMUM_CAPACITY) {
return;
@@ -414,15 +407,12 @@ void rehash() {
* table right now.
*/
- HashEntry[] newTable = new HashEntry[oldCapacity << 1];
+ HashEntry[] newTable = new HashEntry[oldCapacity << 1];
threshold = (int) (newTable.length * loadFactor);
int sizeMask = newTable.length - 1;
- for (int i = 0; i < oldCapacity; i++) {
+ for (HashEntry e : oldTable) {
// We need to guarantee that any existing reads of old Map can
// proceed. So we cannot yet null out each bin.
- // noinspection unchecked
- HashEntry e = oldTable[i];
-
if (e != null) {
HashEntry next = e.next;
int idx = e.hash & sizeMask;
@@ -446,7 +436,6 @@ void rehash() {
// Clone all remaining nodes
for (HashEntry p = e; p != lastRun; p = p.next) {
int k = p.hash & sizeMask;
- // noinspection unchecked
HashEntry n = newTable[k];
newTable[k] = new HashEntry<>(p.key1, p.key2, p.key3, p.key4, p.hash, n, p.value);
}
@@ -463,9 +452,8 @@ V remove(Object key1, Object key2, Object key3, Object key4, int hash, Object va
lock();
try {
int c = count - 1;
- HashEntry[] tab = table;
+ HashEntry[] tab = table;
int index = hash & tab.length - 1;
- // noinspection unchecked
HashEntry first = tab[index];
HashEntry e = first;
while (e != null && (e.hash != hash || key1 != null && !key1.equals(e.key1) || key2 != null && !key2.equals(e.key2)
@@ -500,10 +488,8 @@ void clear() {
if (count != 0) {
lock();
try {
- HashEntry[] tab = table;
- for (int i = 0; i < tab.length; i++) {
- tab[i] = null;
- }
+ HashEntry[] tab = table;
+ Arrays.fill(tab, null);
++modCount;
count = 0; // write-volatile
} finally {
@@ -588,7 +574,7 @@ public MultiKeyConcurrentHashMap() {
* @see java.util.Map#isEmpty()
*/
public boolean isEmpty() {
- final Segment[] segments = this.segments;
+ final Segment[] segments = this.segments;
/*
* We keep track of per-segment modCounts to avoid ABA problems in which an element in one segment was added and in
* another removed during traversal, in which case the table was never actually empty at any point. Note the similar use
@@ -621,7 +607,7 @@ public boolean isEmpty() {
* @see java.util.Map#size()
*/
public int size() {
- final Segment[] segments = this.segments;
+ final Segment[] segments = this.segments;
long sum = 0;
long check = 0;
int[] mc = new int[segments.length];
@@ -650,14 +636,14 @@ public int size() {
}
if (check != sum) { // Resort to locking all segments
sum = 0;
- for (int i = 0; i < segments.length; ++i) {
- segments[i].lock();
+ for (Segment segment : segments) {
+ segment.lock();
}
- for (int i = 0; i < segments.length; ++i) {
- sum += segments[i].count;
+ for (Segment segment : segments) {
+ sum += segment.count;
}
- for (int i = 0; i < segments.length; ++i) {
- segments[i].unlock();
+ for (Segment segment : segments) {
+ segment.unlock();
}
}
if (sum > Integer.MAX_VALUE) {
@@ -762,7 +748,7 @@ public boolean containsValue(Object value) {
// See explanation of modCount use above
- final Segment[] segments = this.segments;
+ final Segment[] segments = this.segments;
int[] mc = new int[segments.length];
// Try a few times without locking
@@ -1031,8 +1017,8 @@ public V replace(K key, V value) {
* Removes all mappings from this map.
*/
public void clear() {
- for (int i = 0; i < segments.length; ++i) {
- segments[i].clear();
+ for (Segment segment : segments) {
+ segment.clear();
}
}
diff --git a/impl/src/main/java/com/sun/faces/util/RequestStateManager.java b/impl/src/main/java/com/sun/faces/util/RequestStateManager.java
index 923c80bd98..6de6bad9ca 100644
--- a/impl/src/main/java/com/sun/faces/util/RequestStateManager.java
+++ b/impl/src/main/java/com/sun/faces/util/RequestStateManager.java
@@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import com.sun.faces.RIConstants;
@@ -28,7 +29,7 @@
/**
*
* This helper class is used a central location for per-request state that is needed by Mojarra. This class leverages
- * FacesContext.getAttributes() which as added in 2.0 instead of the request scope to prevent the unecessary triggering
+ * FacesContext.getAttributes() which as added in 2.0 instead of the request scope to prevent the unnecessary triggering
* of ServletRequestAttributeListeners.
*
*/
@@ -56,12 +57,12 @@ public class RequestStateManager {
public static final String RENDER_KIT_IMPL_REQ = RIConstants.FACES_PREFIX + "renderKitImplForRequest";
/**
- * This attribute is used by the StateMangaer during restore view. The values are stored in the request for later use.
+ * This attribute is used by the StateManager during restore view. The values are stored in the request for later use.
*/
public static final String LOGICAL_VIEW_MAP = RIConstants.FACES_PREFIX + "logicalViewMap";
/**
- * This attribute is used by the StateMangaer during restore view. The values are stored in the request for later use.
+ * This attribute is used by the StateManager during restore view. The values are stored in the request for later use.
*/
public static final String ACTUAL_VIEW_MAP = RIConstants.FACES_PREFIX + "actualViewMap";
@@ -88,8 +89,8 @@ public class RequestStateManager {
public static final String FACES_VIEW_STATE = "com.sun.faces.FACES_VIEW_STATE";
/**
- * Leveraged by ResourceHandlerImpl to denote whether or not a request is a resource request. A Boolean
- * value will be assoicated with this key.
+ * Leveraged by ResourceHandlerImpl to denote whether a request is a resource request. A Boolean
+ * value will be associated with this key.
*/
public static final String RESOURCE_REQUEST = "com.sun.faces.RESOURCE_REQUEST";
@@ -123,8 +124,10 @@ public class RequestStateManager {
*/
public static final String RENDERED_RESOURCE_DEPENDENCIES = ResourceHandler.RESOURCE_IDENTIFIER;
- // TODO: refactor this thing to common map.
- private static final String[] ATTRIBUTES_TO_CLEAR_ON_CHANGE_OF_VIEW = { SCRIPT_STATE, PROCESSED_RESOURCE_DEPENDENCIES, PROCESSED_RADIO_BUTTON_GROUPS };
+ /**
+ * Attributes to be removed while changing the view root
+ */
+ private static final Set ATTRIBUTES_TO_CLEAR_ON_CHANGE_OF_VIEW = Set.of( SCRIPT_STATE, PROCESSED_RESOURCE_DEPENDENCIES, PROCESSED_RADIO_BUTTON_GROUPS );
/**
*
@@ -204,10 +207,8 @@ public static void clearAttributesOnChangeOfView(FacesContext ctx) {
return;
}
- Map attrs = ctx.getAttributes();
- for (String key : ATTRIBUTES_TO_CLEAR_ON_CHANGE_OF_VIEW) {
- attrs.remove(key);
- }
+ Map attrs = ctx.getAttributes();
+ attrs.keySet().removeAll(ATTRIBUTES_TO_CLEAR_ON_CHANGE_OF_VIEW);
PartialViewContext pvc = ctx.getPartialViewContext();
diff --git a/impl/src/main/java/com/sun/faces/util/Util.java b/impl/src/main/java/com/sun/faces/util/Util.java
index d445f08854..1b0a4ae0be 100644
--- a/impl/src/main/java/com/sun/faces/util/Util.java
+++ b/impl/src/main/java/com/sun/faces/util/Util.java
@@ -593,6 +593,14 @@ public static boolean isEmpty(String string) {
return string == null || string.isEmpty();
}
+ /**
+ * Returns true if the given string is not null and not empty.
+ *
+ * @param string The string to be checked on emptiness.
+ * @return True if the given string is not null and not empty.
+ */
+ public static boolean isNotEmpty(String string) { return !isEmpty(string); }
+
/**
* Returns true if the given string is null or is blank.
*
@@ -630,6 +638,8 @@ public static boolean isEmpty(Collection> collection) {
return collection == null || collection.isEmpty();
}
+ public static boolean isNotEmpty(Collection> collection) { return !isEmpty(collection); }
+
/**
* Returns true if the given value is null or is empty. Types of String, Collection, Map, Optional and
* Array are recognized. If none is recognized, then examine the emptiness of the toString() representation instead.
@@ -1402,12 +1412,11 @@ public static long getLastModified(URL url) {
try {
conn = url.openConnection();
- if (conn instanceof JarURLConnection) {
+ if (conn instanceof JarURLConnection jarUrlConnection) {
/*
* Note this is a work around for JarURLConnection since the getLastModified method is buggy. See JAVASERVERFACES-2725
* and JAVASERVERFACES-2734.
*/
- JarURLConnection jarUrlConnection = (JarURLConnection) conn;
URL jarFileUrl = jarUrlConnection.getJarFileURL();
URLConnection jarFileConnection = jarFileUrl.openConnection();
lastModified = jarFileConnection.getLastModified();
diff --git a/impl/src/main/java/jakarta/faces/component/UIComponentBase.java b/impl/src/main/java/jakarta/faces/component/UIComponentBase.java
index a465224f4a..14c6d11af1 100644
--- a/impl/src/main/java/jakarta/faces/component/UIComponentBase.java
+++ b/impl/src/main/java/jakarta/faces/component/UIComponentBase.java
@@ -37,6 +37,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
@@ -1135,8 +1136,6 @@ public Object saveState(FacesContext context) {
throw new NullPointerException();
}
- Object[] values = null;
-
if (initialStateMarked()) {
Object savedFacesListeners = listeners != null ? listeners.saveState(context) : null;
Object savedSysEventListeners = saveSystemEventListeners(context);
@@ -1152,9 +1151,7 @@ public Object saveState(FacesContext context) {
return null;
}
- if (values == null || values.length != 5) {
- values = new Object[5];
- }
+ Object[] values = new Object[5];
// Since we're saving partial state, skip id and clientId
// as this will be reconstructed from the template execution
@@ -1167,10 +1164,9 @@ public Object saveState(FacesContext context) {
return values;
- } else {
- if (values == null || values.length != 6) {
- values = new Object[6];
- }
+ }
+ else {
+ Object[] values = new Object[6];
values[0] = listeners != null ? listeners.saveState(context) : null;
values[1] = saveSystemEventListeners(context);
@@ -1411,8 +1407,7 @@ public static Object restoreAttachedState(FacesContext context, Object stateObj)
result = retMap;
}
- } else if (stateObj instanceof StateHolderSaver) {
- StateHolderSaver saver = (StateHolderSaver) stateObj;
+ } else if (stateObj instanceof StateHolderSaver saver) {
result = saver.restore(context);
} else {
throw new IllegalStateException("Unknown object type");
@@ -1469,8 +1464,7 @@ private Map, List> restoreSyst
Object[][] listeners = (Object[][]) state;
Map, List> m = new HashMap<>(listeners.length, 1.0f);
- for (int i = 0, len = listeners.length; i < len; i++) {
- Object[] source = listeners[i];
+ for (Object[] source : listeners) {
m.put((Class extends SystemEvent>) source[0], (List) restoreAttachedState(ctx, source[1]));
}
@@ -1671,7 +1665,7 @@ private boolean isClientBehaviorHolder() {
*/
private Object saveBehaviorsState(FacesContext context) {
Object state = null;
- if (null != behaviors && behaviors.size() > 0) {
+ if (null != behaviors && !behaviors.isEmpty()) {
boolean stateWritten = false;
Object[] attachedBehaviors = new Object[behaviors.size()];
int i = 0;
@@ -1719,8 +1713,8 @@ private BehaviorsMap restoreBehaviorsState(FacesContext context, Object state) {
for (int i = 0; i < attachedBehaviors.length; i++) {
Object[] attachedEventBehaviors = (Object[]) attachedBehaviors[i];
ArrayList eventBehaviors = new ArrayList<>(attachedBehaviors.length);
- for (int j = 0; j < attachedEventBehaviors.length; j++) {
- eventBehaviors.add((ClientBehavior) restoreAttachedState(context, attachedEventBehaviors[j]));
+ for (Object attachedEventBehavior : attachedEventBehaviors) {
+ eventBehaviors.add((ClientBehavior) restoreAttachedState(context, attachedEventBehavior));
}
modifiableMap.put(names[i], eventBehaviors);
@@ -1781,16 +1775,16 @@ private static void publishAfterViewEvents(FacesContext context, Application app
component.pushComponentToEL(context, component);
application.publishEvent(context, PostAddToViewEvent.class, component);
if (component.getChildCount() > 0) {
- Collection clist = new ArrayList<>(component.getChildren());
- for (UIComponent c : clist) {
- publishAfterViewEvents(context, application, c);
+ Collection children = new ArrayList<>(component.getChildren());
+ for (UIComponent child : children) {
+ publishAfterViewEvents(context, application, child);
}
}
if (component.getFacetCount() > 0) {
- Collection clist = new ArrayList<>(component.getFacets().values());
- for (UIComponent c : clist) {
- publishAfterViewEvents(context, application, c);
+ Collection facets = new ArrayList<>(component.getFacets().values());
+ for (UIComponent facet : facets) {
+ publishAfterViewEvents(context, application, facet);
}
}
} finally {
@@ -1806,14 +1800,14 @@ private static void disconnectFromView(FacesContext context, Application applica
component.compositeParent = null;
if (component.getChildCount() > 0) {
List children = component.getChildren();
- for (UIComponent c : children) {
- disconnectFromView(context, application, c);
+ for (UIComponent child : children) {
+ disconnectFromView(context, application, child);
}
}
if (component.getFacetCount() > 0) {
Map facets = component.getFacets();
- for (UIComponent c : facets.values()) {
- disconnectFromView(context, application, c);
+ for (UIComponent facet : facets.values()) {
+ disconnectFromView(context, application, facet);
}
}
@@ -1836,22 +1830,23 @@ private static void disconnectFromView(FacesContext context, Application applica
// private 'attributes' map directly to the state saving process.
private static class AttributesMap implements Map, Serializable {
+ @Serial
+ private static final long serialVersionUID = -6773035086539772945L;
+
// this KEY is special to the AttributesMap - this allows the implementation
// to access the the List containing the attributes that have been set
private static final String ATTRIBUTES_THAT_ARE_SET_KEY = UIComponentBase.class.getName() + ".attributesThatAreSet";
// private Map attributes;
+ private transient UIComponent component;
private transient Map pdMap;
private transient ConcurrentMap readMap;
- private transient UIComponent component;
- private static final long serialVersionUID = -6773035086539772945L;
// -------------------------------------------------------- Constructors
private AttributesMap(UIComponent component) {
-
this.component = component;
- pdMap = ((UIComponentBase) component).getDescriptorMap();
+ this.pdMap = ((UIComponentBase) component).getDescriptorMap();
}
@Override
@@ -2149,7 +2144,6 @@ private void writeObject(ObjectOutputStream out) throws IOException {
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
- // noinspection unchecked
Class> clazz = (Class>) in.readObject();
try {
component = (UIComponent) clazz.getDeclaredConstructor().newInstance();
@@ -2164,12 +2158,11 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
// required by UIComponent.getChildren()
private static class ChildrenList extends ArrayList {
- /**
- *
- */
+ @Serial
private static final long serialVersionUID = 8926987612679576963L;
- private UIComponent component;
- private FacesContext context;
+
+ private final UIComponent component;
+ private final FacesContext context;
public ChildrenList(UIComponent component) {
super(6);
@@ -2288,7 +2281,7 @@ public boolean remove(Object elementObj) {
if (isNotRenderingResponse(context)) {
removeFromDescendantMarkIdCache(component, element);
}
- if (super.indexOf(element) != -1) {
+ if (super.contains(element)) {
element.setParent(null);
}
if (super.remove(element)) {
@@ -2344,9 +2337,13 @@ public UIComponent set(int index, UIComponent element) {
// Private implementation of ListIterator for ChildrenList
private static class ChildrenListIterator implements ListIterator {
+ private final ChildrenList list;
+ private int index;
+ private int last = -1; // Index last returned by next() or previous()
+
public ChildrenListIterator(ChildrenList list) {
this.list = list;
- index = 0;
+ this.index = 0;
}
public ChildrenListIterator(ChildrenList list, int index) {
@@ -2358,10 +2355,6 @@ public ChildrenListIterator(ChildrenList list, int index) {
}
}
- private ChildrenList list;
- private int index;
- private int last = -1; // Index last returned by next() or previous()
-
// Iterator methods
@Override
@@ -2441,30 +2434,30 @@ public void set(UIComponent o) {
// Private implementation of Iterator for getFacetsAndChildren()
private final static class FacetsAndChildrenIterator implements Iterator {
+ private final UIComponent component;
private Iterator iterator;
private boolean childMode;
- private UIComponent c;
public FacetsAndChildrenIterator(UIComponent c) {
- this.c = c;
- childMode = false;
+ this.component = c;
+ this.childMode = false;
}
private void update() {
if (iterator == null) {
// we must guarantee that 'iterator' is never null
- if (c.getFacetCount() != 0) {
- iterator = c.getFacets().values().iterator();
+ if (component.getFacetCount() != 0) {
+ iterator = component.getFacets().values().iterator();
childMode = false;
- } else if (c.getChildCount() != 0) {
- iterator = c.getChildren().iterator();
+ } else if (component.getChildCount() != 0) {
+ iterator = component.getChildren().iterator();
childMode = true;
} else {
iterator = Collections.emptyIterator();
childMode = true;
}
- } else if (!childMode && !iterator.hasNext() && c.getChildCount() != 0) {
- iterator = c.getChildren().iterator();
+ } else if (!childMode && !iterator.hasNext() && component.getChildCount() != 0) {
+ iterator = component.getChildren().iterator();
childMode = true;
}
}
@@ -2492,12 +2485,11 @@ public void remove() {
// required by UIComponent.getFacets()
private static class FacetsMap extends HashMap {
- /**
- *
- */
+ @Serial
private static final long serialVersionUID = -1444791615672259097L;
- private UIComponent component;
- private FacesContext context;
+
+ private final UIComponent component;
+ private final FacesContext context;
public FacetsMap(UIComponent component) {
super(3, 1.0f);
@@ -2583,12 +2575,12 @@ Iterator keySetIterator() {
// Private implementation of Set for FacetsMap.getEntrySet()
private static class FacetsMapEntrySet extends AbstractSet> {
+ private final FacetsMap map;
+
public FacetsMapEntrySet(FacetsMap map) {
this.map = map;
}
- private FacetsMap map = null;
-
@Override
public boolean add(Map.Entry o) {
throw new UnsupportedOperationException();
@@ -2612,16 +2604,16 @@ public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) {
return false;
}
- Map.Entry e = (Map.Entry) o;
- Object k = e.getKey();
- Object v = e.getValue();
- if (!map.containsKey(k)) {
+ Entry entry = (Entry) o;
+ String name = entry.getKey();
+ UIComponent component = entry.getValue();
+ if (!map.containsKey(name)) {
return false;
}
- if (v == null) {
- return map.get(k) == null;
+ if (component == null) {
+ return map.get(name) == null;
} else {
- return v.equals(map.get(k));
+ return component.equals(map.get(name));
}
}
@@ -2640,12 +2632,12 @@ public boolean remove(Object o) {
if (o == null) {
throw new NullPointerException();
}
- if (!(o instanceof Map.Entry)) {
+ if (!(o instanceof Map.Entry,?>)) {
return false;
}
- Object k = ((Map.Entry) o).getKey();
- if (map.containsKey(k)) {
- map.remove(k);
+ String name = ((Entry) o).getKey();
+ if (map.containsKey(name)) {
+ map.remove(name);
return true;
} else {
return false;
@@ -2686,14 +2678,14 @@ public int size() {
// Private implementation of Map.Entry for FacetsMapEntrySet
private static class FacetsMapEntrySetEntry implements Map.Entry {
+ private final FacetsMap map;
+ private final String key;
+
public FacetsMapEntrySetEntry(FacetsMap map, String key) {
this.map = map;
this.key = key;
}
- private FacetsMap map;
- private String key;
-
@Override
public boolean equals(Object o) {
if (o == null) {
@@ -2753,15 +2745,15 @@ public UIComponent setValue(UIComponent value) {
// Private implementation of Set for FacetsMap.getEntrySet().iterator()
private static class FacetsMapEntrySetIterator implements Iterator> {
+ private final FacetsMap map;
+ private final Iterator iterator;
+ private Map.Entry last = null;
+
public FacetsMapEntrySetIterator(FacetsMap map) {
this.map = map;
- iterator = map.keySetIterator();
+ this.iterator = map.keySetIterator();
}
- private FacetsMap map = null;
- private Iterator iterator = null;
- private Map.Entry last = null;
-
@Override
public boolean hasNext() {
return iterator.hasNext();
@@ -2787,12 +2779,12 @@ public void remove() {
// Private implementation of Set for FacetsMap.getKeySet()
private static class FacetsMapKeySet extends AbstractSet {
+ private final FacetsMap map;
+
public FacetsMapKeySet(FacetsMap map) {
this.map = map;
}
- private FacetsMap map = null;
-
@Override
public boolean add(String o) {
throw new UnsupportedOperationException();
@@ -2878,15 +2870,15 @@ public int size() {
// Private implementation of Set for FacetsMap.getKeySet().iterator()
private static class FacetsMapKeySetIterator implements Iterator {
+ private final FacetsMap map;
+ private final Iterator iterator;
+ private String last = null;
+
public FacetsMapKeySetIterator(FacetsMap map) {
this.map = map;
- iterator = map.keySetIterator();
+ this.iterator = map.keySetIterator();
}
- private FacetsMap map = null;
- private Iterator iterator = null;
- private String last = null;
-
@Override
public boolean hasNext() {
return iterator.hasNext();
@@ -2912,12 +2904,12 @@ public void remove() {
// Private implementation of Collection for FacetsMap.values()
private static class FacetsMapValues extends AbstractCollection {
+ private final FacetsMap map;
+
public FacetsMapValues(FacetsMap map) {
this.map = map;
}
- private FacetsMap map;
-
@Override
public boolean add(UIComponent o) {
throw new UnsupportedOperationException();
@@ -2953,15 +2945,15 @@ public int size() {
// Private implementation of Iterator for FacetsMap.values().iterator()
private static class FacetsMapValuesIterator implements Iterator {
+ private final FacetsMap map;
+ private final Iterator iterator;
+ private String last = null;
+
public FacetsMapValuesIterator(FacetsMap map) {
this.map = map;
- iterator = map.keySetIterator();
+ this.iterator = map.keySetIterator();
}
- private FacetsMap map = null;
- private Iterator iterator = null;
- private Object last = null;
-
@Override
public boolean hasNext() {
return iterator.hasNext();
@@ -2988,11 +2980,11 @@ public void remove() {
// Note that this Map must be unmodifiable to the external world,
// but UIComponentBase itself needs to be able to write to the Map.
// We solve these requirements wrapping the underlying modifiable
- // Map inside of a unmodifiable map and providing private access to
+ // Map inside an unmodifiable map and providing private access to
// the underlying (modifiable) Map
private static class BehaviorsMap extends AbstractMap> {
- private Map> unmodifiableMap;
- private Map> modifiableMap;
+ private final Map> unmodifiableMap;
+ private final Map> modifiableMap;
private BehaviorsMap(Map> modifiableMap) {
this.modifiableMap = modifiableMap;
@@ -3011,6 +3003,7 @@ private Map> getModifiableMap() {
private static class PassThroughAttributesMap extends ConcurrentHashMap implements Serializable {
+ @Serial
private static final long serialVersionUID = 4230540513272170861L;
@Override
@@ -3096,8 +3089,7 @@ private PropertyDescriptor[] getPropertyDescriptors() {
}
private String addParentId(FacesContext context, String parentId, String childId) {
- return new StringBuilder(parentId.length() + 1 + childId.length()).append(parentId).append(UINamingContainer.getSeparatorChar(context)).append(childId)
- .toString();
+ return parentId + UINamingContainer.getSeparatorChar(context) + childId;
}
private String getParentId(FacesContext context, UIComponent parent) {