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


Java Context类代码示例

本文整理汇总了Java中org.apache.velocity.context.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createVelocityContext

import org.apache.velocity.context.Context; //导入依赖的package包/类
/**
 * 创建velocity的Context后注如一些工具类和widget
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Context createVelocityContext(Map model, HttpServletRequest request, HttpServletResponse response)
                                                                                                            throws Exception {
    Context context = super.createVelocityContext(model, request, response);
    if (contextPath == null) {
        contextPath = request.getContextPath();
    }
    context.put("base", contextPath);

    if (viewTools == null) {
        initViewTools();
    }
    if (viewTools.size() != 0) {
        for (String name : viewTools.keySet()) {
            context.put(name, viewTools.get(name));
            logger.debug("the view tool named " + name + " is added to velocity context");
        }
    }

    context.put("widget", new Widget(applicationContext, request, response));
    return context;
}
 
开发者ID:wanghuizi,项目名称:fengduo,代码行数:26,代码来源:CustomVelocityLayoutView.java

示例2: doRender

import org.apache.velocity.context.Context; //导入依赖的package包/类
/**
 * Overrides the normal rendering process in order to pre-process the Context,
 * merging it with the screen template into a single value (identified by the
 * value of screenContentKey). The layout template is then merged with the
 * modified Context in the super class.
 */
@Override
protected void doRender(Context context, HttpServletResponse response) throws Exception {
	renderScreenContent(context);

	// Velocity context now includes any mappings that were defined
	// (via #set) in screen content template.
	// The screen template can overrule the layout by doing
	// #set( $layout = "MyLayout.vm" )
	String layoutUrlToUse = (String) context.get(this.layoutKey);
	if (layoutUrlToUse != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Screen content template has requested layout [" + layoutUrlToUse + "]");
		}
	}
	else {
		// No explicit layout URL given -> use default layout of this view.
		layoutUrlToUse = this.layoutUrl;
	}

	mergeTemplate(getTemplate(layoutUrlToUse), context, response);
}
 
开发者ID:ghimisradu,项目名称:spring-velocity-adapter,代码行数:28,代码来源:VelocityLayoutView.java

示例3: mergeTemplate

import org.apache.velocity.context.Context; //导入依赖的package包/类
/**
 * Merge the template with the context.
 * Can be overridden to customize the behavior.
 * @param template the template to merge
 * @param context the Velocity context to use for rendering
 * @param response servlet response (use this to get the OutputStream or Writer)
 * @throws Exception if thrown by Velocity
 * @see org.apache.velocity.Template#merge
 */
protected void mergeTemplate(
		Template template, Context context, HttpServletResponse response) throws Exception {

	try {
		template.merge(context, response.getWriter());
	}
	catch (MethodInvocationException ex) {
		Throwable cause = ex.getWrappedThrowable();
		throw new NestedServletException(
				"Method invocation failed during rendering of Velocity view with name '" +
				getBeanName() + "': " + ex.getMessage() + "; reference [" + ex.getReferenceName() +
				"], method '" + ex.getMethodName() + "'",
				cause==null ? ex : cause);
	}
}
 
开发者ID:ghimisradu,项目名称:spring-velocity-adapter,代码行数:25,代码来源:VelocityView.java

示例4: createVelocityContext

import org.apache.velocity.context.Context; //导入依赖的package包/类
/**
 * Overridden to create a ChainedContext, which is part of the view package
 * of Velocity Tools, as special context. ChainedContext is needed for
 * initialization of ViewTool instances.
 * @see #initTool
 */
