KEYCLOAK-13713 Define a write method for XMLGregorianCalendar attributes

This commit is contained in:
Luca Leonardo Scorcia 2020-04-03 20:00:25 -04:00 committed by Hynek Mlnařík
parent f30395d535
commit b4127bb7d7

View file

@ -172,6 +172,8 @@ public class BaseWriter {
writeStringAttributeValue((String) attributeValue);
} else if (attributeValue instanceof NameIDType) {
writeNameIDTypeAttributeValue((NameIDType) attributeValue);
} else if (attributeValue instanceof XMLGregorianCalendar) {
writeDateAttributeValue((XMLGregorianCalendar) attributeValue);
} else
throw logger.writerUnsupportedAttributeValueError(attributeValue.getClass().getName());
} else {
@ -203,6 +205,22 @@ public class BaseWriter {
StaxUtil.writeEndElement(writer);
}
public void writeDateAttributeValue(XMLGregorianCalendar attributeValue) throws ProcessingException {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_VALUE.get(), ASSERTION_NSURI.get());
StaxUtil.writeNameSpace(writer, JBossSAMLURIConstants.XSI_PREFIX.get(), JBossSAMLURIConstants.XSI_NSURI.get());
StaxUtil.writeNameSpace(writer, "xs", JBossSAMLURIConstants.XMLSCHEMA_NSURI.get());
StaxUtil.writeAttribute(writer, "xsi", JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xs:" + attributeValue.getXMLSchemaType().getLocalPart());
if (attributeValue == null) {
StaxUtil.writeAttribute(writer, "xsi", JBossSAMLURIConstants.XSI_NSURI.get(), "nil", "true");
} else {
StaxUtil.writeCharacters(writer, attributeValue.toString());
}
StaxUtil.writeEndElement(writer);
}
public void writeLocalizedNameType(LocalizedNameType localizedNameType, QName startElement) throws ProcessingException {
StaxUtil.writeStartElement(writer, startElement.getPrefix(), startElement.getLocalPart(),
startElement.getNamespaceURI());