001/*
002 * Copyright 2002-2014 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.config;
018
019import org.w3c.dom.Element;
020
021import org.springframework.beans.factory.support.AbstractBeanDefinition;
022import org.springframework.beans.factory.support.BeanDefinitionBuilder;
023import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
024import org.springframework.beans.factory.xml.ParserContext;
025
026
027/**
028 * Parse the <mvc:velocity-configurer> MVC namespace element and register an
029 * VelocityConfigurer bean
030 *
031 * @author Rossen Stoyanchev
032 * @since 4.1
033 */
034public class VelocityConfigurerBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
035
036        public static final String BEAN_NAME = "mvcVelocityConfigurer";
037
038        @Override
039        protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) {
040                return BEAN_NAME;
041        }
042
043        @Override
044        protected String getBeanClassName(Element element) {
045                return "org.springframework.web.servlet.view.velocity.VelocityConfigurer";
046        }
047
048        @Override
049        protected boolean isEligibleAttribute(String attributeName) {
050                return attributeName.equals("resource-loader-path");
051        }
052
053        @Override
054        protected void postProcess(BeanDefinitionBuilder builder, Element element) {
055                if (!builder.getBeanDefinition().hasAttribute("resourceLoaderPath")) {
056                        builder.getBeanDefinition().setAttribute("resourceLoaderPath", "/WEB-INF/");
057                }
058        }
059}