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.caching; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.NodeData; |
37 |
|
import info.magnolia.imaging.ImageGenerator; |
38 |
|
import info.magnolia.imaging.ParameterProvider; |
39 |
|
import info.magnolia.jcr.util.NodeTypes; |
40 |
|
|
41 |
|
import java.util.Calendar; |
42 |
|
|
43 |
|
import javax.jcr.Node; |
44 |
|
import javax.jcr.PathNotFoundException; |
45 |
|
import javax.jcr.Property; |
46 |
|
import javax.jcr.RepositoryException; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@link@link |
51 |
|
|
52 |
|
@param |
53 |
|
|
|
|
| 59.1% |
Uncovered Elements: 9 (22) |
Complexity: 7 |
Complexity Density: 0.47 |
|
54 |
|
public abstract class AbstractNodeBasedCachingStrategy<P> implements CachingStrategy<P> { |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
18 |
@Override... |
57 |
|
public String getCachePath(ImageGenerator<ParameterProvider<P>> generator, ParameterProvider<P> parameterProvider) { |
58 |
19 |
final P param = parameterProvider.getParameter(); |
59 |
19 |
return "/" + generator.getName() + "/" + getWorkspaceName(param) + getPathOf(param); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
@deprecated@link |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
65 |
0 |
@Deprecated... |
66 |
|
public boolean shouldRegenerate(NodeData cachedBinary, ParameterProvider<P> parameterProvider) { |
67 |
0 |
try { |
68 |
0 |
return shouldRegenerate(cachedBinary.getJCRProperty(), parameterProvider); |
69 |
|
} catch (PathNotFoundException e) { |
70 |
0 |
throw new IllegalStateException("Unable to obtain JCR Property from NodeData " + cachedBinary, e); |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@return |
77 |
|
|
|
|
| 64.3% |
Uncovered Elements: 5 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
78 |
10 |
@Override... |
79 |
|
public boolean shouldRegenerate(Property cachedBinary, ParameterProvider<P> parameterProvider) { |
80 |
10 |
try { |
81 |
|
|
82 |
10 |
final Calendar cacheLastMod = NodeTypes.LastModified.getLastModified(cachedBinary.getParent()); |
83 |
|
|
84 |
|
|
85 |
10 |
final Node node = getContent(parameterProvider.getParameter()); |
86 |
10 |
final Calendar srcLastMod = NodeTypes.LastModified.getLastModified(node); |
87 |
|
|
88 |
|
|
89 |
10 |
if (srcLastMod == null ) { |
90 |
|
|
91 |
0 |
return false; |
92 |
10 |
} else if (cacheLastMod == null) { |
93 |
|
|
94 |
0 |
return true; |
95 |
|
} else { |
96 |
10 |
return cacheLastMod.before(srcLastMod); |
97 |
|
} |
98 |
|
} catch (RepositoryException e) { |
99 |
0 |
throw new RuntimeException(e); |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
abstract protected String getWorkspaceName(P param); |
104 |
|
|
105 |
|
abstract protected Node getContent(P param); |
106 |
|
|
107 |
|
abstract protected String getPathOf(P param); |
108 |
|
} |