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

File GalleryMacro.java

 

Coverage histogram

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

Code metrics

12
24
3
1
142
80
9
0.38
8
3
3

Classes

Class Line # Actions
GalleryMacro 52 24 0% 9 4
0.897435989.7%
 

Contributing tests

This file is covered by 3 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.gallery;
21   
22    import java.util.Collections;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import javax.inject.Inject;
28    import javax.inject.Named;
29    import javax.inject.Singleton;
30   
31    import org.apache.commons.lang3.StringUtils;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.rendering.block.Block;
34    import org.xwiki.rendering.block.GroupBlock;
35    import org.xwiki.rendering.macro.AbstractMacro;
36    import org.xwiki.rendering.macro.MacroContentParser;
37    import org.xwiki.rendering.macro.MacroExecutionException;
38    import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
39    import org.xwiki.rendering.macro.gallery.GalleryMacroParameters;
40    import org.xwiki.rendering.transformation.MacroTransformationContext;
41    import org.xwiki.skinx.SkinExtension;
42   
43    /**
44    * Displays the images found in the provided content using a slide-show view.
45    *
46    * @version $Id: 5f8d18a04c9b226c9d6905a8b4bff2d55333160a $
47    * @since 3.0M3
48    */
49    @Component
50    @Named("gallery")
51    @Singleton
 
52    public class GalleryMacro extends AbstractMacro<GalleryMacroParameters>
53    {
54    /**
55    * The description of the macro.
56    */
57    private static final String DESCRIPTION =
58    "Displays the images found in the provided content using a slide-show view.";
59   
60    /**
61    * The description of the macro content.
62    */
63    private static final String CONTENT_DESCRIPTION =
64    "The images to be displayed in the gallery. All the images found in the provided wiki content are included. "
65    + "Images should be specified using the syntax of the current document. "
66    + "Example, for XWiki 2.0 syntax: image:Space.Page@alice.png image:http://www.example.com/path/to/bob.jpg";
67   
68    /**
69    * The parser used to parse gallery content.
70    */
71    @Inject
72    private MacroContentParser contentParser;
73   
74    /**
75    * The component used to import JavaScript file extensions.
76    */
77    @Inject
78    @Named("jsfx")
79    private SkinExtension jsfx;
80   
81    /**
82    * The component used to import style-sheet file extensions.
83    */
84    @Inject
85    @Named("ssfx")
86    private SkinExtension ssfx;
87   
88    /**
89    * Create and initialize the descriptor of the macro.
90    */
 
91  3 toggle public GalleryMacro()
92    {
93  3 super("Gallery", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION), GalleryMacroParameters.class);
94  3 setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
95    }
96   
 
97  3 toggle @Override
98    public List<Block> execute(GalleryMacroParameters parameters, String content, MacroTransformationContext context)
99    throws MacroExecutionException
100    {
101  3 if (context != null) {
102  3 Map<String, Object> skinExtensionParameters = Collections.singletonMap("forceSkinAction", (Object) true);
103  3 this.jsfx.use("uicomponents/widgets/gallery/gallery.js", skinExtensionParameters);
104  3 this.ssfx.use("uicomponents/widgets/gallery/gallery.css");
105   
106  3 StringBuilder inlineStyle = new StringBuilder();
107  3 if (!StringUtils.isEmpty(parameters.getWidth())) {
108    // Non-empty width value. The empty value means "no explicit width".
109  1 inlineStyle.append("width: ").append(parameters.getWidth()).append(';');
110  2 } else if (parameters.getWidth() == null) {
111    // Default width when none is specified.
112  1 inlineStyle.append("width: 620px;");
113    }
114  3 if (!StringUtils.isEmpty(parameters.getHeight())) {
115    // Non-empty height value. The empty value means "no explicit height".
116  1 inlineStyle.append("height: ").append(parameters.getHeight()).append(';');
117  2 } else if (parameters.getHeight() == null) {
118    // Default height when none is specified (16:9 aspect ratio).
119  1 inlineStyle.append("height: 349px;");
120    }
121   
122  3 Map<String, String> groupParameters = new HashMap<>();
123  3 groupParameters.put("class", ("gallery " + StringUtils.defaultString(parameters.getClassNames())).trim());
124  3 if (inlineStyle.length() > 0) {
125  2 groupParameters.put("style", inlineStyle.toString());
126    }
127   
128  3 Block galleryBlock = new GroupBlock(groupParameters);
129    // Don't execute transformations explicitly. They'll be executed on the generated content later on.
130  3 galleryBlock.addChildren(this.contentParser.parse(content, context, false, false).getChildren());
131  3 return Collections.singletonList(galleryBlock);
132    } else {
133  0 return Collections.emptyList();
134    }
135    }
136   
 
137  0 toggle @Override
138    public boolean supportsInlineMode()
139    {
140  0 return false;
141    }
142    }