Class Context
- java.lang.Object
-
- com.priint.pubserver.plugin.entitydata.Context
-
- All Implemented Interfaces:
GetIdentifier,EntityData,PersistentData,java.io.Serializable
@Entity public class Context extends java.lang.Object implements java.io.Serializable, GetIdentifier, EntityData, PersistentData
Holds context data like language, country, assortment, well, target group, market etc.
Context contains a list of data used to specify or filter data from connectors.
- Since:
- 4.0.0, 4.0.5 added JPA annotations
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Context()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Contextcopy()Creates a copy (deep clone) of the object and return it.booleanequals(java.lang.Object obj)static ContextfromLanguageAndCountry(java.lang.String language, java.lang.String country)Creates a context prefilled with language and country codes.static ContextfromLanguageTag(java.lang.String languageTag)Creates a context from a IETF Language Tag (IETF BCP 47) and sets country, language and script fields accordingly.static ContextfromLanguageTagAndCountry(java.lang.String languageTag, java.lang.String country)Creates a context filled with language and country codes.java.lang.StringgetAssortmentName()ContextgetContext()java.lang.StringgetCountry()Get country value.java.lang.StringgetCreatedBy()java.util.DategetCreatedOn()java.lang.StringgetDefaultIdentifier()java.lang.StringgetDocumentId()java.lang.StringgetEntityIdentifier()Identifier of an entity in the entity model where the current object refers to.java.lang.StringgetIdentifier()Get identifier for context.java.lang.StringgetLanguage()Get language value.java.lang.StringgetMarketName()Get name of a market in a content systemjava.lang.StringgetPublication()java.lang.StringgetScript()Get script value.java.lang.StringgetTargetGroup()Get name of a target group in a content systemjava.lang.StringgetUpdatedBy()java.util.DategetUpdatedOn()java.lang.StringgetWellName()Get name of well, i.e.inthashCode()ContextmergeCopy(Context mergeContext)Creates a copy of the current object and merges fields from mergeContext if they are not empty.static ContextnewContext(java.lang.String language, java.lang.String country)Creates a new Context object from language and country tag.voidrecalculateIdentifier()This method calculate and set identifier value based on default identifier (seegetDefaultIdentifier()).voidsetAssortmentName(java.lang.String assortmentName)voidsetContext(Context context)set the context of entity data objectvoidsetCountry(java.lang.String country)Set the context country.voidsetCreatedBy(java.lang.String createdBy)voidsetCreatedOn(java.util.Date createdOn)voidsetDocumentId(java.lang.String documentId)voidsetEntityIdentifier(java.lang.String entityIdentifier)Identifier of an entity in the entity model where the current object refers to.voidsetIdentifier(java.lang.String identifier)Set identifier for this context.voidsetLanguage(java.lang.String language)Set the context language.voidsetMarketName(java.lang.String marketName)voidsetPublication(java.lang.String publication)voidsetScript(java.lang.String script)Set the context script (writing system).voidsetTargetGroup(java.lang.String targetGroup)voidsetUpdatedBy(java.lang.String updatedBy)voidsetUpdatedOn(java.util.Date updatedOn)voidsetWellName(java.lang.String wellName)java.lang.StringtoLanguageTag()Returns a well-formed IETF BCP 47 language tag representing the locale of this context.
Well, assortment, publication are not part of this representation.java.lang.StringtoString()
-
-
-
Method Detail
-
getIdentifier
public java.lang.String getIdentifier()
Get identifier for context. If not already set, default identifier will be returned (seegetDefaultIdentifier()).- Specified by:
getIdentifierin interfaceEntityData- Specified by:
getIdentifierin interfaceGetIdentifier- Specified by:
getIdentifierin interfacePersistentData- Returns:
- string identifier
-
recalculateIdentifier
public void recalculateIdentifier()
This method calculate and set identifier value based on default identifier (seegetDefaultIdentifier()).
-
getDefaultIdentifier
public java.lang.String getDefaultIdentifier()
- Returns:
- default identifier is constructed from context data already set.
-
setIdentifier
public void setIdentifier(java.lang.String identifier)
Set identifier for this context.Throws NullArgumentException if identifier is
null.- Specified by:
setIdentifierin interfaceEntityData- Parameters:
identifier- data object id as string
-
getCountry
public java.lang.String getCountry()
Get country value.ISO 3166 alpha-2 country code (two-letter upper-case representation) e.g. "DE" for Germany or "CH" for Switzerland.
Empty string is used for ANY country.- Returns:
- country
-
setCountry
public void setCountry(java.lang.String country)
Set the context country.In cases where the calling source code uses country codes different from ISO 3166-1 (or UN M.49) you have to transform the input argument in advance.
Example for codes in IOC (International Olympic Committee):
new Context().setCountry(LocaleUtils.getPubServerCountry(country, "IOC"));
This expects that a translation table from IOC to ISO 3166-1 has been loaded (e.g. translating "GER" to "DE").- Parameters:
country- a valid ISO 3166-1 country code, e.g. "DE" (Germany), or "EG" (Egypt)
-
getLanguage
public java.lang.String getLanguage()
Get language value.ISO 639 alpha-3 language code (three-letter lower-case representation) e.g. "deu" for German or "fra" for French.
Empty string is used for ANY language.- Returns:
- language value
-
setLanguage
public void setLanguage(java.lang.String language)
Set the context language.In cases where the calling source code uses language codes different from ISO-639-2-Alpha3/B you have to transform the input argument in advance.
Example for codes in ISO_639_1_Alpha2:
new Context().setLanguage(LocaleUtils.getPubServerLanguage(language, LocaleUtils.ISO_639_1_Alpha2));
Example for codes in ISO 639-2/T:
new Context().setLanguage(LocaleUtils.getPubServerLanguage(language, "ISO-639-2/T"));
This expects that a translation table from ISO-639-2/T to ISO-639-2/B has been loaded (e.g. translating "ger" to "deu").- Parameters:
language- a valid ISO_639_3_Alpha3 language code, e.g. "deu" (German), or "ara" (Arabic)
-
getScript
public java.lang.String getScript()
Get script value.ISO 15924 four letter code for writing system (four-letter title-case presentation) e.g. "Latn" oder "Cyrl"
Empty string is used for ANY script.- Returns:
- script value
-
setScript
public void setScript(java.lang.String script)
Set the context script (writing system). Script hat to be a 4-letter code conforming ISO-15924.Examples for codes "Latn" or "Cyrl".
In cases where the calling source code uses script codes different from ISO-15924 you have to transform the input argument in advance.
Example for codes in ISO_15924:
new Context().setScript(LocaleUtils.getPubServerScript(script, LocaleUtils.ISO_15924));
- Parameters:
script- a valid ISO_15924 script code, e.g. "Latn" (Latin), or "Hang" (Hangul - i.e. Korean alphabet)
-
getWellName
public java.lang.String getWellName()
Get name of well, i.e. a string representing a data "pool" in a content system- Returns:
- well name
-
setWellName
public void setWellName(java.lang.String wellName)
- Parameters:
wellName- seegetWellName()
-
getAssortmentName
public java.lang.String getAssortmentName()
- Returns:
- assortment of goods to which this context is bound
-
setAssortmentName
public void setAssortmentName(java.lang.String assortmentName)
- Parameters:
assortmentName- seegetAssortmentName()
-
getPublication
public java.lang.String getPublication()
- Returns:
- publication identifier
-
setPublication
public void setPublication(java.lang.String publication)
- Parameters:
publication-getPublication()
-
getDocumentId
public java.lang.String getDocumentId()
- Returns:
- document identifier
-
setDocumentId
public void setDocumentId(java.lang.String documentId)
- Parameters:
documentId-getDocumentId()
-
getCreatedBy
public java.lang.String getCreatedBy()
-
setCreatedBy
public void setCreatedBy(java.lang.String createdBy)
-
getCreatedOn
public java.util.Date getCreatedOn()
-
setCreatedOn
public void setCreatedOn(java.util.Date createdOn)
-
getUpdatedBy
public java.lang.String getUpdatedBy()
-
setUpdatedBy
public void setUpdatedBy(java.lang.String updatedBy)
-
getUpdatedOn
public java.util.Date getUpdatedOn()
-
setUpdatedOn
public void setUpdatedOn(java.util.Date updatedOn)
-
getTargetGroup
public java.lang.String getTargetGroup()
Get name of a target group in a content system- Returns:
- target group
-
setTargetGroup
public void setTargetGroup(java.lang.String targetGroup)
- Parameters:
targetGroup- seegetTargetGroup()
-
getMarketName
public java.lang.String getMarketName()
Get name of a market in a content system- Returns:
- target group
-
setMarketName
public void setMarketName(java.lang.String marketName)
- Parameters:
marketName- seegetMarketName()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
fromLanguageTag
public static Context fromLanguageTag(java.lang.String languageTag)
Creates a context from a IETF Language Tag (IETF BCP 47) and sets country, language and script fields accordingly.
Compare to @link{LocaleLocale.forLanguageTag(String)- Parameters:
languageTag- IETF Language Tag- Returns:
- new context object filled with language, country and script
- Throws:
java.lang.NullPointerException- - if languageTag is null
-
fromLanguageAndCountry
public static Context fromLanguageAndCountry(java.lang.String language, java.lang.String country)
Creates a context prefilled with language and country codes.- Parameters:
language- a valid ISO_639_3_Alpha3 language code or an empty stringcountry- a valid ISO_3166_1_Alpha2 country code or an empty string- Returns:
- created context object
- Throws:
java.lang.NullPointerException- - if language or country are nulljava.lang.IllegalArgumentException- - if language or country are not listed in pubservers key lists
-
fromLanguageTagAndCountry
public static Context fromLanguageTagAndCountry(java.lang.String languageTag, java.lang.String country)
Creates a context filled with language and country codes.- Parameters:
languageTag- IETF Language Tagcountry- a valid ISO_3166_1_Alpha2 country code or an empty string- Returns:
- created context object
- Throws:
java.lang.NullPointerException- - if languageTag or country are nulljava.lang.IllegalArgumentException- - if language, region or country are not listed in pubservers key lists
-
copy
public Context copy()
Creates a copy (deep clone) of the object and return it.- Returns:
- copy of object
-
mergeCopy
public Context mergeCopy(Context mergeContext)
Creates a copy of the current object and merges fields from mergeContext if they are not empty.- Parameters:
mergeContext- other context used if fields are not empty fields- Returns:
- cloned context with merged fields from other context
-
getEntityIdentifier
public java.lang.String getEntityIdentifier()
Description copied from interface:EntityDataIdentifier of an entity in the entity model where the current object refers to.- Specified by:
getEntityIdentifierin interfaceEntityData- Returns:
- entity identifier as string
-
getContext
public Context getContext()
- Specified by:
getContextin interfaceEntityData- Returns:
- entity context
-
setContext
public void setContext(Context context)
Description copied from interface:EntityDataset the context of entity data object- Specified by:
setContextin interfaceEntityData
-
setEntityIdentifier
public void setEntityIdentifier(java.lang.String entityIdentifier)
Description copied from interface:EntityDataIdentifier of an entity in the entity model where the current object refers to.- Specified by:
setEntityIdentifierin interfaceEntityData
-
toLanguageTag
public java.lang.String toLanguageTag()
Returns a well-formed IETF BCP 47 language tag representing the locale of this context.
Well, assortment, publication are not part of this representation.
ISO_639_1_Alpha2 is preferred if existing, otherwise three letter language representation is used. For details seeLocale.toLanguageTag()- Returns:
- IETF Language Tag
-
newContext
public static Context newContext(java.lang.String language, java.lang.String country)
Creates a new Context object from language and country tag.
- Parameters:
language- language tagcountry- country tag- Returns:
- new Context object
-
-