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

File XDOMEditorConfiguration.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
12
2
1
87
48
6
0.5
6
2
3

Classes

Class Line # Actions
XDOMEditorConfiguration 47 12 0% 6 1
0.9545454495.5%
 

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 javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.apache.commons.lang3.StringUtils;
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.configuration.ConfigurationSource;
29    import org.xwiki.edit.Editor;
30    import org.xwiki.edit.EditorConfiguration;
31    import org.xwiki.rendering.block.XDOM;
32   
33    /**
34    * Custom configuration for {@link XDOM} {@link Editor}s, which serves two roles:
35    * <ul>
36    * <li>preserves backward compatibility (because it looks for configuration properties that existed before the edit
37    * module was written)</li>
38    * <li>provides the default editor when there's no one configured</li>
39    * </ul>
40    * .
41    *
42    * @version $Id: e29072dbe23d4673dc4c971b769a60c88b17b8cd $
43    * @since 8.2RC1
44    */
45    @Component
46    @Singleton
 
47    public class XDOMEditorConfiguration implements EditorConfiguration<XDOM>
48    {
49    @Inject
50    @Named("user")
51    private ConfigurationSource userConfig;
52   
53    @Inject
54    @Named("documents")
55    private ConfigurationSource documentsConfig;
56   
57    @Inject
58    @Named("xwikicfg")
59    private ConfigurationSource xwikiConfig;
60   
 
61  92 toggle @Override
62    public String getDefaultEditor()
63    {
64  92 String propertyName = "editor";
65  92 String defaultEditor = this.userConfig.getProperty(propertyName, String.class);
66  92 if (StringUtils.isEmpty(defaultEditor)) {
67  84 defaultEditor = this.documentsConfig.getProperty(propertyName, String.class);
68  84 if (StringUtils.isEmpty(defaultEditor)) {
69  84 defaultEditor = this.xwikiConfig.getProperty("xwiki.editor", TextXDOMEditor.ROLE_HINT);
70    }
71    }
72    // We need to keep the value case insensitive for backwards compatibility.
73  92 return StringUtils.lowerCase(defaultEditor);
74    }
75   
 
76  429 toggle @Override
77    public String getDefaultEditor(String category)
78    {
79  429 if (StringUtils.isEmpty(category)) {
80  92 return getDefaultEditor();
81  337 } else if (TextXDOMEditor.ROLE_HINT.equals(category)) {
82  264 return TextXDOMEditor.ROLE_HINT;
83    } else {
84  73 return null;
85    }
86    }
87    }