Clover icon

Magnolia Crop UI for Imaging Module 3.2.7

  1. Project Clover database Fri Sep 9 2016 14:52:54 CEST
  2. Package info.magnolia.module.cropui

File CropAndResizeControl.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
50% of files have more coverage

Code metrics

12
57
4
1
158
95
11
0.19
14.25
4
2.75
2.7% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
CropAndResizeControl 59 57 2.7% 11 73
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2007-2016 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
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    * A control that's related to another control (named with fileControlName) and opens an edit window.
55    *
56    * @author gjoseph
57    * @version $Revision: $ ($Author: $)
58    */
 
59    public class CropAndResizeControl extends DialogBox {
60    private Content configNode;
61   
 
62  0 toggle @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   
 
68    toggle public Content getConfigNode() {
69    return configNode;
70    }
71   
 
72  0 toggle @Override
73    public void drawHtml(Writer out) throws IOException {
74  0 drawHtmlPre(out);
75   
76    // TODO : for now we can't handle a paragraph where the image hasn't been uploaded yet. (MGNLIMG-7)
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    //width=\"" + width + "\">");
89  0 out.write("<tr><td class=\"" + CssConstants.CSSCLASS_FILEIMAGE + "\">");
90   
91    // preview
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    // if the height wasn't stored .. should really not happen except if you used an old snapshot of this module ...
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=\""); // just to give a little padding
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   
 
151  0 toggle public static String getCropperInfoPropertyName(String fileControlName) {
152  0 return fileControlName + "_cropperInfo";
153    }
154   
 
155  0 toggle public static String getTargetBinaryPropertyName(String fileControlName) {
156  0 return fileControlName + "_resized";
157    }
158    }