KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > admin > action > type > AddTypeAction


1 package org.nextime.ion.admin.action.type;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import org.apache.struts.action.Action;
9 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionForward;
11 import org.apache.struts.action.ActionMapping;
12
13 import org.nextime.ion.admin.form.*;
14 import org.nextime.ion.framework.business.*;
15 import org.nextime.ion.framework.business.User;
16 import org.nextime.ion.framework.mapping.Mapping;
17 import org.nextime.ion.framework.config.Config;
18
19 import java.io.*;
20
21 public class AddTypeAction extends Action {
22
23     public ActionForward perform(
24         ActionMapping mapping,
25         ActionForm form,
26         HttpServletRequest JavaDoc request,
27         HttpServletResponse JavaDoc response)
28         throws IOException JavaDoc, ServletException JavaDoc {
29
30         // pour situer la vue
31
request.setAttribute("view", "type");
32
33         String JavaDoc id = "";
34
35         try {
36
37             // si on a pas soumis le formulaire
38
if (request.getParameter("addSubmit") == null)
39                 return new ActionForward( mapping.getInput() );
40
41             // creation de l'objet
42
TypeForm f = (TypeForm) form;
43             Mapping.begin();
44             id = f.getId();
45             TypePublication u = TypePublication.create(f.getId());
46             
47             // creation du modele.xml de base
48
File file = new File( new File( Config.getInstance().getTypePublicationDirectory(), "models" ), f.getId()+".xml");
49             if( !file.exists() ) {
50                 PrintStream os = new PrintStream( new FileOutputStream(file) );
51                 os.println( "<!DOCTYPE publication SYSTEM \"modele.dtd\">" );
52                 os.println( "<publication name=\""+f.getId()+"\"/>");
53                 os.close();
54             }
55             
56             // creation du repertoire pour les styles
57
File dir = new File( new File( Config.getInstance().getTypePublicationDirectory(), "styles" ), f.getId());
58             if( !dir.exists() ) {
59                 dir.mkdir();
60             }
61                                                 
62             Mapping.commit();
63
64         } catch (Exception JavaDoc e) {
65             Mapping.rollback();
66             request.setAttribute("error", e.getMessage());
67             return new ActionForward( mapping.getInput() );
68         }
69         
70         // on va passer l'id en request pour aller directement
71
// la page d'edition
72
request.setAttribute("id", id);
73         
74         return mapping.findForward("success");
75     }
76
77 }
Popular Tags