org.apache.velocity.VelocityContext Java Examples

The following examples show how to use org.apache.velocity.VelocityContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QywxGroupMsgController.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 跳转到编辑页面
 * @return
 */
@RequestMapping(params="toGroupMsgSend",method ={RequestMethod.GET, RequestMethod.POST})
public void toGroupMsgSend(@ModelAttribute QywxGroup group , HttpServletResponse response, HttpServletRequest request) throws Exception{
		 VelocityContext velocityContext = new VelocityContext();
		 List<QywxAgent> agentList= qywxAgentDao.getAllQywxAgents();
		 velocityContext.put("agentList", agentList);
		 //分组展示
		 List<QywxGroup> list =qywxGroupDao.getAllQywxpid();
		 
		//页面图片显示的路径
		 String yuming=ConfigUtil.getProperty("domain");
		 velocityContext.put("yuming", yuming);
		 velocityContext.put("list", list);
		 String viewName = "qywx/msg/groupMsgSend.vm"; 
		 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #2
Source File: AbstractPOJOGenMojo.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected void parseObj(
    final File base,
    final boolean append,
    final String pkg,
    final String name,
    final String out,
    final Map<String, Object> objs)
    throws MojoExecutionException {

  final VelocityContext ctx = newContext();
  ctx.put("package", pkg);

  if (objs != null) {
    for (Map.Entry<String, Object> obj : objs.entrySet()) {
      if (StringUtils.isNotBlank(obj.getKey()) && obj.getValue() != null) {
        ctx.put(obj.getKey(), obj.getValue());
      }
    }
  }

  final Template template = Velocity.getTemplate(name + ".vm");
  writeFile(out, base, ctx, template, append);
}
 
Example #3
Source File: AlipayNewsitemController.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 跳转到编辑页面
 * @return
 */
@RequestMapping(params="goMessage",method = RequestMethod.GET)
public void goMessage(@RequestParam(required = true, value = "templateId" ) String templateId,HttpServletResponse response,HttpServletRequest request) throws Exception{
		 VelocityContext velocityContext = new VelocityContext();
		 List<AlipayNewsitem> headerList = alipayNewsitemDao.getAlipayNewsitemByTemplateId(templateId);
		 if(headerList.size()>0){
			 velocityContext.put("headerNews", headerList.get(0));
				if(headerList.size()>1){
					ArrayList list = new ArrayList(headerList);
					list.remove(0);
					velocityContext.put("newsList", list);
				}
			} 
		 AlipayNewstemplate alipayNewstemplate = alipayNewstemplateDao.get(templateId);
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		 if(alipayNewstemplate.getCreateDate()!=null){
			 velocityContext.put("addtime", sdf.format(alipayNewstemplate.getCreateDate()));
		 }
		 String viewName = "alipay/sucai/alipayNewsitem-showmessage.vm";
		 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #4
Source File: ScorecardEditorServletHandler.java    From urule with Apache License 2.0 6 votes vote down vote up
@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/scorecard-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
Example #5
Source File: DefaultMailPlugin.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
private String populateTemplate(String templateName) {
	VelocityEngine ve = new VelocityEngine();
	ve.init();
	Template t = ve.getTemplate(templateName);
	/* create a context and add data */
	VelocityContext context = new VelocityContext();
	String host = System.getProperty("server.address");
	if (null == host) {
		host = "localhost";
	}
	String port = System.getProperty("server.port");
	if (null == port) {
		port = "8080";
	}
	context.put("host", host);
	context.put("port", port);
	context.put("meta", getMetadata());
	final StringWriter writer = new StringWriter();
	t.merge(context, writer);
	return writer.toString();
}
 
Example #6
Source File: RsVelocity.java    From takes with MIT License 6 votes vote down vote up
/**
 * Render it.
 * @param folder Template folder
 * @param template Page template
 * @param params Params for velocity
 * @return Page body
 * @throws IOException If fails
 */
private static InputStream render(final String folder,
    final InputStream template,
    final Map<String, Object> params) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (Writer writer = new WriterTo(baos)) {
        final VelocityEngine engine = new VelocityEngine();
        engine.setProperty(
            "file.resource.loader.path",
            folder
        );
        engine.evaluate(
            new VelocityContext(params),
            writer,
            "",
            new ReaderOf(template)
        );
    }
    return new ByteArrayInputStream(baos.toByteArray());
}
 
Example #7
Source File: DiffObjectPage.java    From hollow with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUpContext(HttpServletRequest req, HollowUISession session, VelocityContext ctx) {
    String type = req.getParameter("type");
    int fromOrdinal = Integer.parseInt(req.getParameter("fromOrdinal"));
    int toOrdinal = Integer.parseInt(req.getParameter("toOrdinal"));

    int fieldIdx = -1;
    if(req.getParameter("fieldIdx") != null)
        fieldIdx = Integer.parseInt(req.getParameter("fieldIdx"));

    ctx.put("typeName", type);
    ctx.put("fromOrdinal", fromOrdinal);
    ctx.put("toOrdinal", toOrdinal);

    HollowObjectView diffView = diffUI.getHollowObjectViewProvider().getObjectView(req, session);

    HollowDiffHtmlKickstarter htmlKickstarter = new HollowDiffHtmlKickstarter(diffUI.getBaseURLPath());

    ctx.put("initialHtml", htmlKickstarter.initialHtmlRows(diffView));

    ctx.put("breadcrumbs", getBreadcrumbs(type, fieldIdx, fromOrdinal, toOrdinal));
}
 
Example #8
Source File: QUtil.java    From jfinalQ-gencode with MIT License 6 votes vote down vote up
/**
 * 生成代码 by velocity
 * @param map		变量
 * @param destPath	目的地址
 * @param destFile	目的文件名
 * @param tmpPath	模版地址
 * @param tmpFile	模版文件名
 * @return
 */
public static boolean generateCodeByVelocity(Map<String, Object> map, String destPath, String destFile, String tmpPath, String tmpFile){
	try {
		// 1.初始化
		Properties properties = new Properties();
		properties.put("file.resource.loader.path", tmpPath);  
		properties.put("input.encoding", "UTF-8");
		properties.put("output.encoding", "UTF-8");
		Velocity.init(properties);
		VelocityContext context = new VelocityContext(map);
			
		// 2.生成代码
		FileUtil.mkdir(destPath);
		BufferedWriter sw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(destPath, destFile)), "UTF-8"));
		Velocity.getTemplate(tmpFile).merge(context, sw);
		sw.flush();
		sw.close();
		
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
Example #9
Source File: PwChangeController.java    From olat with Apache License 2.0 6 votes vote down vote up
private MailerResult sendEmail(final UserRequest ureq, Identity identity, TemporaryKey tk) {
    final String ip = ureq.getHttpReq().getRemoteAddr();
    final String today = DateFormat.getDateInstance(DateFormat.LONG, ureq.getLocale()).format(new Date());
    // mailer configuration
    final String serverpath = Settings.getServerContextPathURI();
    final String servername = ureq.getHttpReq().getServerName();
    if (log.isDebugEnabled()) {
        log.debug("this servername is " + servername + " and serverpath is " + serverpath, null);
    }
    final Translator userTrans = PackageUtil.createPackageTranslator(PwChangeController.class, ureq.getLocale());
    String body = userTrans.translate("pwchange.intro", new String[] { identity.getName() })
            + userTrans.translate("pwchange.body", new String[] { serverpath, tk.getRegistrationKey(), I18nManager.getInstance().getLocaleKey(ureq.getLocale()) })
            + SEPARATOR + userTrans.translate("reg.wherefrom", new String[] { serverpath, today, ip });
    String subject = userTrans.translate("pwchange.subject");
    final MailTemplate mailTempl = new MailTemplate(subject, body, MailTemplateHelper.getMailFooter(ureq.getIdentity(), null), null) {
        @Override
        public void putVariablesInMailContext(final VelocityContext context, final OLATPrincipal recipient) {
            // nothing to do
        }
    };

    final MailerResult result = MailerWithTemplate.getInstance().sendMail(identity, null, null, mailTempl, null);
    return result;
}
 
