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.operations.cropresize; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.Content; |
37 |
|
import info.magnolia.cms.core.NodeData; |
38 |
|
import info.magnolia.imaging.ImagingException; |
39 |
|
import info.magnolia.imaging.ParameterProvider; |
40 |
|
|
41 |
|
import java.awt.image.BufferedImage; |
42 |
|
import java.util.Collections; |
43 |
|
import java.util.Map; |
44 |
|
|
45 |
|
import javax.jcr.RepositoryException; |
46 |
|
|
47 |
|
import org.apache.commons.lang3.StringUtils; |
48 |
|
|
49 |
|
import net.sf.json.JSONObject; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@deprecated |
61 |
|
|
62 |
|
@Deprecated |
|
|
| 26.1% |
Uncovered Elements: 17 (23) |
Complexity: 6 |
Complexity Density: 0.38 |
|
63 |
|
public class SelectedCropAndResize extends AbstractCropAndResize<ParameterProvider<Content>> { |
64 |
|
private int targetWidth; |
65 |
|
private int targetHeight; |
66 |
|
private String cropInfoSiblingPropertySuffix; |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
68 |
0 |
@Override... |
69 |
|
protected Coords getCroopCoords(BufferedImage source, ParameterProvider<Content> params) throws ImagingException { |
70 |
0 |
try { |
71 |
0 |
final Content imageNode = params.getParameter(); |
72 |
0 |
final String cropInfoPropertyName = imageNode.getName() + cropInfoSiblingPropertySuffix; |
73 |
0 |
final Content parent = imageNode.getParent(); |
74 |
0 |
if (!parent.hasNodeData(cropInfoPropertyName)) { |
75 |
0 |
throw new ImagingException("There is no '" + cropInfoPropertyName + "' property at " + parent.getHandle()); |
76 |
|
} |
77 |
0 |
final NodeData cropInfoND = parent.getNodeData(cropInfoPropertyName); |
78 |
0 |
final CroppingInfo cropInfo = decode(cropInfoND.getString()); |
79 |
0 |
return cropInfo.getCoords(); |
80 |
|
} catch (RepositoryException e) { |
81 |
0 |
throw new RuntimeException(e); |
82 |
|
} |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
@Override... |
86 |
|
protected Size getEffectiveTargetSize(BufferedImage source, Coords cropCoords, ParameterProvider<Content> params) { |
87 |
0 |
return Size.conformToCropRatio(cropCoords, targetWidth, targetHeight); |
88 |
|
} |
89 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
90 |
|
public void setCropInfoSiblingPropertySuffix(String cropInfoSiblingPropertySuffix) {... |
91 |
|
this.cropInfoSiblingPropertySuffix = cropInfoSiblingPropertySuffix; |
92 |
|
} |
93 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
94 |
|
public void setTargetWidth(int targetWidth) {... |
95 |
|
this.targetWidth = targetWidth; |
96 |
|
} |
97 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
98 |
|
public void setTargetHeight(int targetHeight) {... |
99 |
|
this.targetHeight = targetHeight; |
100 |
|
} |
101 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
102 |
1 |
protected CroppingInfo decode(String jsonString) {... |
103 |
1 |
if (StringUtils.isEmpty(jsonString)) { |
104 |
0 |
return null; |
105 |
|
} |
106 |
1 |
final JSONObject json = JSONObject.fromObject(jsonString); |
107 |
1 |
final Map map = (Map) JSONObject.toBean(json, Map.class, Collections.singletonMap("CropperInfo", CroppingInfo.class)); |
108 |
1 |
return (CroppingInfo) map.get("CropperInfo"); |
109 |
|
} |
110 |
|
} |