1. /*
  2. * Copyright 2002-2004 the original author or authors.
  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. package org.springframework.ui.velocity;
  17. import java.io.IOException;
  18. import org.apache.velocity.app.VelocityEngine;
  19. import org.apache.velocity.exception.VelocityException;
  20. import org.springframework.beans.factory.FactoryBean;
  21. import org.springframework.beans.factory.InitializingBean;
  22. import org.springframework.context.ResourceLoaderAware;
  23. /**
  24. * Factory bean that configures a VelocityEngine and provides it as bean
  25. * reference. This bean is intended for any kind of usage of Velocity in
  26. * application code, e.g. for generating email content. For web views,
  27. * VelocityConfigurer is used to set up a VelocityEngine for views.
  28. *
  29. * <p>See base class VelocityEngineFactory for configuration details.
  30. *
  31. * @author Juergen Hoeller
  32. * @see #setConfigLocation
  33. * @see #setVelocityProperties
  34. * @see #setResourceLoaderPath
  35. * @see CommonsLoggingLogSystem
  36. * @see org.springframework.web.servlet.view.velocity.VelocityConfigurer
  37. */
  38. public class VelocityEngineFactoryBean extends VelocityEngineFactory
  39. implements FactoryBean, InitializingBean, ResourceLoaderAware {
  40. private VelocityEngine velocityEngine;
  41. public void afterPropertiesSet() throws IOException, VelocityException {
  42. this.velocityEngine = createVelocityEngine();
  43. }
  44. public Object getObject() {
  45. return this.velocityEngine;
  46. }
  47. public Class getObjectType() {
  48. return VelocityEngine.class;
  49. }
  50. public boolean isSingleton() {
  51. return true;
  52. }
  53. }