Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../../img/srcFileCovDistChart8.png 68% of files have more coverage
95   229   30   13.57
44   160   0.32   7
7     4.29  
1    
 
  StyleRadeoxMacroConverter       Line # 42 95 0% 30 29 80.1% 0.80136985
 
  (1)
 
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.internal.parser.xwiki10.macro;
21   
22    import java.util.LinkedHashMap;
23    import java.util.Map;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.rendering.parser.xwiki10.FilterContext;
30    import org.xwiki.rendering.parser.xwiki10.macro.AbstractRadeoxMacroConverter;
31    import org.xwiki.rendering.parser.xwiki10.macro.RadeoxMacroConverter;
32    import org.xwiki.rendering.parser.xwiki10.macro.RadeoxMacroParameter;
33    import org.xwiki.rendering.parser.xwiki10.macro.RadeoxMacroParameters;
34   
35    /**
36    * @version $Id: 3e7a629d6770600076299e875288a3d62df01287 $
37    * @since 1.8M1
38    */
39    @Component
40    @Named("style")
41    @Singleton
 
42    public class StyleRadeoxMacroConverter extends AbstractRadeoxMacroConverter
43    {
 
44  1 toggle public StyleRadeoxMacroConverter()
45    {
46  1 registerParameter("type");
47  1 registerParameter("id", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
48  1 registerParameter("class", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
49  1 registerParameter("align", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
50  1 registerParameter("name", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
51  1 registerParameter("font-size", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
52  1 registerParameter("font-family", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
53  1 registerParameter("color", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
54  1 registerParameter("background-color", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
55  1 registerParameter("float", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
56  1 registerParameter("width", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
57  1 registerParameter("height", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
58  1 registerParameter("border", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
59  1 registerParameter("document");
60  1 registerParameter("icon", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE);
61    }
62   
 
63  2 toggle @Override
64    public String convert(String name, RadeoxMacroParameters parameters, String content, FilterContext filterContext)
65    {
66  2 StringBuffer result = new StringBuffer();
67   
68  2 boolean inline = parameters.get("type") != null && parameters.get("type").getValue().equals("span");
69   
70    // Print parameters
71  2 StringBuffer parametersOpen = new StringBuffer();
72  2 Map<String, String> styleParameters = convertParameters(parameters);
73  2 if (styleParameters.size() > 0) {
74  2 parametersOpen.append("(% ");
75  2 appendParameters(parametersOpen, styleParameters);
76  2 parametersOpen.append(" %)");
77  2 result.append(filterContext.addProtectedContent(parametersOpen.toString(), inline));
78    }
79   
80  2 if (!inline) {
81    // Open standalone group
82  1 result.append(filterContext.addProtectedContent("(((", false));
83    }
84   
85    // Print content
86  2 result.append(convertContent(content.trim(), parameters, filterContext));
87   
88    // Print group close
89  2 if (inline) {
90    // Close inline group
91  1 result.append(filterContext.addProtectedContent("(%%)", true));
92    } else {
93    // Close standalone group
94  1 result.append(filterContext.addProtectedContent(")))", false));
95    }
96   
97  2 return result.toString();
98    }
99   
 
100  2 toggle @Override
101    protected String convertContent(String content, RadeoxMacroParameters parameters, FilterContext filterContext)
102    {
103  2 StringBuffer result = new StringBuffer();
104   
105    // Print icon
106  2 appendIcon(result, parameters, filterContext);
107   
108  2 if (content.length() > 0) {
109  2 result.append(' ');
110    }
111   
112    // Print content
113  2 result.append(content);
114   
115  2 return result.toString();
116    }
117   
 
118  2 toggle @Override
119    protected Map<String, String> convertParameters(RadeoxMacroParameters parameters)
120    {
121  2 Map<String, String> boxParameters = new LinkedHashMap<String, String>();
122   
123  2 RadeoxMacroParameter classes = parameters.get("class");
124  2 RadeoxMacroParameter icon = parameters.get("icon");
125  2 RadeoxMacroParameter id = parameters.get("id");
126  2 RadeoxMacroParameter align = parameters.get("align");
127  2 RadeoxMacroParameter name = parameters.get("name");
128  2 RadeoxMacroParameter size = parameters.get("font-size");
129  2 RadeoxMacroParameter font = parameters.get("font-family");
130  2 RadeoxMacroParameter color = parameters.get("color");
131  2 RadeoxMacroParameter bgcolor = parameters.get("background-color");
132  2 RadeoxMacroParameter fl = parameters.get("float");
133  2 RadeoxMacroParameter width = parameters.get("width");
134  2 RadeoxMacroParameter height = parameters.get("height");
135  2 RadeoxMacroParameter border = parameters.get("border");
136   
137    // add class support
138  2 if (classes != null) {
139  0 boxParameters.put("class", classes.getValue().trim());
140  2 } else if (icon != null) {
141  2 boxParameters.put("class", "stylemacro");
142    }
143   
144    // add id support
145  2 if (id != null) {
146  0 boxParameters.put("id", id.getValue().trim());
147    }
148   
149    // add name support
150  2 if (name != null) {
151  0 boxParameters.put("name", name.getValue().trim());
152    }
153   
154    // add align support
155  2 if (align != null) {
156  0 boxParameters.put("align", align.getValue().trim());
157    }
158   
159    // add style support
160  2 StringBuffer styleStr = new StringBuffer();
161   
162  2 if (size != null) {
163  0 styleStr.append("font-size:" + size.getValue().trim() + "; ");
164    }
165  2 if (font != null) {
166  0 styleStr.append("font-family:" + font.getValue().trim() + "; ");
167    }
168  2 if (color != null) {
169  2 styleStr.append("color:" + color.getValue().trim() + "; ");
170    }
171  2 if (bgcolor != null) {
172  2 styleStr.append("background-color:" + bgcolor.getValue().trim() + "; ");
173    }
174  2 if (width != null) {
175  2 styleStr.append("width:" + width.getValue().trim() + "; ");
176    }
177  2 if (fl != null) {
178  0 styleStr.append("float:" + fl.getValue().trim() + "; ");
179    }
180  2 if (height != null) {
181  2 styleStr.append("height:" + height.getValue().trim() + "; ");
182    }
183  2 if (border != null) {
184  2 styleStr.append("border:" + border.getValue().trim() + "; ");
185    }
186   
187  2 if (styleStr.length() > 0) {
188  2 boxParameters.put("style", styleStr.toString());
189    }
190   
191  2 return boxParameters;
192    }
193   
 
194  2 toggle private void appendIcon(StringBuffer result, RadeoxMacroParameters parameters, FilterContext filterContext)
195    {
196  2 RadeoxMacroParameter document = parameters.get("document");
197  2 RadeoxMacroParameter icon = parameters.get("icon");
198  2 boolean hasIcon = false;
199   
200  2 if (document != null && document.getValue().contains("=")) {
201  0 document = null;
202    }
203   
204  2 if (icon != null) {
205  2 hasIcon = true;
206    }
207   
208    // add icon support
209  2 if (hasIcon) {
210  2 result.append(filterContext.addProtectedContent("image:", true));
211  2 if (document != null) {
212  2 result.append(document + "@" + icon);
213    } else {
214  0 result.append(icon.getValue().trim());
215    }
216    }
217    }
218   
 
219  2 toggle @Override
220    public boolean protectResult()
221    {
222  2 return false;
223    }
224   
 
225  6 toggle public boolean supportContent()
226    {
227  6 return true;
228    }
229    }