1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.notifications.notifiers.internal.email

File AbstractNotificationEmailRenderer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
7
3
1
79
34
4
0.57
2.33
3
1.33

Classes

Class Line # Actions
AbstractNotificationEmailRenderer 38 7 0% 4 1
0.916666791.7%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.notifications.notifiers.internal.email;
21   
22    import javax.inject.Inject;
23   
24    import org.xwiki.notifications.CompositeEvent;
25    import org.xwiki.notifications.NotificationException;
26    import org.xwiki.notifications.notifiers.email.NotificationEmailRenderer;
27    import org.xwiki.rendering.block.Block;
28    import org.xwiki.rendering.syntax.Syntax;
29    import org.xwiki.template.Template;
30    import org.xwiki.template.TemplateManager;
31   
32    /**
33    * Helper for NotificationEmailRenderer that use the Template Manager to render notifications.
34    *
35    * @version $Id: 912ceb81ee2e0ee2d00ff5cfb0c1651dc9888ce4 $
36    * @since 9.5RC1
37    */
 
38    public abstract class AbstractNotificationEmailRenderer implements NotificationEmailRenderer
39    {
40    @Inject
41    protected EmailTemplateRenderer emailTemplateRenderer;
42   
43    @Inject
44    protected TemplateManager templateManager;
45   
46    /**
47    * Execute a template.
48    *
49    * @param event composite event to render
50    * @param userId id of the user who will receive the email
51    * @param templatePath path of the template to use (with a %s that the method will replace by the event type)
52    * @param syntax syntax of the template and of the output
53    * @return the rendered template
54    * @throws NotificationException if something wrong happens
55    */
 
56  4 toggle protected Block executeTemplate(CompositeEvent event, String userId, String templatePath, Syntax syntax)
57    throws NotificationException
58    {
59    // Generate the full template name
60  4 String templateName = String.format(templatePath, event.getType().replaceAll("\\/", "."));
61    // Get the template
62  4 Template template = templateManager.getTemplate(templateName);
63  4 if (template == null) {
64  4 template = templateManager.getTemplate(String.format(templatePath, "default"));
65    }
66  4 return emailTemplateRenderer.executeTemplate(event, userId, template, syntax);
67    }
68   
 
69  2 toggle protected String renderHTML(Block block)
70    {
71  2 return emailTemplateRenderer.renderHTML(block);
72    }
73   
 
74  2 toggle protected String renderPlainText(Block block)
75    {
76  2 return emailTemplateRenderer.renderPlainText(block);
77    }
78   
79    }