All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.freelibrary.iiif.presentation.v3.properties.Localized Maven / Gradle / Ivy

There is a newer version: 0.12.4
Show newest version

package info.freelibrary.iiif.presentation.v3.properties;

import java.util.List;
import java.util.Locale;

import com.fasterxml.jackson.annotation.JsonIgnore;

import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;

import info.freelibrary.iiif.presentation.v3.utils.MessageCodes;

/**
 * Interface that allows resources to be localized.
 */
public interface Localized {

    /**
     * Gets this localized external resource's languages.
     *
     * @return The localized external resource's languages
     */
    @JsonIgnore
    List getLanguages();

    /**
     * Sets the languages for this localized external resource.
     *
     * @param aLangArray The languages to set
     * @return The localized external resource
     * @throws IllegalArgumentException If the language tag is invalid
     */
    @JsonIgnore
    default Localized setLanguages(final String... aLangArray) {
        final List languages = getLanguages();

        languages.clear();

        for (final String element : aLangArray) {
            final String tag = Locale.forLanguageTag(element).toLanguageTag();

            if ("und".equals(tag)) {
                final Logger logger = LoggerFactory.getLogger(Localized.class, MessageCodes.BUNDLE);
                throw new IllegalArgumentException(logger.getMessage(MessageCodes.JPA_020, element));
            }

            languages.add(tag);
        }

        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy