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

File DefaultNotificationEmailRenderer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart4.png
80% of files have more coverage

Code metrics

12
21
4
1
103
67
11
0.52
5.25
4
2.75

Classes

Class Line # Actions
DefaultNotificationEmailRenderer 43 21 0% 11 23
0.378378437.8%
 

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    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentLookupException;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.notifications.CompositeEvent;
30    import org.xwiki.notifications.NotificationException;
31    import org.xwiki.notifications.notifiers.email.NotificationEmailRenderer;
32    import org.xwiki.rendering.syntax.Syntax;
33    import org.xwiki.text.StringUtils;
34   
35    /**
36    * Default implementation of {@link NotificationEmailRenderer}.
37    *
38    * @version $Id: 9501a56121eb6168015610deb3559d0ce35d2a98 $
39    * @since 9.5RC1
40    */
41    @Component
42    @Singleton
 
43    public class DefaultNotificationEmailRenderer extends AbstractNotificationEmailRenderer
44    {
45    @Inject
46    @Named("context")
47    private ComponentManager componentManager;
48   
 
49  4 toggle private NotificationEmailRenderer getRenderer(CompositeEvent event)
50    {
51  4 try {
52  4 return componentManager.getInstance(NotificationEmailRenderer.class, event.getType());
53    } catch (ComponentLookupException e) {
54  4 return null;
55    }
56    }
57   
 
58  2 toggle @Override
59    public String renderHTML(CompositeEvent event, String userId) throws NotificationException
60    {
61  2 NotificationEmailRenderer renderer = getRenderer(event);
62  2 if (renderer != null) {
63  0 String result = renderer.renderHTML(event, userId);
64  0 if (StringUtils.isNotBlank(result)) {
65  0 return result;
66    }
67    }
68   
69  2 return renderHTML(executeTemplate(event, userId, "notification/email/%s.html.vm",
70    Syntax.XHTML_1_0));
71    }
72   
73   
 
74  2 toggle @Override
75    public String renderPlainText(CompositeEvent event, String userId) throws NotificationException
76    {
77  2 NotificationEmailRenderer renderer = getRenderer(event);
78  2 if (renderer != null) {
79  0 String result = renderer.renderPlainText(event, userId);
80  0 if (StringUtils.isNotBlank(result)) {
81  0 return result;
82    }
83    }
84   
85  2 return renderPlainText(executeTemplate(event, userId, "notification/email/%s.plain.vm",
86    Syntax.PLAIN_1_0));
87    }
88   
 
89  0 toggle @Override
90    public String generateEmailSubject(CompositeEvent event, String userId) throws NotificationException
91    {
92  0 NotificationEmailRenderer renderer = getRenderer(event);
93  0 if (renderer != null) {
94  0 String result = renderer.generateEmailSubject(event, userId);
95  0 if (StringUtils.isNotBlank(result)) {
96  0 return result;
97    }
98    }
99   
100  0 return renderPlainText(executeTemplate(event, userId, "notification/email/%s.subject.vm",
101    Syntax.PLAIN_1_0));
102    }
103    }