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

File AbstractMacroDescriptor.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

4
20
11
1
190
82
13
0.65
1.82
11
1.18

Classes

Class Line # Actions
AbstractMacroDescriptor 36 20 0% 13 11
0.685714368.6%
 

Contributing tests

This file is covered by 256 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   
30    /**
31    * Describe a macro.
32    *
33    * @version $Id: 3863090a3d0bbaff3711797682b4ac0d3e335f38 $
34    * @since 1.6M1
35    */
 
36    public abstract class AbstractMacroDescriptor implements MacroDescriptor
37    {
38    /**
39    * @see #getId()
40    */
41    private MacroId id;
42   
43    /**
44    * @see #getName()
45    */
46    private String name;
47   
48    /**
49    * The description of the macro.
50    */
51    private String description;
52   
53    /**
54    * Define a macro content.
55    */
56    private ContentDescriptor contentDescriptor;
57   
58    /**
59    * The description of the parameters bean.
60    */
61    private BeanDescriptor parametersBeanDescriptor;
62   
63    /**
64    * Default macro category.
65    */
66    private String defaultCategory;
67   
68    /**
69    * A map containing the {@link ParameterDescriptor} for each parameters supported for this macro.
70    * <p>
71    * The {@link Map} keys are lower cased for easier case insensitive search, to get the "real" name of the property
72    * use {@link ParameterDescriptor#getName()}.
73    */
74    private Map<String, ParameterDescriptor> parameterDescriptorMap = new LinkedHashMap<String, ParameterDescriptor>();
75   
76    /**
77    * @param id the id of the macro
78    * @param name the name of the macro (eg "Table Of Contents" for the TOC macro)
79    * @param description the description of the macro.
80    * @param contentDescriptor the description of the macro content. null indicate macro does not support content.
81    * @param parametersBeanDescriptor the description of the parameters bean or null if there are no parameters for
82    * this macro.
83    * @since 2.3M1
84    */
 
85  472 toggle public AbstractMacroDescriptor(MacroId id, String name, String description, ContentDescriptor contentDescriptor,
86    BeanDescriptor parametersBeanDescriptor)
87    {
88  472 this.id = id;
89  472 this.name = name;
90  472 this.description = description;
91  472 this.contentDescriptor = contentDescriptor;
92  472 this.parametersBeanDescriptor = parametersBeanDescriptor;
93    }
94   
95    /**
96    * @param name the name of the macro (eg "Table Of Contents" for the TOC macro)
97    * @param description the description of the macro.
98    * @param contentDescriptor the description of the macro content. null indicate macro does not support content.
99    * @param parametersBeanDescriptor the description of the parameters bean or null if there are no parameters for
100    * this macro.
101    * @since 2.0M3
102    * @deprecated since 2.3M1 use
103    * {@link #AbstractMacroDescriptor(MacroId, String, String, ContentDescriptor, BeanDescriptor)} instead
104    */
 
105  0 toggle @Deprecated
106    public AbstractMacroDescriptor(String name, String description, ContentDescriptor contentDescriptor,
107    BeanDescriptor parametersBeanDescriptor)
108    {
109  0 this.name = name;
110  0 this.description = description;
111  0 this.contentDescriptor = contentDescriptor;
112  0 this.parametersBeanDescriptor = parametersBeanDescriptor;
113    }
114   
115    /**
116    * Extract parameters informations from {@link #parametersBeanDescriptor} and insert it in
117    * {@link #parameterDescriptorMap}.
118    *
119    * @since 1.7M2
120    */
 
121  469 toggle protected void extractParameterDescriptorMap()
122    {
123  469 for (PropertyDescriptor propertyDescriptor : this.parametersBeanDescriptor.getProperties()) {
124  1129 DefaultParameterDescriptor desc = new DefaultParameterDescriptor(propertyDescriptor);
125  1129 this.parameterDescriptorMap.put(desc.getId().toLowerCase(), desc);
126    }
127    }
128   
129    /**
130    * {@inheritDoc}
131    *
132    * @since 2.3M1
133    */
 
134  17499 toggle @Override
135    public MacroId getId()
136    {
137  17500 return this.id;
138    }
139   
140    /**
141    * {@inheritDoc}
142    *
143    * @since 2.0M3
144    */
 
145  0 toggle @Override
146    public String getName()
147    {
148  0 return this.name;
149    }
150   
 
151  4 toggle @Override
152    public ContentDescriptor getContentDescriptor()
153    {
154  4 return this.contentDescriptor;
155    }
156   
 
157  0 toggle @Override
158    public String getDescription()
159    {
160  0 return this.description;
161    }
162   
 
163  17281 toggle @Override
164    public Class<?> getParametersBeanClass()
165    {
166  17280 return (null != this.parametersBeanDescriptor) ? this.parametersBeanDescriptor.getBeanClass() : Object.class;
167    }
168   
 
169  6 toggle @Override
170    public Map<String, ParameterDescriptor> getParameterDescriptorMap()
171    {
172  6 return (null != this.parametersBeanDescriptor) ? Collections.unmodifiableMap(this.parameterDescriptorMap)
173    : Collections.<String, ParameterDescriptor>emptyMap();
174    }
175   
 
176  46 toggle @Override
177    public String getDefaultCategory()
178    {
179  46 return this.defaultCategory;
180    }
181   
182    /**
183    * @param defaultCategory default category under which this macro should be listed.
184    * @see MacroDescriptor#getDefaultCategory()
185    */
 
186  464 toggle public void setDefaultCategory(String defaultCategory)
187    {
188  464 this.defaultCategory = defaultCategory;
189    }
190    }