public class AttrBuilder
extends java.lang.Object
XSSAPI
. It will encode the value automatically. If the value is
null
, it will be ignored.Constructor and Description |
---|
AttrBuilder(HttpServletRequest req,
XSSAPI xssAPI) |
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String name,
java.lang.Boolean value)
Adds attribute with the given name.
|
void |
add(java.lang.String name,
java.lang.Double value)
Adds attribute with the given name.
|
void |
add(java.lang.String name,
java.lang.Integer value)
Adds attribute with the given name.
|
void |
add(java.lang.String name,
java.lang.String value)
Adds attribute with the given name.
|
void |
addBoolean(java.lang.String name,
boolean value)
Adds boolean attribute (behaves like
disabled ) for the given name. |
void |
addChecked(boolean checked)
Adds
checked attribute. |
void |
addClass(java.lang.String value)
Adds
class attribute with the given value. |
void |
addDisabled(boolean disabled)
Adds
disabled attribute. |
void |
addHref(java.lang.String name,
java.lang.String value)
Adds an attribute that behave like
href attribute. |
void |
addMultiple(boolean multiple)
Adds
multiple attribute. |
void |
addOther(java.lang.String name,
java.lang.String value)
Adds the given name as
data-* attribute. |
void |
addOthers(java.util.Map<java.lang.String,java.lang.Object> data,
java.lang.String... exclusions)
Adds the given data as
data-* attributes. |
void |
addRel(java.lang.String value)
Adds relationship.
|
void |
addSelected(boolean selected)
Adds
selected attribute. |
java.lang.String |
build()
Builds the attributes in the form of
<attr-name>='<attr-value>'* . |
void |
build(java.io.Writer out)
Builds the attributes in the form of
<attr-name>='<attr-value>'* *. |
java.util.Map<java.lang.String,java.lang.String> |
getData()
Gets the raw
Map of attributes, with un-encoded values |
boolean |
isEmpty()
Returns
true if there is no attribute in this builder, false
otherwise. |
void |
set(java.lang.String name,
java.lang.String value)
Sets attribute with the given name.
|
java.lang.String |
toString() |
public AttrBuilder(HttpServletRequest req, XSSAPI xssAPI)
public java.util.Map<java.lang.String,java.lang.String> getData()
Map
of attributes, with un-encoded valuesMap
of attributespublic void addRel(java.lang.String value)
class
attribute.value
- the relationship to addpublic void addClass(java.lang.String value)
class
attribute with the given value.value
- the class attribute to addpublic void addHref(java.lang.String name, java.lang.String value)
href
attribute. i.e. the value
will be prepended with context path (if absolute path) and checked using
XSSAPI.getValidHref(String)
.name
- the name of the attribute to addvalue
- the value of the specified attributepublic void addDisabled(boolean disabled)
disabled
attribute.disabled
- the boolean value of the disabled
attributepublic void addChecked(boolean checked)
checked
attribute.checked
- the boolean value of the checked
attributepublic void addSelected(boolean selected)
selected
attribute.selected
- the boolean value of the selected
attributepublic void addMultiple(boolean multiple)
multiple
attribute.multiple
- the boolean value of the multiple
attributepublic void addBoolean(java.lang.String name, boolean value)
disabled
) for the given name.
When the given value is true
, it will be printed as "disabled=''",
instead of "disabled='true'". When the given value is false
, it will
NOT be printed, instead of "disabled='false'".name
- the name of the boolean attribute to addvalue
- the boolean value of the attributepublic void addOther(java.lang.String name, java.lang.String value)
data-*
attribute.name
- the name of the data-*
attribute to addvalue
- the value of the attributepublic void addOthers(java.util.Map<java.lang.String,java.lang.Object> data, java.lang.String... exclusions)
data-*
attributes. Entries with keys specified
in exclusions parameter or having namespace (e.g. "jcr:primaryType") will be
excluded.data
- the map containing key/value pairs to add as data-*
attributesexclusions
- the keys which must not be added as data-*
attributespublic void add(java.lang.String name, java.lang.Boolean value)
name
- the name of the attribute to addvalue
- the boolean value of the attributepublic void add(java.lang.String name, java.lang.Integer value)
name
- the name of the attribute to addvalue
- the integer value of the attributepublic void add(java.lang.String name, java.lang.Double value)
name
- the name of the attribute to addvalue
- the double value of the attributepublic void add(java.lang.String name, java.lang.String value)
name
- the name of the attribute to addvalue
- the string value of the attributepublic void set(java.lang.String name, java.lang.String value)
name
- the name of the attribute to set or replace (if exists)value
- the string value of the attributepublic boolean isEmpty()
true
if there is no attribute in this builder, false
otherwise.true
if there is no attribute in this builder, false
otherwisepublic java.lang.String build()
<attr-name>='<attr-value>'*
.public void build(java.io.Writer out) throws java.io.IOException
<attr-name>='<attr-value>'*
*.out
- the writerjava.io.IOException
- in case there's an error when appending to the writerpublic java.lang.String toString()
toString
in class java.lang.Object
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"