本文整理汇总了Java中org.apache.velocity.context.Context.get方法的典型用法代码示例。如果您正苦于以下问题:Java Context.get方法的具体用法?Java Context.get怎么用?Java Context.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.velocity.context.Context
的用法示例。
在下文中一共展示了Context.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: testExposeSpringMacroHelpers
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public void testExposeSpringMacroHelpers() 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);
}
示例5: doRender
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
@Override
protected void doRender(Context context, HttpServletResponse response) throws Exception {
renderScreenContent(context);
String layoutUrlToUse = (String) context.get(this.layoutKey);
if(layoutUrlToUse == null){
layoutUrlToUse = this.layoutUrl;
}
mergeTemplate(getTemplate(getTotalLayoutUrl(layoutUrlToUse)), context, response);
}
示例6: outputContent
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public void outputContent(PrintWriter writer, Context context)
throws Exception {
ExampleCategory category = (ExampleCategory) context.get("category");
String summary = StringUtils.defaultIfEmpty(category.getSummary(),
"''(no description)''");
String html = BikiUtils.render(summary);
writer.append(html);
}
示例7: buildCloudoLink
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public void buildCloudoLink(PrintWriter writer, Context context)
throws Exception {
Example example = (Example) context.get("example");
String url = example.getUrl();
if (PathUtils.match("*com.bstek.dorado.sample.*.d", url)) {
String viewName = StringUtils.substringBeforeLast(url, ".d").replace(".", "/");
context.put("cloudoLink", "dorado/cloudo/vidor?url=" + viewName+ ".view.xml");
}
}
示例8: outputContent
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public void outputContent(PrintWriter writer, Context context)
throws Exception {
Example example = (Example) context.get("example");
String summary = StringUtils.defaultIfEmpty(example.getSummary(),
"''(no description)''");
String html = BikiUtils.render(summary);
writer.append(html);
}
示例9: doRender
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
protected void doRender(Context context, HttpServletResponse response) throws Exception {
Object o = context.get(Widget.IS_WIDGET);
Object layout = context.get(USE_LAYOUT);
// widget时不需要布局
if (o != null && "true".equals(o.toString())) {
renderScreenContent(context, response, getUrl());
}
// 手工设置不需要布局时,不需要布局
else if (layout != null && "false".equals(layout.toString())) {
renderScreenContent(context, response, buildViewName());
} else {
mergeScreenContent(context);
mergeTemplate(getLayoutTemplate(buildViewName()), context, response);
}
}
示例10: render
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public void render(String template, LoginRenderContext rcontext, Writer out)
throws Exception {
Context vc = ((VelocityLoginRenderContext) 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",
((VelocityLoginRenderContext) rcontext).getVelocityContext(), out);
}
示例11: isInContain
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public static boolean isInContain(Context context) {
// 如果是在执行一个contain渲染,则无需layout,执行普通渲染逻辑即可
Integer cCount = (Integer) context.get(Contain.ContainCounterKey);
if (cCount != null && cCount > 0) {
return true;
}
return false;
}
示例12: isInContain
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private boolean isInContain(Context context) {
Integer cCount = (Integer) context.get(Contain.ContainCounterKey);
if (cCount != null && cCount > 0) {
return true;
}
return false;
}
示例13: doRender
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
@Override
protected void doRender(Context context, HttpServletResponse response)
throws Exception {
if (isInAsyncContain()) {
if (logger.isDebugEnabled()) {
logger.debug("in async contain render for:" + this.getUrl());
}
renderCotainContent(context, response);
return;
}
if (isInContain(context)) {
if (logger.isDebugEnabled()) {
logger.debug("in contain render for:" + this.getUrl());
}
renderCotainContent(context, response);
return;
}
renderScreenContent(context);
try {
String layoutUrlToUse = (String) context.get(this.layoutKey);
if (StringUtils.isNotBlank(layoutUrlToUse)) {
if (logger.isDebugEnabled()) {
logger.debug("Screen content template has requested layout ["
+ layoutUrlToUse + "]");
}
mergeTemplate(getTemplate(layoutUrlToUse), context, response);
} else {
if (layoutUrlToUse == null) {
mergeTemplate(findLayoutTemplate(), context, response);
} else {
screenLocal.get().writeTo(response.getWriter());
}
}
} finally {
screenLocal.get().reset();
}
}
示例14: testExposeHelpers
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
@Test
public void testExposeHelpers() throws Exception {
final String templateName = "test.vm";
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
final Template expectedTemplate = new Template();
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine(templateName, expectedTemplate);
}
};
Map<String, VelocityConfig> configurers = new HashMap<String, VelocityConfig>();
configurers.put("velocityConfigurer", vc);
given(wac.getBeansOfType(VelocityConfig.class, true, false)).willReturn(configurers);
// let it ask for locale
HttpServletRequest req = mock(HttpServletRequest.class);
given(req.getAttribute(View.PATH_VARIABLES)).willReturn(null);
given(req.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).willReturn(new AcceptHeaderLocaleResolver());
given(req.getLocale()).willReturn(Locale.CANADA);
final HttpServletResponse expectedResponse = new MockHttpServletResponse();
VelocityView vv = new VelocityView() {
@Override
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
assertTrue(template == expectedTemplate);
assertTrue(response == expectedResponse);
assertEquals("myValue", context.get("myHelper"));
assertTrue(context.get("math") instanceof MathTool);
assertTrue(context.get("dateTool") instanceof DateTool);
DateTool dateTool = (DateTool) context.get("dateTool");
assertTrue(dateTool.getLocale().equals(Locale.CANADA));
assertTrue(context.get("numberTool") instanceof NumberTool);
NumberTool numberTool = (NumberTool) context.get("numberTool");
assertTrue(numberTool.getLocale().equals(Locale.CANADA));
}
@Override
protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
model.put("myHelper", "myValue");
}
};
vv.setUrl(templateName);
vv.setApplicationContext(wac);
Map<String, Class<?>> toolAttributes = new HashMap<String, Class<?>>();
toolAttributes.put("math", MathTool.class);
vv.setToolAttributes(toolAttributes);
vv.setDateToolAttribute("dateTool");
vv.setNumberToolAttribute("numberTool");
vv.setExposeSpringMacroHelpers(false);
vv.render(new HashMap<String, Object>(), req, expectedResponse);
assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, expectedResponse.getContentType());
}
示例15: testVelocityToolboxView
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
@Test
public void testVelocityToolboxView() throws Exception {
final String templateName = "test.vm";
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
final Template expectedTemplate = new Template();
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine(templateName, expectedTemplate);
}
};
wac.getDefaultListableBeanFactory().registerSingleton("velocityConfigurer", vc);
final HttpServletRequest expectedRequest = new MockHttpServletRequest();
final HttpServletResponse expectedResponse = new MockHttpServletResponse();
VelocityToolboxView vv = new VelocityToolboxView() {
@Override
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
assertTrue(template == expectedTemplate);
assertTrue(response == expectedResponse);
assertTrue(context instanceof ChainedContext);
assertEquals("this is foo.", context.get("foo"));
assertTrue(context.get("map") instanceof HashMap<?,?>);
assertTrue(context.get("date") instanceof DateTool);
assertTrue(context.get("math") instanceof MathTool);
assertTrue(context.get("link") instanceof LinkTool);
LinkTool linkTool = (LinkTool) context.get("link");
assertNotNull(linkTool.getContextURL());
assertTrue(context.get("link2") instanceof LinkTool);
LinkTool linkTool2 = (LinkTool) context.get("link2");
assertNotNull(linkTool2.getContextURL());
}
};
vv.setUrl(templateName);
vv.setApplicationContext(wac);
Map<String, Class<?>> toolAttributes = new HashMap<String, Class<?>>();
toolAttributes.put("math", MathTool.class);
toolAttributes.put("link2", LinkTool.class);
vv.setToolAttributes(toolAttributes);
vv.setToolboxConfigLocation("org/springframework/web/servlet/view/velocity/toolbox.xml");
vv.setExposeSpringMacroHelpers(false);
vv.render(new HashMap<String,Object>(), expectedRequest, expectedResponse);
}