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; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
|
38 |
|
import javax.inject.Inject; |
39 |
|
import javax.inject.Provider; |
40 |
|
import javax.jcr.LoginException; |
41 |
|
import javax.jcr.RepositoryException; |
42 |
|
import javax.jcr.Session; |
43 |
|
|
44 |
|
import info.magnolia.context.SystemContext; |
45 |
|
import info.magnolia.imaging.caching.CachingImageStreamer; |
46 |
|
import info.magnolia.imaging.caching.CachingStrategy; |
47 |
|
import info.magnolia.objectfactory.annotation.LazySingleton; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@see |
53 |
|
|
54 |
|
@LazySingleton |
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 8 |
Complexity Density: 0.4 |
|
55 |
|
public class Imaging { |
56 |
|
private final ImagingModule config; |
57 |
|
|
58 |
|
private final Provider<SystemContext> contextProvider; |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
60 |
0 |
@Inject... |
61 |
|
public Imaging(ImagingModule config, Provider<SystemContext> contextProvider) { |
62 |
0 |
this.config = config; |
63 |
0 |
this.contextProvider = contextProvider; |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
66 |
0 |
public <ENV, PT> void generate(String generatorName, ENV input, ImageResponse imageResponse) throws IOException, ImagingException {... |
67 |
0 |
final ImageGenerator<ParameterProvider<PT>> generator = getGenerator(generatorName); |
68 |
0 |
if (generator == null) { |
69 |
0 |
throw new IllegalArgumentException("No ImageGenerator with name " + generatorName); |
70 |
|
} |
71 |
|
|
72 |
0 |
final ParameterProviderFactory<ENV, PT> parameterProviderFactory = generator.getParameterProviderFactory(); |
73 |
0 |
final ParameterProvider<PT> p = parameterProviderFactory.newParameterProviderFor(input); |
74 |
|
|
75 |
0 |
final ImageStreamer<PT> streamer = getStreamer(parameterProviderFactory); |
76 |
0 |
streamer.serveImage(generator, p, imageResponse); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
protected ImageGenerator getGenerator(String generatorName) {... |
80 |
0 |
return config.getGenerators().get(generatorName); |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.4 |
|
83 |
0 |
protected <E, PT> ImageStreamer<PT> getStreamer(ParameterProviderFactory<E, PT> parameterProviderFactory) {... |
84 |
0 |
final DefaultImageStreamer<PT> newDefaultImageStreamer = new DefaultImageStreamer<PT>(); |
85 |
0 |
if (!config.isStoreGeneratedImages()) { |
86 |
0 |
return newDefaultImageStreamer; |
87 |
|
} else { |
88 |
0 |
Session session; |
89 |
0 |
try { |
90 |
0 |
session = contextProvider.get().getJCRSession(ImagingModule.IMAGING); |
91 |
0 |
final CachingStrategy<PT> cachingStrategy = parameterProviderFactory.getCachingStrategy(); |
92 |
0 |
return new CachingImageStreamer<PT>(session, cachingStrategy, newDefaultImageStreamer, contextProvider.get()); |
93 |
|
} catch (LoginException e) { |
94 |
0 |
throw new RuntimeException("Could not connect to imaging repository.", e); |
95 |
|
} catch (RepositoryException e) { |
96 |
0 |
throw new RuntimeException("Could not connect to imaging repository.", e); |
97 |
|
} |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
} |