1 package org.nextime.ion.admin.action.type; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 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 request, 27 HttpServletResponse response) 28 throws IOException , ServletException { 29 30 request.setAttribute("view", "type"); 32 33 String id = ""; 34 35 try { 36 37 if (request.getParameter("addSubmit") == null) 39 return new ActionForward( mapping.getInput() ); 40 41 TypeForm f = (TypeForm) form; 43 Mapping.begin(); 44 id = f.getId(); 45 TypePublication u = TypePublication.create(f.getId()); 46 47 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 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 e) { 65 Mapping.rollback(); 66 request.setAttribute("error", e.getMessage()); 67 return new ActionForward( mapping.getInput() ); 68 } 69 70 request.setAttribute("id", id); 73 74 return mapping.findForward("success"); 75 } 76 77 } | Popular Tags |