1 | package com.medias.megapoli.struts.actions; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | |
---|
5 | import javax.servlet.ServletException; |
---|
6 | import javax.servlet.http.HttpServletRequest; |
---|
7 | import javax.servlet.http.HttpServletResponse; |
---|
8 | |
---|
9 | import org.apache.struts.action.Action; |
---|
10 | import org.apache.struts.action.ActionError; |
---|
11 | import org.apache.struts.action.ActionErrors; |
---|
12 | import org.apache.struts.action.ActionForm; |
---|
13 | import org.apache.struts.action.ActionForward; |
---|
14 | import org.apache.struts.action.ActionMapping; |
---|
15 | import com.medias.annuaire.Annuaire; |
---|
16 | import com.medias.xml.hierarchie.Hierarchie; |
---|
17 | import com.medias.megapoli.struts.forms.DeleteForm; |
---|
18 | import com.medias.megapoli.utils.MegapoliInitialisation; |
---|
19 | import com.medias.Context; |
---|
20 | |
---|
21 | /** |
---|
22 | * @author combaz |
---|
23 | * |
---|
24 | * Created on 23 févr. 2005 |
---|
25 | */ |
---|
26 | public class DeleteSetAction extends Action { |
---|
27 | public ActionForward execute (ActionMapping mapping,ActionForm form, |
---|
28 | HttpServletRequest request, HttpServletResponse response) |
---|
29 | throws ServletException { |
---|
30 | String target = "failure"; |
---|
31 | ActionErrors errors = new ActionErrors(); |
---|
32 | |
---|
33 | if(this.isCancelled(request)) |
---|
34 | target = "cancel"; |
---|
35 | |
---|
36 | else if(form!=null) { |
---|
37 | DeleteForm df = (DeleteForm) form; |
---|
38 | String setPath = df.getPath(); |
---|
39 | String setName = df.getName(); |
---|
40 | Hierarchie tree = (Hierarchie) request.getSession().getServletContext().getAttribute("APP_UPLOADTREE"); |
---|
41 | Annuaire annu = (Annuaire) request.getSession().getServletContext().getAttribute("APP_ANNUAIRE"); |
---|
42 | try { |
---|
43 | tree.deleteFolder(setPath); |
---|
44 | annu.deleteSet(setName); |
---|
45 | File pathImg = new File(MegapoliInitialisation.pathImages+"/"+setPath); |
---|
46 | if (pathImg.exists()) { |
---|
47 | File[] imgs =pathImg.listFiles(); |
---|
48 | for (File img: imgs) img.delete(); |
---|
49 | pathImg.delete(); |
---|
50 | } |
---|
51 | target="success"; |
---|
52 | } |
---|
53 | catch(Exception e) { |
---|
54 | e.printStackTrace(); |
---|
55 | errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("errors.upload.deleteSet.failed",Context.getWebmaster(request))); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | if(!errors.isEmpty()){ |
---|
60 | saveErrors(request, errors); |
---|
61 | } |
---|
62 | |
---|
63 | return mapping.findForward(target); |
---|
64 | } |
---|
65 | |
---|
66 | } |
---|