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

File WikiMacroDescriptor.java

 

Coverage histogram

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

Code metrics

0
24
10
1
183
84
10
0.42
2.4
10
1

Classes

Class Line # Actions
WikiMacroDescriptor 37 24 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 20 tests. .

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.rendering.macro.wikibridge;
21   
22    import java.util.LinkedHashMap;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.xwiki.rendering.macro.MacroId;
27    import org.xwiki.rendering.macro.descriptor.ContentDescriptor;
28    import org.xwiki.rendering.macro.descriptor.MacroDescriptor;
29    import org.xwiki.rendering.macro.descriptor.ParameterDescriptor;
30   
31    /**
32    * A {@link MacroDescriptor} for describing wiki macros.
33    *
34    * @version $Id: 9fa7e986539fad155152db3b1c48d15e7de8aaa3 $
35    * @since 2.0M2
36    */
 
37    public class WikiMacroDescriptor implements MacroDescriptor
38    {
39    /**
40    * Macro id.
41    */
42    private MacroId id;
43   
44    /**
45    * Macro name.
46    */
47    private String name;
48   
49    /**
50    * Macro description.
51    */
52    private String description;
53   
54    /**
55    * Default category under which this macro should be listed.
56    */
57    private String defaultCategory;
58   
59    /**
60    * Whether the macro is visible in the current wiki, for the current user or global.
61    */
62    private WikiMacroVisibility visibility;
63   
64    /**
65    * Macro content description.
66    */
67    private ContentDescriptor contentDescriptor;
68   
69    /**
70    * Parameter descriptors.
71    */
72    private List<WikiMacroParameterDescriptor> parameterDescriptors;
73   
74    /**
75    * Creates a new {@link WikiMacroDescriptor} instance.
76    *
77    * @param id the macro id
78    * @param name the macro name
79    * @param description macro description
80    * @param defaultCategory default category under which this macro should be listed.
81    * @param visibility the macro visibility (only visible in the current wiki, for the current user or global)
82    * @param contentDescriptor macro content description.
83    * @param parameterDescriptors parameter descriptors.
84    * @since 2.3M1
85    */
 
86  248 toggle public WikiMacroDescriptor(MacroId id, String name, String description, String defaultCategory,
87    WikiMacroVisibility visibility, ContentDescriptor contentDescriptor,
88    List<WikiMacroParameterDescriptor> parameterDescriptors)
89    {
90  248 this.id = id;
91  248 this.name = name;
92  248 this.description = description;
93  248 this.contentDescriptor = contentDescriptor;
94  248 this.parameterDescriptors = parameterDescriptors;
95  248 this.defaultCategory = defaultCategory;
96  248 this.visibility = visibility;
97    }
98   
99    /**
100    * Creates a new {@link WikiMacroDescriptor} instance.
101    *
102    * @param name the macro name
103    * @param description macro description
104    * @param defaultCategory default category under which this macro should be listed.
105    * @param visibility the macro visibility (only visible in the current wiki, for the current user or global)
106    * @param contentDescriptor macro content description.
107    * @param parameterDescriptors parameter descriptors.
108    * @since 2.2M1
109    * @deprecated since 2.3M1 use {@link #WikiMacroDescriptor(MacroId, String, String, String, WikiMacroVisibility, ContentDescriptor, List)} instead
110    */
 
111  1 toggle @Deprecated
112    public WikiMacroDescriptor(String name, String description, String defaultCategory, WikiMacroVisibility visibility,
113    ContentDescriptor contentDescriptor, List<WikiMacroParameterDescriptor> parameterDescriptors)
114    {
115  1 this.name = name;
116  1 this.description = description;
117  1 this.contentDescriptor = contentDescriptor;
118  1 this.parameterDescriptors = parameterDescriptors;
119  1 this.defaultCategory = defaultCategory;
120  1 this.visibility = visibility;
121    }
122   
 
123  464 toggle @Override
124    public MacroId getId()
125    {
126  464 return this.id;
127    }
128   
 
129  2 toggle @Override
130    public String getName()
131    {
132  2 return this.name;
133    }
134   
 
135  1 toggle @Override
136    public String getDescription()
137    {
138  1 return this.description;
139    }
140   
 
141  166 toggle @Override
142    public ContentDescriptor getContentDescriptor()
143    {
144  166 return this.contentDescriptor;
145    }
146   
 
147  154 toggle @Override
148    public Class< ? > getParametersBeanClass()
149    {
150  154 return WikiMacroParameters.class;
151    }
152   
 
153  155 toggle @Override
154    public Map<String, ParameterDescriptor> getParameterDescriptorMap()
155    {
156    // Note: use a linked hash map to preserve the parameter order.
157    // TODO: Replace saving the descriptors as a list and use a map instead so that this method becomes performant
158    // (as it should be).
159  155 Map<String, ParameterDescriptor> descriptors = new LinkedHashMap<String, ParameterDescriptor>();
160   
161  155 for (WikiMacroParameterDescriptor descriptor : this.parameterDescriptors) {
162  1227 descriptors.put(descriptor.getId(), descriptor);
163    }
164   
165  155 return descriptors;
166    }
167   
 
168  1 toggle @Override
169    public String getDefaultCategory()
170    {
171  1 return this.defaultCategory;
172    }
173   
174    /**
175    * @return the visibility of the macro (ie whether the macro is visible in the current wiki, for the current user or
176    * global)
177    * @since 2.2M1
178    */
 
179  535 toggle public WikiMacroVisibility getVisibility()
180    {
181  535 return this.visibility;
182    }
183    }