KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > resource > ViewResourceAction


1 package org.nextime.ion.backoffice.action.resource;
2
3
4 import java.io.File JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.util.Vector JavaDoc;
7
8 import javax.servlet.ServletException JavaDoc;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionForward;
13 import org.apache.struts.action.ActionMapping;
14 import org.nextime.ion.backoffice.action.BaseAction;
15 import org.nextime.ion.backoffice.bean.ResourceXmlBean;
16 import org.nextime.ion.backoffice.bean.Resources;
17 import org.nextime.ion.common.ResourceServlet;
18
19
20
21 public class ViewResourceAction extends BaseAction {
22
23     public ActionForward perform(ActionMapping mapping,
24                                  ActionForm form,
25                                  HttpServletRequest JavaDoc request,
26                                  HttpServletResponse JavaDoc response)
27         throws IOException JavaDoc, ServletException JavaDoc {
28             
29         // check if user is correctly logged
30
checkUser(request);
31         
32         // retrieve resources selected
33
String JavaDoc id = request.getSession().getAttribute("selectedResources")+"";
34         String JavaDoc path = null;
35         try {
36             ResourceXmlBean bean = Resources.getResourceXmlBean(servlet,id);
37             path = bean.getDirectory();
38         } catch( Exception JavaDoc e ) {
39             throw new ServletException JavaDoc(e);
40         }
41         
42         String JavaDoc realPath = servlet.getServletContext().getRealPath("/");
43         File JavaDoc resources = new File JavaDoc(realPath,ResourceServlet.relativePath);
44         File JavaDoc tresources = new File JavaDoc(resources,path);
45         
46         File JavaDoc[] files = tresources.listFiles();
47         Vector JavaDoc mfiles = new Vector JavaDoc();
48         for( int i=0; i<files.length; i++ ) {
49             mfiles.add(new org.nextime.ion.backoffice.bean.File(files[i]));
50         }
51         
52         request.setAttribute("files",mfiles);
53         
54         // Forward to the next page
55
return (mapping.findForward("view"));
56
57     }
58
59 }
60
Popular Tags