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.core.Content; |
37 |
|
import info.magnolia.cms.core.NodeData; |
38 |
|
import info.magnolia.cms.gui.control.Button; |
39 |
|
import info.magnolia.cms.gui.control.File; |
40 |
|
import info.magnolia.cms.gui.control.Hidden; |
41 |
|
import info.magnolia.cms.gui.dialog.DialogBox; |
42 |
|
import info.magnolia.cms.gui.misc.CssConstants; |
43 |
|
|
44 |
|
import java.io.IOException; |
45 |
|
import java.io.Writer; |
46 |
|
|
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
import javax.servlet.http.HttpServletRequest; |
49 |
|
import javax.servlet.http.HttpServletResponse; |
50 |
|
|
51 |
|
import org.apache.commons.lang3.StringUtils; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@author |
57 |
|
@version |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 73 (73) |
Complexity: 11 |
Complexity Density: 0.19 |
|
59 |
|
public class CropAndResizeControl extends DialogBox { |
60 |
|
private Content configNode; |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
62 |
0 |
@Override... |
63 |
|
public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode) throws RepositoryException { |
64 |
0 |
super.init(request, response, websiteNode, configNode); |
65 |
0 |
this.configNode = configNode; |
66 |
|
} |
67 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
68 |
|
public Content getConfigNode() {... |
69 |
|
return configNode; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 65 (65) |
Complexity: 8 |
Complexity Density: 0.15 |
|
72 |
0 |
@Override... |
73 |
|
public void drawHtml(Writer out) throws IOException { |
74 |
0 |
drawHtmlPre(out); |
75 |
|
|
76 |
|
|
77 |
0 |
if (getWebsiteNode() != null) { |
78 |
0 |
final String fileControlName = getConfigValue("fileControlName", null); |
79 |
0 |
if (fileControlName == null) { |
80 |
0 |
throw new IllegalStateException("Need a fileControlName config parameter to know which file control to use."); |
81 |
|
} |
82 |
0 |
final File fileControl = new File(fileControlName, getWebsiteNode()); |
83 |
0 |
final String imagePath = fileControl.getHandle() + "." + fileControl.getExtension(); |
84 |
0 |
final String cropperInfoControlName = getCropperInfoPropertyName(fileControlName); |
85 |
0 |
final String previewId = cropperInfoControlName + "_previewZone"; |
86 |
|
|
87 |
0 |
out.write("\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"); |
88 |
|
|
89 |
0 |
out.write("<tr><td class=\"" + CssConstants.CSSCLASS_FILEIMAGE + "\">"); |
90 |
|
|
91 |
|
|
92 |
0 |
final NodeData bin = getWebsiteNode().getNodeData(getTargetBinaryPropertyName(fileControlName)); |
93 |
0 |
out.write("<div id=\""); |
94 |
0 |
out.write(previewId); |
95 |
0 |
out.write("\">"); |
96 |
0 |
if (bin.isExist()) { |
97 |
0 |
final File preview = new File(getTargetBinaryPropertyName(fileControlName), getWebsiteNode()); |
98 |
0 |
int previewHeight = -1; |
99 |
0 |
try { |
100 |
0 |
previewHeight = Integer.parseInt(preview.getImageHeight()); |
101 |
0 |
if (previewHeight > 100) { |
102 |
0 |
previewHeight = 100; |
103 |
|
} |
104 |
|
} catch (NumberFormatException e) { |
105 |
|
|
106 |
|
} |
107 |
|
|
108 |
0 |
out.write("<img src=\""); |
109 |
0 |
out.write(getRequest().getContextPath()); |
110 |
0 |
out.write(preview.getPath()); |
111 |
0 |
if (previewHeight > 0) { |
112 |
0 |
out.write("\" height=\""); |
113 |
0 |
out.write(String.valueOf(previewHeight)); |
114 |
|
} |
115 |
0 |
out.write("\" />"); |
116 |
0 |
if (StringUtils.isNotEmpty(preview.getImageWidth())) { |
117 |
0 |
out.write("<p><em style='white-space:nowrap'>"); |
118 |
0 |
out.write(getMessage("cropper.preview.widthheight", new String[]{preview.getImageWidth(), preview.getImageHeight()})); |
119 |
0 |
out.write("</em></p>\n"); |
120 |
|
} |
121 |
|
} |
122 |
0 |
out.write("<p style=\"display: none;\" class=\"warning\">"); |
123 |
0 |
out.write(getMessage("cropper.preview.tobeprocessed")); |
124 |
0 |
out.write("</p>"); |
125 |
0 |
out.write("</div>"); |
126 |
|
|
127 |
0 |
out.write("</td><td>"); |
128 |
|
|
129 |
0 |
final Hidden cropperInfo = new Hidden(cropperInfoControlName, getWebsiteNode()); |
130 |
0 |
cropperInfo.setId(cropperInfoControlName); |
131 |
0 |
cropperInfo.setSaveInfo(true); |
132 |
|
|
133 |
0 |
final String controlUUID = configNode.getUUID(); |
134 |
0 |
final Button button = new Button(); |
135 |
0 |
button.setLabel(getMessage("cropper.edit.button")); |
136 |
0 |
button.setOnclick("new mgnl.cropui.ImageCropper.openCropper('" + cropperInfo.getId() + "', '" + controlUUID + "', '" + imagePath + "');"); |
137 |
|
|
138 |
0 |
out.write("<div class=\""); |
139 |
0 |
out.write(CssConstants.CSSCLASS_DESCRIPTION); |
140 |
0 |
out.write("\">"); |
141 |
0 |
out.write(button.getHtml()); |
142 |
0 |
out.write(cropperInfo.getHtml()); |
143 |
0 |
out.write("</div>"); |
144 |
|
|
145 |
0 |
out.write("</td></tr></table>"); |
146 |
|
} |
147 |
|
|
148 |
0 |
drawHtmlPost(out); |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0 |
public static String getCropperInfoPropertyName(String fileControlName) {... |
152 |
0 |
return fileControlName + "_cropperInfo"; |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
0 |
public static String getTargetBinaryPropertyName(String fileControlName) {... |
156 |
0 |
return fileControlName + "_resized"; |
157 |
|
} |
158 |
|
} |