Example #10
Source File: MailITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Test for the mail template and the context variable methods
 */
@Test
public void testMailAttachmentsInvalid() {
    String subject = "Subject: Hello $firstname with attachment";
    String body = "Body: \n\n Hey $login, here's a file for you: ";

    // some attachemnts - but no file
    File[] attachments = new File[1];

    MailTemplate template = new MailTemplate(subject, body, null, attachments) {
        @Override
        public void putVariablesInMailContext(VelocityContext context, OLATPrincipal principal) {
            // Put user variables
            context.put("firstname", principal.getAttributes().getFirstName());
            context.put("login", principal.getName());
        }
    };

    // some recipients data
    List<OLATPrincipal> recipients = new ArrayList<OLATPrincipal>();
    recipients.add(id1);

    MailerResult result = new MailerResult();
    result = MailerWithTemplate.getInstance().sendMailAsSeparateMails(recipients, null, null, template, id2);
    assertEquals(MailerResult.ATTACHMENT_INVALID, result.getReturnCode());
}
 
Example #11
Source File: MacroForwardDefineTestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testLogResult()
    throws Exception
{
    VelocityContext context = new VelocityContext();
    Template template = Velocity.getTemplate("macros.vm");

    // try to get only messages during merge
    logger.startCapture();
    template.merge(context, new StringWriter());
    logger.stopCapture();

    String resultLog = logger.getLog();
    if ( !isMatch(resultLog, COMPARE_DIR, "velocity.log", "cmp"))
    {
        String compare = getFileContents(COMPARE_DIR, "velocity.log", CMP_FILE_EXT);

        String msg = "Log output was incorrect\n"+
            "-----Result-----\n"+ resultLog +
            "----Expected----\n"+ compare +
            "----------------";

        fail(msg);
    }
}
 
