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

File DefaultAnnotationConfiguration.java

 

Coverage histogram

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

Code metrics

2
13
7
1
135
76
8
0.62
1.86
7
1.14

Classes

Class Line # Actions
DefaultAnnotationConfiguration 47 13 0% 8 13
0.409090940.9%
 

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.annotation.internal;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28   
29    import org.xwiki.annotation.AnnotationConfiguration;
30    import org.xwiki.bridge.DocumentAccessBridge;
31    import org.xwiki.configuration.ConfigurationSource;
32    import org.xwiki.model.EntityType;
33    import org.xwiki.model.ModelContext;
34    import org.xwiki.model.reference.DocumentReference;
35    import org.xwiki.model.reference.DocumentReferenceResolver;
36    import org.xwiki.model.reference.EntityReference;
37    import org.xwiki.model.reference.EntityReferenceProvider;
38    import org.xwiki.model.reference.SpaceReference;
39    import org.xwiki.model.reference.WikiReference;
40   
41    /**
42    * Default implementation using as configuration source the configuration document on the current wiki.
43    *
44    * @version $Id: a8f3f28efc2e9dcd77367abcb6e3707bf70ebd79 $
45    * @since 4.0M2
46    */
 
47    public class DefaultAnnotationConfiguration implements AnnotationConfiguration
48    {
49    /**
50    * Annotation configuration source that is read from the configuration document on the current wiki.
51    */
52    @Inject
53    @Named("annotation")
54    protected Provider<ConfigurationSource> configuration;
55   
56    /**
57    * Resolver used to read the string values from the configuration as document references.
58    */
59    @Inject
60    @Named("currentmixed")
61    protected DocumentReferenceResolver<String> resolver;
62   
63    /**
64    * @see #getCurrentWikiReference()
65    */
66    @Inject
67    protected ModelContext modelContext;
68   
69    @Inject
70    @Named("current")
71    protected EntityReferenceProvider entityReferenceProvider;
72   
73    /**
74    * @see #isInstalled()
75    */
76    @Inject
77    protected DocumentAccessBridge dab;
78   
 
79  9 toggle @Override
80    public boolean isInstalled()
81    {
82  9 return dab.exists(new DocumentReference(getCurrentWikiReference().getName(),
83    AnnotationConfiguration.CONFIGURATION_PAGE_SPACE_NAME, AnnotationConfiguration.CONFIGURATION_PAGE_NAME));
84    }
85   
 
86  0 toggle @Override
87    public boolean isActivated()
88    {
89  0 return configuration.get().getProperty("activated", 0) == 1;
90    }
91   
 
92  0 toggle @Override
93    public List<SpaceReference> getExceptionSpaces()
94    {
95  0 List<String> exceptionSpaces = configuration.get().getProperty("exceptionSpaces", List.class);
96   
97  0 List<SpaceReference> result = new ArrayList<SpaceReference>();
98  0 for (String exceptionSpace : exceptionSpaces) {
99  0 result.add(new SpaceReference(exceptionSpace, getCurrentWikiReference()));
100    }
101   
102  0 return result;
103    }
104   
 
105  0 toggle @Override
106    public boolean isDisplayedByDefault()
107    {
108  0 return configuration.get().getProperty("displayed", 0) == 1;
109    }
110   
 
111  0 toggle @Override
112    public boolean isDisplayedHighlightedByDefault()
113    {
114  0 return configuration.get().getProperty("displayHighlight", 0) == 1;
115    }
116   
 
117  38 toggle @Override
118    public DocumentReference getAnnotationClassReference()
119    {
120  38 String annotationClassName = configuration.get().getProperty("annotationClass", "XWiki.XWikiComments");
121   
122  38 return resolver.resolve(annotationClassName);
123    }
124   
125    /**
126    * @return the reference pointing to the current wiki
127    */
 
128  9 toggle protected WikiReference getCurrentWikiReference()
129    {
130  9 EntityReference wikiReference = this.entityReferenceProvider.getDefaultReference(EntityType.WIKI);
131   
132  9 return wikiReference instanceof WikiReference ? (WikiReference) wikiReference
133    : new WikiReference(wikiReference);
134    }
135    }