1 package org.nextime.ion.backoffice.action.resource; 2 3 4 import java.io.File ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import javax.servlet.ServletException ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionForward; 12 import org.apache.struts.action.ActionMapping; 13 import org.nextime.ion.backoffice.action.BaseAction; 14 import org.nextime.ion.backoffice.bean.ResourceXmlBean; 15 import org.nextime.ion.backoffice.bean.Resources; 16 import org.nextime.ion.backoffice.form.UploadResourceForm; 17 import org.nextime.ion.common.ResourceServlet; 18 19 20 21 public class UploadResourceAction extends BaseAction { 22 23 public ActionForward perform(ActionMapping mapping, 24 ActionForm form, 25 HttpServletRequest request, 26 HttpServletResponse response) 27 throws IOException , ServletException { 28 29 checkUser(request); 31 32 UploadResourceForm sform = (UploadResourceForm)form; 34 35 String id = request.getSession().getAttribute("selectedResources")+""; 37 String path = null; 38 try { 39 ResourceXmlBean bean = Resources.getResourceXmlBean(servlet,id); 40 path = bean.getDirectory(); 41 } catch( Exception e ) { 42 throw new ServletException (e); 43 } 44 String realPath = servlet.getServletContext().getRealPath("/"); 45 File resources = new File (realPath,ResourceServlet.relativePath); 46 File tresources = new File (resources,path); 47 48 String on = sform.getFile().getFileName(); 49 String ext = (on.indexOf(".")!=-1)?on.substring(on.indexOf(".")+1):"res"; 50 String fileName = sform.getName()+"."+ext; 51 52 File ofile = new File ( tresources, fileName ); 53 FileOutputStream fos = new FileOutputStream (ofile); 54 fos.write(sform.getFile().getFileData()); 55 56 sform.setName(""); 58 59 return (mapping.findForward("view")); 61 62 } 63 64 } 65 | Popular Tags |