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.parameters; |
35 |
|
|
36 |
|
import info.magnolia.context.MgnlContext; |
37 |
|
import info.magnolia.imaging.ImagingRuntimeException; |
38 |
|
import info.magnolia.imaging.ParameterProvider; |
39 |
|
import info.magnolia.imaging.ParameterProviderFactory; |
40 |
|
import info.magnolia.imaging.util.PathSplitter; |
41 |
|
|
42 |
|
import javax.jcr.ItemNotFoundException; |
43 |
|
import javax.jcr.NoSuchWorkspaceException; |
44 |
|
import javax.jcr.PathNotFoundException; |
45 |
|
import javax.jcr.RepositoryException; |
46 |
|
import javax.jcr.Session; |
47 |
|
import javax.servlet.http.HttpServletRequest; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@param |
54 |
|
|
|
|
| 66.7% |
Uncovered Elements: 6 (18) |
Complexity: 5 |
Complexity Density: 0.38 |
|
55 |
|
public abstract class AbstractJcrWorkspaceAndIdentifierParameterProviderFactory<PT> implements ParameterProviderFactory<HttpServletRequest, PT> { |
56 |
|
|
57 |
|
private boolean trimExtension = true; |
58 |
|
|
|
|
| 64.7% |
Uncovered Elements: 6 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
59 |
3 |
@Override... |
60 |
|
public ParameterProvider<PT> newParameterProviderFor(HttpServletRequest request) { |
61 |
3 |
final String pathInfo = request.getPathInfo(); |
62 |
3 |
if (pathInfo == null) { |
63 |
0 |
throw new ImagingRuntimeException(String.format("Can't determine node, no pathInfo is available for uri '%s'", request.getRequestURI())); |
64 |
|
} |
65 |
|
|
66 |
3 |
final PathSplitter pathSplitter = new PathSplitter(pathInfo, trimExtension); |
67 |
3 |
if (pathSplitter.count() < 2) { |
68 |
0 |
throw new ImagingRuntimeException(String.format("Can't determine node from pathInfo '%s'", pathInfo)); |
69 |
|
|
70 |
|
} |
71 |
|
|
72 |
3 |
final String workspaceName = pathSplitter.skipTo(1); |
73 |
3 |
final String identifier = pathSplitter.skipTo(2); |
74 |
3 |
try { |
75 |
3 |
final Session session = MgnlContext.getJCRSession(workspaceName); |
76 |
3 |
return newParameterProviderForIdentifier(session, identifier); |
77 |
|
} catch (NoSuchWorkspaceException | ItemNotFoundException | PathNotFoundException e) { |
78 |
0 |
throw new ImagingRuntimeException(String.format("Can't load source for identifier '%s' from workspace '%s'", identifier, workspaceName), e); |
79 |
|
} catch (RepositoryException e) { |
80 |
0 |
throw new RuntimeException(String.format("Can't load source for identifier '%s' from workspace '%s'", identifier, workspaceName), e); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
|
abstract protected ParameterProvider<PT> newParameterProviderForIdentifier(Session session, String identifier) throws RepositoryException; |
85 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
86 |
|
public void setTrimExtension(boolean trimExtension) {... |
87 |
|
this.trimExtension = trimExtension; |
88 |
|
} |
89 |
|
|
90 |
|
} |