1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Named("gallery") |
51 |
|
@Singleton |
|
|
| 89.7% |
Uncovered Elements: 4 (39) |
Complexity: 9 |
Complexity Density: 0.38 |
|
52 |
|
public class GalleryMacro extends AbstractMacro<GalleryMacroParameters> |
53 |
|
{ |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private static final String DESCRIPTION = |
58 |
|
"Displays the images found in the provided content using a slide-show view."; |
59 |
|
|
60 |
|
|
61 |
|
|
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 |
|
|
70 |
|
|
71 |
|
@Inject |
72 |
|
private MacroContentParser contentParser; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@Inject |
78 |
|
@Named("jsfx") |
79 |
|
private SkinExtension jsfx; |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@Inject |
85 |
|
@Named("ssfx") |
86 |
|
private SkinExtension ssfx; |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
91 |
3 |
public GalleryMacro()... |
92 |
|
{ |
93 |
3 |
super("Gallery", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION), GalleryMacroParameters.class); |
94 |
3 |
setDefaultCategory(DEFAULT_CATEGORY_FORMATTING); |
95 |
|
} |
96 |
|
|
|
|
| 93.9% |
Uncovered Elements: 2 (33) |
Complexity: 7 |
Complexity Density: 0.33 |
|
97 |
3 |
@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 |
|
|
109 |
1 |
inlineStyle.append("width: ").append(parameters.getWidth()).append(';'); |
110 |
2 |
} else if (parameters.getWidth() == null) { |
111 |
|
|
112 |
1 |
inlineStyle.append("width: 620px;"); |
113 |
|
} |
114 |
3 |
if (!StringUtils.isEmpty(parameters.getHeight())) { |
115 |
|
|
116 |
1 |
inlineStyle.append("height: ").append(parameters.getHeight()).append(';'); |
117 |
2 |
} else if (parameters.getHeight() == null) { |
118 |
|
|
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 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
@Override... |
138 |
|
public boolean supportsInlineMode() |
139 |
|
{ |
140 |
0 |
return false; |
141 |
|
} |
142 |
|
} |