KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > presentation > DM_DownloadPO


1 package org.enhydra.snapper.presentation;
2
3 import java.io.File JavaDoc;
4 import org.enhydra.xml.xmlc.XMLObject;
5 import java.net.URLDecoder JavaDoc;
6 import java.util.Vector JavaDoc;
7 import org.enhydra.snapper.Log;
8 //import org.enhydra.snapper.business.SiteListImpl;
9
import org.enhydra.snapper.spec.*;
10
11 public class DM_DownloadPO extends BasePO {
12
13     
14     protected XMLObject getDOM() throws Exception JavaDoc {
15       try {
16            
17             
18             String JavaDoc url=comms.request.getParameter("url");
19             String JavaDoc type=comms.request.getParameter("type");
20             String JavaDoc siteName=comms.request.getParameter("id");
21             
22             if(type!=null)
23              type=manageType(type);
24             
25        
26        if(checkIsGrantedDownload(siteName))
27        {
28             
29           if(!url.startsWith("ftp"))
30             downloadFile(url,type);
31            else
32            {
33                downloadFtpFile(url,comms.request.getParameter("type"));
34            }
35        }
36           } catch (Exception JavaDoc e) {
37             Log.logException(e);
38       }
39
40         return null;
41     }
42
43     protected void downloadFile(String JavaDoc filePath,String JavaDoc type) throws Exception JavaDoc {
44
45         FileDownloadBO theBO = new FileDownloadBO(new File JavaDoc(filePath), comms);
46
47         try {
48             theBO.setContentType(type);
49             theBO.download();
50         } catch (Exception JavaDoc e) {
51             Log.logException(e);
52        }
53     }
54     
55    protected String JavaDoc manageType(String JavaDoc type)
56     {
57       String JavaDoc result;
58       if(type.equals("html"))
59           result = FileDownloadBO.HTML_CONTENT_TYPE;
60       else if(type.equals("pdf"))
61           result = FileDownloadBO.PDF_CONTENT_TYPE;
62       else if(type.equals("xls"))
63           result = FileDownloadBO.EXCEL_CONTENT_TYPE;
64       else if(type.equals("doc"))
65           result = FileDownloadBO.WORD_CONTENT_TYPE;
66       else if(type.equals("rtf"))
67           result = FileDownloadBO.RTF_CONTENT_TYPE;
68       else if(type.equals("sxw"))
69           result = FileDownloadBO.SXW_CONTENT_TYPE;
70       else if(type.equals("stw"))
71           result = FileDownloadBO.STW_CONTENT_TYPE;
72       else if(type.equals("sxg"))
73           result = FileDownloadBO.SXG_CONTENT_TYPE;
74       else if(type.equals("sxc"))
75           result = FileDownloadBO.SXC_CONTENT_TYPE;
76       else if(type.equals("stc"))
77           result = FileDownloadBO.STC_CONTENT_TYPE;
78       else if(type.equals("sxi"))
79           result = FileDownloadBO.SXI_CONTENT_TYPE;
80       else if(type.equals("sti"))
81           result = FileDownloadBO.STI_CONTENT_TYPE;
82       else if(type.equals("sxd"))
83           result = FileDownloadBO.SXD_CONTENT_TYPE;
84       else if(type.equals("std"))
85           result = FileDownloadBO.STD_CONTENT_TYPE;
86       else if(type.equals("sxm"))
87           result = FileDownloadBO.SXM_CONTENT_TYPE;
88       else if(type.equals("msg"))
89           result = FileDownloadBO.EML_CONTENT_TYPE;
90       else if(type.equals("ppt"))
91           result = FileDownloadBO.PPT_CONTENT_TYPE;
92       else if(type.equals("pps"))
93           result = FileDownloadBO.PPS_CONTENT_TYPE;
94       else if(type.equals("zip"))
95           result = FileDownloadBO.ZIP_CONTENT_TYPE;
96       else if(type.equals("eml"))
97           result = FileDownloadBO.EML_CONTENT_TYPE;
98       else if(type.equals("txt"))
99           result = FileDownloadBO.HTML_CONTENT_TYPE;
100       else
101           result = "";
102       return result;
103     }
104  
105  
106    
107    public void downloadFtpFile(String JavaDoc id, String JavaDoc type){
108     try{
109         
110  
111         Download dw = DownloadFactory.getDownload("org.enhydra.snapper.business.DownloadImpl");
112         File JavaDoc retVal = dw.downloadFtpFile(id,type);
113        if(retVal!=null)
114         {
115         FileDownloadBO theBO = new FileDownloadBO(retVal, comms);
116         theBO.setContentType(manageType(type));
117         theBO.download();
118         retVal.delete();
119         }
120        else
121        {
122            return;
123        }
124     } catch (Exception JavaDoc e) {
125         Log.logException(e);
126     }
127    }
128    
129   public boolean checkIsGrantedDownload(String JavaDoc siteName)
130    {
131        if(siteName==null)
132          return false;
133     try {
134         SiteList sl = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
135         Site[] list = sl.getList(dbTransaction);
136         
137         for(int i=0;i<list.length;i++)
138            {
139                 Site currentSite = list[i];
140                 String JavaDoc id = currentSite.getID();
141                 String JavaDoc name = currentSite.getName();
142             
143           if(name.equals(siteName))
144                 return currentSite.getDOWNLOAD();
145            }
146         
147         return false;
148         
149         
150     }catch (Exception JavaDoc e){
151         Log.logException(e);
152         return false;
153     }
154    
155    }
156  
157   
158
159  
160     
161 }
Popular Tags