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.cropui; |
35 |
|
|
36 |
|
import info.magnolia.cms.beans.config.ContentRepository; |
37 |
|
import info.magnolia.cms.core.Content; |
38 |
|
import info.magnolia.cms.core.HierarchyManager; |
39 |
|
import info.magnolia.cms.gui.dialog.Dialog; |
40 |
|
import info.magnolia.cms.gui.dialog.DialogControlImpl; |
41 |
|
import info.magnolia.cms.gui.dialog.DialogTab; |
42 |
|
import info.magnolia.content2bean.Content2BeanException; |
43 |
|
import info.magnolia.content2bean.Content2BeanUtil; |
44 |
|
import info.magnolia.context.MgnlContext; |
45 |
|
import info.magnolia.freemarker.FreemarkerUtil; |
46 |
|
import info.magnolia.module.admininterface.TemplatedMVCHandler; |
47 |
|
|
48 |
|
import java.io.IOException; |
49 |
|
import java.io.Writer; |
50 |
|
import java.util.ArrayList; |
51 |
|
import java.util.Collection; |
52 |
|
import java.util.HashMap; |
53 |
|
import java.util.Iterator; |
54 |
|
import java.util.List; |
55 |
|
|
56 |
|
import javax.jcr.RepositoryException; |
57 |
|
import javax.servlet.http.HttpServletRequest; |
58 |
|
import javax.servlet.http.HttpServletResponse; |
59 |
|
|
60 |
|
import org.apache.commons.lang3.StringUtils; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
|
|
| 24.5% |
Uncovered Elements: 37 (49) |
Complexity: 12 |
Complexity Density: 0.33 |
|
65 |
|
public class CropperPage extends TemplatedMVCHandler { |
66 |
|
|
67 |
|
private String configDialogUUID; |
68 |
|
private String imagePath; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
private String currentCrop; |
74 |
|
private List cropAndResizeConfigs; |
75 |
|
private Content imageControlConfigNode; |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public CropperPage(String name, HttpServletRequest request, HttpServletResponse response) {... |
78 |
0 |
super(name, request, response); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.36 |
|
81 |
0 |
@Override... |
82 |
|
public void init() { |
83 |
0 |
super.init(); |
84 |
|
|
85 |
0 |
if (configDialogUUID == null) { |
86 |
0 |
throw new IllegalStateException("configDialogUUID should have been set"); |
87 |
|
} |
88 |
0 |
try { |
89 |
0 |
final HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.CONFIG); |
90 |
0 |
imageControlConfigNode = hm.getContentByUUID(configDialogUUID); |
91 |
|
|
92 |
0 |
cropAndResizeConfigs = new ArrayList(); |
93 |
0 |
final Collection configNodes = imageControlConfigNode.getChildren(); |
94 |
0 |
final Iterator it = configNodes.iterator(); |
95 |
0 |
while (it.hasNext()) { |
96 |
0 |
final Content configNode = (Content) it.next(); |
97 |
0 |
cropAndResizeConfigs.add(fromNode(configNode)); |
98 |
|
} |
99 |
|
|
100 |
|
} catch (RepositoryException e) { |
101 |
0 |
throw new RuntimeException(e); |
102 |
|
} catch (Content2BeanException e) { |
103 |
0 |
throw new RuntimeException(e); |
104 |
|
} |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
107 |
8 |
public static CropAndResizeConfig fromNode(Content node) throws Content2BeanException {... |
108 |
|
|
109 |
8 |
final CropAndResizeConfig cfg = (CropAndResizeConfig) Content2BeanUtil.setProperties(new CropAndResizeConfig(), node); |
110 |
|
|
111 |
|
|
112 |
8 |
if (StringUtils.isEmpty(cfg.getName())) { |
113 |
2 |
cfg.setName(node.getName()); |
114 |
|
} |
115 |
8 |
if (StringUtils.isEmpty(cfg.getLabel())) { |
116 |
|
|
117 |
|
|
118 |
4 |
cfg.setLabel(cfg.getName()); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
8 |
cfg.setName(node.getName()); |
123 |
8 |
return cfg; |
124 |
|
|
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
|
127 |
0 |
@Override... |
128 |
|
public void renderHtml(String view) throws IOException { |
129 |
0 |
try { |
130 |
|
|
131 |
0 |
final Dialog dialog = new CropperDialog(); |
132 |
0 |
dialog.init(request, response, null, imageControlConfigNode); |
133 |
|
|
134 |
0 |
dialog.setConfig("i18nBasename", "info.magnolia.module.cropui.messages"); |
135 |
0 |
dialog.setConfig("saveLabel", dialog.getMessage("cropper.apply.button")); |
136 |
0 |
dialog.setConfig("saveOnclick", "cropperSubmit();"); |
137 |
|
|
138 |
0 |
final String tabLabel = dialog.getMessage("cropper.tab.label"); |
139 |
0 |
final DialogTab tab = dialog.addTab(tabLabel); |
140 |
0 |
tab.addSub(new CropperControl()); |
141 |
|
|
142 |
0 |
dialog.drawHtml(getResponse().getWriter()); |
143 |
|
|
144 |
|
} catch (RepositoryException e) { |
145 |
0 |
throw new RuntimeException(e); |
146 |
|
} |
147 |
|
} |
148 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
149 |
|
public void setConfigDialogUUID(String configDialogUUID) {... |
150 |
|
this.configDialogUUID = configDialogUUID; |
151 |
|
} |
152 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
153 |
|
public void setImagePath(String imagePath) {... |
154 |
|
this.imagePath = imagePath; |
155 |
|
} |
156 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
157 |
|
public void setCurrentCrop(String currentCrop) {... |
158 |
|
this.currentCrop = currentCrop; |
159 |
|
} |
160 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
161 |
|
public String getImagePath() {... |
162 |
|
return imagePath; |
163 |
|
} |
164 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
165 |
|
public String getCurrentCrop() {... |
166 |
|
return currentCrop; |
167 |
|
} |
168 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
169 |
|
public List getConfigs() { ... |
170 |
|
return cropAndResizeConfigs; |
171 |
|
} |
172 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.33 |
|
173 |
|
private final class CropperDialog extends Dialog { |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
174 |
0 |
@Override... |
175 |
|
protected void drawHtmlPreSubsHead(Writer out) throws IOException { |
176 |
0 |
super.drawHtmlPreSubsHead(out); |
177 |
0 |
renderTemplate("/info/magnolia/module/cropui/CropperPage.head.html", out); |
178 |
0 |
out.flush(); |
179 |
|
} |
180 |
|
} |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.2 |
|
182 |
|
private final class CropperControl extends DialogControlImpl { |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
183 |
0 |
@Override... |
184 |
|
public void drawHtml(Writer out) throws IOException { |
185 |
0 |
out.write("<tbody><tr><td>"); |
186 |
0 |
out.flush(); |
187 |
0 |
renderTemplate("/info/magnolia/module/cropui/CropperPage.html", out); |
188 |
0 |
out.flush(); |
189 |
0 |
out.write("</td></tr></tbody>"); |
190 |
|
} |
191 |
|
} |
192 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
193 |
0 |
private void renderTemplate(String templateName, Writer out) {... |
194 |
0 |
final HashMap map = new HashMap(); |
195 |
0 |
map.put("this", this); |
196 |
0 |
FreemarkerUtil.process(templateName, map, out); |
197 |
|
} |
198 |
|
|
199 |
|
} |