Class XMPLanguageAlternative

java.lang.Object
com.adobe.xmp.core.XMPLanguageAlternative

public class XMPLanguageAlternative extends Object
Language alternatives allow the text value of a property to be chosen based on a desired language. XMPLanguageAlternative is implemented as a XMPArray (Alternate) whose children are XMPSimple with text value, each of which must have a language qualifier (xml:lang) associated with it.
  • Method Details

    • getArray

      public XMPArray getArray()
      Gets underlying XMPArray
      Returns:
      XMPArray
    • newInstance

      public static XMPLanguageAlternative newInstance(XMPArray array)
      Constructs a XMPLanguageAlternative which wraps the given XMPArray. If this XMPArray does not represent a Lang Alt as per XMP Specification this method returns null. To detect whether a language alternative, these prerequisites must be fulfilled:
      • the array contains only simple properties
      • at least one property has an xml:lang qualifier.
      Parameters:
      array -
    • normalize

      public void normalize()
      This will normalize the alternative array to meet the criteria of a XMPLanguage alternative. This is only important if a XMPArray is constructed outside of this facade and then used within this context. If you only use this facade, a currupt XMPArray will never be created. Normalization will do the following:
      • x-default is moved to top (first one if multiple)
      • Items with empty languages become the default language, when there is no "x-default". (first one if multiple)
      • Any other item qualifiers than xml:lang are deleted.
      • language will be normalized to RFC 3066 form
      after cleanup, other x-defaults than the first one and other items with no xml:lang will not be deleted at this point x-defaults will be deleted while setting a new default. Emptys will be preserved but not accessible with this fassade.
    • isEmpty

      public boolean isEmpty()
      Checks if the Language Alternative is empty
      Returns:
      True if the array is empty False otherwise
    • size

      public int size()
      returns the number of elements
      Returns:
      the number of elements
    • clear

      public void clear()
      Delete all elements
    • setLocalizedText

      public XMPSimple setLocalizedText(String language, String value)
      Set or overwrites a localized text entry for this language alternative.
      Parameters:
      language - the language String, has to follow the RFC 3066 format
      value - the value for this language alternative entry
      Returns:
      the localized text entry just created or null if nothing was created
      Throws:
      IllegalArgumentException - IllegalArgumentException is thrown if value is null
    • setDefaultText

      public XMPSimple setDefaultText(String language, String value)
      Set or overwrites the default localized text entry for this language alternative.
      Parameters:
      language - the language of the default entry (or null or x-default. if no specific language is given)
      value - the value for this language alternative entry
      Returns:
      the localized text entry just created or null if nothing was created
    • setDefaultText

      public XMPSimple setDefaultText(String value)
      Sets the default text entry (first one in array) in an language alternative array. If a new entry must be created (array is empty), x-default will be used as language
      Parameters:
      value - the value for this language alternative entry
      Returns:
      the localized text entry just created or null if nothing was created
    • setDefaultLanguage

      public XMPSimple setDefaultLanguage(String language)
      Sets the entry with a certain language as the default entry (pushes it to the first location)
      Parameters:
      language - the language to set as default
      Returns:
      the new default entry or null if nothing could be set (language entry does not exist)
    • getLocalizedText

      public XMPSimple getLocalizedText(String language)
      Returns the language alternative array item for a specific language If language is x-default the first entry of the array is returned, even if someone accidently added an "x-default" entry at another position than the first one (not possible while using this class)
      Parameters:
      language - the language for the desired array item
      Returns:
      the array item requested or null if it does not exist
    • getDefaultText

      public XMPSimple getDefaultText()
      Returns the default language from an alternative array. This is always the first entry (even if someone accidently added an "x-default" entry at another position than the first one (not possible while using this class)
      Returns:
      the array item requested or null if it does not exist
    • getAvailableLanguages

      public List<String> getAvailableLanguages()
      Returns:
      Returns a list of languages that are set in this language alternative.
    • removeLocalizedText

      public XMPSimple removeLocalizedText(String language)
      Removes the specified language item from an alternative array
      Parameters:
      language - the language that shall be removed
      Returns:
      the removed item or null if it did not exist
    • removeDefaultText

      public XMPSimple removeDefaultText()
      removes the default entry (the first one) and the second one will be default
      Returns:
      the removed item or null if it did not exist
    • iterator

      public Iterator<XMPNode> iterator()