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

File SendMailConfigClassDocumentConfigurationSource.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
13
4
1
100
54
7
0.54
3.25
4
1.75

Classes

Class Line # Actions
SendMailConfigClassDocumentConfigurationSource 43 13 0% 7 2
0.904761990.5%
 

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.configuration;
21   
22    import javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.configuration.internal.AbstractDocumentConfigurationSource;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.LocalDocumentReference;
29   
30    import com.xpn.xwiki.XWikiException;
31   
32    /**
33    * Provides configuration from the Mail.SendMailConfigClass document in the current wiki.
34    * If the Mail.SendMailConfigClass xobject exists in the Mail.MailConfig document then always use configuration
35    * values from it and if it doesn't then use the passed default values (if a default value is passed).
36    *
37    * @version $Id: fdf1f5a23e091edfb909eb55893f8687143fc794 $
38    * @since 6.4M2
39    */
40    @Component
41    @Named("mailsend")
42    @Singleton
 
43    public class SendMailConfigClassDocumentConfigurationSource extends AbstractDocumentConfigurationSource
44    {
45    private static final String MAIL_SPACE = "Mail";
46   
47    /**
48    * The local reference of the Mail.SendMailConfigClass xclass.
49    */
50    private static final LocalDocumentReference CLASS_REFERENCE =
51    new LocalDocumentReference(MAIL_SPACE, "SendMailConfigClass");
52   
53    /**
54    * The local reference of the Mail.MailConfig document.
55    */
56    private static final LocalDocumentReference DOC_REFERENCE =
57    new LocalDocumentReference(MAIL_SPACE, "MailConfig");
58   
 
59  84 toggle @Override
60    protected String getCacheId()
61    {
62  84 return "configuration.document.mail.send";
63    }
64   
 
65  404 toggle @Override
66    protected DocumentReference getDocumentReference()
67    {
68  404 return new DocumentReference(DOC_REFERENCE, getCurrentWikiReference());
69    }
70   
 
71  53 toggle @Override
72    protected LocalDocumentReference getClassReference()
73    {
74  53 return CLASS_REFERENCE;
75    }
76   
 
77  255 toggle @Override
78    public <T> T getProperty(String key, T defaultValue)
79    {
80  255 T result;
81  255 if (defaultValue != null) {
82  2 try {
83  2 if (getBaseObject() == null) {
84    // No Mail.SendMailConfigClass xobject in the Mail.MailConfig document, use the default value!
85  1 result = super.getProperty(key, defaultValue);
86    } else {
87    // A Mail.SendMailConfigClass xobject exists in the Mail.MailConfig document, always use the
88    // value from it.
89  1 result = super.getProperty(key, (Class<? extends T>) defaultValue.getClass());
90    }
91    } catch (XWikiException e) {
92  0 this.logger.error("Failed to access configuration property [{}]", key, e);
93  0 result = null;
94    }
95    } else {
96  253 result = super.getProperty(key);
97    }
98  255 return result;
99    }
100    }