use of org.apache.velocity.VelocityContext in project cals-api by ca-cwds.
the class DictionaryLiquibaseGenerator method main.
public static void main(String[] args) throws IOException, URISyntaxException {
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
ve.init();
VelocityContext context = new VelocityContext();
context.put("tableName", TABLE_NAME);
Template template = null;
template = ve.getTemplate("LegacyComplaintDictionaryLiquibaseTemplate.vm");
context.put("dictItems", readItems());
StringWriter sw = new StringWriter();
template.merge(context, sw);
sw.flush();
System.out.println(sw);
sw.close();
}
use of org.apache.velocity.VelocityContext in project openolat by klemens.
the class UserBulkChangeManager method getDemoContext.
public Context getDemoContext(Translator propertyTrans) {
Context vcContext = new VelocityContext();
List<UserPropertyHandler> userPropertyHandlers2 = userManager.getAllUserPropertyHandlers();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers2) {
String propertyName = userPropertyHandler.getName();
String userValue = propertyTrans.translate("import.example." + userPropertyHandler.getName());
vcContext.put(propertyName, userValue);
}
return vcContext;
}
use of org.apache.velocity.VelocityContext in project openolat by klemens.
the class UserImportController method createMailTemplateForNewIdentity.
private MailTemplate createMailTemplateForNewIdentity(Identity identity, TransientIdentity transientIdentity) {
// get some data about the actor and fetch the translated subject / body via i18n module
String[] bodyArgs = new String[] { // {0}
identity.getName(), // {1}
identity.getUser().getProperty(UserConstants.FIRSTNAME, null), // {2}
identity.getUser().getProperty(UserConstants.LASTNAME, null), // {3}
UserManager.getInstance().getUserDisplayEmail(identity, getLocale()), // {4}
Settings.getServerContextPathURI(), // {5}
transientIdentity.getPassword() };
Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
Translator translator = Util.createPackageTranslator(UserImportController.class, locale);
String subject = translator.translate("mail.new.identity.subject");
String body = translator.translate("mail.new.identity.text", bodyArgs);
// create a mail template which all these data
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables into velocity context
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
// the email of the user, needs to stay named 'login'
context.put("login", user.getProperty(UserConstants.EMAIL, null));
}
};
return mailTempl;
}
use of org.apache.velocity.VelocityContext in project openolat by klemens.
the class DENManager method getRemovedMailTemplate.
/**
* Generates a mail template for users who were removed from a date
* @param identity
* @param event
* @param trans
* @return MailTemplate
*/
protected MailTemplate getRemovedMailTemplate(UserRequest ureq, String subjectStr, Translator trans) {
Identity identity = ureq.getIdentity();
String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
String subject = trans.translate("mail.participants.remove.subject", bodyArgs);
String body = trans.translate("mail.participants.remove.body", bodyArgs);
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity ident) {
//
}
};
return mailTempl;
}
use of org.apache.velocity.VelocityContext in project openolat by klemens.
the class DENManager method getAddedMailTemplate.
/**
* Generates a mail template for users who were added to a date
* @param identity
* @param event
* @param translator
* @return MailTemplate
*/
protected MailTemplate getAddedMailTemplate(UserRequest ureq, String subjectStr, Translator translator) {
Identity identity = ureq.getIdentity();
String[] bodyArgs = new String[] { identity.getUser().getProperty(UserConstants.FIRSTNAME, ureq.getLocale()), identity.getUser().getProperty(UserConstants.LASTNAME, ureq.getLocale()), UserManager.getInstance().getUserDisplayEmail(identity, ureq.getLocale()), "", subjectStr };
String subject = translator.translate("mail.participants.add.subject", bodyArgs);
String body = translator.translate("mail.participants.add.body", bodyArgs);
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity ident) {
//
}
};
return mailTempl;
}
Aggregations