當前位置: 首頁>>代碼示例>>Java>>正文


Java VelocityEngineUtils類代碼示例

本文整理匯總了Java中org.springframework.ui.velocity.VelocityEngineUtils的典型用法代碼示例。如果您正苦於以下問題:Java VelocityEngineUtils類的具體用法?Java VelocityEngineUtils怎麽用?Java VelocityEngineUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VelocityEngineUtils類屬於org.springframework.ui.velocity包,在下文中一共展示了VelocityEngineUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendEmail

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public void sendEmail(final UserDTO user, String url) {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(user.getEmail());
            message.setSubject(SUBJECT);
            message.setFrom(EMAIL_FROM); // could be parameterized...
            Map model = new HashMap();
            model.put("user", user);
            model.put("url", url);
            String text = VelocityEngineUtils.mergeTemplateIntoString(
                    velocityEngine, "org/enricogiurin/sushibar/registration-confirmation.vm", model);
            message.setText(text, true);
        }
    };
    this.emailSender.send(preparator);
}
 
開發者ID:egch,項目名稱:sushi-bar-BE,代碼行數:19,代碼來源:EmailSenderImpl.java

示例2: send

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
/**
 * Sends e-mail using Velocity template for the body and the properties
 * passed in as Velocity variables.
 *
 * @param msg The e-mail message to be sent, except for the body.
 * @param hTemplateVariables Variables to use when processing the template.
 */
protected void send(SimpleMailMessage msg, String language, String template, Map<String, Object> hTemplateVariables) {

    LOG.info("Send email ...");
    MimeMessagePreparator preparator = (MimeMessage mimeMessage) -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
        message.setTo(msg.getTo());
        message.setFrom(msg.getFrom());
        message.setSubject(msg.getSubject());

        String body = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, 
                "/" + template + "." + language + ".vm", 
                "UTF-8", 
                hTemplateVariables);

        LOG.log(Level.INFO, "Body: {0}", body);

        message.setText(body, true);
    };

    mailSender.send(preparator);

    LOG.log(Level.INFO, "Sender {0}", msg.getFrom());
    LOG.log(Level.INFO, "Recipient {0}", msg.getTo());
}
 
開發者ID:lordoftheflies,項目名稱:wonderjameeee,代碼行數:33,代碼來源:VelocityEmailSender.java

示例3: sendMailWithTemplate

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public void sendMailWithTemplate(final TemplateMailTO mailParameters) throws MailException {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);

            message.setTo(mailParameters.getToMailAddress());
            message.setFrom(mailParameters.getFromMailAddress());
            message.setSubject(mailParameters.getSubject());
            if (mailParameters.hasCcMailAddress()) {
                message.setCc(mailParameters.getCcMailAddress());
            }
            if (mailParameters.hasReplyTo()) {
                message.setReplyTo(mailParameters.getReplyTo());
            }
            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailParameters.getTemplateLocation(), mailParameters.getTemplateProperties());
            log.debug("*** TEST text='" + text + "'");
            message.setText(text, true);
            message.setValidateAddresses(true);

        }
    };
    this.mailSender.send(preparator);
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:26,代碼來源:MailServiceImpl.java

示例4: velocityConfigurerWithCsvPathAndNonFileAccess

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Test
@SuppressWarnings("deprecation")
public void velocityConfigurerWithCsvPathAndNonFileAccess() throws IOException, VelocityException {
	VelocityConfigurer vc = new VelocityConfigurer();
	vc.setResourceLoaderPath("file:/mydir,file:/yourdir");
	vc.setResourceLoader(new ResourceLoader() {
		@Override
		public Resource getResource(String location) {
			if ("file:/yourdir/test".equals(location)) {
				return new DescriptiveResource("");
			}
			return new ByteArrayResource("test".getBytes(), "test");
		}
		@Override
		public ClassLoader getClassLoader() {
			return getClass().getClassLoader();
		}
	});
	vc.setPreferFileSystemAccess(false);
	vc.afterPropertiesSet();
	assertThat(vc.createVelocityEngine(), instanceOf(VelocityEngine.class));
	VelocityEngine ve = vc.createVelocityEngine();
	assertEquals("test", VelocityEngineUtils.mergeTemplateIntoString(ve, "test", Collections.emptyMap()));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:VelocityConfigurerTests.java

示例5: sendActivation

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public void sendActivation(User user) throws InvalidTokenException {

    if (user.getActivationToken() == null) {
        throw new InvalidTokenException("No activation token found for " + user.toString());
    }

    Map<String, Object> model = getBaseModel(user);
    model.put("url", hostname + "#/activation/" + user.getUsername() + "/" + user.getActivationToken().getToken());

    final String body = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "templates/sendActivation.vm", "UTF-8", model);

    MimeMessagePreparator preparator = mimeMessage -> {
        mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
        mimeMessage.setFrom(new InternetAddress(mailFromAddress));
        mimeMessage.setSubject("Kanbanboard WGM Accountaktivierung");
        mimeMessage.setText(body, "UTF-8", "html");
    };

    try {
        mailSender.send(preparator);
        log.info("Activation Mail sent to "+ user.getEmail());
    } catch (MailException e) {
        log.error("Could not send activation mail to " + user.getEmail() + ". The error was :", e);
    }
}
 
