/** {@inheritDoc} */ protected void processElementContent(XMLObject samlObject, String elementContent) { LocalizedName name = (LocalizedName) samlObject; name.setValue(elementContent); } }
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(); } }
/** * {@inheritDoc} */ protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException { LocalizedName name = (LocalizedName) samlObject; if (name.getXMLLang() != null) { Attr attribute = AttributeSupport.constructAttribute(domElement.getOwnerDocument(), XMLConstants.XML_NS, LangBearing.XML_LANG_ATTR_LOCAL_NAME, XMLConstants.XML_PREFIX); attribute.setValue(name.getXMLLang()); domElement.setAttributeNodeNS(attribute); } }
/** * {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && XMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { LocalizedName name = (LocalizedName) samlObject; name.setXMLLang(attribute.getValue()); } }
/** * 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).getValue(); } if (item instanceof XSString) { value = ((XSString) item).getValue(); } LOGGER.trace("Loading first available locale [{}]", value); return value; } return null; }