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

File AbstractTypedEditScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart3.png
80% of files have more coverage

Code metrics

0
8
8
1
121
50
8
1
1
8
1

Classes

Class Line # Actions
AbstractTypedEditScriptService 42 8 0% 8 12
0.2525%
 

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.script;
21   
22    import java.lang.reflect.ParameterizedType;
23    import java.lang.reflect.Type;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27   
28    import org.xwiki.edit.EditConfiguration;
29    import org.xwiki.edit.Editor;
30    import org.xwiki.edit.EditorManager;
31    import org.xwiki.script.service.ScriptService;
32    import org.xwiki.stability.Unstable;
33   
34    /**
35    * Base class for specialized edit script services that target specific types of editors.
36    *
37    * @param <D> the type of data edited by the editors targeted by this script service
38    * @version $Id: f8f7ccc755640bc8f4976b21ac9775dfa2f13eb6 $
39    * @since 8.2RC1
40    */
41    @Unstable
 
42    public abstract class AbstractTypedEditScriptService<D> implements ScriptService
43    {
44    @Inject
45    private EditorManager editorManager;
46   
47    @Inject
48    private EditConfiguration editConfig;
49   
50    /**
51    * @return the type of data edited by the editors targeted by this script service
52    */
 
53  45 toggle protected Type getDataType()
54    {
55  45 return ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
56    }
57   
58    /**
59    * @return the list of editors that can edit the type of data bound to this script service
60    */
 
61  0 toggle public List<Editor<D>> getEditors()
62    {
63  0 return this.editorManager.getEditors(this.getDataType());
64    }
65   
66    /**
67    * @param category the editor category
68    * @return the list of editors that have the specified category and which can edit the type of data bound to this
69    * script service
70    */
 
71  0 toggle public List<Editor<D>> getEditors(String category)
72    {
73  0 return this.editorManager.getEditors(this.getDataType(), category);
74    }
75   
76    /**
77    * @param hint the {@link Editor} component role hint
78    * @return an editor that can edit the type of data bound to this script service and which has the given
79    * {@link Editor} component role hint, or {@code null} if no such editor can be found
80    */
 
81  0 toggle public Editor<D> getEditor(String hint)
82    {
83  0 return this.editorManager.getEditor(this.getDataType(), hint);
84    }
85   
86    /**
87    * @return the configured default editor that can edit the type of data bound to this script service
88    */
 
89  0 toggle public Editor<D> getDefaultEditor()
90    {
91  0 return this.editorManager.getDefaultEditor(this.getDataType());
92    }
93   
94    /**
95    * @param category the editor category
96    * @return the configured default editor that has the specified category and which can edit the type of data bound
97    * to this script service
98    */
 
99  45 toggle public Editor<D> getDefaultEditor(String category)
100    {
101  45 return this.editorManager.getDefaultEditor(this.getDataType(), category);
102    }
103   
104    /**
105    * @return the id of the configured default editor that can edit the type of data bound to this script service
106    */
 
107  0 toggle public String getDefaultEditorId()
108    {
109  0 return this.editConfig.getDefaultEditor(this.getDataType());
110    }
111   
112    /**
113    * @param category the editor category
114    * @return the id of the configured default editor for the specified category and which can edit the type of data
115    * bound to this script service
116    */
 
117  0 toggle public String getDefaultEditorId(String category)
118    {
119  0 return this.editConfig.getDefaultEditor(this.getDataType(), category);
120    }
121    }