開發者ID:Morbrolhc,項目名稱:kanbanboard,代碼行數:27,代碼來源:EMailServiceImpl.java

示例6: sendPasswordReset

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public void sendPasswordReset(User user) throws InvalidTokenException {

    if (user.getPasswordResetToken() == null) {
        throw new InvalidTokenException("No password reset token found for " + user.toString());
    }

    final Map<String, Object> model = getBaseModel(user);
    model.put("url", hostname + "#/reset/" + user.getUsername() + "/" + user.getPasswordResetToken().getToken());

    final String body = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "templates/sendPasswordReset.vm", "UTF-8", model);

    MimeMessagePreparator preparator = mimeMessage -> {
        mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
        mimeMessage.setFrom(new InternetAddress(mailFromAddress));
        mimeMessage.setSubject("Kanbanboard WGM Passwort Reset");
        mimeMessage.setText(body, "UTF-8", "html");
    };

    try {
        mailSender.send(preparator);
        log.info("Reset Mail sent to {}", user.getEmail());
    } catch (MailException e) {
        log.error("Could not send mail to " + user.getEmail() + ". The error was :", e);
    }
}
 
開發者ID:Morbrolhc,項目名稱:kanbanboard,代碼行數:27,代碼來源:EMailServiceImpl.java

示例7: getOpenfireHttpAuthProperties

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
/**
 * Render the http auth properties file to be used with openfire
 *
 * @param request
 *            the request to use
 * @return the rendered properties
 */
public static String getOpenfireHttpAuthProperties(HttpServletRequest request) {
    // TODO change JSPs to VM and parse the http_auth.properties template
    VelocityEngine engine = ServiceLocator.findService(VelocityEngine.class);
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("defaultHost", ApplicationProperty.WEB_SERVER_HOST_NAME.getValue());
    context.put("defaultPort", ApplicationProperty.WEB_HTTP_PORT.getValue());
    context.put("internalHost", request.getServerName());
    context.put("internalPort", request.getServerPort());
    if (request.isSecure()) {
        context.put("internalProtocol", "https");
    } else {
        context.put("internalProtocol", "http");
    }
    context.put("defaultPortHttps", ApplicationProperty.WEB_HTTPS_PORT.getValue());
    context.put("context", request.getContextPath());
    String render = VelocityEngineUtils.mergeTemplateIntoString(engine,
            VELOCITY_TEMPLATE_HTTP_AUTH_PROPERTIES, context);
    return render;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:27,代碼來源:XmppController.java

示例8: buildMessageBody

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public String buildMessageBody(EmailInfo info, Map<String,Object> props) {
    if (props == null) {
        props = new HashMap<String, Object>();
    }

    if (props instanceof HashMap) {
        HashMap<String, Object> hashProps = (HashMap<String, Object>) props;
        @SuppressWarnings("unchecked")
        Map<String,Object> propsCopy = (Map<String, Object>) hashProps.clone();
        if (additionalConfigItems != null) {
            propsCopy.putAll(additionalConfigItems);
        }
        return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, info.getEmailTemplate(), info.getEncoding(), propsCopy);
    }

    throw new IllegalArgumentException("Property map must be of type HashMap<String, Object>");
}
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:19,代碼來源:VelocityMessageCreator.java

示例9: sendMessage

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
/**
    * Send a simple message based on a Velocity template.
    * 
    * @param msg
    *                the message to populate
    * @param templateName
    *                the Velocity template to use (relative to classpath)
    * @param model
    *                a map containing key/value pairs
    */
   @SuppressWarnings("unchecked")
   public void sendMessage(SimpleMailMessage msg, String templateName,
    Map model) {
String result = null;

try {
    result = VelocityEngineUtils.mergeTemplateIntoString(
	    velocityEngine, templateName, model);
} catch (VelocityException e) {
    log.error(e.getMessage());
}

msg.setText(result);
send(msg);
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:26,代碼來源:MailEngine.java

示例10: sendMessage

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
/**
 * Send a simple message based on a Velocity template.
 * @param msg the message to populate
 * @param templateName the Velocity template to use (relative to classpath)
 * @param model a map containing key/value pairs
 */
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
    String result = null;

    try {
        result =
            VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                                                        templateName, "UTF-8", model);
    } catch (VelocityException e) {
        e.printStackTrace();
        log.error(e.getMessage());
    }

    msg.setText(result);
    send(msg);
}
 
