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

File AbstractMessageMacro.java

 

Coverage histogram

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

Code metrics

4
12
3
1
94
46
5
0.42
4
3
1.67

Classes

Class Line # Actions
AbstractMessageMacro 42 12 0% 5 2
0.894736889.5%
 

Contributing tests

This file is covered by 5 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.internal.macro.message;
21   
22    import java.util.List;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.apache.commons.lang3.StringUtils;
28    import org.xwiki.rendering.block.Block;
29    import org.xwiki.rendering.macro.AbstractMacro;
30    import org.xwiki.rendering.macro.Macro;
31    import org.xwiki.rendering.macro.MacroExecutionException;
32    import org.xwiki.rendering.macro.box.BoxMacroParameters;
33    import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
34    import org.xwiki.rendering.transformation.MacroTransformationContext;
35   
36    /**
37    * Common implementation for message macros (e.g. info, error, warning, success, etc).
38    *
39    * @version $Id: b8546972d13d5d11ae3b59bd2411abc9118b7931 $
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  31 toggle public AbstractMessageMacro(String macroName, String macroDescription)
63    {
64  31 super(macroName, macroDescription, new DefaultContentDescriptor(true));
65    }
66   
 
67  134 toggle @Override
68    public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
69    throws MacroExecutionException
70    {
71  134 if (StringUtils.isEmpty(content)) {
72  0 throw new MacroExecutionException(CONTENT_MISSING_ERROR);
73    }
74   
75  134 BoxMacroParameters boxParameters = new BoxMacroParameters();
76   
77  134 boxParameters.setCssClass(context.getCurrentMacroBlock().getId() + "message");
78   
79  134 List<Block> result;
80  134 if (!context.isInline()) {
81  130 boxParameters.setTitle(content);
82  130 result = this.boxMacro.execute(boxParameters, StringUtils.EMPTY, context);
83    } else {
84  4 result = this.boxMacro.execute(boxParameters, content, context);
85    }
86  134 return result;
87    }
88   
 
89  4 toggle @Override
90    public boolean supportsInlineMode()
91    {
92  4 return true;
93    }
94    }