Example #12
Source File: ReportBuilder.java    From custom-bytecode-analyzer with GNU General Public License v3.0 6 votes vote down vote up
private static List<String> generateHtmlChunks(List<ReportItem> reportItemList) {
  List<String> htmlChunks = new ArrayList<>();

  VelocityEngine velocityEngine = new VelocityEngine();
  Properties p = new Properties();
  p.setProperty("resource.loader", "class");
  p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
  velocityEngine.init(p);
  Template template = velocityEngine.getTemplate("template/report_template.html");

  int maxItemsInReport = CliHelper.getMaxItemsInReport();
  List<List<ReportItem>> reportItemsChunks = Lists.partition(reportItemList, maxItemsInReport);

  for (List<ReportItem> reportItemsChunk : reportItemsChunks ) {
    VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("jarPath", CliHelper.getPathToAnalyze());
    velocityContext.put("ruleName", reportItemsChunk.get(0).getRuleName());
    velocityContext.put("reportItems", reportItemsChunk);

    StringWriter stringWriter = new StringWriter();
    template.merge(velocityContext, stringWriter);
    htmlChunks.add(stringWriter.toString());
  }
  return htmlChunks;
}
 
Example #13
Source File: FileGenerator.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
public void writeDescriptorGenerate(VelocityContext context, Template temp) throws IOException {
    StringWriter wr = new StringWriter();
    temp.merge(context, wr);
    File descriptorFile = new File(vpc.getDestinationFolder()
            + "/src/main/resources/"
            + "descriptor.xml");
    FileUtils.writeStringToFile(descriptorFile, wr.toString());
}
 
Example #14
Source File: WeixinTmessgaeTaskController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到添加页面
 * @return
 */
