1 43 package net.jforum.view.admin; 44 45 import java.io.File ; 46 47 import net.jforum.dao.DataAccessDriver; 48 import net.jforum.dao.SmilieDAO; 49 import net.jforum.entities.Smilie; 50 import net.jforum.repository.SmiliesRepository; 51 import net.jforum.util.MD5; 52 import net.jforum.util.legacy.commons.fileupload.FileItem; 53 import net.jforum.util.preferences.ConfigKeys; 54 import net.jforum.util.preferences.SystemGlobals; 55 import net.jforum.util.preferences.TemplateKeys; 56 import net.jforum.view.forum.common.UploadUtils; 57 58 62 public class SmiliesAction extends AdminCommand 63 { 64 private String processUpload() throws Exception 65 { 66 String imgName = ""; 67 68 if (this.request.getObjectParameter("smilie_img") != null) { 69 FileItem item = (FileItem)this.request.getObjectParameter("smilie_img"); 70 UploadUtils uploadUtils = new UploadUtils(item); 71 72 imgName = MD5.crypt(item.getName()); 73 74 uploadUtils.saveUploadedFile(SystemGlobals.getApplicationPath() 75 + "/" 76 + SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_DIR) 77 + "/" 78 + imgName + "." + uploadUtils.getExtension()); 79 80 imgName += "." + uploadUtils.getExtension(); 81 } 82 83 return imgName; 84 } 85 86 public void insert() 87 { 88 this.setTemplateName(TemplateKeys.SMILIES_INSERT); 89 this.context.put("action", "insertSave"); 90 } 91 92 public void insertSave() throws Exception 93 { 94 Smilie s = new Smilie(); 95 s.setCode(this.request.getParameter("code")); 96 97 String imgName = this.processUpload(); 98 s.setUrl(SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_PATTERN).replaceAll("#IMAGE#", imgName)); 99 100 s.setDiskName(imgName); 101 102 DataAccessDriver.getInstance().newSmilieDAO().addNew(s); 103 104 SmiliesRepository.loadSmilies(); 105 this.list(); 106 } 107 108 public void edit() throws Exception 109 { 110 int id = 1; 111 112 if (this.request.getParameter("id") != null) { 113 id = this.request.getIntParameter("id"); 114 } 115 116 this.setTemplateName(TemplateKeys.SMILIES_EDIT); 117 this.context.put("smilie", DataAccessDriver.getInstance().newSmilieDAO().selectById(id)); 118 this.context.put("action", "editSave"); 119 } 120 121 public void editSave() throws Exception 122 { 123 Smilie s = DataAccessDriver.getInstance().newSmilieDAO().selectById(this.request.getIntParameter("id")); 124 s.setCode(this.request.getParameter("code")); 125 126 if (this.request.getObjectParameter("smilie_img") != null) { 127 String imgName = this.processUpload(); 128 s.setUrl(SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_PATTERN).replaceAll("#IMAGE#", imgName)); 129 s.setDiskName(imgName); 130 } 131 132 DataAccessDriver.getInstance().newSmilieDAO().update(s); 133 134 SmiliesRepository.loadSmilies(); 135 this.list(); 136 } 137 138 public void delete() throws Exception 139 { 140 String [] ids = this.request.getParameterValues("id"); 141 142 if (ids != null) { 143 SmilieDAO dao = DataAccessDriver.getInstance().newSmilieDAO(); 144 145 for (int i = 0; i < ids.length; i++) { 146 int id = Integer.parseInt(ids[i]); 147 148 Smilie s = dao.selectById(id); 149 dao.delete(id); 150 151 File f = new File (SystemGlobals.getApplicationPath() 152 + "/" 153 + SystemGlobals.getValue(ConfigKeys.SMILIE_IMAGE_DIR) 154 + "/" 155 + s.getDiskName()); 156 157 if (f.exists()) { 158 f.delete(); 159 } 160 } 161 } 162 163 SmiliesRepository.loadSmilies(); 164 this.list(); 165 } 166 167 170 public void list() throws Exception 171 { 172 this.context.put("smilies", SmiliesRepository.getSmilies()); 173 this.setTemplateName(TemplateKeys.SMILIES_LIST); 174 } 175 } 176 | Popular Tags |