View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.Map;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.opensaml.xml.util.DatatypeHelper;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
30  import org.springframework.beans.factory.xml.ParserContext;
31  import org.w3c.dom.Element;
32  
33  /**
34   * Spring bean definition parser for scripted attribute configuration elements.
35   */
36  public class TemplateAttributeDefinitionBeanDefinitionParser extends BaseAttributeDefinitionBeanDefinitionParser {
37  
38      /** Schema type name. */
39      public static final QName TYPE_NAME = new QName(AttributeDefinitionNamespaceHandler.NAMESPACE, "Template");
40  
41      /** SourceValue element name. */
42      public static final QName TEMPLATE_ELEMENT_NAME = new QName(AttributeDefinitionNamespaceHandler.NAMESPACE,
43              "Template");
44  
45      /** SourceValue element name. */
46      public static final QName SOURCE_ATTRIBUTE_ELEMENT_NAME = new QName(AttributeDefinitionNamespaceHandler.NAMESPACE,
47              "SourceAttribute");
48  
49      /** Class logger. */
50      @SuppressWarnings("unused")
51      private final Logger log = LoggerFactory.getLogger(TemplateAttributeDefinitionBeanDefinitionParser.class);
52  
53      /** {@inheritDoc} */
54      protected Class getBeanClass(Element arg0) {
55          return TemplateAttributeDefinitionFactoryBean.class;
56      }
57  
58      /** {@inheritDoc} */
59      protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
60              BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
61          super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);
62  
63          if (pluginConfigChildren.containsKey(TEMPLATE_ELEMENT_NAME)) {
64              Element templateElement = pluginConfigChildren.get(TEMPLATE_ELEMENT_NAME).get(0);
65              String attributeTemplate = DatatypeHelper.safeTrimOrNullString(templateElement.getTextContent());
66              pluginBuilder.addPropertyValue("attributeTemplate", attributeTemplate);
67          }
68  
69          List<String> sourceAttributes = new ArrayList<String>();
70          for (Element element : pluginConfigChildren.get(SOURCE_ATTRIBUTE_ELEMENT_NAME)) {
71              sourceAttributes.add(DatatypeHelper.safeTrimOrNullString(element.getTextContent()));
72          }
73          pluginBuilder.addPropertyValue("sourceAttributes", sourceAttributes);
74          
75          String velocityEngineRef = pluginConfig.getAttributeNS(null, "velocityEngine");
76          pluginBuilder.addPropertyReference("velocityEngine", velocityEngineRef);
77      }
78  }