1 13 package info.magnolia.cms.gui.dialog; 14 15 import info.magnolia.cms.beans.config.MIMEMapping; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.gui.control.File; 18 import info.magnolia.cms.gui.misc.CssConstants; 19 import info.magnolia.cms.gui.misc.Spacer; 20 21 import java.io.IOException ; 22 import java.io.Writer ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import javax.jcr.PropertyType; 27 import javax.jcr.RepositoryException; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.apache.commons.lang.StringUtils; 32 33 34 38 public class DialogFile extends DialogBox { 39 40 private List imageExtensions = new ArrayList (); 41 42 45 protected DialogFile() { 46 } 47 48 51 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode) 52 throws RepositoryException { 53 super.init(request, response, websiteNode, configNode); 54 initImageExtensions(); 55 } 56 57 public List getImageExtensions() { 58 return this.imageExtensions; 59 } 60 61 public void setImageExtensions(List l) { 62 this.imageExtensions = l; 63 } 64 65 public void initImageExtensions() { 66 this.getImageExtensions().add("jpg"); this.getImageExtensions().add("jpeg"); this.getImageExtensions().add("gif"); this.getImageExtensions().add("png"); this.getImageExtensions().add("bpm"); this.getImageExtensions().add("swf"); } 73 74 77 public void drawHtml(Writer out) throws IOException { 78 File control = getFileControl(); 79 control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING)); control.setSaveInfo(false); control.setCssClass(CssConstants.CSSCLASS_FILE); 82 control.setCssClassFileName(CssConstants.CSSCLASS_EDIT); 83 control.setCssStyles("width", this.getConfigValue("width", "100%")); 85 this.drawHtmlPre(out); 86 87 String width = this.getConfigValue("width", "100%"); boolean showImage = this.getImageExtensions().contains(control.getExtension().toLowerCase()); 89 90 String htmlControlBrowse = control.getHtmlBrowse(); 91 StringBuffer htmlControlFileName = new StringBuffer (); 92 htmlControlFileName.append("<span class=\"" + CssConstants.CSSCLASS_DESCRIPTION 94 + "\">" + getMessage("dialog.file.filename") + "</span>"); htmlControlFileName.append(Spacer.getHtml(1, 1)); 98 htmlControlFileName.append(control.getHtmlFileName() + "<span id=\"" + this.getName() 100 + "_fileNameExtension\">." + control.getExtension() 102 + "</span>"); String htmlContentEmpty = htmlControlBrowse + Spacer.getHtml(0, 0) + htmlControlFileName; 104 out.write("<div id=\"" + this.getName() + "_contentDiv\" style=\"width:100%;\">"); boolean exists = false; 106 107 if (this.getWebsiteNode() != null) { 108 exists = this.getWebsiteNode().getNodeData(this.getName()).isExist(); 109 } 110 111 if (!exists) { 112 out.write(htmlContentEmpty); 113 out.write("</div>"); } 115 else { 116 if (showImage) { 117 118 out.write("\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"" + width + "\">"); out.write("<tr><td class=\"" + CssConstants.CSSCLASS_FILEIMAGE + "\">"); 121 if ("swf".equals(control.getExtension().toLowerCase())) { 122 123 out.write("<object type=\"application/x-shockwave-flash\" data=\""); 125 out.write(this.getRequest().getContextPath()); 126 out.write(getFileURI(control)); 127 out.write("\" title=\""); 128 out.write(control.getFileName()); 129 out.write("\" "); 130 out.write("width=\"150\" "); 131 out.write("height=\"100\" "); 132 out.write(">"); 133 134 out.write("<param name=\"movie\" value=\""); 135 out.write(this.getRequest().getContextPath()); 136 out.write(getFileURI(control)); 137 out.write("\"/>"); 138 139 out.write("</object>\n"); 140 141 } 142 else { 143 145 151 int imgwidth = 150; 152 int imgheight = 150; 153 154 try{ 155 imgwidth = Integer.parseInt(control.getImageWidth()); 156 imgheight = Integer.parseInt(control.getImageHeight()); 157 } 158 catch(NumberFormatException e){ 159 } 161 int bigger = Math.max(imgwidth,imgheight); 162 if(bigger > 150){ 163 imgwidth=150; 164 } 165 166 out.write("<img width=\"" + imgwidth + "\" SRC=\""); out.write(this.getRequest().getContextPath()); 168 out.write(getFileURI(control)); 169 out.write("\" class=\""); out.write(CssConstants.CSSCLASS_FILEIMAGE); 171 out.write("\" alt=\""); out.write(control.getFileName()); 173 out.write("\" title=\""); out.write(control.getFileName()); 175 out.write("\" />\n"); 177 178 if (StringUtils.isNotEmpty(control.getImageWidth())) { 179 out.write("<em style='white-space:nowrap'>"); 181 out.write("width: "); out.write(control.getImageWidth()); 183 184 out.write(" height: "); out.write(control.getImageHeight()); 186 187 out.write("</em>\n"); } 189 190 } 191 192 out.write("</td><td>"); } 194 out.write(htmlControlFileName.toString()); 195 if (!showImage) { 196 String iconPath = MIMEMapping.getMIMETypeIcon(control.getExtension()); 197 198 out.write(Spacer.getHtml(0, 0)); 199 out.write("<a HREF=" + this.getRequest().getContextPath() + control.getPath() + " target=\"_blank\">"); out.write("<img SRC=\"" + this.getRequest().getContextPath() 202 + iconPath 203 + "\" class=\"" + CssConstants.CSSCLASS_FILEICON 205 + "\" border=\"0\">"); out.write(control.getFileName() + "." + control.getExtension() + "</a>"); } 208 out.write(Spacer.getHtml(12, 12)); 209 out.write(control.getHtmlRemove("mgnlDialogFileRemove('" + this.getName() + "');")); if (showImage) { 211 out.write("</td></tr></table>"); } 213 out.write("</div>\n"); out.write("<div style=\"position:absolute;top:-500px;left:-500px;visibility:hidden;\">\n<textarea id=\""); out.write(this.getName()); 216 out.write("_contentEmpty\">"); out.write(htmlContentEmpty); 218 219 out.write("</textarea>\n</div>\n"); } 223 control.setSaveInfo(true); 224 out.write(control.getHtmlSaveInfo()); 225 control.setNodeDataTemplate(this.getConfigValue("nodeDataTemplate", null)); out.write(control.getHtmlNodeDataTemplate()); 227 this.drawHtmlPost(out); 228 } 229 230 235 protected String getFileURI(File control) { 236 return control.getHandle(); 237 } 238 239 242 protected File getFileControl() { 243 File control = new File(this.getName(), this.getWebsiteNode()); 244 return control; 245 } 246 } 247 | Popular Tags |