Package nl.gx.webmanager.cms.core
Interface PersonalizationAttributes
-
public interface PersonalizationAttributes
The PersonalizationAttributes models all required data to personalize an element. A personalization is defined by- Personalization items
PersonalizationItem
- Personalization operator
PersonalizationModel.Operator
- Group (id)
- Variant (name and id)
PersonalizationAttributesImpl
which also has utility methods to read the attributes from aNode
. For example a <p> node might look like<p data-wm-personalization-group="group1" data-wm-personalization-variant="variant1" data-wm-personalization-variant-name="My variant" data-wm-personalization="12 42" data-wm-personalization-group="and" >...</p>
A personalization has a group iff it has a variant. The default operator is
PersonalizationModel.Operator.AND
. An element with an empty list of personalization items should be consideredtrue
and be rendered.The personalization items are referenced by id,
Wrapper.getId()
. The methodloadPersonalizationItems(Session)
loads thePersonalizationItem
s by their ids from theSession
.getPersonalizationItems()
throws anIllegalStateException
if the personalization items have not been loaded or set. - Personalization items
-
-
Field Summary
Fields Modifier and Type Field Description static String
WM_PERSONALIZATION_ATTR
HTML attribute containing the list of personalization idsstatic String
WM_PERSONALIZATION_GROUP_ATTR
HTML attribute containing the group idstatic String
WM_PERSONALIZATION_OPERATOR_ATTR
HTML attribute containing the personalization operatorstatic String
WM_PERSONALIZATION_VARIANT_ATTR
HTML attribute containing the variant idstatic String
WM_PERSONALIZATION_VARIANT_NAME_ATTR
HTML attribute containing the variant name
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getGroupId()
Returns the group id.PersonalizationModel.Operator
getOperator()
Returns the variant operator.String
getOperatorAttribute()
Returns the operator as HTML attribute valueString
getPersonalizationAttribute()
Returns the value for the HTMLdata-wm-personalization
attribute, containing allWrapper.getId()
s.List<Integer>
getPersonalizationIds()
Returns the ids of all personalization items.PersonalizationItem[]
getPersonalizationItems()
Returns thePersonalizationItem
s if available.String
getVariantId()
Returns the variant id.String
getVariantName()
Returns the variant nameboolean
hasGroupAndVariant()
Returns true if group and variant have been definied.boolean
hasPersonalization()
Returns true if personalization items have been definied.void
loadPersonalizationItems(Session session)
Loads thePersonalizationItem
s from thegetPersonalizationIds()
.String
toHTMLAttributes()
Returns all attributes (key and value).String
toHTMLGroupVariantAttributes()
Returns the group and variant attributes (key and value).void
writeAttributesTo(org.jsoup.nodes.Node node)
Sets all personalization attributes in the given nodevoid
writeGroupVariantTo(org.jsoup.nodes.Node node)
Sets the group and variant attributes in the given node
-
-
-
Field Detail
-
WM_PERSONALIZATION_GROUP_ATTR
static final String WM_PERSONALIZATION_GROUP_ATTR
HTML attribute containing the group id- See Also:
- Constant Field Values
-
WM_PERSONALIZATION_VARIANT_ATTR
static final String WM_PERSONALIZATION_VARIANT_ATTR
HTML attribute containing the variant id- See Also:
- Constant Field Values
-
WM_PERSONALIZATION_VARIANT_NAME_ATTR
static final String WM_PERSONALIZATION_VARIANT_NAME_ATTR
HTML attribute containing the variant name- See Also:
- Constant Field Values
-
WM_PERSONALIZATION_ATTR
static final String WM_PERSONALIZATION_ATTR
HTML attribute containing the list of personalization ids- See Also:
- Constant Field Values
-
WM_PERSONALIZATION_OPERATOR_ATTR
static final String WM_PERSONALIZATION_OPERATOR_ATTR
HTML attribute containing the personalization operator- See Also:
- Constant Field Values
-
-
Method Detail
-
getPersonalizationAttribute
String getPersonalizationAttribute()
Returns the value for the HTMLdata-wm-personalization
attribute, containing allWrapper.getId()
s. For example:12 42
- Returns:
- String of all
Wrapper.getId()
s seperated by space - See Also:
getPersonalizationIds()
-
toHTMLGroupVariantAttributes
String toHTMLGroupVariantAttributes()
Returns the group and variant attributes (key and value). This can be inserted in a HTML tag. For example:data-wm-personalization-group="group1" data-wm-personalization-variant="var1" data-wm-personalization-variant-name="My variant"
- Returns:
- HTML group and variant attributes sepeared by space
- See Also:
toHTMLAttributes()
-
toHTMLAttributes
String toHTMLAttributes()
Returns all attributes (key and value). This can be inserted in a HTML tag. For example:data-wm-personalization-group="group1" data-wm-personalization-variant="variant1" data-wm-personalization-variant-name="My variant" data-wm-personalization="12 42" data-wm-personalization-group="and"
- Returns:
-
getOperatorAttribute
String getOperatorAttribute()
Returns the operator as HTML attribute value- Returns:
- the operator as HTML attribute value
-
writeGroupVariantTo
void writeGroupVariantTo(org.jsoup.nodes.Node node)
Sets the group and variant attributes in the given node- Parameters:
node
- Node to set attributes- See Also:
writeAttributesTo(Node)
-
writeAttributesTo
void writeAttributesTo(org.jsoup.nodes.Node node)
Sets all personalization attributes in the given node- Parameters:
node
- Node to set attributes- See Also:
writeGroupVariantTo(Node)
-
hasGroupAndVariant
boolean hasGroupAndVariant()
Returns true if group and variant have been definied.- Returns:
- True iff group ids and variant ids are not empty
-
hasPersonalization
boolean hasPersonalization()
Returns true if personalization items have been definied.- Returns:
- True iff personalization items is not empty
-
getGroupId
String getGroupId()
Returns the group id.- Returns:
- the group id or empty string
-
getVariantId
String getVariantId()
Returns the variant id.- Returns:
- the variant id or empty string
-
getOperator
PersonalizationModel.Operator getOperator()
Returns the variant operator.- Returns:
- The operator defined or AND by default
-
getVariantName
String getVariantName()
Returns the variant name- Returns:
- the variant name or empty string
-
getPersonalizationIds
List<Integer> getPersonalizationIds()
Returns the ids of all personalization items.- Returns:
- List of all personalization item ids.
-
getPersonalizationItems
PersonalizationItem[] getPersonalizationItems()
Returns thePersonalizationItem
s if available. ASession
is required to load thePersonalizationItem
s from the ids.- Returns:
- Throws:
IllegalStateException
- IfPersonalizationItem
s have not been loaded or set.- See Also:
loadPersonalizationItems(nl.gx.webmanager.foundation.Session)
-
loadPersonalizationItems
void loadPersonalizationItems(Session session)
Loads thePersonalizationItem
s from thegetPersonalizationIds()
. Ids that can not be resolved, will be silently deleted.- Parameters:
session
- The session used to load thePersonalizationItem
s
-
-