1 41 package com.mvnforum.common; 42 43 import java.io.File ; 44 import java.io.IOException ; 45 import java.util.Collection ; 46 import java.util.Iterator ; 47 48 import com.mvnforum.MVNForumConfig; 49 import com.mvnforum.ManagerFactory; 50 import com.mvnforum.db.AttachmentBean; 51 import com.mvnforum.db.DAOFactory; 52 import net.myvietnam.mvncore.exception.DatabaseException; 53 import net.myvietnam.mvncore.service.BinaryStorage; 54 import net.myvietnam.mvncore.util.FileUtil; 55 import org.apache.commons.logging.Log; 56 import org.apache.commons.logging.LogFactory; 57 58 public class AttachmentUtil { 59 60 private static Log log = LogFactory.getLog(AttachmentUtil.class); 61 62 private AttachmentUtil() { 63 } 64 65 public static String getAttachFilenameOnDisk(int attachID) { 66 String filename = MVNForumConfig.getAttachmentDir() + File.separatorChar + attachID + ".mvn"; 67 return filename; 68 } 69 70 82 83 public static String getPmAttachFilenameOnDisk(int attachID) { 84 String filename = MVNForumConfig.getPmAttachmentDir() + File.separatorChar + attachID + ".mvn"; 85 return filename; 86 } 87 88 98 99 106 public static void deleteAttachments_inForum(int forumID) throws DatabaseException { 107 108 BinaryStorage binaryStorage = ManagerFactory.getBinaryStorage(); 109 110 Collection attachmentBeans = DAOFactory.getAttachmentDAO().getAttachments_inForum(forumID); 112 113 log.info("Delete forum = " + forumID + " attachment count = " + attachmentBeans.size()); 114 115 for (Iterator iter = attachmentBeans.iterator(); iter.hasNext(); ) { 117 AttachmentBean attachmentBean = (AttachmentBean)iter.next(); 118 int attachID = attachmentBean.getAttachID(); 119 120 try { 123 binaryStorage.deleteData(BinaryStorage.CATEGORY_POST_ATTACHMENT, String.valueOf(attachID), null); 124 } catch (IOException ex) { 125 log.error("Cannot delete file", ex); 126 } 128 129 try { 130 DAOFactory.getAttachmentDAO().delete(attachID); 131 } catch (Exception ex) { 132 log.warn("Cannot delete attachment in database", ex); 133 } 134 } 135 } 136 137 } 138 | Popular Tags |