1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.macro.descriptor

File AbstractMacroDescriptor.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

4
22
13
1
213
94
15
0.68
1.69
13
1.15

Classes

Class Line # Actions
AbstractMacroDescriptor 37 22 0% 15 7
0.8205128382.1%
 

Contributing tests

This file is covered by 295 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.descriptor;
21   
22    import java.util.Collections;
23    import java.util.LinkedHashMap;
24    import java.util.Map;
25   
26    import org.xwiki.properties.BeanDescriptor;
27    import org.xwiki.properties.PropertyDescriptor;
28    import org.xwiki.rendering.macro.MacroId;
29    import org.xwiki.stability.Unstable;
30   
31    /**
32    * Describe a macro.
33    *
34    * @version $Id: 5640c0c500db5c8b43985811ed96cbe2592891ec $
35    * @since 1.6M1
36    */
 
37    public abstract class AbstractMacroDescriptor implements MacroDescriptor
38    {
39    /**
40    * @see #getId()
41    */
42    private MacroId id;
43   
44    /**
45    * @see #getName()
46    */
47    private String name;
48   
49    /**
50    * The description of the macro.
51    */
52    private String description;
53   
54    /**
55    * Define a macro content.
56    */
57    private ContentDescriptor contentDescriptor;
58   
59    /**
60    * The description of the parameters bean.
61    */
62    private BeanDescriptor parametersBeanDescriptor;
63   
64    /**
65    * Default macro category.
66    */
67    private String defaultCategory;
68   
69    /**
70    * @see #supportsInlineMode()
71    */
72    private boolean supportsInlineMode;
73   
74    /**
75    * A map containing the {@link ParameterDescriptor} for each parameters supported for this macro.
76    * <p>
77    * The {@link Map} keys are lower cased for easier case insensitive search, to get the "real" name of the property
78    * use {@link ParameterDescriptor#getName()}.
79    */
80    private Map<String, ParameterDescriptor> parameterDescriptorMap = new LinkedHashMap<String, ParameterDescriptor>();
81   
82    /**
83    * @param id the id of the macro
84    * @param name the name of the macro (eg "Table Of Contents" for the TOC macro)
85    * @param description the description of the macro.
86    * @param contentDescriptor the description of the macro content. null indicate macro does not support content.
87    * @param parametersBeanDescriptor the description of the parameters bean or null if there are no parameters for
88    * this macro.
89    * @since 2.3M1
90    */
 
91  648 toggle public AbstractMacroDescriptor(MacroId id, String name, String description, ContentDescriptor contentDescriptor,
92    BeanDescriptor parametersBeanDescriptor)
93    {
94  648 this.id = id;
95  648 this.name = name;
96  648 this.description = description;
97  648 this.contentDescriptor = contentDescriptor;
98  648 this.parametersBeanDescriptor = parametersBeanDescriptor;
99    }
100   
101    /**
102    * @param name the name of the macro (eg "Table Of Contents" for the TOC macro)
103    * @param description the description of the macro.
104    * @param contentDescriptor the description of the macro content. null indicate macro does not support content.
105    * @param parametersBeanDescriptor the description of the parameters bean or null if there are no parameters for
106    * this macro.
107    * @since 2.0M3
108    * @deprecated since 2.3M1 use
109    * {@link #AbstractMacroDescriptor(MacroId, String, String, ContentDescriptor, BeanDescriptor)} instead
110    */
 
111  0 toggle @Deprecated
112    public AbstractMacroDescriptor(String name, String description, ContentDescriptor contentDescriptor,
113    BeanDescriptor parametersBeanDescriptor)
114    {
115  0 this.name = name;
116  0 this.description = description;
117  0 this.contentDescriptor = contentDescriptor;
118  0 this.parametersBeanDescriptor = parametersBeanDescriptor;
119    }
120   
121    /**
122    * Extract parameters informations from {@link #parametersBeanDescriptor} and insert it in
123    * {@link #parameterDescriptorMap}.
124    *
125    * @since 1.7M2
126    */
 
127  645 toggle protected void extractParameterDescriptorMap()
128    {
129  645 for (PropertyDescriptor propertyDescriptor : this.parametersBeanDescriptor.getProperties()) {
130  1803 DefaultParameterDescriptor desc = new DefaultParameterDescriptor(propertyDescriptor);
131  1803 this.parameterDescriptorMap.put(desc.getId().toLowerCase(), desc);
132    }
133    }
134   
135    /**
136    * {@inheritDoc}
137    *
138    * @since 2.3M1
139    */
 
140  538682 toggle @Override
141    public MacroId getId()
142    {
143  538769 return this.id;
144    }
145   
146    /**
147    * {@inheritDoc}
148    *
149    * @since 2.0M3
150    */
 
151  3379 toggle @Override
152    public String getName()
153    {
154  3379 return this.name;
155    }
156   
 
157  19 toggle @Override
158    public ContentDescriptor getContentDescriptor()
159    {
160  19 return this.contentDescriptor;
161    }
162   
 
163  3379 toggle @Override
164    public String getDescription()
165    {
166  3379 return this.description;
167    }
168   
 
169  514472 toggle @Override
170    public Class<?> getParametersBeanClass()
171    {
172  514641 return (null != this.parametersBeanDescriptor) ? this.parametersBeanDescriptor.getBeanClass() : Object.class;
173    }
174   
 
175  7 toggle @Override
176    public Map<String, ParameterDescriptor> getParameterDescriptorMap()
177    {
178  7 return (null != this.parametersBeanDescriptor) ? Collections.unmodifiableMap(this.parameterDescriptorMap)
179    : Collections.<String, ParameterDescriptor>emptyMap();
180    }
181   
 
182  3437 toggle @Override
183    public String getDefaultCategory()
184    {
185  3437 return this.defaultCategory;
186    }
187   
188    /**
189    * @param defaultCategory default category under which this macro should be listed.
190    * @see MacroDescriptor#getDefaultCategory()
191    */
 
192  639 toggle public void setDefaultCategory(String defaultCategory)
193    {
194  639 this.defaultCategory = defaultCategory;
195    }
196   
 
197  2 toggle @Override
198    public boolean supportsInlineMode()
199    {
200  2 return this.supportsInlineMode;
201    }
202   
203    /**
204    * @param supportsInlineMode {@code true} to support in-line mode, {@code false} otherwise
205    * @see #supportsInlineMode()
206    * @since 10.10RC1
207    */
 
208  639 toggle @Unstable
209    public void setSupportsInlineMode(boolean supportsInlineMode)
210    {
211  639 this.supportsInlineMode = supportsInlineMode;
212    }
213    }