source: ether_megapoli/trunk/service/implementation/com/medias/megapoli/struts/actions/DeleteSetAction.java @ 151

Last change on this file since 151 was 151, checked in by vmipsl, 13 years ago

Import medias files and cleanup

File size: 2.0 KB
Line 
1package com.medias.megapoli.struts.actions;
2
3import java.io.File;
4
5import javax.servlet.ServletException;
6import javax.servlet.http.HttpServletRequest;
7import javax.servlet.http.HttpServletResponse;
8
9import org.apache.struts.action.Action;
10import org.apache.struts.action.ActionError;
11import org.apache.struts.action.ActionErrors;
12import org.apache.struts.action.ActionForm;
13import org.apache.struts.action.ActionForward;
14import org.apache.struts.action.ActionMapping;
15import com.medias.annuaire.Annuaire;
16import com.medias.xml.hierarchie.Hierarchie;
17import com.medias.megapoli.struts.forms.DeleteForm;
18import com.medias.megapoli.utils.MegapoliInitialisation;
19import com.medias.Context;
20
21/**
22 * @author combaz
23 *
24 * Created on 23 févr. 2005
25 */
26public 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}
Note: See TracBrowser for help on using the repository browser.