Java 类org.springframework.ui.velocity.VelocityEngineFactoryBean 实例源码

项目:cas-5.1.0    文件:CoreSamlConfiguration.java   
@Lazy
@Bean(name = "shibboleth.VelocityEngine")
public VelocityEngineFactoryBean velocityEngineFactoryBean() {
    final VelocityEngineFactoryBean bean = new VelocityEngineFactoryBean();

    final Properties properties = new Properties();
    properties.put(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SLF4JLogChute.class.getName());
    properties.put(RuntimeConstants.INPUT_ENCODING, StandardCharsets.UTF_8.name());
    properties.put(RuntimeConstants.OUTPUT_ENCODING, StandardCharsets.UTF_8.name());
    properties.put(RuntimeConstants.ENCODING_DEFAULT, StandardCharsets.UTF_8.name());
    properties.put(RuntimeConstants.RESOURCE_LOADER, "file, classpath, string");
    properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FileUtils.getTempDirectory().getAbsolutePath());
    properties.put(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, Boolean.FALSE);
    properties.put("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    properties.put("string.resource.loader.class", StringResourceLoader.class.getName());
    properties.put("file.resource.loader.class", FileResourceLoader.class.getName());
    bean.setOverrideLogging(false);
    bean.setVelocityProperties(properties);
    return bean;
}
项目:spring4-understanding    文件:VelocityConfigurerTests.java   
@Test
public void velocityEngineFactoryBeanWithVelocityProperties() throws VelocityException, IOException {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    vefb.setVelocityProperties(props);
    Object value = new Object();
    Map<String, Object> 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"));
}
项目:class-guard    文件:VelocityConfigurerTests.java   
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()));
}
项目:ARCLib    文件:VelocityAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public VelocityEngineFactoryBean velocityConfiguration() {
    VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
    applyProperties(velocityEngineFactoryBean);
    return velocityEngineFactoryBean;
}
项目:spring4-understanding    文件:VelocityConfigurerTests.java   
@Test
public void velocityEngineFactoryBeanWithConfigLocation() 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
    }
}
项目:spring4-understanding    文件:VelocityConfigurerTests.java   
@Test
public void velocityEngineFactoryBeanWithResourceLoaderPath() 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));
}
项目:spring4-understanding    文件:VelocityConfigurerTests.java   
@Test
@SuppressWarnings("deprecation")
public void velocityEngineFactoryBeanWithNonFileResourceLoaderPath() 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", Collections.emptyMap()));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:VelocityAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public VelocityEngineFactoryBean velocityConfiguration() {
    VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
    applyProperties(velocityEngineFactoryBean);
    return velocityEngineFactoryBean;
}
项目:wonderjameeee    文件:MailConfig.java   
@Bean
public VelocityEngine velocityEngine() throws IOException {
    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");
    factory.setVelocityProperties(props);

    return factory.createVelocityEngine();
}
项目:spring-boot-concourse    文件:VelocityAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public VelocityEngineFactoryBean velocityConfiguration() {
    VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
    applyProperties(velocityEngineFactoryBean);
    return velocityEngineFactoryBean;
}
项目:contestparser    文件:VelocityAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean
public VelocityEngineFactoryBean velocityConfiguration() {
    VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
    applyProperties(velocityEngineFactoryBean);
    return velocityEngineFactoryBean;
}
项目:r01fb    文件:GuiceSpringTest.java   
@Bean @Scope("singleton")   // the method name (mockMessageService) becomes the bean "name"
VelocityEngineFactory velocityEngine() {
    Properties velocityProps = new Properties();
    velocityProps.put("resource.loader","class");
       velocityProps.put("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    VelocityEngineFactory outVelocityEngineFactory = new VelocityEngineFactoryBean();
    outVelocityEngineFactory.setVelocityProperties(velocityProps);
    return outVelocityEngineFactory;
}
项目:r01fb    文件:GuiceSpringTest.java   
@Override
protected void configure() {
    R01F.initSystemEnv();

    bind(MailManager.class).toInstance(new MailManager());

    bind(JavaMailSender.class).toInstance(GMailSMTPMailSender.create("futuretelematics",
                                                                     "qewsvvedftyinsgm"));
    bind(MailMessage.class).toInstance(new SimpleMailMessage());

    bind(VelocityEngine.class).toProvider(new Provider<VelocityEngine>() {
                                                    @Override
                                                    public VelocityEngine get() {
                                                        Properties velocityProps = new Properties();
                                                        velocityProps.put("resource.loader","class");
                                                        velocityProps.put("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

                                                        VelocityEngineFactory velocityEngineFactory = new VelocityEngineFactoryBean();
                                                        velocityEngineFactory.setVelocityProperties(velocityProps);
                                                        VelocityEngine outVelocityEngine = null;
                                                        try  {
                                                            outVelocityEngine = velocityEngineFactory.createVelocityEngine();
                                                        } catch(IOException ioEx) {
                                                            ioEx.printStackTrace(System.out);
                                                        }
                                                        return outVelocityEngine;
                                                    }
                                          })
                              .in(Singleton.class);
}
项目:mybus    文件:WebApplicationConfig.java   
@Bean
public VelocityEngine velocityEngine() throws VelocityException, IOException{
    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");
    factory.setVelocityProperties(props);
    return factory.createVelocityEngine();
}
项目:modules    文件:OpenMRSTaskDataProviderBuilderTest.java   
private int getGeneratedJSONObjectsCount(int amountOfConfigs) throws IOException {
    List<Config> simpleConfigs = new ArrayList<>();

    for(int i = 0; i < amountOfConfigs; i++) {
        Config simpleConfig = new Config();
        simpleConfig.setName("simpleConfiguration" + Integer.toString(i));
        simpleConfigs.add(simpleConfig);
    }

    Configs configs = new Configs(simpleConfigs, "simpleConfiguration");

    when(configService.getConfigs()).thenReturn(configs);
    openMRSTaskDataProviderBuilder.setOpenMRSConfigService(configService);

    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    Map<String, Object> velocityPropertiesMap = new HashMap<String, Object>();
    velocityPropertiesMap.put("resource.loader", "class");
    velocityPropertiesMap.put("class.resource.loader.class", "org.motechproject.openmrs.tasks.VelocityResourceLoader");
    vefb.setVelocityPropertiesMap(velocityPropertiesMap);

    VelocityEngine velocityEngine = vefb.createVelocityEngine();
    assertNotNull(velocityEngine);

    openMRSTaskDataProviderBuilder.setVelocityEngine(velocityEngine);

    String generatedJSON = openMRSTaskDataProviderBuilder.generateDataProvider();

    JSONObject jsonResult = new JSONObject(generatedJSON);
    JSONArray objects = jsonResult.getJSONArray("objects");

    return objects.length();
}
项目:LivingDocumentsServer    文件:VelocityConfig.java   
@Bean
public VelocityEngineFactoryBean velocityEngine() {
    VelocityEngineFactoryBean factoryBean = new VelocityEngineFactoryBean();
    Properties properties = new Properties();
    properties.put("resource.loader", "class");
    properties.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
    factoryBean.setVelocityProperties(properties);
    return factoryBean;
}
项目:class-guard    文件:VelocityConfigurerTests.java   
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
    }
}
项目:class-guard    文件:VelocityConfigurerTests.java   
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"));
}
项目:class-guard    文件:VelocityConfigurerTests.java   
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));
}
项目:Daily-Email-WebApp    文件:WebMvcContextConfiguration.java   
/**
 * Velocity engine.
 * 
 * @return the velocity engine factory bean
 */
@Bean
public VelocityEngineFactoryBean velocityEngine() {
    VelocityEngineFactoryBean velocityFactoryBean = new VelocityEngineFactoryBean();
    Properties velocityProperties = new Properties();
    velocityProperties.put("resource.loader", "class");
    velocityProperties
            .put("class.resource.loader.class",
                    "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    velocityFactoryBean.setVelocityProperties(velocityProperties);
    return velocityFactoryBean;
}
项目:hotel_shop    文件:VelocityConfig.java   
public VelocityEngineFactoryBean velocityConfiguration() {
    VelocityEngineFactoryBean velocityEngineFactoryBean = new VelocityEngineFactoryBean();
    applyProperties(velocityEngineFactoryBean);
    return velocityEngineFactoryBean;
}