Skip to content

Commit

Permalink
Adding HtmlComponentUtils.handleAttribute
Browse files Browse the repository at this point in the history
Signed-off-by: Emil Sierżęga <emilsierzega@gmail.com>
  • Loading branch information
Emkas committed Jun 26, 2022
1 parent 420f761 commit a801bdd
Show file tree
Hide file tree
Showing 31 changed files with 606 additions and 1,277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ public String getDefaultEventName() {
return "click";
}

// TODO The same as jakarta.faces.component.html.HtmlComponentUtils#handleAttribute
private void handleAttribute(String name, Object value) {
@SuppressWarnings("unchecked")
List<String> setAttributes = (List<String>) getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet");
if (setAttributes == null) {
String cname = this.getClass().getName();
Expand Down
64 changes: 20 additions & 44 deletions impl/src/main/java/jakarta/faces/component/html/HtmlBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*/
package jakarta.faces.component.html;

import java.util.ArrayList;
import static jakarta.faces.component.html.HtmlComponentUtils.handleAttribute;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import jakarta.el.ValueExpression;
import jakarta.faces.component.UIOutput;
import jakarta.faces.component.behavior.ClientBehaviorHolder;

Expand All @@ -36,8 +35,6 @@
*/
public class HtmlBody extends UIOutput implements ClientBehaviorHolder {

private static final String OPTIMIZED_PACKAGE = "jakarta.faces.component.";

/**
* Default constructor setting the renderer type.
*/
Expand Down Expand Up @@ -100,7 +97,7 @@ public java.lang.String getDir() {
*/
public void setDir(java.lang.String dir) {
getStateHelper().put(PropertyKeys.dir, dir);
handleAttribute("dir", dir);
handleAttribute(this, "dir", dir);
}

/**
Expand All @@ -126,7 +123,7 @@ public java.lang.String getLang() {
*/
public void setLang(java.lang.String lang) {
getStateHelper().put(PropertyKeys.lang, lang);
handleAttribute("lang", lang);
handleAttribute(this, "lang", lang);
}

/**
Expand All @@ -152,7 +149,7 @@ public java.lang.String getOnclick() {
*/
public void setOnclick(java.lang.String onclick) {
getStateHelper().put(PropertyKeys.onclick, onclick);
handleAttribute("onclick", onclick);
handleAttribute(this, "onclick", onclick);
}

/**
Expand All @@ -178,7 +175,7 @@ public java.lang.String getOndblclick() {
*/
public void setOndblclick(java.lang.String ondblclick) {
getStateHelper().put(PropertyKeys.ondblclick, ondblclick);
handleAttribute("ondblclick", ondblclick);
handleAttribute(this, "ondblclick", ondblclick);
}

/**
Expand All @@ -204,7 +201,7 @@ public java.lang.String getOnkeydown() {
*/
public void setOnkeydown(java.lang.String onkeydown) {
getStateHelper().put(PropertyKeys.onkeydown, onkeydown);
handleAttribute("onkeydown", onkeydown);
handleAttribute(this, "onkeydown", onkeydown);
}

/**
Expand All @@ -230,7 +227,7 @@ public java.lang.String getOnkeypress() {
*/
public void setOnkeypress(java.lang.String onkeypress) {
getStateHelper().put(PropertyKeys.onkeypress, onkeypress);
handleAttribute("onkeypress", onkeypress);
handleAttribute(this, "onkeypress", onkeypress);
}

/**
Expand All @@ -256,7 +253,7 @@ public java.lang.String getOnkeyup() {
*/
public void setOnkeyup(java.lang.String onkeyup) {
getStateHelper().put(PropertyKeys.onkeyup, onkeyup);
handleAttribute("onkeyup", onkeyup);
handleAttribute(this, "onkeyup", onkeyup);
}

/**
Expand All @@ -280,7 +277,7 @@ public java.lang.String getOnload() {
*/
public void setOnload(java.lang.String onload) {
getStateHelper().put(PropertyKeys.onload, onload);
handleAttribute("onload", onload);
handleAttribute(this, "onload", onload);
}

/**
Expand All @@ -306,7 +303,7 @@ public java.lang.String getOnmousedown() {
*/
public void setOnmousedown(java.lang.String onmousedown) {
getStateHelper().put(PropertyKeys.onmousedown, onmousedown);
handleAttribute("onmousedown", onmousedown);
handleAttribute(this, "onmousedown", onmousedown);
}

/**
Expand All @@ -332,7 +329,7 @@ public java.lang.String getOnmousemove() {
*/
public void setOnmousemove(java.lang.String onmousemove) {
getStateHelper().put(PropertyKeys.onmousemove, onmousemove);
handleAttribute("onmousemove", onmousemove);
handleAttribute(this, "onmousemove", onmousemove);
}

/**
Expand All @@ -358,7 +355,7 @@ public java.lang.String getOnmouseout() {
*/
public void setOnmouseout(java.lang.String onmouseout) {
getStateHelper().put(PropertyKeys.onmouseout, onmouseout);
handleAttribute("onmouseout", onmouseout);
handleAttribute(this, "onmouseout", onmouseout);
}

/**
Expand All @@ -384,7 +381,7 @@ public java.lang.String getOnmouseover() {
*/
public void setOnmouseover(java.lang.String onmouseover) {
getStateHelper().put(PropertyKeys.onmouseover, onmouseover);
handleAttribute("onmouseover", onmouseover);
handleAttribute(this, "onmouseover", onmouseover);
}

/**
Expand All @@ -410,7 +407,7 @@ public java.lang.String getOnmouseup() {
*/
public void setOnmouseup(java.lang.String onmouseup) {
getStateHelper().put(PropertyKeys.onmouseup, onmouseup);
handleAttribute("onmouseup", onmouseup);
handleAttribute(this, "onmouseup", onmouseup);
}

/**
Expand All @@ -434,7 +431,7 @@ public java.lang.String getOnunload() {
*/
public void setOnunload(java.lang.String onunload) {
getStateHelper().put(PropertyKeys.onunload, onunload);
handleAttribute("onunload", onunload);
handleAttribute(this, "onunload", onunload);
}

/**
Expand Down Expand Up @@ -472,7 +469,7 @@ public java.lang.String getRole() {
*/
public void setRole(java.lang.String role) {
getStateHelper().put(PropertyKeys.role, role);
handleAttribute("role", role);
handleAttribute(this, "role", role);
}

/**
Expand All @@ -498,7 +495,7 @@ public java.lang.String getStyle() {
*/
public void setStyle(java.lang.String style) {
getStateHelper().put(PropertyKeys.style, style);
handleAttribute("style", style);
handleAttribute(this, "style", style);
}

/**
Expand Down Expand Up @@ -550,7 +547,7 @@ public java.lang.String getTitle() {
*/
public void setTitle(java.lang.String title) {
getStateHelper().put(PropertyKeys.title, title);
handleAttribute("title", title);
handleAttribute(this, "title", title);
}

/**
Expand All @@ -576,7 +573,7 @@ public java.lang.String getXmlns() {
*/
public void setXmlns(java.lang.String xmlns) {
getStateHelper().put(PropertyKeys.xmlns, xmlns);
handleAttribute("xmlns", xmlns);
handleAttribute(this, "xmlns", xmlns);
}

private static final Collection<String> EVENT_NAMES = Collections.unmodifiableCollection(
Expand All @@ -592,25 +589,4 @@ public String getDefaultEventName() {
return null;
}

private void handleAttribute(String name, Object value) {
List<String> setAttributes = (List<String>) getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet");
if (setAttributes == null) {
String cname = this.getClass().getName();
if (cname != null && cname.startsWith(OPTIMIZED_PACKAGE)) {
setAttributes = new ArrayList<>(6);
getAttributes().put("jakarta.faces.component.UIComponentBase.attributesThatAreSet", setAttributes);
}
}
if (setAttributes != null) {
if (value == null) {
ValueExpression ve = getValueExpression(name);
if (ve == null) {
setAttributes.remove(name);
}
} else if (!setAttributes.contains(name)) {
setAttributes.add(name);
}
}
}

}
Loading

0 comments on commit a801bdd

Please sign in to comment.