Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../img/srcFileCovDistChart7.png 76% of files have more coverage
12   94   5   4
4   46   0.42   3
3     1.67  
1    
 
  AbstractMessageMacro       Line # 42 12 0% 5 6 68.4% 0.68421054
 
  (4)
 
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.macro.message;
21   
22    import org.xwiki.rendering.macro.AbstractMacro;
23    import org.xwiki.rendering.macro.Macro;
24    import org.xwiki.rendering.macro.MacroExecutionException;
25    import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
26    import org.xwiki.rendering.macro.box.BoxMacroParameters;
27    import org.xwiki.rendering.block.Block;
28    import org.xwiki.rendering.transformation.MacroTransformationContext;
29    import org.apache.commons.lang3.StringUtils;
30   
31    import java.util.List;
32   
33    import javax.inject.Inject;
34    import javax.inject.Named;
35   
36    /**
37    * Common implementation for info, error and warning macros.
38    *
39    * @version $Id: 6e6f3bdfef3b41aacbe6c4d0e25e0c61ed8f627b $
40    * @since 2.0M3
41    */
 
42    public abstract class AbstractMessageMacro extends AbstractMacro<Object>
43    {
44    /**
45    * Predefined error message.
46    */
47    public static final String CONTENT_MISSING_ERROR = "The required content is missing.";
48   
49    /**
50    * Injected by the component manager.
51    */
52    @Inject
53    @Named("box")
54    private Macro<BoxMacroParameters> boxMacro;
55   
56    /**
57    * Create and initialize the descriptor of the macro.
58    *
59    * @param macroName the macro name (eg "Error", "Info", etc)
60    * @param macroDescription the macro description
61    */
 
62  8 toggle public AbstractMessageMacro(String macroName, String macroDescription)
63    {
64  8 super(macroName, macroDescription, new DefaultContentDescriptor(true));
65    }
66   
 
67  4 toggle @Override
68    public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
69    throws MacroExecutionException
70    {
71  4 if (StringUtils.isEmpty(content)) {
72  0 throw new MacroExecutionException(CONTENT_MISSING_ERROR);
73    }
74   
75  4 BoxMacroParameters boxParameters = new BoxMacroParameters();
76   
77  4 boxParameters.setCssClass(context.getCurrentMacroBlock().getId() + "message");
78   
79  4 List<Block> result;
80  4 if (!context.isInline()) {
81  4 boxParameters.setTitle(content);
82  4 result = this.boxMacro.execute(boxParameters, StringUtils.EMPTY, context);
83    } else {
84  0 result = this.boxMacro.execute(boxParameters, content, context);
85    }
86  4 return result;
87    }
88   
 
89  0 toggle @Override
90    public boolean supportsInlineMode()
91    {
92  0 return true;
93    }
94    }