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

File DefaultEditConfiguration.java

 

Coverage histogram

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

Code metrics

8
18
4
1
105
67
9
0.5
4.5
4
2.25

Classes

Class Line # Actions
DefaultEditConfiguration 46 18 0% 9 4
0.866666786.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.edit.internal;
21   
22    import java.lang.reflect.Type;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Provider;
27    import javax.inject.Singleton;
28   
29    import org.apache.commons.lang3.StringUtils;
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.component.util.DefaultParameterizedType;
34    import org.xwiki.configuration.ConfigurationSource;
35    import org.xwiki.edit.EditConfiguration;
36    import org.xwiki.edit.EditorConfiguration;
37   
38    /**
39    * Default {@link EditConfiguration} implementation.
40    *
41    * @version $Id: beb76e228b94d912bfd5f4d63efeccfe9117a807 $
42    * @since 8.2RC1
43    */
44    @Component
45    @Singleton
 
46    public class DefaultEditConfiguration implements EditConfiguration
47    {
48    @Inject
49    @Named("context")
50    private Provider<ComponentManager> componentManagerProvider;
51   
52    @Inject
53    @Named("editorBindings/all")
54    private ConfigurationSource allEditorBindingsSource;
55   
56    @Inject
57    @Named("xwikiproperties")
58    private ConfigurationSource xwikiPropertiesSource;
59   
 
60  92 toggle @Override
61    public String getDefaultEditor(Type dataType)
62    {
63  92 return getDefaultEditor(dataType, null);
64    }
65   
 
66  429 toggle @Override
67    public String getDefaultEditor(Type dataType, String category)
68    {
69  429 String dataTypeName = dataType.getTypeName();
70  429 if (!StringUtils.isEmpty(category)) {
71  337 dataTypeName += "#" + category;
72    }
73    // Get the default editor configured using the standard configuration properties and sources.
74  429 String defaultEditor = getDefaultEditor(dataTypeName);
75  429 if (StringUtils.isEmpty(defaultEditor)) {
76    // A custom configuration can look for the default editor in custom configuration sources, using custom
77    // properties, or it can simply return the default editor where there's no one configured.
78  429 EditorConfiguration<?> customConfig = getCustomConfiguration(dataType);
79  429 if (customConfig != null) {
80  429 defaultEditor = customConfig.getDefaultEditor(category);
81    }
82    }
83  429 return defaultEditor;
84    }
85   
 
86  429 toggle private <D extends Type> EditorConfiguration<D> getCustomConfiguration(D dataType)
87    {
88  429 DefaultParameterizedType customConfigType =
89    new DefaultParameterizedType(null, EditorConfiguration.class, dataType);
90  429 try {
91  429 return this.componentManagerProvider.get().getInstance(customConfigType);
92    } catch (ComponentLookupException e) {
93  0 return null;
94    }
95    }
96   
 
97  429 toggle private String getDefaultEditor(String dataType)
98    {
99  429 String defaultEditor = this.allEditorBindingsSource.getProperty(dataType, String.class);
100  429 if (StringUtils.isEmpty(defaultEditor)) {
101  429 defaultEditor = this.xwikiPropertiesSource.getProperty("edit.defaultEditor." + dataType, String.class);
102    }
103  429 return defaultEditor;
104    }
105    }