開發者ID:SMVBE,項目名稱:ldadmin,代碼行數:22,代碼來源:MailEngine.java

示例11: send

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public void send(final SimpleMailMessage msg,
        final Map<String, Object> hTemplateVariables, final String templateFileName) {
    
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(msg.getTo());
            message.setFrom(msg.getFrom());
            message.setSubject(msg.getSubject());
            String body = VelocityEngineUtils.mergeTemplateIntoString(
                    velocityEngine, templateFileName, hTemplateVariables);

           //logger.info("body={}", body);
            message.setText(body, true);
        }
    };

    mailSender.send(preparator);
}
 
開發者ID:UKCA,項目名稱:CAPortal,代碼行數:22,代碼來源:VelocityEmailSender.java

示例12: sendMail

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
public void sendMail(Mail mail, Map<String, Object> model)
		throws MessagingException {

	//TODO: Deepak. not the perfect way to pull resources from the below code
	//but accordng to http://velocity.apache.org/engine/releases/velocity-1.7/developer-guide.html#resourceloaders
	//File resource handelers needs more config for which we don't have enough time.
	MimeMessage mimeMessage = mailSender.createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false,"utf-8");
	
	helper.setSubject(mail.getSubject());
	helper.setFrom(AppConstants.APP_EMAILID);
	
	for (MailReceiver mailReceiver : mail.getReceivers()) {
		model.put("_receiverFirstName", mailReceiver.firstName);
		model.put("_receiverLastName", mailReceiver.lastName);
		model.put("_receiverEmail", mailReceiver.email);
		model.put("_receiverImageUrl", mailReceiver.imageUrl);
		
		String mailBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "com/gendevs/bedrock/appengine/integration/mail/templates/" + mail.getTemplateName(), "UTF-8", model);
		mimeMessage.setContent(mailBody, mail.getContentType());
		
		helper.setTo(mailReceiver.email);
		mailSender.send(mimeMessage);
	}
}
 
開發者ID:generaldevelopers,項目名稱:bedrock,代碼行數:26,代碼來源:Mailer.java

示例13: sendRegistrationConfirmEmail

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
private void sendRegistrationConfirmEmail(final User user) {
    final MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(user.getEmail());
            message.setFrom("[email protected]");
            message.setSubject("注冊coconut成功");

            Map model = new HashMap();
            model.put("user", user);
            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/templates/registration-confirm-mail.html", "gb2312", model);
            message.setText(text, true);
        }
    };
    this.mailSender.send(preparator);
}
 
開發者ID:gukt,項目名稱:umbrella,代碼行數:17,代碼來源:UserService.java

示例14: sendMailWithTemplate

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
public void sendMailWithTemplate(final TemplateMailTO mailParameters) throws MailException {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);

            message.setTo(mailParameters.getToMailAddress());
            message.setFrom(mailParameters.getFromMailAddress());
            message.setSubject(mailParameters.getSubject());
            if (mailParameters.hasCcMailAddress()) {
                message.setCc(mailParameters.getCcMailAddress());
            }
            if (mailParameters.hasReplyTo()) {
                message.setReplyTo(mailParameters.getReplyTo());
            }
            String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailParameters.getTemplateLocation(), mailParameters.getTemplateProperties());
            log.debug("*** TEST text='" + text + "'");
            message.setText(text, true);
            message.setValidateAddresses(true);

        }
    };
    this.mailSender.send(preparator);
}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:24,代碼來源:MailServiceImpl.java

示例15: sendTplLocationEmail

import org.springframework.ui.velocity.VelocityEngineUtils; //導入依賴的package包/類
@Override
public void sendTplLocationEmail(final String from, final List<String> to,
                                 final List<String> cc, final String subject, final String tplLocation,
                                 final Map<String, Object> model) {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(to.toArray(new String[to.size()]));
            message.setCc(cc.toArray(new String[cc.size()]));
            message.setFrom(from);
            message.setSubject(subject);
            String tpl;
            tpl = VelocityEngineUtils.mergeTemplateIntoString(
                    velocityEngine, tplLocation, "utf-8", model);
            message.setText(tpl, true);
        }
    };
    JavaMailSenderImpl javaMailSenderImpl = (JavaMailSenderImpl) mailSender;
    javaMailSenderImpl.send(preparator);
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:21,代碼來源:MailServiceImpl.java


注:本文中的org.springframework.ui.velocity.VelocityEngineUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。