Examples of VelocityEngineFactoryBean


Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

    validatorSuite = new SAML2ValidatorSuite();
  }

  protected VelocityEngine velocityEngine() {

    final VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
    velocityEngineFactoryBean.setPreferFileSystemAccess(false);
    Properties velocityEngineProperties = new Properties();
    velocityEngineProperties.setProperty("resource.loader", "classpath");
    velocityEngineProperties.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    velocityEngineFactoryBean.setVelocityProperties(velocityEngineProperties);

    try {
      return velocityEngineFactoryBean.createVelocityEngine();
    } catch (IOException e) {
      throw new RuntimeException("Unable to create velocity engine instance");
    }
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

* @author Juergen Hoeller
*/
public class VelocityConfigurerTests extends TestCase {

  public void testVelocityEngineFactoryBeanWithConfigLocation() throws VelocityException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setConfigLocation(new FileSystemResource("myprops.properties"));
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    vefb.setVelocityProperties(props);
    try {
      vefb.afterPropertiesSet();
      fail("Should have thrown IOException");
    }
    catch (IOException ex) {
      // expected
    }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

      // expected
    }
  }

  public void testVelocityEngineFactoryBeanWithVelocityProperties() throws VelocityException, IOException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    vefb.setVelocityProperties(props);
    Object value = new Object();
    Map map = new HashMap();
    map.put("myentry", value);
    vefb.setVelocityPropertiesMap(map);
    vefb.afterPropertiesSet();
    assertTrue(vefb.getObject() instanceof VelocityEngine);
    VelocityEngine ve = (VelocityEngine) vefb.getObject();
    assertEquals("/mydir", ve.getProperty("myprop"));
    assertEquals(value, ve.getProperty("myentry"));
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

    assertEquals("/mydir", ve.getProperty("myprop"));
    assertEquals(value, ve.getProperty("myentry"));
  }

  public void testVelocityEngineFactoryBeanWithResourceLoaderPath() throws IOException, VelocityException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setResourceLoaderPath("file:/mydir");
    vefb.afterPropertiesSet();
    assertTrue(vefb.getObject() instanceof VelocityEngine);
    VelocityEngine ve = (VelocityEngine) vefb.getObject();
    assertEquals(new File("/mydir").getAbsolutePath(), ve.getProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH));
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

    VelocityEngine ve = (VelocityEngine) vefb.getObject();
    assertEquals(new File("/mydir").getAbsolutePath(), ve.getProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH));
  }

  public void testVelocityEngineFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setResourceLoaderPath("file:/mydir");
    vefb.setResourceLoader(new ResourceLoader() {
      public Resource getResource(String location) {
        if (location.equals("file:/mydir") || location.equals("file:/mydir/test")) {
          return new ByteArrayResource("test".getBytes(), "test");
        }
        try {
          return new UrlResource(location);
        }
        catch (MalformedURLException ex) {
          throw new IllegalArgumentException(ex.toString());
        }
      }
      public ClassLoader getClassLoader() {
        return getClass().getClassLoader();
      }
    });
    vefb.afterPropertiesSet();
    assertTrue(vefb.getObject() instanceof VelocityEngine);
    VelocityEngine ve = (VelocityEngine) vefb.getObject();
    assertEquals("test", VelocityEngineUtils.mergeTemplateIntoString(ve, "test", new HashMap()));
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

* @author Juergen Hoeller
*/
public class VelocityConfigurerTests extends TestCase {

  public void testVelocityEngineFactoryBeanWithConfigLocation() throws VelocityException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setConfigLocation(new FileSystemResource("myprops.properties"));
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    vefb.setVelocityProperties(props);
    try {
      vefb.afterPropertiesSet();
      fail("Should have thrown IOException");
    }
    catch (IOException ex) {
      // expected
    }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

      // expected
    }
  }

  public void testVelocityEngineFactoryBeanWithVelocityProperties() throws VelocityException, IOException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    vefb.setVelocityProperties(props);
    Object value = new Object();
    Map map = new HashMap();
    map.put("myentry", value);
    vefb.setVelocityPropertiesMap(map);
    vefb.afterPropertiesSet();
    assertThat(vefb.getObject(), instanceOf(VelocityEngine.class));
    VelocityEngine ve = vefb.getObject();
    assertEquals("/mydir", ve.getProperty("myprop"));
    assertEquals(value, ve.getProperty("myentry"));
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

    assertEquals("/mydir", ve.getProperty("myprop"));
    assertEquals(value, ve.getProperty("myentry"));
  }

  public void testVelocityEngineFactoryBeanWithResourceLoaderPath() throws IOException, VelocityException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setResourceLoaderPath("file:/mydir");
    vefb.afterPropertiesSet();
    assertThat(vefb.getObject(), instanceOf(VelocityEngine.class));
    VelocityEngine ve = vefb.getObject();
    assertEquals(new File("/mydir").getAbsolutePath(), ve.getProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH));
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

    VelocityEngine ve = vefb.getObject();
    assertEquals(new File("/mydir").getAbsolutePath(), ve.getProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH));
  }

  public void testVelocityEngineFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    vefb.setResourceLoaderPath("file:/mydir");
    vefb.setResourceLoader(new ResourceLoader() {
      @Override
      public Resource getResource(String location) {
        if (location.equals("file:/mydir") || location.equals("file:/mydir/test")) {
          return new ByteArrayResource("test".getBytes(), "test");
        }
        try {
          return new UrlResource(location);
        }
        catch (MalformedURLException ex) {
          throw new IllegalArgumentException(ex.toString());
        }
      }
      @Override
      public ClassLoader getClassLoader() {
        return getClass().getClassLoader();
      }
    });
    vefb.afterPropertiesSet();
    assertThat(vefb.getObject(), instanceOf(VelocityEngine.class));
    VelocityEngine ve = vefb.getObject();
    assertEquals("test", VelocityEngineUtils.mergeTemplateIntoString(ve, "test", new HashMap()));
  }
View Full Code Here

Examples of org.springframework.ui.velocity.VelocityEngineFactoryBean

    private static final Logger log = LoggerFactory.getLogger(MailConfiguration.class);

    @Bean
    public VelocityEngine velocityEngine() throws IOException {
        log.debug("Starting Velocity Engine");
        VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
        Properties props = new Properties();

        props.put("resource.loader", "class");
        props.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        // necessary to get logs on templates's error
        props.put("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
        props.put("runtime.log.error.stacktrace", "true");
        props.put("runtime.log.warn.stacktrace", "true");
        props.put("runtime.log.info.stacktrace", "true");
        props.put("runtime.log.invalid.reference", "true");
        // TODO : FileResourceLoader could be used to externalize templates

        // enable relative includes
        props.put("eventhandler.include.class", "org.apache.velocity.app.event.implement.IncludeRelativePath");

        factory.setVelocityProperties(props);
        return factory.createVelocityEngine();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.