1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opensaml.saml2.metadata.impl;
22
23 import java.util.Map.Entry;
24
25 import javax.xml.namespace.QName;
26
27 import org.opensaml.Configuration;
28 import org.opensaml.common.impl.AbstractSAMLObjectMarshaller;
29 import org.opensaml.saml2.common.CacheableSAMLObject;
30 import org.opensaml.saml2.common.TimeBoundSAMLObject;
31 import org.opensaml.saml2.metadata.AffiliationDescriptor;
32 import org.opensaml.xml.XMLObject;
33 import org.opensaml.xml.io.MarshallingException;
34 import org.opensaml.xml.util.XMLHelper;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.w3c.dom.Attr;
38 import org.w3c.dom.Element;
39
40
41
42
43 public class AffiliationDescriptorMarshaller extends AbstractSAMLObjectMarshaller {
44
45
46 private final Logger log = LoggerFactory.getLogger(AffiliationDescriptorMarshaller.class);
47
48
49 protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException {
50 AffiliationDescriptor descriptor = (AffiliationDescriptor) samlElement;
51
52
53 if (descriptor.getOwnerID() != null) {
54 domElement.setAttributeNS(null, AffiliationDescriptor.OWNER_ID_ATTRIB_NAME, descriptor.getOwnerID());
55 }
56
57
58 if (descriptor.getID() != null) {
59 domElement.setAttributeNS(null, AffiliationDescriptor.ID_ATTRIB_NAME, descriptor.getID());
60 domElement.setIdAttributeNS(null, AffiliationDescriptor.ID_ATTRIB_NAME, true);
61 }
62
63
64 if (descriptor.getValidUntil() != null) {
65 log.debug("Writting validUntil attribute to AffiliationDescriptor DOM element");
66 String validUntilStr = Configuration.getSAMLDateFormatter().print(descriptor.getValidUntil());
67 domElement.setAttributeNS(null, TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME, validUntilStr);
68 }
69
70
71 if (descriptor.getCacheDuration() != null) {
72 log.debug("Writting cacheDuration attribute to AffiliationDescriptor DOM element");
73 String cacheDuration = XMLHelper.longToDuration(descriptor.getCacheDuration());
74 domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
75 }
76
77 Attr attribute;
78 for (Entry<QName, String> entry : descriptor.getUnknownAttributes().entrySet()) {
79 attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
80 attribute.setValue(entry.getValue());
81 domElement.setAttributeNodeNS(attribute);
82 if (Configuration.isIDAttribute(entry.getKey())
83 || descriptor.getUnknownAttributes().isIDAttribute(entry.getKey())) {
84 attribute.getOwnerElement().setIdAttributeNode(attribute, true);
85 }
86 }
87 }
88 }