@RequestMapping(value = "/toAdd",method ={RequestMethod.GET, RequestMethod.POST})
public void toAddDialog(HttpServletRequest request,HttpServletResponse response,ModelMap model)throws Exception{
	 VelocityContext velocityContext = new VelocityContext();
	 String jwid = request.getSession().getAttribute("jwid").toString();
	 List<WeixinTmessage> tmessages = weixinTmessageService.queryByJwid(jwid);
	 velocityContext.put("tmessages", tmessages);
	 List<WeixinTag> weixinTags = weixinTagService.getAllTags(jwid);
	 velocityContext.put("weixinTags", weixinTags);
	 String viewName = "tmessage/back/weixinTmessgaeTask-add.vm";
	 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #15
Source File: GenServiceImpl.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 生成代码预览
 * @param tableName
 * @param templates
 * @return
 */
@Override
public Map<String, String> previewCode(String tableName, List<String> templates){
    Map<String, String> dataMap = new LinkedHashMap<>();
    // 查询表信息
    TableInfo table = this.selectTableByName(tableName);
    // 查询列信息
    List<ColumnInfo> columns = this.selectTableColumnsByName(tableName);
    if (Lang.isNotEmpty(table) && Lang.isNotEmpty(columns)) {
        // 生成代码

        // 表名转换成Java属性名
        String className = GenUtils.tableToJava(table.getTableName());
        table.setClassName(className);
        table.setClassname(StringUtils.uncapitalize(className));
        // 列信息
        table.setColumns(GenUtils.transColums(columns));
        // 设置主键
        table.setPrimaryKey(table.getColumnsLast());

        VelocityInitializer.initVelocity();
        String packageName = GenConfig.getPackageName();
        String moduleName = GenUtils.getModuleName(packageName);
        VelocityContext context = GenUtils.getVelocityContext(table);
        for (String template : templates) {
            // 渲染模板
            StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate(template, Globals.UTF8);
            tpl.merge(context, sw);
            dataMap.put(template, sw.toString());
        }
        return dataMap;
    }
    return null;
}
 
Example #16
Source File: VelocityUtil.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String processTemplate(String templateName, VelocityContext vContext) {
	Template template = getVelocityEngine().getTemplate(templateName, "UTF-8");

	StringWriter writer = new StringWriter(128);
	template.merge(vContext, writer);
	writer.flush();
	try {
		writer.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	return writer.getBuffer().toString();
}
 
Example #17
Source File: FileTemplateUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String mergeTemplate(Properties attributes, String content, boolean useSystemLineSeparators) throws IOException {
  VelocityContext context = new VelocityContext();
  Enumeration<?> names = attributes.propertyNames();
  while (names.hasMoreElements()) {
    String name = (String)names.nextElement();
    context.put(name, attributes.getProperty(name));
  }
  return mergeTemplate(content, context, useSystemLineSeparators);
}
 
Example #18
Source File: JwSystemRegisterController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到添加页面
 * @return
 */
@RequestMapping(value = "/toAdd",method ={RequestMethod.GET, RequestMethod.POST})
public void toAddDialog(HttpServletRequest request,HttpServletResponse response,ModelMap model)throws Exception{
	 VelocityContext velocityContext = new VelocityContext();
	 String viewName = "system/back/jwSystemRegister-add.vm";
	 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #19
Source File: WxActGoldeneggsRecordController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到添加页面
 * @return
 */
@RequestMapping(value = "/toAdd",method ={RequestMethod.GET, RequestMethod.POST})
public void toAddDialog(HttpServletRequest request,HttpServletResponse response,ModelMap model)throws Exception{
	 VelocityContext velocityContext = new VelocityContext();
	 String viewName = "goldeneggs/back/wxActGoldeneggsRecord-add.vm";
	 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #20
Source File: J2clAstProcessor.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private void writeGeneralClass(
    String templateName,
    String className,
    String packageName,
    List<VisitableClass> visitableClasses) {

  boolean success = false;
  try {
    VelocityContext velocityContext =
        createVelocityContextForVisitor(packageName, visitableClasses);
    StringWriter writer = new StringWriter();

    success =
        velocityEngine.mergeTemplate(
            templateName, StandardCharsets.UTF_8.name(), velocityContext, writer);
    writeString(Joiner.on('.').join(packageName, className), writer.toString());
  } catch (Throwable e) {
    StringWriter stringWriter = new StringWriter();
    e.printStackTrace(new PrintWriter(stringWriter));
    reportError("Could not generate visitor class" + e + stringWriter.toString());
    success = false;
  } finally {
    if (!success) {
      reportError("Could not generate visitor class");
    }
  }
}
 
Example #21
Source File: WeixinQrcodeScanRecordController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到添加页面
 * @return
 */
@RequestMapping(value = "/toAdd",method ={RequestMethod.GET, RequestMethod.POST})
public void toAddDialog(HttpServletRequest request,HttpServletResponse response,ModelMap model)throws Exception{
	 VelocityContext velocityContext = new VelocityContext();
	 String viewName = "qrcode/back/weixinQrcodeScanRecord-add.vm";
	 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #22
Source File: BaseContentRenderer.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String render(Content content, long modelId, String langCode, RequestContext reqCtx) {
	String renderedEntity = null;
	List<TextAttributeCharReplaceInfo> conversions = null;
	try {
		conversions = this.convertSpecialCharacters(content, langCode);
		String contentModel = this.getModelShape(modelId);
		Context velocityContext = new VelocityContext();
		ContentWrapper contentWrapper = (ContentWrapper) this.getEntityWrapper(content);
		contentWrapper.setRenderingLang(langCode);
		contentWrapper.setReqCtx(reqCtx);
		velocityContext.put(this.getEntityWrapperContextName(), contentWrapper);
		I18nManagerWrapper i18nWrapper = new I18nManagerWrapper(langCode, this.getI18nManager());
		velocityContext.put("i18n", i18nWrapper);
		SystemInfoWrapper systemInfoWrapper = new SystemInfoWrapper(reqCtx);
		velocityContext.put("info", systemInfoWrapper);
		StringWriter stringWriter = new StringWriter();
		boolean isEvaluated = Velocity.evaluate(velocityContext, stringWriter, "render", contentModel);
		if (!isEvaluated) {
			throw new ApsSystemException("Error rendering content");
		}
		stringWriter.flush();
		renderedEntity = stringWriter.toString();
	} catch (Throwable t) {
		_logger.error("Error rendering content", t);
		//ApsSystemUtils.logThrowable(t, this, "render", "Error rendering content");
		renderedEntity = "";
	} finally {
		if (null != conversions) {
			this.replaceSpecialCharacters(conversions);
		}
	}
	return renderedEntity;
}
 
Example #23
Source File: JwSystemProjectController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到添加页面
 * @return
 */
@RequestMapping(value = "/toAdd",method ={RequestMethod.GET, RequestMethod.POST})
public void toAddDialog(HttpServletRequest request,HttpServletResponse response,ModelMap model)throws Exception{
	 VelocityContext velocityContext = new VelocityContext();
	 String viewName = "system/back/jwSystemProject-add.vm";
	 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #24
Source File: BuiltInEventHandlerTestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test reporting of invalid syntax
 * @throws Exception
 */
public void testReportNullInvalidReferences() throws Exception
{
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("event_handler.invalid_references.null","true");
    ReportInvalidReferences reporter = new ReportInvalidReferences();
    ve.init();

    VelocityContext context = new VelocityContext();
    EventCartridge ec = new EventCartridge();
    ec.addEventHandler(reporter);
    ec.attachToContext(context);

    context.put("a1","test");
    context.put("b1","test");
    context.put("n1", null);
    Writer writer = new StringWriter();

    ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar() $!c1 $n1 $!n1 #if($c1) nop #end");

    List errors = reporter.getInvalidReferences();
    assertEquals(3,errors.size());
    assertEquals("$c1",((InvalidReferenceInfo) errors.get(0)).getInvalidReference());
    assertEquals("$a1.foobar()",((InvalidReferenceInfo) errors.get(1)).getInvalidReference());
    assertEquals("$n1",((InvalidReferenceInfo) errors.get(2)).getInvalidReference());

    log("Caught invalid references (local configuration).");
}
 
Example #25
Source File: CourseCreationMailHelper.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Sent notification mail for signalling that course creation was successful.
 * 
 * @param ureq
 *            user request
 * @param config
 *            course configuration object
 * @return mailer result object
 */
public static final MailerResult sentNotificationMail(final UserRequest ureq, final CourseCreationConfiguration config) {
    final Translator translator = PackageUtil.createPackageTranslator(CourseCreationMailHelper.class, ureq.getLocale());
    log.info("Course creation with wizard finished. [User: " + ureq.getIdentity().getName() + "] [Course name: " + config.getCourseTitle() + "]");
    final String subject = translator.translate("mail.subject", new String[] { config.getCourseTitle() });
    String body = translator.translate("mail.body.0", new String[] { config.getCourseTitle() });
    body += translator.translate("mail.body.1");
    body += translator.translate("mail.body.2", new String[] { config.getExtLink() });
    body += translator.translate("mail.body.3");
    body += translator.translate("mail.body.4");

    int counter = 1;
    if (config.isCreateSinglePage()) {
        body += translator.translate("mail.body.4.2", new String[] { Integer.toString(++counter) });
    }
    if (config.isCreateEnrollment()) {
        body += translator.translate("mail.body.4.3", new String[] { Integer.toString(++counter) });
    }
    if (config.isCreateDownloadFolder()) {
        body += translator.translate("mail.body.4.4", new String[] { Integer.toString(++counter) });
    }
    if (config.isCreateForum()) {
        body += translator.translate("mail.body.4.5", new String[] { Integer.toString(++counter) });
    }
    if (config.isCreateContactForm()) {
        body += translator.translate("mail.body.4.6", new String[] { Integer.toString(++counter) });
    }
    body += translator.translate("mail.body.5");
    body += translator.translate("mail.body.6");
    body += translator.translate("mail.body.greetings");

    final MailTemplate template = new MailTemplate(subject, body, MailTemplateHelper.getMailFooter(ureq.getIdentity(), null), null) {
        @Override
        @SuppressWarnings("unused")
        public void putVariablesInMailContext(final VelocityContext context, final OLATPrincipal identity) {
            // nothing to do
        }
    };
    return MailerWithTemplate.getInstance().sendMail(ureq.getIdentity(), null, null, template, null);
}
 
Example #26
Source File: AbstractGenerator.java    From webstart with MIT License 5 votes vote down vote up
private void addPropertiesToContext( Map<?, ?> properties, VelocityContext context )
{
    if ( properties != null )
    {
        for ( Object o : properties.keySet() )
        {
            String nextKey = (String) o;
            Object nextValue = properties.get( nextKey );
            context.put( nextKey, nextValue.toString() );
        }
    }
}
 
Example #27
Source File: CmsArticleController.java    From jeewx-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到编辑页面
 * @return
 */
@RequestMapping(value="toEdit",method = RequestMethod.GET)
public void toEdit(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request) throws Exception{
		 VelocityContext velocityContext = new VelocityContext();
		 CmsArticle cmsArticle = cmsArticleService.queryById(id);
		 velocityContext.put("cmsArticle",cmsArticle);
		 velocityContext.put("mainId", request.getParameter("mainId"));
		 String viewName = "cms/back/cmsArticle-edit.vm";
		 ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example #28
Source File: AlipayMessageLogController.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 详情
 * 
 * @return
 */
@RequestMapping(params = "toDetail", method = RequestMethod.GET)
public void alipayMessageLogDetail(@RequestParam(required = true, value = "id") String id,
		HttpServletResponse response, HttpServletRequest request) throws Exception {
	VelocityContext velocityContext = new VelocityContext();
	// update-start--Author:chenchunpeng  Date:20160715 for:修改群发记录详情页面的页面名
	String viewName = "alipay/base/alipayMessagelog-detail.vm";
	AlipayMessageLog alipayMessageLog = alipayMessagelogDao.get(id);
	// update-end--Author:chenchunpeng  Date:20160715 for:修改群发记录详情页面的页面名
	velocityContext.put("alipayMessagelog", alipayMessageLog);
	ViewVelocity.view(request, response, viewName, velocityContext);
}
 
Example #29
Source File: AlertMessageDecorator.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@Override
protected VelocityContext fillInContext(AlertEntity alert, VelocityContext context) {
    context.put(alert.getAlertType().name(), alert.getAlertType());
    context.put("redisAlert", alert);
    context.put("title", generateTitle(alert));
    return context;
}
 
Example #30
Source File: AlipayGzuserinfoController.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到编辑页面
 * @return
 */
@RequestMapping(params="toEdit",method = RequestMethod.GET)
public void toEdit(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request) throws Exception{
		 VelocityContext velocityContext = new VelocityContext();
		 AlipayGzuserinfo alipayGzuserinfo = alipayGzuserinfoDao.get(id);
		 velocityContext.put("alipayGzuserinfo",alipayGzuserinfo);
		 String viewName = "alipay/base/alipayGzuserinfo-edit.vm";
		 ViewVelocity.view(request,response,viewName,velocityContext);
}