View Javadoc

1   /*
2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.saml2.metadata.impl;
18  
19  import org.opensaml.Configuration;
20  import org.opensaml.common.impl.AbstractSAMLObjectMarshaller;
21  import org.opensaml.saml2.common.CacheableSAMLObject;
22  import org.opensaml.saml2.common.TimeBoundSAMLObject;
23  import org.opensaml.saml2.metadata.EntitiesDescriptor;
24  import org.opensaml.xml.XMLObject;
25  import org.opensaml.xml.util.XMLHelper;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  import org.w3c.dom.Element;
29  
30  /**
31   * A thread safe Marshaller for {@link org.opensaml.saml2.metadata.EntitiesDescriptor} objects.
32   */
33  public class EntitiesDescriptorMarshaller extends AbstractSAMLObjectMarshaller {
34  
35      /** Class logger. */
36      private final Logger log = LoggerFactory.getLogger(EntitiesDescriptorMarshaller.class);
37  
38      /** {@inheritDoc} */
39      protected void marshallAttributes(XMLObject samlElement, Element domElement) {
40  
41          EntitiesDescriptor entitiesDescriptor = (EntitiesDescriptor) samlElement;
42  
43          // Set the ID attribute
44          if (entitiesDescriptor.getID() != null) {
45              log.debug("Writing ID attribute to EntitiesDescriptor DOM element.");
46              domElement.setAttributeNS(null, EntitiesDescriptor.ID_ATTRIB_NAME, entitiesDescriptor.getID());
47              domElement.setIdAttributeNS(null, EntitiesDescriptor.ID_ATTRIB_NAME, true);
48          }
49  
50          // Set the validUntil attribute
51          if (entitiesDescriptor.getValidUntil() != null) {
52              log.debug("Writting validUntil attribute to EntitiesDescriptor DOM element");
53              String validUntilStr = Configuration.getSAMLDateFormatter().print(entitiesDescriptor.getValidUntil());
54              domElement.setAttributeNS(null, TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME, validUntilStr);
55          }
56  
57          // Set the cacheDuration attribute
58          if (entitiesDescriptor.getCacheDuration() != null) {
59              log.debug("Writting cacheDuration attribute to EntitiesDescriptor DOM element");
60              String cacheDuration = XMLHelper.longToDuration(entitiesDescriptor.getCacheDuration());
61              domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
62          }
63  
64          // Set the Name attribute
65          if (entitiesDescriptor.getName() != null) {
66              log.debug("Writting Name attribute to EntitiesDescriptor DOM element");
67              domElement.setAttributeNS(null, EntitiesDescriptor.NAME_ATTRIB_NAME, entitiesDescriptor.getName());
68          }
69      }
70  }