1 3 package org.contineo.documan; 4 5 import java.util.Collection ; 6 import java.util.Iterator ; 7 8 import org.contineo.admin.Menu; 9 import org.contineo.admin.dao.MenuDAO; 10 import org.contineo.admin.dao.UserDocDAO; 11 import org.contineo.core.config.SettingConfigurator; 12 import org.contineo.core.doxter.Storer; 13 import org.contineo.documan.dao.DocumentDAO; 14 import org.contineo.documan.dao.TermDAO; 15 import org.contineo.searchengine.crawler.Indexer; 16 import org.contineo.searchengine.dao.SearchDocumentDAO; 17 18 22 public class DeleteItemUtil { 23 28 public static boolean deleteMenu(int menuId, String userName) { 29 MenuDAO mdao = new MenuDAO(); 30 Menu menu = mdao.findByPrimaryKey(menuId); 31 int type = menu.getMenuType(); 32 try { 33 if (type == Menu.MENUTYPE_FILE) { 34 deleteFile(menu, menuId, userName); 35 } else if (type == Menu.MENUTYPE_DIRECTORY) { 36 Collection children = mdao.findByParentId(menuId); 37 Iterator childIter = children.iterator(); 38 while (childIter.hasNext()) { 39 Menu m = (Menu)childIter.next(); 40 deleteFile(m, m.getMenuId(), userName); 41 } 42 } 43 return mdao.delete(menuId); 44 } catch (Exception ex) { 45 return false; 46 } 47 } 48 49 52 private static void deleteFile(Menu menu, int id, String username) throws Exception { 53 SearchDocumentDAO searchDocDao = new SearchDocumentDAO(); 54 searchDocDao.delete(id); 55 UserDocDAO uddao = new UserDocDAO(); 56 uddao.delete(username, id); 57 DocumentDAO ddao = new DocumentDAO(); 58 Document doc = ddao.findByMenuId(id); 59 if (doc != null) { 60 Indexer indexer = new Indexer(); 61 indexer.deleteFile(String.valueOf(id)); 62 } 63 boolean deleted1 = ddao.deleteByMenuId(id); 65 TermDAO termDao = new TermDAO(); 66 boolean deleted2 = termDao.delete(id); 67 MenuDAO mdao = new MenuDAO(); 68 boolean deleted = mdao.delete(id); 69 String menupath = menu.getMenuPath() + "/" + String.valueOf(id); 71 SettingConfigurator conf = new SettingConfigurator(); 73 Class clazz = Class.forName(conf.getValue("storer")); 74 Storer storer = (Storer)clazz.newInstance(); 75 if (!storer.delete(menupath) || !deleted || !deleted1 || !deleted2) 76 throw new Exception (); 77 } 78 }
| Popular Tags
|