Search in sources :

Example 11 with XWikiMessageTool

use of com.xpn.xwiki.web.XWikiMessageTool in project celements-blog by celements.

the class NewsletterReceivers method sendNewsletterToOneReceiver.

String[] sendNewsletterToOneReceiver(String from, String replyTo, String subject, XWikiDocument doc, String baseURL, String[] userMailPair, XWikiContext context) throws XWikiException {
    VelocityContext vcontext = (VelocityContext) context.get("vcontext");
    String[] result;
    LOGGER.debug("userMailPair: " + ArrayUtils.toString(userMailPair));
    context.setUser(userMailPair[0]);
    String language = userMailPair[2];
    context.setLanguage(language);
    vcontext.put("firstname", userMailPair[3]);
    vcontext.put("name", userMailPair[4]);
    vcontext.put("email", userMailPair[1]);
    vcontext.put("language", language);
    vcontext.put("newsletter_language", language);
    vcontext.put("admin_language", language);
    XWikiMessageTool msgTool = getWebUtilsService().getMessageTool(language);
    vcontext.put("msg", msgTool);
    vcontext.put("adminMsg", msgTool);
    if (context.getWiki().checkAccess("view", doc, context)) {
        String senderContextLang = context.getLanguage();
        context.setLanguage(language);
        String htmlContent = getHtmlContent(doc, baseURL);
        context.setLanguage(language);
        htmlContent += getUnsubscribeFooter(userMailPair[1], doc);
        context.setLanguage(senderContextLang);
        XWikiMessageTool messageTool = getWebUtilsService().getMessageTool(language);
        int singleResult = sendMail(from, replyTo, userMailPair[1], subject, baseURL, htmlContent);
        result = new String[] { userMailPair[1], Integer.toString(singleResult) };
    } else {
        LOGGER.warn("Tried to send " + doc + " to user " + userMailPair[0] + " which" + " has no view rights on this Document.");
        List<String> params = new ArrayList<>();
        params.add(doc.toString());
        XWikiMessageTool messageTool = getWebUtilsService().getMessageTool(language);
        result = new String[] { userMailPair[1], messageTool.get("cel_blog_newsletter_receiver_no_rights", params) };
    }
    return result;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) XWikiMessageTool(com.xpn.xwiki.web.XWikiMessageTool)

Aggregations

XWikiMessageTool (com.xpn.xwiki.web.XWikiMessageTool)11 XWikiContext (com.xpn.xwiki.XWikiContext)5 TreeMap (java.util.TreeMap)5 Test (org.junit.Test)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 BaseObject (com.xpn.xwiki.objects.BaseObject)4 ArrayList (java.util.ArrayList)3 VelocityContext (org.apache.velocity.VelocityContext)2 XWikiException (com.xpn.xwiki.XWikiException)1 Locale (java.util.Locale)1 ContextualLocalizationManager (org.xwiki.localization.ContextualLocalizationManager)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1