本文整理汇总了Java中org.apache.velocity.VelocityContext.put方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityContext.put方法的具体用法?Java VelocityContext.put怎么用?Java VelocityContext.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.velocity.VelocityContext
的用法示例。
在下文中一共展示了VelocityContext.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
private void sendEmail(final String fromEmail, final IUser to, final String inSubject, final String inTemplate, final Map<String, Object> values) {
final Properties props = new Properties();
props.setProperty("resource.loader", "class");
props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
final VelocityEngine engine = new VelocityEngine(props);
final VelocityContext context = new VelocityContext();
engine.init();
for(final String key : values.keySet()) {
LOGGER.debug(() -> String.format("\t -- %s=%s", key, values.get(key)));
context.put(key, values.get(key));
}
final StringWriter writer = new StringWriter();
final Template template = engine.getTemplate("templates/" + inTemplate);
template.merge(context, writer);
final String inBody = writer.toString();
sendEmail(fromEmail, to.getEmail(), inSubject, inBody);
}
示例2: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/action-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例3: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if(!((PermissionService)permissionStore).isAdmin()){
throw new NoPermissionException();
}
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/permission-config-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例4: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
String file=req.getParameter("file");
String project = buildProjectNameFromFile(file);
if(project!=null){
context.put("project", project);
}
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/decisiontree-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例5: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/variable-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例6: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/parameter-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例7: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("uflo-html/designer.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例8: execute
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
String file=req.getParameter("file");
file=Utils.decodeURL(file);
String project = buildProjectNameFromFile(file);
if(project!=null){
context.put("project", project);
}
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("html/ruleset-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例9: writeUIOther
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
protected void writeUIOther(String destResourcePath, List<String> tables, List<String> modelNames, List<String> varModelNames) throws IOException {
Template indexHtml = VelocityUtil.getTempate("/templates/pom/ui/html/index.vm");
VelocityContext ctx = new VelocityContext();
ctx.put("modelNames", modelNames);
ctx.put("tables", tables);
ctx.put("varModelNames", varModelNames);
ctx.put("project", this.project);
ctx.put("project", VelocityUtil.tableNameConvertModelName(this.project.split("-")[0]));
ctx.put("miniProject", VelocityUtil.tableNameConvertModelName(this.project.split("-")[0]).substring(0, 1));
write(merge(indexHtml, ctx), destResourcePath + "/static/index.html");
}
示例10: writeUI
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
protected void writeUI(String destResourcePath, VelocityContext ctx, String tableName, String primaryKey, List<MetaData> metaDates) throws IOException {
String uiSrcFilePath = getUISrcFilePath();
if (uiSrcFilePath == null) {
return;
}
Template template = VelocityUtil.getTempate(uiSrcFilePath);
List<String> filedNames = new ArrayList<>();
List<String> varFiledNames = new ArrayList<>();
for (MetaData metaDate : metaDates) {
filedNames.add(VelocityUtil.tableNameConvertModelName(metaDate.getColumnName()));
varFiledNames.add(VelocityUtil.toHump(metaDate.getColumnName()));
}
ctx.put("filedNames", filedNames);
ctx.put("varFiledNames", varFiledNames);
ctx.put("primaryKey", primaryKey);
ctx.put("modelName", VelocityUtil.tableNameConvertModelName(tableName));
ctx.put("varModelName", VelocityUtil.toHump(tableName));
if (getUIComponentFilesDestDirectoryPath() != null) {
for (String componentFile : getUIComponentFilesPath()) {
Template tc = VelocityUtil.getTempate(componentFile);
int ext = componentFile.lastIndexOf(".");
write(merge(tc, ctx), (destResourcePath + "/" + getUIComponentFilesDestDirectoryPath()).replaceAll("[/]+", "/") + "/" + tableName + componentFile.substring(ext));
}
}
write(merge(template, ctx), (destResourcePath + "/" + getUIDestDirectoryPath()).replaceAll("[/]+", "/") + "/" + tableName + ".html");
}
示例11: populateVelocityContext
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void populateVelocityContext(VelocityContext velocityContext, SAMLMessageContext messageContext,
String endpointURL) throws MessageEncodingException {
super.populateVelocityContext(velocityContext, messageContext, endpointURL);
Credential signingCredential = messageContext.getOuboundSAMLMessageSigningCredential();
if (signingCredential == null) {
log.debug("No signing credential was supplied, skipping HTTP-Post simple signing");
return;
}
// TODO pull SecurityConfiguration from SAMLMessageContext? needs to be added
// TODO pull binding-specific keyInfoGenName from encoder setting, etc?
String sigAlgURI = getSignatureAlgorithmURI(signingCredential, null);
velocityContext.put("SigAlg", sigAlgURI);
String formControlData = buildFormDataToSign(velocityContext, messageContext, sigAlgURI);
velocityContext.put("Signature", generateSignature(signingCredential, sigAlgURI, formControlData));
KeyInfoGenerator kiGenerator = SecurityHelper.getKeyInfoGenerator(signingCredential, null, null);
if (kiGenerator != null) {
String kiBase64 = buildKeyInfo(signingCredential, kiGenerator);
if (!DatatypeHelper.isEmpty(kiBase64)) {
velocityContext.put("KeyInfo", kiBase64);
}
}
}
示例12: doHandleRequest
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
protected ModelAndView doHandleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
Properties properties=new Properties();
properties.setProperty("resource.loader", "file");
properties.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
String contextPath=request.getContextPath();
if(!contextPath.endsWith("/")){
contextPath+="/";
}
VelocityEngine velocityEngine=new VelocityEngine(properties);
VelocityContext context=new VelocityContext();
StringBuffer sb=new StringBuffer();
sb.append("\r");
sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\""+contextPath+"dorado/res/dorado/resources/jquery.contextMenu.css\" />");
sb.append("\r");
sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\""+contextPath+"dorado/res/dorado/resources/jquery-ui-1.8.19.custom.css\" />");
sb.append("\r");
sb.append("<script type=\"text/javascript\" src=\""+contextPath+"dorado/res/dorado/scripts/jbpm4-designer-all-in-one.js\"></script>");
sb.append("\r");
String serverUrl=this.buildServerUrl(request.getScheme(),request.getServerName(),request.getServerPort());
if(contextPath.endsWith("/")){
serverUrl+=contextPath.substring(0,contextPath.length()-1);
}
context.put("cssandscript", sb.toString());
context.put("baseIconsDir", contextPath+"dorado/res/dorado/resources");
context.put("serverUrl", serverUrl);
StringWriter writer=new StringWriter();
velocityEngine.mergeTemplate("dorado/resources/jbpm4-designer.html","utf-8", context, writer);
response.setContentType("text/html; charset=utf-8");
PrintWriter out=response.getWriter();
out.write(writer.toString());
out.flush();
out.close();
return null;
}
示例13: generate
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
public static void generate(String projectPath, BeanTemplate beanTemplate, Template template){
try{
String beanPackage = beanTemplate.getPackageName();
String className = beanTemplate.getClzName();
beanPackage = beanPackage.replaceAll("\\.", "\\/");
File folder = new File(projectPath+beanPackage);
if (!folder.exists()){
folder.mkdirs();
}
File file = new File(projectPath+beanPackage+"/"+ className+".java");
VelocityContext context = new VelocityContext();
context.put("package", beanTemplate.getPackageName());
context.put("className", className);
context.put("propList", beanTemplate.getPropList());
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(file)));
if ( template != null)
template.merge(context, writer);
writer.flush();
writer.close();
}catch( Exception e ){
System.out.println(e);
}
}
示例14: writeUIOther
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
@Override
protected void writeUIOther(String destResourcePath, List<String> tables, List<String> modelNames, List<String> varModelNames) throws IOException {
Template indexHtml = VelocityUtil.getTempate("/templates/pom/ui/angular1/index.vm");
Template indexJs = VelocityUtil.getTempate("/templates/pom/ui/angular1/indexjs.vm");
Template confirmModal = VelocityUtil.getTempate("/templates/pom/ui/angular1/confirm_modal.html");
VelocityContext ctx = new VelocityContext();
ctx.put("modelNames", modelNames);
ctx.put("tables", tables);
ctx.put("varModelNames", varModelNames);
ctx.put("project", VelocityUtil.tableNameConvertModelName(this.project.split("-")[0]));
ctx.put("miniProject", VelocityUtil.tableNameConvertModelName(this.project.split("-")[0]).substring(0, 1));
write(merge(indexHtml, ctx), destResourcePath + "/static/index.html");
write(merge(indexJs, ctx), destResourcePath + "/static/js/app.js");
write(merge(confirmModal, ctx), destResourcePath + "/static/confirm_modal.html");
}
示例15: buildEmailTemplate
import org.apache.velocity.VelocityContext; //导入方法依赖的package包/类
private String buildEmailTemplate(Job job, JobStatus jobStatus) {
try {
Template template = null;
if (Job.SUCCESS_STATUS.contains(jobStatus)) {
template = velocityEngine.getTemplate("email/success_email.vm");
}
if (Job.FAILURE_STATUS.contains(jobStatus)) {
template = velocityEngine.getTemplate("email/failure_email.vm");
}
final String detailUrl = HttpURL.build(webDomain)
.append("flows")
.append(job.getNodeName())
.append("jobs")
.append(job.getNumber().toString())
.toString();
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("job", job);
velocityContext.put("detailUrl", detailUrl);
StringWriter stringWriter = new StringWriter();
template.merge(velocityContext, stringWriter);
return stringWriter.toString();
} catch (Throwable e) {
LOGGER.warn("sendMessage", "send message to all member error : %s",
ExceptionUtil.findRootCause(e).getMessage());
return null;
}
}