Class SnippetContext

java.lang.Object
com.priint.pubserver.comet.bridge.snippet.SnippetContext
All Implemented Interfaces:
Serializable

public class SnippetContext extends Object implements Serializable

Holds context data like language, country, assortment, well, target group, market etc.

SnippetContext contains a list of data used to specify or filter snippets.

Since:
4.0.0
See Also:
  • Constructor Details

    • SnippetContext

      public SnippetContext()
  • Method Details

    • getDefaultIdentifier

      public String getDefaultIdentifier()
      Gets default identifier.
      Returns:
      default identifier is constructed from context data already set.
    • getCountry

      public 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 country
    • setCountry

      public void setCountry(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 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(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 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(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 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(String wellName)
      Sets well name.
      Parameters:
      wellName - see getWellName()
    • getAssortmentName

      public String getAssortmentName()
      Gets assortment name.
      Returns:
      assortment of goods to which this context is bound
    • setAssortmentName

      public void setAssortmentName(String assortmentName)
      Sets assortment name.
      Parameters:
      assortmentName - see getAssortmentName()
    • getTargetGroup

      public String getTargetGroup()
      Get name of a target group in a content system
      Returns:
      target group
    • setTargetGroup

      public void setTargetGroup(String targetGroup)
      Sets target group.
      Parameters:
      targetGroup - see getTargetGroup()
    • getMarketName

      public String getMarketName()
      Get name of a market in a content system
      Returns:
      target group
    • setMarketName

      public void setMarketName(String marketName)
      Sets market name.
      Parameters:
      marketName - see getMarketName()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • fromLanguageTagAndCountry

      public static SnippetContext fromLanguageTagAndCountry(String languageTag, String country)
      Creates a context filled with language and country codes.
      Parameters:
      languageTag - IETF Language Tag
      country - a valid ISO_3166_1_Alpha2 country code or an empty string
      Returns:
      created context object
      Throws:
      NullPointerException - - if languageTag or country are null
      IllegalArgumentException - - if language, region or country are not listed in pubservers key lists
    • fromJSON

      public static Optional<SnippetContext> fromJSON(String jsonString)
      Creates a snippetContext from JSON string
      Parameters:
      jsonString - json String stored in the column SnippetContext
      Returns:
      optional of created snippet context object, if jsonString is invalid or empty, returns Optional.empty()
    • fromLanguageTag

      public static SnippetContext fromLanguageTag(String languageTag)
      Creates a context from a IETF Language Tag (IETF BCP 47) and sets country, language and script fields accordingly.
      Compare to @link{Locale Locale.forLanguageTag(String)
      Parameters:
      languageTag - IETF Language Tag
      Returns:
      new context object filled with language, country and script
      Throws:
      NullPointerException - - if languageTag is null
    • fromLanguageAndCountry

      public static SnippetContext fromLanguageAndCountry(String language, String country)
      Creates a context prefilled with language and country codes.
      Parameters:
      language - a valid ISO_639_3_Alpha3 language code or an empty string
      country - a valid ISO_3166_1_Alpha2 country code or an empty string
      Returns:
      created context object
      Throws:
      NullPointerException - - if language or country are null
      IllegalArgumentException - - if language or country are not listed in pubservers key lists
    • toLanguageTag

      public 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 see Locale.toLanguageTag()
      Returns:
      IETF Language Tag
    • newContext

      public static SnippetContext newContext(String language, String country)

      Creates a new Context object from language and country tag.

      Parameters:
      language - language tag
      country - country tag
      Returns:
      new SnippetContext object
    • equalsLanguageAndCountry

      public static boolean equalsLanguageAndCountry(SnippetContext sc, SnippetContext sc2)

      Compare language and country.

      Parameters:
      sc - language tag
      sc2 - country tag
      Returns:
      true if language and country from both SnippetContext objects are equal
    • snippetContextToJSON

      public static String snippetContextToJSON(SnippetContext snippetContext)
      Snippet context to json string.
      Parameters:
      snippetContext - the snippet context
      Returns:
      the string