当前位置: 首页>>代码示例>>Java>>正文


Java VelocityEngine.setApplicationAttribute方法代码示例

本文整理汇总了Java中org.apache.velocity.app.VelocityEngine.setApplicationAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityEngine.setApplicationAttribute方法的具体用法?Java VelocityEngine.setApplicationAttribute怎么用?Java VelocityEngine.setApplicationAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.velocity.app.VelocityEngine的用法示例。


在下文中一共展示了VelocityEngine.setApplicationAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postProcessVelocityEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Provides a ClasspathResourceLoader in addition to any default or user-defined
 * loader in order to load the spring Velocity macros from the class path.
 * @see org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
 */
@Override
protected void postProcessVelocityEngine(VelocityEngine velocityEngine) {
	velocityEngine.setApplicationAttribute(ServletContext.class.getName(), this.servletContext);
	velocityEngine.setProperty(
			SPRING_MACRO_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
	velocityEngine.addProperty(
			VelocityEngine.RESOURCE_LOADER, SPRING_MACRO_RESOURCE_LOADER_NAME);
	velocityEngine.addProperty(
			VelocityEngine.VM_LIBRARY, SPRING_MACRO_LIBRARY);

	if (logger.isInfoEnabled()) {
		logger.info("ClasspathResourceLoader with name '" + SPRING_MACRO_RESOURCE_LOADER_NAME +
				"' added to configured VelocityEngine");
	}
}
 
开发者ID:ghimisradu,项目名称:spring-velocity-adapter,代码行数:21,代码来源:VelocityConfigurer.java

示例2: initSpringResourceLoader

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Initialize a SpringResourceLoader for the given VelocityEngine.
 * <p>Called by {@code initVelocityResourceLoader}.
 * @param velocityEngine the VelocityEngine to configure
 * @param resourceLoaderPath the path to load Velocity resources from
 * @see SpringResourceLoader
 * @see #initVelocityResourceLoader
 */
protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
	velocityEngine.setProperty(
			RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME);
	velocityEngine.setProperty(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName());
	velocityEngine.setProperty(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true");
	velocityEngine.setApplicationAttribute(
			SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader());
	velocityEngine.setApplicationAttribute(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:VelocityEngineFactory.java

示例3: initSpringResourceLoader

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Initialize a SpringResourceLoader for the given VelocityEngine.
 * <p>Called by {@code initVelocityResourceLoader}.
 *
 * @param velocityEngine     the VelocityEngine to configure
 * @param resourceLoaderPath the path to load Velocity resources from
 * @see SpringResourceLoader
 * @see #initVelocityResourceLoader
 */
protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
    velocityEngine.setProperty(
            RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME);
    velocityEngine.setProperty(
            SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName());
    velocityEngine.setProperty(
            SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true");
    velocityEngine.setApplicationAttribute(
            SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader());
    velocityEngine.setApplicationAttribute(
            SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath);
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:22,代码来源:VelocityEngineFactory.java

示例4: initSpringResourceLoader

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
protected void initSpringResourceLoader(VelocityEngine velocityEngine, String resourceLoaderPath) {
	velocityEngine.setProperty(
			RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME);
	velocityEngine.setProperty(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, SpringResourceLoader.class.getName());
	velocityEngine.setProperty(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_CACHE, "true");
	velocityEngine.setApplicationAttribute(
			SpringResourceLoader.SPRING_RESOURCE_LOADER, getResourceLoader());
	velocityEngine.setApplicationAttribute(
			SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPath);
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:13,代码来源:EmailEngine.java

示例5: getVelocityEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Produces
@ViewEngineConfig
public VelocityEngine getVelocityEngine() {
    VelocityEngine velocityEngine = new VelocityEngine();
    velocityEngine.setProperty("resource.loader", "webapp");
    velocityEngine.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getCanonicalName());
    velocityEngine.setApplicationAttribute("javax.servlet.ServletContext", servletContext);
    velocityEngine.init();
    return velocityEngine;
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:11,代码来源:DefaultVelocityEngineProducer.java

示例6: main

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static void main(String[] args) {
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

ve.init();

String path = ve.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH) + File.separator;
Object path1 = ve.getProperty(Velocity.RESOURCE_LOADER) + File.separator;

ve.setApplicationAttribute("app_chen", "app--------------------------");
Template t = ve.getTemplate("org/apache/velocity/demo/hellovelocity.vm");
//Template t = ve.getTemplate("D:/hellovelocity.vm");


VelocityContext ctx = new VelocityContext();

ctx.put("name", "velocity");
ctx.put("date1", (new Date()).toString());
ctx.put("dateO", new Date());
ctx.put("staticUser", User.class);
ctx.put("orderBusinessType", OrderBusinessType.class);
ctx.put("orderBusinessTypeOne", OrderBusinessType.RDPS);

User user =  User.getUser();

ctx.put("user",user);

List temp = new ArrayList();
temp.add("1");
temp.add("2");
temp.add("322");
ctx.put("list", temp);

StringWriter sw = new StringWriter();

t.merge(ctx, sw);

System.out.println(sw.toString());
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:41,代码来源:HelloVelocity.java

示例7: newVelocityEngine

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * <p>
 * Instantiates a new VelocityEngine.
 * </p>
 * <p>
 * The following is the default Velocity configuration
 * </p>
 *
 * <pre>
 *  resource.loader = file, class
 *  file.resource.loader.path = real path of webapp
 *  class.resource.loader.description = Velocity Classpath Resource Loader
 *  class.resource.loader.class = org.apache.struts2.views.velocity.StrutsResourceLoader
 * </pre>
 * <p>
 * this default configuration can be overridden by specifying a struts.velocity.configfile property in the
 * struts.properties file.  the specified config file will be searched for in the following order:
 * </p>
 *
 * <ul>
 * <li>relative to the servlet context path</li>
 * <li>relative to the WEB-INF directory</li>
 * <li>on the classpath</li>
 * </ul>
 *
 * @param context the current ServletContext. may <b>not</b> be null
 *
 * @return the new velocity engine
 */
protected VelocityEngine newVelocityEngine(ServletContext context) {
    if (context == null) {
        String gripe = "Error attempting to create a new VelocityEngine from a null ServletContext!";
        LOG.error(gripe);
        throw new IllegalArgumentException(gripe);
    }

    Properties p = loadConfiguration(context);

    VelocityEngine velocityEngine = new VelocityEngine();

    //  Set the velocity attribute for the servlet context
    //  if this is not set the webapp loader WILL NOT WORK
    velocityEngine.setApplicationAttribute(ServletContext.class.getName(),
            context);

    try {
        velocityEngine.init(p);
    } catch (Exception e) {
        throw new StrutsException("Unable to instantiate VelocityEngine!", e);
    }

    return velocityEngine;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:54,代码来源:VelocityManager.java

示例8: init

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Initialise the velocity and hibernate engine.
 * @see HttpServlet#init()
 */
@Override
public void init() {

	log.info("Initialising servlet");

	// Create the velocity properties.
	Properties props = new Properties();
	props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute");
	props.setProperty("resource.loader", "webapp");
	props.setProperty("webapp.resource.loader.class", "org.apache.velocity.tools.view.WebappResourceLoader");
	props.setProperty("webapp.resource.loader.path", "/WEB-INF/templates/");

	// IMPORTANT: Make sure to add the servlet context before calling
	// init().
	velocityEngine = new VelocityEngine(props);
	velocityEngine.setApplicationAttribute("javax.servlet.ServletContext", this.getServletContext());

	// Initialise the engine.
	velocityEngine.init();

	// Attempt to initialise hibernate.
	// Doing this in servlet initialisation means the first request doesn't have to perform this action.
	HibernateUtil.getSessionFactory().openSession().close();
	
	// Fetch the pepper from the servlet.
	// Load up any context parameters and put them into the configuration object.
	TiramisuConfiguration.pepper = getServletContext().getInitParameter("pepper");
	
	// Add the routes to the application.
	// These are controlled by the 
	try {
		// User Index Method
		routeList.add(new Route(Pattern.compile("^.*\\/users[/]?$"), Arrays.asList("GET"), UserController.class, UserController.class.getDeclaredMethod("index")));
		
		// User Read Method
		routeList.add(new Route(Pattern.compile("^.*/users/([0-9]{1,})[/]?$"), Arrays.asList("GET"), UserController.class, UserController.class.getDeclaredMethod("read", String.class)));
		
		// User Register Method
		routeList.add(new Route(Pattern.compile("^.*/users/register[/]?$"), Arrays.asList("GET", "POST"), UserController.class, UserController.class.getDeclaredMethod("register")));
		
		// User Login Method
		routeList.add(new Route(Pattern.compile("^.*/login[/]?$"), Arrays.asList("GET", "POST"), UserController.class, UserController.class.getDeclaredMethod("login")));
		
		// User Logout Method.
		routeList.add(new Route(Pattern.compile("^.*/logout[/]?$"), Arrays.asList("GET"), UserController.class, UserController.class.getDeclaredMethod("logout")));
	
	} catch (NoSuchMethodException | SecurityException e) {
		e.printStackTrace();
	}
}
 
开发者ID:arcynum,项目名称:tiramisu,代码行数:55,代码来源:RouterServlet.java


注:本文中的org.apache.velocity.app.VelocityEngine.setApplicationAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。