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

File DefaultGadgetRenderer.java

 

Coverage histogram

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

Code metrics

2
16
1
1
95
45
2
0.12
16
1
2

Classes

Class Line # Actions
DefaultGadgetRenderer 46 16 0% 2 2
0.894736889.5%
 

Contributing tests

This file is covered by 2 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.dashboard;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.block.GroupBlock;
32    import org.xwiki.rendering.block.HeaderBlock;
33    import org.xwiki.rendering.listener.HeaderLevel;
34    import org.xwiki.rendering.macro.dashboard.Gadget;
35    import org.xwiki.rendering.macro.dashboard.GadgetRenderer;
36   
37    /**
38    * Default implementation of the gadget renderer, rendering the title of the gadget in a level 2 heading and the content
39    * as is, in a container that helps group it together and separate from title.
40    *
41    * @version $Id: f2b4d63879ad33bc28698165173f1d073926662d $
42    * @since 3.0rc1
43    */
44    @Component
45    @Singleton
 
46    public class DefaultGadgetRenderer implements GadgetRenderer
47    {
48    /**
49    * The HTML class attribute name.
50    */
51    protected static final String CLASS = "class";
52   
53    /**
54    * The HTML id attribute name.
55    */
56    protected static final String ID = "id";
57   
58    @Inject
59    @Named("empty")
60    private XDOMChecker emptyXDOMChecker;
61   
 
62  13 toggle @Override
63    public List<Block> decorateGadget(Gadget gadget)
64    {
65  13 List<Block> result;
66   
67    // We only decorate the gadget if it has some content. This allows to dynamically decide whether to display
68    // a gadget or not.
69  13 if (!this.emptyXDOMChecker.check(gadget.getContent())) {
70    // prepare the title of the gadget, in a heading 2
71  13 HeaderBlock titleBlock = new HeaderBlock(gadget.getTitle(), HeaderLevel.LEVEL1);
72  13 titleBlock.setParameter(CLASS, "gadget-title");
73   
74    // And then the content wrapped in a group block with class, to style it
75  13 GroupBlock contentGroup = new GroupBlock();
76  13 contentGroup.setParameter(CLASS, "gadget-content");
77  13 contentGroup.addChildren(gadget.getContent());
78   
79    // and wrap everything in a container, to give it a class
80  13 GroupBlock gadgetBlock = new GroupBlock();
81  13 String idPrefix = "gadget";
82  13 gadgetBlock.setParameter(CLASS, idPrefix);
83    // put an underscore here because it doesn't hurt at this level and it helps scriptaculous on the frontend
84  13 gadgetBlock.setParameter(ID, idPrefix + "_" + gadget.getId());
85  13 gadgetBlock.addChild(titleBlock);
86  13 gadgetBlock.addChild(contentGroup);
87   
88  13 result = Collections.singletonList(gadgetBlock);
89    } else {
90  0 result = Collections.emptyList();
91    }
92   
93  13 return result;
94    }
95    }