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 |
|
@param |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.38 |
|
54 |
|
public abstract class AbstractJcrWorkspaceAndPathParameterProviderFactory<PT> implements ParameterProviderFactory<HttpServletRequest, PT> { |
55 |
|
|
56 |
|
private boolean trimExtension = true; |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
58 |
0 |
@Override... |
59 |
|
public ParameterProvider<PT> newParameterProviderFor(HttpServletRequest req) { |
60 |
0 |
String pathInfo = req.getPathInfo(); |
61 |
0 |
if (pathInfo == null) { |
62 |
0 |
throw new ImagingRuntimeException("Can't determine node, no pathInfo is available for uri " + req.getRequestURI()); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
0 |
final PathSplitter pathSplitter = new PathSplitter(pathInfo, trimExtension); |
68 |
0 |
if (pathSplitter.count() < 2) { |
69 |
0 |
throw new ImagingRuntimeException("Can't determine node from pathInfo: " + pathInfo); |
70 |
|
|
71 |
|
} |
72 |
0 |
final String workspaceName = pathSplitter.skipTo(1); |
73 |
0 |
final String path = "/" + pathSplitter.remaining(); |
74 |
|
|
75 |
0 |
try { |
76 |
0 |
final Session session = MgnlContext.getJCRSession(workspaceName); |
77 |
0 |
return newParameterProviderForPath(session, path); |
78 |
|
} catch (NoSuchWorkspaceException | ItemNotFoundException | PathNotFoundException e) { |
79 |
0 |
throw new ImagingRuntimeException("Can't load source from " + path + " from workspace " + workspaceName, e); |
80 |
|
} catch (RepositoryException e) { |
81 |
0 |
throw new RuntimeException("Can't load source from " + path + " from workspace " + workspaceName, e); |
82 |
|
} |
83 |
|
} |
84 |
|
|
85 |
|
protected abstract ParameterProvider<PT> newParameterProviderForPath(final Session session, final String path) throws RepositoryException; |
86 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
87 |
|
public void setTrimExtension(boolean trimExtension) {... |
88 |
|
this.trimExtension = trimExtension; |
89 |
|
} |
90 |
|
|
91 |
|
} |