Search in sources :

Example 1 with LocalizedName

use of org.opensaml.saml.saml2.metadata.LocalizedName in project cas by apereo.

the class SamlMetadataUIInfo method findLocale.

private static Optional<String> findLocale(final String locale, final List<?> items) {
    LOGGER.trace("Looking for locale [{}]", locale);
    val p = Pattern.compile(locale, Pattern.CASE_INSENSITIVE);
    return items.stream().filter(item -> item instanceof LocalizedName).map(item -> (LocalizedName) item).filter(item -> {
        val xmlLang = item.getXMLLang();
        return StringUtils.isNotBlank(xmlLang) && p.matcher(xmlLang).matches() && StringUtils.isNotBlank(item.getValue());
    }).map(XSString::getValue).findFirst();
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) XSURI(org.opensaml.core.xml.schema.XSURI) Getter(lombok.Getter) LocalizedName(org.opensaml.saml.saml2.metadata.LocalizedName) Collection(java.util.Collection) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) LocalizedURI(org.opensaml.saml.saml2.metadata.LocalizedURI) ToString(lombok.ToString) DefaultRegisteredServiceUserInterfaceInfo(org.apereo.cas.web.flow.services.DefaultRegisteredServiceUserInterfaceInfo) Optional(java.util.Optional) UIInfo(org.opensaml.saml.ext.saml2mdui.UIInfo) Pattern(java.util.regex.Pattern) XSString(org.opensaml.core.xml.schema.XSString) LocalizedName(org.opensaml.saml.saml2.metadata.LocalizedName)

Example 2 with LocalizedName

use of org.opensaml.saml.saml2.metadata.LocalizedName in project cas by apereo.

the class SamlMetadataUIInfo method getLocalizedValues.

/**
 * Gets localized values.
 *
 * @param locale browser preferred language
 * @param items  the items
 * @return the string value
 */
private static String getLocalizedValues(final String locale, final List<?> items) {
    val foundLocale = findLocale(StringUtils.defaultString(locale, "en"), items);
    if (foundLocale.isPresent()) {
        return foundLocale.get();
    }
    if (!items.isEmpty()) {
        val item = items.get(0);
        var value = StringUtils.EMPTY;
        if (item instanceof LocalizedName) {
            value = ((LocalizedName) item).getValue();
        }
        if (item instanceof LocalizedURI) {
            value = ((LocalizedURI) item).getURI();
        }
        if (item instanceof XSString) {
            value = ((XSString) item).getValue();
        }
        LOGGER.trace("Loading first available locale [{}]", value);
        return value;
    }
    return null;
}
Also used : lombok.val(lombok.val) LocalizedURI(org.opensaml.saml.saml2.metadata.LocalizedURI) LocalizedName(org.opensaml.saml.saml2.metadata.LocalizedName) XSString(org.opensaml.core.xml.schema.XSString)

Aggregations

lombok.val (lombok.val)2 XSString (org.opensaml.core.xml.schema.XSString)2 LocalizedName (org.opensaml.saml.saml2.metadata.LocalizedName)2 LocalizedURI (org.opensaml.saml.saml2.metadata.LocalizedURI)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 ToString (lombok.ToString)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 DefaultRegisteredServiceUserInterfaceInfo (org.apereo.cas.web.flow.services.DefaultRegisteredServiceUserInterfaceInfo)1 XSURI (org.opensaml.core.xml.schema.XSURI)1 UIInfo (org.opensaml.saml.ext.saml2mdui.UIInfo)1