Search in sources :

Example 91 with VelocityContext

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();
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) ClasspathResourceLoader(org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader) Template(org.apache.velocity.Template)

Example 92 with VelocityContext

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;
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 93 with VelocityContext

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;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 94 with VelocityContext

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;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 95 with VelocityContext

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;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Aggregations

VelocityContext (org.apache.velocity.VelocityContext)492 StringWriter (java.io.StringWriter)156 Template (org.apache.velocity.Template)120 Test (org.junit.Test)72 IOException (java.io.IOException)60 VelocityEngine (org.apache.velocity.app.VelocityEngine)53 File (java.io.File)47 ArrayList (java.util.ArrayList)39 HashMap (java.util.HashMap)36 Map (java.util.Map)36 Identity (org.olat.core.id.Identity)36 Context (org.apache.velocity.context.Context)32 MailTemplate (org.olat.core.util.mail.MailTemplate)28 Writer (java.io.Writer)22 Properties (java.util.Properties)20 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)19 ParseErrorException (org.apache.velocity.exception.ParseErrorException)16 ClasspathResourceLoader (org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader)16 FileWriter (java.io.FileWriter)15 OutputStreamWriter (java.io.OutputStreamWriter)14