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.module.resources.setup; |
35 |
|
|
36 |
|
import info.magnolia.cms.beans.runtime.FileProperties; |
37 |
|
import info.magnolia.cms.util.ClasspathResourcesUtil; |
38 |
|
import info.magnolia.jcr.util.NodeTypes; |
39 |
|
import info.magnolia.module.InstallContext; |
40 |
|
import info.magnolia.module.delta.TaskExecutionException; |
41 |
|
import info.magnolia.module.resources.ResourceTypes; |
42 |
|
|
43 |
|
import java.io.InputStream; |
44 |
|
|
45 |
|
import javax.jcr.Binary; |
46 |
|
import javax.jcr.Node; |
47 |
|
|
48 |
|
import org.apache.commons.io.IOUtils; |
49 |
|
import org.apache.commons.io.input.CountingInputStream; |
50 |
|
import org.apache.commons.lang3.StringUtils; |
51 |
|
import org.apache.jackrabbit.JcrConstants; |
52 |
|
import org.devlib.schmidt.imageinfo.ImageInfo; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
|
|
| 83.3% |
Uncovered Elements: 6 (36) |
Complexity: 8 |
Complexity Density: 0.3 |
|
57 |
|
public class InstallBinaryResourceTask extends AbstractInstallResourceTask { |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
3 |
public InstallBinaryResourceTask(String resource) {... |
60 |
3 |
super(resource, ResourceTypes.BINARY, false, null, null, null, false); |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0 |
public InstallBinaryResourceTask(String resource, boolean preserveResourceParameters) {... |
64 |
0 |
super(resource, ResourceTypes.BINARY, false, null, null, null, preserveResourceParameters); |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
public InstallBinaryResourceTask(String resource, String version, String source, String rights, boolean preserveResourceParameters) {... |
68 |
0 |
super(resource, ResourceTypes.BINARY, false, version, source, rights, preserveResourceParameters); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
8 |
public InstallBinaryResourceTask(String resource, String version, String source, String rights, boolean preserveResourceParameters, boolean stripExtension) {... |
72 |
8 |
super(resource, ResourceTypes.BINARY, false, version, source, rights, preserveResourceParameters, stripExtension); |
73 |
|
} |
74 |
|
|
|
|
| 92.6% |
Uncovered Elements: 2 (27) |
Complexity: 4 |
Complexity Density: 0.17 |
|
75 |
11 |
@Override... |
76 |
|
public void execute(InstallContext installContext) throws TaskExecutionException { |
77 |
|
|
78 |
11 |
super.execute(installContext); |
79 |
|
|
80 |
10 |
try { |
81 |
10 |
InputStream stream = ClasspathResourcesUtil.getStream(resource); |
82 |
|
|
83 |
10 |
CountingInputStream countingStream = new CountingInputStream(stream); |
84 |
10 |
Binary binary = node.getSession().getValueFactory().createBinary(countingStream); |
85 |
|
|
86 |
10 |
Node binaryNode = null; |
87 |
10 |
if (node.hasNode(ResourceTypes.BINARY_SUFFIX)) { |
88 |
1 |
node.getNode(ResourceTypes.BINARY_SUFFIX).remove(); |
89 |
|
} |
90 |
|
|
91 |
10 |
binaryNode = node.addNode(ResourceTypes.BINARY_SUFFIX, NodeTypes.Resource.NAME); |
92 |
10 |
binaryNode.setProperty(JcrConstants.JCR_DATA, binary); |
93 |
10 |
binaryNode.setProperty(FileProperties.PROPERTY_FILENAME, name); |
94 |
10 |
binaryNode.setProperty(FileProperties.PROPERTY_EXTENSION, StringUtils.substringAfterLast(resource, ".")); |
95 |
10 |
binaryNode.setProperty(FileProperties.PROPERTY_SIZE, binary.getSize()); |
96 |
|
|
97 |
|
|
98 |
10 |
InputStream imageStream = ClasspathResourcesUtil.getStream(resource); |
99 |
|
|
100 |
10 |
try { |
101 |
10 |
ImageInfo ii = new ImageInfo(); |
102 |
10 |
ii.setInput(imageStream); |
103 |
10 |
if (ii.check()) { |
104 |
10 |
binaryNode.setProperty(FileProperties.PROPERTY_WIDTH, Long.toString(ii.getWidth())); |
105 |
10 |
binaryNode.setProperty(FileProperties.PROPERTY_HEIGHT, Long.toString(ii.getHeight())); |
106 |
10 |
binaryNode.setProperty(JcrConstants.JCR_MIMETYPE, ii.getMimeType()); |
107 |
|
} |
108 |
|
} finally { |
109 |
10 |
IOUtils.closeQuietly(imageStream); |
110 |
|
} |
111 |
|
} catch (Exception e) { |
112 |
0 |
throw new TaskExecutionException("Can't install resource [" + resource + "]", e); |
113 |
|
} |
114 |
|
|
115 |
|
} |
116 |
|
|
117 |
|
} |