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

File EditorDescriptorBuilder.java

 

Coverage histogram

../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

8
24
11
1
168
89
15
0.62
2.18
11
1.36

Classes

Class Line # Actions
EditorDescriptorBuilder 41 24 0% 15 21
0.511627951.2%
 

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;
21   
22    import javax.inject.Inject;
23   
24    import org.apache.commons.lang3.StringUtils;
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.component.annotation.InstantiationStrategy;
27    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
28    import org.xwiki.edit.internal.DefaultEditorDescriptor;
29    import org.xwiki.localization.ContextualLocalizationManager;
30    import org.xwiki.stability.Unstable;
31   
32    /**
33    * Builds an {@link EditorDescriptor} instance.
34    *
35    * @version $Id: dbd5e3d00aa7aecd57e3cfd33089b3bc95fa82d9 $
36    * @since 8.2RC1
37    */
38    @Component(roles = EditorDescriptorBuilder.class)
39    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
40    @Unstable
 
41    public class EditorDescriptorBuilder implements EditorDescriptor
42    {
43    private String id;
44   
45    private String name;
46   
47    private String description;
48   
49    private String icon;
50   
51    private String category;
52   
53    @Inject
54    private ContextualLocalizationManager localization;
55   
56    /**
57    * Sets the editor id.
58    *
59    * @param id the editor id
60    * @return this builder
61    */
 
62  35 toggle public EditorDescriptorBuilder setId(String id)
63    {
64  35 this.id = id;
65  35 return this;
66    }
67   
 
68  0 toggle @Override
69    public String getId()
70    {
71  0 return this.id;
72    }
73   
74    /**
75    * Sets the editor name.
76    *
77    * @param name the editor name
78    * @return this builder
79    */
 
80  0 toggle public EditorDescriptorBuilder setName(String name)
81    {
82  0 this.name = name;
83  0 return this;
84    }
85   
 
86  0 toggle @Override
87    public String getName()
88    {
89  0 return this.name;
90    }
91   
92    /**
93    * Sets the editor description.
94    *
95    * @param description the editor description
96    * @return this builder
97    */
 
98  0 toggle public EditorDescriptorBuilder setDescription(String description)
99    {
100  0 this.description = description;
101  0 return this;
102    }
103   
 
104  0 toggle @Override
105    public String getDescription()
106    {
107  0 return this.description;
108    }
109   
110    /**
111    * Sets the editor icon.
112    *
113    * @param icon the editor icon
114    * @return this builder
115    */
 
116  0 toggle public EditorDescriptorBuilder setIcon(String icon)
117    {
118  0 this.icon = icon;
119  0 return this;
120    }
121   
 
122  0 toggle @Override
123    public String getIcon()
124    {
125  0 return this.icon;
126    }
127   
128    /**
129    * Sets the editor category.
130    *
131    * @param category the editor category
132    * @return this builder
133    */
 
134  35 toggle public EditorDescriptorBuilder setCategory(String category)
135    {
136  35 this.category = category;
137  35 return this;
138    }
139   
 
140  0 toggle @Override
141    public String getCategory()
142    {
143  0 return this.category;
144    }
145   
146    /**
147    * Builds the editor descriptor.
148    *
149    * @return the editor descriptor
150    */
 
151  219 toggle public EditorDescriptor build()
152    {
153  219 if (StringUtils.isEmpty(this.id)) {
154  0 throw new RuntimeException("The editor id is mandatory.");
155    }
156  219 if (StringUtils.isEmpty(this.name)) {
157  27 this.name = this.localization.getTranslationPlain(String.format("edit.editor.%s.name", this.id));
158  27 if (StringUtils.isEmpty(this.name)) {
159  18 this.name = this.id;
160    }
161    }
162  219 if (this.description == null) {
163  155 this.description =
164    this.localization.getTranslationPlain(String.format("edit.editor.%s.description", this.id));
165    }
166  219 return new DefaultEditorDescriptor(this.id, this.name, this.description, this.icon, this.category);
167    }
168    }