1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging.functions; |
35 |
|
|
36 |
|
import info.magnolia.imaging.ImagingSupport; |
37 |
|
import info.magnolia.jcr.util.ContentMap; |
38 |
|
import info.magnolia.jcr.util.NodeUtil; |
39 |
|
import info.magnolia.rendering.template.TemplateDefinition; |
40 |
|
|
41 |
|
import javax.inject.Inject; |
42 |
|
import javax.inject.Singleton; |
43 |
|
import javax.jcr.Node; |
44 |
|
|
45 |
|
import org.apache.commons.lang3.StringUtils; |
46 |
|
import org.apache.jackrabbit.JcrConstants; |
47 |
|
import org.apache.jackrabbit.util.Text; |
48 |
|
import org.slf4j.Logger; |
49 |
|
import org.slf4j.LoggerFactory; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@Singleton |
|
|
| 97.5% |
Uncovered Elements: 1 (40) |
Complexity: 14 |
Complexity Density: 0.64 |
|
55 |
|
public class ImagingTemplatingFunctions { |
56 |
|
|
57 |
|
private static final Logger log = LoggerFactory.getLogger(ImagingTemplatingFunctions.class); |
58 |
|
|
59 |
|
public static final String PROPERTY_IMAGE_VARIATION = "imageVariation"; |
60 |
|
|
61 |
|
private ImagingSupport imagingSupport; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
12 |
@Inject... |
64 |
|
public ImagingTemplatingFunctions(ImagingSupport imagingSupport) { |
65 |
12 |
this.imagingSupport = imagingSupport; |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
@link |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
71 |
4 |
public String resolveImageVariationName(TemplateDefinition definition) {... |
72 |
4 |
if (definition == null) { |
73 |
1 |
return ImagingSupport.VARIATION_ORIGINAL; |
74 |
|
} |
75 |
|
|
76 |
3 |
String variationName = (String) definition.getParameters().get(PROPERTY_IMAGE_VARIATION); |
77 |
3 |
if (StringUtils.isNotBlank(variationName)) { |
78 |
2 |
return variationName; |
79 |
|
} |
80 |
|
|
81 |
1 |
return ImagingSupport.VARIATION_ORIGINAL; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@see |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
87 |
2 |
public String getImageVariationLinkFromBinary(ContentMap binaryContent, TemplateDefinition definition) {... |
88 |
2 |
if (binaryContent == null) { |
89 |
1 |
return null; |
90 |
|
} |
91 |
1 |
return getImageVariationLinkFromBinary(binaryContent.getJCRNode(), definition); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
@see |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
4 |
public String getImageVariationLinkFromBinary(Node binaryContent, TemplateDefinition definition) {... |
98 |
4 |
return getImageVariationLinkFromBinary(binaryContent, resolveImageVariationName(definition)); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@see |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
104 |
2 |
public String getImageVariationLinkFromBinary(ContentMap binaryContent, String variation) {... |
105 |
2 |
if (binaryContent == null) { |
106 |
1 |
return null; |
107 |
|
} |
108 |
1 |
return getImageVariationLinkFromBinary(binaryContent.getJCRNode(), variation); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
@return |
113 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 5 |
Complexity Density: 0.62 |
|
114 |
9 |
public String getImageVariationLinkFromBinary(Node binaryContent, String variation) {... |
115 |
9 |
if (binaryContent == null || variation == null) { |
116 |
1 |
return null; |
117 |
|
} |
118 |
|
|
119 |
8 |
try { |
120 |
8 |
String link = imagingSupport.createLink(binaryContent.getProperty(JcrConstants.JCR_DATA), variation); |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
7 |
if (link != null) { |
125 |
7 |
return Text.escapePath(link); |
126 |
|
} |
127 |
|
} catch (Exception e) { |
128 |
1 |
log.warn("An error occurred while getting data for binary content at {}", NodeUtil.getPathIfPossible(binaryContent), e); |
129 |
|
} |
130 |
1 |
return null; |
131 |
|
} |
132 |
|
} |