@Override
protected Context createVelocityContext(
		Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {

	// Create a ChainedContext instance.
	ChainedContext velocityContext = new ChainedContext(
			new VelocityContext(model), getVelocityEngine(), request, response, getServletContext());

	// Load a Velocity Tools toolbox, if necessary.
	if (getToolboxConfigLocation() != null) {
		ToolboxManager toolboxManager = ServletToolboxManager.getInstance(
				getServletContext(), getToolboxConfigLocation());
		Map<String, Object> toolboxContext = toolboxManager.getToolbox(velocityContext);
		velocityContext.setToolbox(toolboxContext);
	}

	return velocityContext;
}
 
开发者ID:ghimisradu,项目名称:spring-velocity-adapter,代码行数:25,代码来源:VelocityToolboxView.java

示例5: createVelocityContext

import org.apache.velocity.context.Context; //导入依赖的package包/类
/**
 * Overridden to create a ChainedContext, which is part of the view package
 * of Velocity Tools, as special context. ChainedContext is needed for
 * initialization of ViewTool instances.
 * @see #initTool
 */
@Override
protected Context createVelocityContext(
		Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {

	// Create a ChainedContext instance.
	ChainedContext velocityContext = new ChainedContext(
			new VelocityContext(model), getVelocityEngine(), request, response, getServletContext());

	// Load a Velocity Tools toolbox, if necessary.
	if (getToolboxConfigLocation() != null) {
		ToolboxManager toolboxManager = ServletToolboxManager.getInstance(
				getServletContext(), getToolboxConfigLocation());
		Map<?, ?> toolboxContext = toolboxManager.getToolbox(velocityContext);
		velocityContext.setToolbox(toolboxContext);
	}

	return velocityContext;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:VelocityToolboxView.java

示例6: exposeSpringMacroHelpers

import org.apache.velocity.context.Context; //导入依赖的package包/类
@Test
public void exposeSpringMacroHelpers() throws Exception {
	VelocityView vv = new VelocityView() {
		@Override
		protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
			assertTrue(context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
			RequestContext rc = (RequestContext) context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
			BindStatus status = rc.getBindStatus("tb.name");
			assertEquals("name", status.getExpression());
			assertEquals("juergen", status.getValue());
		}
	};
	vv.setUrl(TEMPLATE_FILE);
	vv.setApplicationContext(wac);
	vv.setExposeSpringMacroHelpers(true);

	Map<String, Object> model = new HashMap<String, Object>();
	model.put("tb", new TestBean("juergen", 99));
	vv.render(model, request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:VelocityMacroTests.java

示例7: springMacroRequestContextAttributeUsed

import org.apache.velocity.context.Context; //导入依赖的package包/类
@Test
public void springMacroRequestContextAttributeUsed() {
	final String helperTool = "wrongType";

	VelocityView vv = new VelocityView() {
		@Override
		protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
			fail();
		}
	};
	vv.setUrl(TEMPLATE_FILE);
	vv.setApplicationContext(wac);
	vv.setExposeSpringMacroHelpers(true);

	Map<String, Object> model = new HashMap<String, Object>();
	model.put(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, helperTool);

	try {
		vv.render(model, request, response);
	}
	catch (Exception ex) {
		assertTrue(ex instanceof ServletException);
		assertTrue(ex.getMessage().contains(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:VelocityMacroTests.java

示例8: doGet

import org.apache.velocity.context.Context; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    Template template = null;

    try {
        template = velocityEngine.getTemplate("authentication.tpl");
    } catch (Exception e) {
        LOG.error("Could not find authentication.tpl");
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find authentication.tpl");
    }
    request.getSession().invalidate();

    Context context = localizedVelocityContexts.get(request.getLocale());
    if (context == null) {
        context = localizedVelocityContexts.get(Locale.ENGLISH);
    }

    StringWriter writer = new StringWriter();
    template.merge(context, writer);

    response.setContentType(TEXT_HTML);
    response.getWriter().write(writer.toString());
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:25,代码来源:AuthenticationServlet.java

示例9: doGet

import org.apache.velocity.context.Context; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    //TODO: use authentication servlet an redirect back and forth
    Template template = null;

    try {
        template = velocityEngine.getTemplate("authentication.tpl");
    } catch (Exception e) {
        LOG.error("Could not find authentication.tpl");
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find authentication.tpl");
    }
    req.getSession().invalidate();

    Context context = localizedVelocityContexts.get(req.getLocale());
    if (context == null) {
        context = localizedVelocityContexts.get(Locale.ENGLISH);
    }

    StringWriter writer = new StringWriter();
    template.merge(context, writer);

    resp.setContentType(TEXT_HTML);
    resp.getWriter().write(writer.toString());
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:26,代码来源:InstallationServlet.java

示例10: format

import org.apache.velocity.context.Context; //导入依赖的package包/类
public static String format(VelocityEngine ve,String pattern, Object dataModel){
	if(ve == null){
		ve = VlocityFormat.ve;
	}
	Context context = createVelocityContext(dataModel);

	//raw return 
	if(context == null){
		return pattern;
	}
	
	StringWriter writer = new StringWriter();
	ve.evaluate(context, writer, "logTag", pattern);
	
	return writer.toString();
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:17,代码来源:VlocityFormat.java

示例11: createVelocityContext

import org.apache.velocity.context.Context; //导入依赖的package包/类
@Override
protected Context createVelocityContext(Map<String, Object> model,
		HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	ViewToolContext velocityContext = new ViewToolContext(getVelocityEngine(), request, response, getServletContext());
	velocityContext.putAll(model);
	if(getToolboxConfigLocation() != null ||getToolboxConfigResource() != null){
		XmlFactoryConfiguration cfg = new XmlFactoryConfiguration();
		URL cfgUrl;
		if(getToolboxConfigLocation() != null){
			cfgUrl = new ServletContextResource(getServletContext(), getToolboxConfigLocation()).getURL();
			cfg.read(cfgUrl);
		}else if(getToolboxConfigResource() != null){
			cfgUrl = getToolboxConfigResource().getURL();
			cfg.read(cfgUrl);
			ToolboxFactory factory = cfg.createFactory();
			
			velocityContext.addToolbox(factory.createToolbox(Scope.APPLICATION));
			velocityContext.addToolbox(factory.createToolbox(Scope.REQUEST));
			velocityContext.addToolbox(factory.createToolbox(Scope.SESSION));
		}
	}
	return velocityContext;
}
 
开发者ID:ivaneye,项目名称:java-template-simple,代码行数:25,代码来源:VelocityToolboxView.java

示例12: render

import org.apache.velocity.context.Context; //导入依赖的package包/类
public void render(String template, PortalRenderContext rcontext, Writer out)
		throws Exception
{
	if (log.isTraceEnabled()) {
	   log.trace("Portal trace is on, dumping PortalRenderContext to log:\n" + rcontext.dump());
	}
	
	Context vc = ((VelocityPortalRenderContext) rcontext).getVelocityContext();
	String skin = (String) vc.get("pageCurrentSkin");
	if (skin == null || skin.length() == 0)
	{
		skin = defaultSkin;
	}
	if (!defaultSkin.equals(skin))
	{
		vengine.getTemplate("/vm/" + skin + "/macros.vm");
	}
	vengine.mergeTemplate("/vm/" + skin + "/" + template + ".vm",
			((VelocityPortalRenderContext) rcontext).getVelocityContext(), out);

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:22,代码来源:VelocityPortalRenderEngine.java

示例13: getTaskDeletedMailBody

import org.apache.velocity.context.Context; //导入依赖的package包/类
private String getTaskDeletedMailBody(final UserRequest ureq, final String fileName, final String courseName, final String courseLink) {
    // grab standard text
    final String confirmation = translate("task.deleted.body");

    final Context c = new VelocityContext();
    final Identity identity = ureq.getIdentity();
    c.put("login", identity.getName());
    c.put("first", getUserService().getUserProperty(identity.getUser(), UserConstants.FIRSTNAME, getLocale()));
    c.put("last", getUserService().getUserProperty(identity.getUser(), UserConstants.LASTNAME, getLocale()));
    c.put("email", getUserService().getUserProperty(identity.getUser(), UserConstants.EMAIL, getLocale()));
    c.put("filename", fileName);
    c.put("coursename", courseName);
    c.put("courselink", courseLink);
    final VelocityHelper vh = (VelocityHelper) CoreSpringFactory.getBean(VelocityHelper.class);
    return vh.evaluateVTL(confirmation, c);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:17,代码来源:TACourseNodeEditController.java

示例14: render

import org.apache.velocity.context.Context; //导入依赖的package包/类
/**
 * org.olat.presentation.framework.components.Component, org.olat.presentation.framework.render.URLBuilder, org.olat.presentation.framework.translator.Translator,
 * org.olat.presentation.framework.render.RenderResult, java.lang.String[])
 */
@Override
public void render(Renderer renderer, StringOutput target, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    VelocityContainer vc = (VelocityContainer) source;
    String pagePath = vc.getPage();
    Context ctx = vc.getContext();

    // the component id of the urlbuilder will be overwritten by the recursive render call for
    // subcomponents (see Renderer)
    Renderer fr = Renderer.getInstance(vc, translator, ubu, renderResult, renderer.getGlobalSettings());
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(fr, vc);
    ctx.put("r", vrdec);
    String mm = velocityHelper.mergeContent(pagePath, ctx, theme);

    // experimental!!!
    // surround with red border if recording mark indicates so.
    if (vc.markingCommandString != null) {
        target.append("<table style=\"border:3px solid red; background-color:#E0E0E0; padding:4px; margin:0px;\"><tr><td>").append(mm).append("</td></tr></table>");
    } else {
        target.append(mm);
    }
}
 
开发者ID:huihoo,项目名称:olat,代码行数:26,代码来源:VelocityContainerRenderer.java

示例15: getConfirmation

import org.apache.velocity.context.Context; //导入依赖的package包/类
private String getConfirmation(final UserRequest ureq, final String filename) {
    // grab standard text
    final String confirmation = getDefaultConfirmationText();

    final Context c = new VelocityContext();
    final Identity identity = ureq.getIdentity();
    c.put("login", identity.getName());
    c.put("first", getUserService().getUserProperty(identity.getUser(), UserConstants.FIRSTNAME, getLocale()));
    c.put("last", getUserService().getUserProperty(identity.getUser(), UserConstants.LASTNAME, getLocale()));
    c.put("email", getUserService().getUserProperty(identity.getUser(), UserConstants.EMAIL, getLocale()));
    c.put("filename", filename);
    final Date now = new Date();
    final Formatter f = Formatter.getInstance(ureq.getLocale());
    c.put("date", f.formatDate(now));
    c.put("time", f.formatTime(now));

    VelocityHelper vh = CoreSpringFactory.getBean(VelocityHelper.class);
    return vh.evaluateVTL(confirmation, c);
}
 
开发者ID:huihoo,项目名称:olat,代码行数:20,代码来源:AbstractDropboxBaseController.java


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