1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal

File DefaultSessionFactory.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
8
1
1
66
32
2
0.25
8
1
2

Classes

Class Line # Actions
DefaultSessionFactory 43 8 0% 2 3
0.7272727572.7%
 

Contributing tests

This file is covered by 2 tests. .

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.mail.internal;
21   
22    import java.util.Map;
23    import java.util.Properties;
24   
25    import javax.inject.Inject;
26    import javax.inject.Singleton;
27    import javax.mail.Session;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.mail.MailSenderConfiguration;
31    import org.xwiki.mail.SessionFactory;
32    import org.xwiki.mail.XWikiAuthenticator;
33   
34    /**
35    * Create a Java Mail {@link javax.mail.Session} object, taking its properties from the XWiki Configuration but allowing
36    * to pass additional properties (for example to reuse an existing Batch Id).
37    *
38    * @version $Id: beeb82bfaeb8d3d94225df05612ac174577850ad $
39    * @since 6.4
40    */
41    @Component
42    @Singleton
 
43    public class DefaultSessionFactory implements SessionFactory
44    {
45    @Inject
46    private MailSenderConfiguration configuration;
47   
 
48  38 toggle @Override
49    public Session create(Map<String, String> additionProperties)
50    {
51  38 Session session;
52   
53  38 Properties properties = this.configuration.getAllProperties();
54  38 for (Map.Entry<String, String> entry : additionProperties.entrySet()) {
55  0 properties.setProperty(entry.getKey(), entry.getValue());
56    }
57   
58  38 if (this.configuration.usesAuthentication()) {
59  0 session = Session.getInstance(properties, new XWikiAuthenticator(this.configuration));
60    } else {
61  38 session = Session.getInstance(properties);
62    }
63   
64  38 return session;
65    }
66    }