KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > upload > SubmitFile


1
2
3  /*
4  -- GeiNuke --
5 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
6  http://www.hostingjava.it/-geinuke/
7
8 This file is part of GeiNuke.
9
10     GeiNuke is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     GeiNuke is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with GeiNuke; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */

24 package com.geinuke.module.upload;
25
26 import java.util.ArrayList JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 import org.apache.velocity.context.Context;
32
33 import com.geinuke.bizlogic.UploadException;
34 import com.geinuke.common.GlobalConfigurationI;
35 import com.geinuke.common.ModuleWidgetI;
36 import com.geinuke.common.NukeModuleI;
37 import com.geinuke.common.UserI;
38 import com.geinuke.middle.IUploadFileBL;
39 import com.geinuke.module.ModuleWriter;
40 import com.geinuke.servlet.GeiServlet;
41 import com.geinuke.util.FileUtils;
42 import com.geinuke.util.MagicUpload;
43 import com.geinuke.util.NukeResource;
44 import com.geinuke.vo.ModuleDBVO;
45 import com.geinuke.vo.UploadFileVO;
46
47
48
49 public class SubmitFile implements ModuleWidgetI{
50
51     
52     public void uploadFile(UserI u,HttpServletRequest JavaDoc req,MagicUpload upload)throws Exception JavaDoc{
53         UploadFileVO uf=null;
54         ArrayList JavaDoc exts=new ArrayList JavaDoc();
55         exts.add("*");
56         String JavaDoc path=GeiServlet.getNukePath();
57         path=path+"./images/users/"+u.getId()+"/";
58         GeiServlet.intLog(" uploadFile "+path);
59         FileUtils.mkDir(path);
60         GeiServlet.intLog(" uploadFile "+path);
61         try{
62             String JavaDoc fn=NukeResource.upload(upload,req,path,exts);
63             uf=new UploadFileVO();
64             IUploadFileBL bl=(IUploadFileBL)GeiServlet.getBL("IUploadFileBL");
65             uf.setFileName(fn);
66             path="./images/users/"+u.getId()+"/";
67             uf.setPath(path+fn);
68             uf.setTime(System.currentTimeMillis());
69             uf.setEUID(u.getId());
70             
71             bl.insUploadFile(uf);
72         }catch(UploadException noAction){}
73     }
74     
75     public NukeModuleI handleAction(ModuleDBVO module, Context ctx,HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res, UserI user, GlobalConfigurationI gConf) throws Exception JavaDoc {
76         String JavaDoc moduleTempName=null;
77         
78         MagicUpload upload=new MagicUpload();
79         
80         this.uploadFile(user,req,upload);
81         res.sendRedirect("Upload.jhtm?op=showF");
82         moduleTempName=gConf.getModulePage(module.getName(),req);
83         return ModuleWriter.fill(ctx,module,moduleTempName);
84     }
85
86 }
87
Popular Tags