View Javadoc

1   /*
2    * Copyright [2007] [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 edu.internet2.middleware.shibboleth.common.config.profile;
18  
19  import org.slf4j.Logger;
20  import org.slf4j.LoggerFactory;
21  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
22  import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
23  import org.w3c.dom.Element;
24  
25  import edu.internet2.middleware.shibboleth.common.profile.provider.VelocityErrorHandler;
26  
27  /**
28   * Spring bean definition parser for {@link VelocityErrorHandler}s.
29   */
30  public class VelocityErrorHandlerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
31  
32      /** Element name. */
33      public static final String ELEMENT_NAME = "VelocityErrorHandler";
34  
35      /** Class logger. */
36      private final Logger log = LoggerFactory.getLogger(VelocityErrorHandlerBeanDefinitionParser.class);
37      
38      /** {@inheritDoc} */
39      protected Class getBeanClass(Element arg0) {
40          return VelocityErrorHandler.class;
41      }
42  
43      /** {@inheritDoc} */
44      protected void doParse(Element config, BeanDefinitionBuilder builder) {
45          log.info("Parsing configuration for velocity error handler.");
46          super.doParse(config, builder);        
47  
48          builder.addConstructorArgReference(config.getAttributeNS(null, "velocityEngine"));
49          
50          if(config.hasAttributeNS(null, "errorTemplatePath")){
51              builder.addConstructorArgValue(config.getAttributeNS(null, "errorTemplatePath"));
52          }else{
53              builder.addConstructorArgValue(config.getAttributeNS(null, "/error.vm"));
54          }
55      }
56  
57      /** {@inheritDoc} */
58      protected boolean shouldGenerateId() {
59          return true;
60      }
61  }