Search in sources :

Example 81 with VelocityContext

use of org.apache.velocity.VelocityContext in project OpenOLAT by OpenOLAT.

the class AssessmentObjectComponentRenderer method renderPositionObjectStage.

private void renderPositionObjectStage(AssessmentRenderer renderer, StringOutput sb, PositionObjectStage positionObjectStage, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
    Context ctx = new VelocityContext();
    ctx.put("positionObjectStage", positionObjectStage);
    String page = getInteractionTemplate(positionObjectStage);
    renderVelocity(renderer, sb, positionObjectStage, ctx, page, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 82 with VelocityContext

use of org.apache.velocity.VelocityContext in project OpenOLAT by OpenOLAT.

the class QTI21ResultsExportMediaResource method createResultListingHTML.

private String createResultListingHTML(List<ResultDetail> assessments, List<File> assessmentDocs, AssessedMember assessedMember) {
    // now put values to velocityContext
    VelocityContext ctx = new VelocityContext();
    ctx.put("t", translator);
    ctx.put("title", translator.translate("table.overview"));
    ctx.put("return", translator.translate("button.return"));
    ctx.put("assessments", assessments);
    ctx.put("assessedMember", assessedMember);
    ctx.put("assessmentDocs", assessmentDocs);
    ctx.put("hasResults", Boolean.valueOf(!assessments.isEmpty()));
    ctx.put("hasDocuments", Boolean.valueOf(!assessmentDocs.isEmpty()));
    String template = FileUtils.load(QTI21ResultsExportMediaResource.class.getResourceAsStream("_content/qtiListing.html"), "utf-8");
    return velocityHelper.evaluateVTL(template, ctx);
}
Also used : VelocityContext(org.apache.velocity.VelocityContext)

Example 83 with VelocityContext

use of org.apache.velocity.VelocityContext in project OpenOLAT by OpenOLAT.

the class QTI21ResultsExportMediaResource method createMemberListingHTML.

private String createMemberListingHTML(List<AssessedMember> assessedMembers) {
    Collections.sort(assessedMembers, new Comparator<AssessedMember>() {

        @Override
        public int compare(AssessedMember o1, AssessedMember o2) {
            return o1.getUsername().compareTo(o2.getUsername());
        }
    });
    // now put values to velocityContext
    VelocityContext ctx = new VelocityContext();
    ctx.put("t", translator);
    ctx.put("rootTitle", translator.translate("table.overview"));
    ctx.put("assessedMembers", assessedMembers);
    String template = FileUtils.load(QTI21ResultsExportMediaResource.class.getResourceAsStream("_content/qtiUserlisting.html"), "utf-8");
    return velocityHelper.evaluateVTL(template, ctx);
}
Also used : VelocityContext(org.apache.velocity.VelocityContext)

Example 84 with VelocityContext

use of org.apache.velocity.VelocityContext in project celements-blog by celements.

the class BlogPlugin method sendNewsletterActivationMail.

void sendNewsletterActivationMail(BaseObject obj, XWikiDocument blogDoc, String docName, Map<String, String> request, XWikiContext context) throws XWikiException {
    String email = request.get("emailadresse");
    email = email.toLowerCase();
    if (context.getWiki().exists("Tools.NewsletterSubscriptionActivation", context)) {
        VelocityContext vcontext = ((VelocityContext) context.get("vcontext"));
        vcontext.put("activationKey", getActivationKey(obj, docName));
        vcontext.put("blog", blogDoc);
        vcontext.put("email", email);
        XWikiDocument emailContentDoc = context.getWiki().getDocument("Tools.NewsletterSubscriptionActivation", context);
        BaseObject blogConf = blogDoc.getObject("Celements2.BlogConfigClass");
        boolean embedImages = blogConf.getIntValue("newsletterEmbedImages", 0) == 1;
        vcontext.put("embedImages", embedImages);
        String emailContent = emailContentDoc.getTranslatedContent(context);
        String htmlContent = context.getWiki().getRenderingEngine().interpretText(emailContent, context.getDoc(), context);
        String emailTitle = emailContentDoc.getTranslatedDocument(context).getTitle();
        String renderedTitle = context.getWiki().getRenderingEngine().interpretText(emailTitle, context.getDoc(), context);
        String from = "";
        String reply = "";
        if (blogConf != null) {
            from = blogConf.getStringValue("from_address");
            reply = blogConf.getStringValue("reply_to_address");
        }
        if ((from == null) || "".equals(from.trim())) {
            from = context.getWiki().getXWikiPreference("admin_email", context);
        }
        if ((reply == null) || "".equals(reply.trim())) {
            reply = from;
        }
        CelementsWebPluginApi celementsweb = (CelementsWebPluginApi) context.getWiki().getPluginApi("celementsweb", context);
        celementsweb.getPlugin().sendMail(from, reply, email, null, null, renderedTitle, htmlContent, "", getAllAttachmentsList(), null, context);
    } else {
        LOGGER.error("No newsletter activation Mail sent for '" + email + "'. No " + "Mailcontent found in Tools.NewsletterSubscriptionActivation");
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) VelocityContext(org.apache.velocity.VelocityContext) CelementsWebPluginApi(com.celements.web.plugin.api.CelementsWebPluginApi) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 85 with VelocityContext

use of org.apache.velocity.VelocityContext in project celements-blog by celements.

the class NewsletterReceivers method sendArticleByMail.

public List<String[]> sendArticleByMail(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    String articleName = request.get("sendarticle");
    String from = request.get("from");
    String replyTo = request.get("reply_to");
    String subject = request.get("subject");
    String testSend = request.get("testSend");
    boolean isTest = false;
    if ((testSend != null) && testSend.equals("1")) {
        isTest = true;
    }
    XWiki wiki = context.getWiki();
    List<String[]> result = new ArrayList<>();
    int successfullySent = 0;
    LOGGER.debug("articleName = " + articleName);
    LOGGER.debug("article exists = " + wiki.exists(articleName, context));
    if ((articleName != null) && (!"".equals(articleName.trim())) && (wiki.exists(articleName, context))) {
        XWikiDocument doc = wiki.getDocument(articleName, context);
        String baseURL = doc.getExternalURL("view", context);
        List<String[]> allUserMailPairs = null;
        LOGGER.debug("is test send: " + isTest);
        if (isTest) {
            String user = context.getUser();
            XWikiDocument userDoc = context.getWiki().getDocument(user, context);
            BaseObject userObj = userDoc.getObject("XWiki.XWikiUsers");
            if (userObj != null) {
                String email = userObj.getStringValue("email");
                if (email.trim().length() > 0) {
                    allUserMailPairs = new ArrayList<>();
                    String[] userFields = getUserAdminLanguage(user, getWebUtilsService().getDefaultLanguage());
                    allUserMailPairs.add((String[]) ArrayUtils.addAll(new String[] { user, email }, userFields));
                }
            }
        } else {
            allUserMailPairs = getNewsletterReceiversList();
        }
        String origUser = context.getUser();
        String origLanguage = context.getLanguage();
        VelocityContext vcontext = (VelocityContext) context.get("vcontext");
        Object origAdminLanguage = vcontext.get("admin_language");
        Object origMsgTool = vcontext.get("msg");
        Object origAdminMsgTool = vcontext.get("adminMsg");
        for (String[] userMailPair : allUserMailPairs) {
            String[] sendResult = sendNewsletterToOneReceiver(from, replyTo, subject, doc, baseURL, userMailPair, context);
            if ("0".equals(sendResult[1])) {
                successfullySent++;
            }
            result.add(sendResult);
        }
        context.setUser(origUser);
        context.setLanguage(origLanguage);
        vcontext.put("language", origLanguage);
        vcontext.put("admin_language", origAdminLanguage);
        vcontext.put("msg", origMsgTool);
        vcontext.put("adminMsg", origAdminMsgTool);
        setNewsletterSentObject(doc, from, replyTo, subject, successfullySent, isTest, context);
    }
    return result;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) XWiki(com.xpn.xwiki.XWiki) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject)

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