本文整理汇总了Java中org.apache.velocity.context.Context.put方法的典型用法代码示例。如果您正苦于以下问题:Java Context.put方法的具体用法?Java Context.put怎么用?Java Context.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.velocity.context.Context
的用法示例。
在下文中一共展示了Context.put方法的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;
}
示例2: 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);
}
示例3: constructEmailMessages
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private String constructEmailMessages(EmailDetails details) {
String emailMessage = null;
if (details.getMessageTemplate() != null) {
Template template = engine.getTemplate(details.getMessageTemplate(), "UTF-8");
StringWriter writer = new StringWriter();
Context ctx = new VelocityContext();
for (Map.Entry<String, Object> entry : details.getMessageTemplateModel().entrySet()) {
ctx.put(entry.getKey(), entry.getValue());
}
ctx.put("baseUrl", baseUrl);
ctx.put("currentUser", details.getCurrentUser());
template.merge(ctx, writer);
return writer.toString();
}
if (details.getMessage() != null) {
emailMessage = details.getMessage();
}
return emailMessage;
}
示例4: renderScreenContent
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
/**
* The resulting context contains any mappings from render, plus screen content.
*/
private void renderScreenContent(Context velocityContext) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Rendering screen content template [" + getUrl() + "]");
}
StringWriter sw = new StringWriter();
Template screenContentTemplate = getTemplate(getUrl());
screenContentTemplate.merge(velocityContext, sw);
// Put rendered content into Velocity context.
velocityContext.put(this.screenContentKey, sw.toString());
}
示例5: exposeToolAttributes
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
/**
* Expose the tool attributes, according to corresponding bean property settings.
* <p>Do not override this method unless for further tools driven by bean properties.
* Override one of the {@code exposeHelpers} methods to add custom helpers.
* @param velocityContext Velocity context that will be passed to the template
* @param request current HTTP request
* @throws Exception if there's a fatal error while we're adding model attributes
* @see #setDateToolAttribute
* @see #setNumberToolAttribute
* @see #exposeHelpers(Map, HttpServletRequest)
* @see #exposeHelpers(org.apache.velocity.context.Context, HttpServletRequest, HttpServletResponse)
*/
protected void exposeToolAttributes(Context velocityContext, HttpServletRequest request) throws Exception {
// Expose generic attributes.
if (this.toolAttributes != null) {
for (Map.Entry<String, Class<?>> entry : this.toolAttributes.entrySet()) {
String attributeName = entry.getKey();
Class<?> toolClass = entry.getValue();
try {
Object tool = toolClass.newInstance();
initTool(tool, velocityContext);
velocityContext.put(attributeName, tool);
}
catch (Exception ex) {
throw new NestedServletException("Could not instantiate Velocity tool '" + attributeName + "'", ex);
}
}
}
// Expose locale-aware DateTool/NumberTool attributes.
if (this.dateToolAttribute != null || this.numberToolAttribute != null) {
if (this.dateToolAttribute != null) {
velocityContext.put(this.dateToolAttribute, new LocaleAwareDateTool(request));
}
if (this.numberToolAttribute != null) {
velocityContext.put(this.numberToolAttribute, new LocaleAwareNumberTool(request));
}
}
}
示例6: evalSubmitFormTemplate
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private String evalSubmitFormTemplate(String inputName) {
logger.log("Found input field with name '" + inputName + "'.");
// eval template
Reader r = new InputStreamReader(getClass().getResourceAsStream("/submit-form.vlt"), StandardCharsets.UTF_8);
Context ctx = createRPContext();
ctx.put("input-field", inputName);
String result = te.eval(ctx, r);
logger.log("Created Selenium script based on found input field '" + inputName + "'.");
logger.log(result);
return result;
}
示例7: doGet
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
D2RServer server = D2RServer.fromServletContext(getServletContext());
server.checkMappingFileChanged();
if (request.getPathInfo() == null) {
response.sendError(404);
return;
}
String classMapName = request.getPathInfo().substring(1);
Model resourceList = getClassMapLister().classMapInventory(
classMapName, server.getConfig().getLimitPerClassMap());
if (resourceList == null) {
response.sendError(404, "Sorry, class map '" + classMapName + "' not found.");
return;
}
Map<String,String> resources = new TreeMap<String,String>();
ResIterator subjects = resourceList.listSubjects();
while (subjects.hasNext()) {
Resource resource = subjects.nextResource();
if (!resource.isURIResource()) {
continue;
}
String uri = resource.getURI();
Statement labelStmt = PageServlet.getBestLabel(resource);
String label = (labelStmt == null) ? resource.getURI() : labelStmt.getString();
resources.put(uri, label);
}
Map<String,String> classMapLinks = new TreeMap<String,String>();
for (String name: getClassMapLister().classMapNames()) {
classMapLinks.put(name, server.baseURI() + "directory/" + name);
}
VelocityWrapper velocity = new VelocityWrapper(this, request, response);
Context context = velocity.getContext();
context.put("rdf_link", server.baseURI() + "all/" + classMapName);
context.put("classmap", classMapName);
context.put("classmap_links", classMapLinks);
context.put("resources", resources);
context.put("limit_per_class_map", server.getConfig().getLimitPerClassMap());
velocity.mergeTemplateXHTML("directory_page.vm");
}
示例8: doGet
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
D2RServer server = D2RServer.fromServletContext(getServletContext());
server.checkMappingFileChanged();
Map<String,String> classMapLinks = new TreeMap<String,String>();
ClassMapLister lister = D2RServer.retrieveSystemLoader(getServletContext()).getClassMapLister();
for (String name: lister.classMapNames()) {
classMapLinks.put(name, server.baseURI() + "directory/" + name);
}
VelocityWrapper velocity = new VelocityWrapper(this, request, response);
Context context = velocity.getContext();
context.put("rdf_link", server.baseURI() + "all");
context.put("classmap_links", classMapLinks);
velocity.mergeTemplateXHTML("root_page.vm");
}
示例9: initDefaultContext
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private static Context initDefaultContext(D2RServer server) {
Context context = new VelocityContext();
context.put("truncated_results", new Boolean(server.hasTruncatedResults()));
context.put("server_name", server.serverName());
context.put("home_link", server.baseURI());
return context;
}
示例10: renderTemplate
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
/**
* Render a template and returns the resulting string which can than be used as note content.
*
* @param templateId
* the ID of the template definition whose template should be rendered
* @param templatePropertiesJSON
* optional string in JSON which should be passed to the template engine and can
* contain any additional data the template might need. The string is converted into
* a nested map for easier processing within the template. The variable is called
* 'props'.
* @param renderContext
* the render context to use when getting the actual template from the template
* definition. The rendering context will also be put into the velocity context so it
* can be used in the template. The variable is called 'context'
* @param validateTemplateProperties
* whether to call the validator of the template definition to validate the template
* properties. In case the definition has no validator this argument is ignored.
* @return the rendered template
* @throws NoteTemplateNotFoundException
* in case there is no template definition for the given ID
* @throws NoteTemplateRenderException
* in case of an error while rendering the template
*/
public String renderTemplate(String templateId, String templatePropertiesJSON,
NoteRenderContext renderContext, boolean validateTemplateProperties)
throws NoteTemplateNotFoundException, NoteTemplateRenderException {
NoteTemplateDefinition definition = getDefinition(templateId);
if (definition == null) {
throw new NoteTemplateNotFoundException(templateId);
}
Context velocityContext = toolManager.createContext();
addTools(velocityContext);
velocityContext.put("context", renderContext);
HashMap<String, Object> jsonObject = prepareTemplateProperties(definition,
templatePropertiesJSON, validateTemplateProperties);
if (jsonObject != null) {
velocityContext.put("props", jsonObject);
}
String velocityResourceName = buildVelocityResourceName(definition,
renderContext.getMode(), renderContext.getLocale());
StringWriter result = new StringWriter();
try {
velocityEngine.mergeTemplate(velocityResourceName, "UTF-8", velocityContext, result);
} catch (VelocityException e) {
LOGGER.error("VelocityEngine couldn't render the template", e);
throw new NoteTemplateRenderException(templateId,
"VelocityEngine couldn't render the template", e);
}
return result.toString();
}
示例11: 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");
}
}
示例12: mergeScreenContent
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private void mergeScreenContent(Context velocityContext) throws Exception {
StringWriter sw = new StringWriter();
Template screenContentTemplate = getTemplate(buildViewName());
screenContentTemplate.merge(velocityContext, sw);
// Put rendered content into Velocity context.
velocityContext.put(this.screenContentKey, new ViewContent(sw.toString()));
}
示例13: generateIbatisDaoFile
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private void generateIbatisDaoFile(ClassMeta classMeta, TableMeta tableMeta) {
Template pojoVm = velocityEngine.getTemplate("daoclass.java.vm");
StringWriter sw = new StringWriter();
Context vmContext = new VelocityContext();
vmContext.put("classMeta", classMeta);
vmContext.put("tableName", tableMeta.getTableName());
vmContext.put("columnMetaList", tableMeta.getColumnMetaList());
vmContext.put("strUtils", new StrUtils());
pojoVm.merge(vmContext, sw);
// System.out.println(sw.toString());
this.outDisk(classMeta.getClassName() + "Dao.java", sw.toString());
}
示例14: generateIbatisXmlFile
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private void generateIbatisXmlFile(ClassMeta classMeta, TableMeta tableMeta) {
Template pojoVm = velocityEngine.getTemplate("ibatis-pojo.xml.vm");
StringWriter sw = new StringWriter();
Context vmContext = new VelocityContext();
vmContext.put("classMeta", classMeta);
vmContext.put("tableName", tableMeta.getTableName());
vmContext.put("columnMetaList", tableMeta.getColumnMetaList());
vmContext.put("strUtils", new StrUtils());
pojoVm.merge(vmContext, sw);
// System.out.println(sw.toString());
this.outDisk(classMeta.getClassName() + ".xml", sw.toString());
}
示例15: generatePojoClassFile
import org.apache.velocity.context.Context; //导入方法依赖的package包/类
private void generatePojoClassFile(ClassMeta classMeta, TableMeta tableMeta) {
Template pojoVm = velocityEngine.getTemplate("Pojo.java.vm");
StringWriter sw = new StringWriter();
Context vmContext = new VelocityContext();
vmContext.put("classMeta", classMeta);
vmContext.put("columnMetaList", tableMeta.getColumnMetaList());
vmContext.put("strUtils", new StrUtils());
pojoVm.merge(vmContext, sw);
outDisk(classMeta.getClassName() + ".java", sw.toString());
}