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

File EditScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

0
8
8
1
148
60
8
1
1
8
1

Classes

Class Line # Actions
EditScriptService 47 8 0% 8 14
0.12512.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.script;
21   
22    import java.lang.reflect.Type;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.edit.EditConfiguration;
31    import org.xwiki.edit.Editor;
32    import org.xwiki.edit.EditorManager;
33    import org.xwiki.script.service.ScriptService;
34    import org.xwiki.script.service.ScriptServiceManager;
35    import org.xwiki.stability.Unstable;
36   
37    /**
38    * Script oriented edit APIs.
39    *
40    * @version $Id: 49c7344075865ee5d8d8aa2673ddea296951df89 $
41    * @since 8.2RC1
42    */
43    @Component
44    @Singleton
45    @Named(EditScriptService.ROLE_HINT)
46    @Unstable
 
47    public class EditScriptService implements ScriptService
48    {
49    /**
50    * The role hint of this component.
51    */
52    public static final String ROLE_HINT = "edit";
53   
54    @Inject
55    private EditorManager editorManager;
56   
57    @Inject
58    private EditConfiguration editConfig;
59   
60    @Inject
61    private ScriptServiceManager scriptServiceManager;
62   
63    /**
64    * @param dataType the data type
65    * @param <D> the data type
66    * @return the list of editors that can edit the specified type of data
67    */
 
68  0 toggle public <D> List<Editor<D>> getEditors(Type dataType)
69    {
70  0 return this.editorManager.getEditors(dataType);
71    }
72   
73    /**
74    * @param dataType the data type
75    * @param category the editor category
76    * @param <D> the data type
77    * @return the list of editors that have the specified category and which are associated with the given data type
78    */
 
79  0 toggle public <D> List<Editor<D>> getEditors(Type dataType, String category)
80    {
81  0 return this.editorManager.getEditors(dataType, category);
82    }
83   
84    /**
85    * @param dataType the data type
86    * @param hint the {@link Editor} component role hint
87    * @param <D> the data type
88    * @return an editor that can edit the specified data type and which has the given {@link Editor} component role
89    * hint, or {@code null} if no such editor can be found
90    */
 
91  0 toggle public <D> Editor<D> getEditor(Type dataType, String hint)
92    {
93  0 return this.editorManager.getEditor(dataType, hint);
94    }
95   
96    /**
97    * @param dataType the data type
98    * @param <D> the data type
99    * @return the configured default editor associated with the specified data type
100    */
 
101  0 toggle public <D> Editor<D> getDefaultEditor(Type dataType)
102    {
103  0 return this.editorManager.getDefaultEditor(dataType);
104    }
105   
106    /**
107    * @param dataType the data type
108    * @param category the editor category
109    * @param <D> the data type
110    * @return the configured default editor that has the specified category and which is associated with the given data
111    * type
112    */
 
113  0 toggle public <D> Editor<D> getDefaultEditor(Type dataType, String category)
114    {
115  0 return this.editorManager.getDefaultEditor(dataType, category);
116    }
117   
118    /**
119    * @param dataType the data type
120    * @return the id of the configured default editor associated with the specified data type
121    */
 
122  0 toggle public String getDefaultEditorId(Type dataType)
123    {
124  0 return this.editConfig.getDefaultEditor(dataType);
125    }
126   
127    /**
128    * @param dataType the data type
129    * @param category the editor category
130    * @return the id of the configured default editor for the specified category and which is associated with the given
131    * data type
132    */
 
133  0 toggle public String getDefaultEditorId(Type dataType, String category)
134    {
135  0 return this.editConfig.getDefaultEditor(dataType, category);
136    }
137   
138    /**
139    * @param serviceName the name of the sub {@link ScriptService}
140    * @param <S> the {@link ScriptService} type
141    * @return the sub {@link ScriptService} with the specified name, or {@code null} if none could be found
142    */
 
143  45 toggle @SuppressWarnings("unchecked")
144    public <S extends ScriptService> S get(String serviceName)
145    {
146  45 return (S) this.scriptServiceManager.get(ROLE_HINT + "." + serviceName);
147    }
148    }