001: package org.enhydra.snapperAdmin.presentation;
002:
003: import java.io.File;
004:
005: import org.enhydra.snapperAdmin.presentation.BasePO;
006: import org.enhydra.snapperAdmin.presentation.FileDownloadBO;
007: import org.enhydra.snapperAdmin.Log;
008: import org.enhydra.snapperAdmin.spec.Download;
009: import org.enhydra.snapperAdmin.spec.DownloadFactory;
010: import org.enhydra.snapperAdmin.spec.Site;
011: import org.enhydra.snapperAdmin.spec.SiteList;
012: import org.enhydra.snapperAdmin.spec.SiteListFactory;
013: import org.enhydra.xml.xmlc.XMLObject;
014:
015: public class DM_DownloadPO extends BasePO {
016:
017: protected XMLObject getDOM() throws Exception {
018: try {
019:
020: String url = comms.request.getParameter("url");
021: String type = comms.request.getParameter("type");
022: String siteName = comms.request.getParameter("id");
023:
024: int indexOf = -1;
025: indexOf = url.lastIndexOf(".");
026: if (indexOf != -1)
027: type = url.substring(indexOf + 1);
028:
029: String ftype = type;
030:
031: if (type != null)
032: type = manageType(type);
033:
034: if (checkIsGrantedDownload(siteName)) {
035:
036: if (url.startsWith("ftp"))
037: downloadFtpFile(url, ftype, siteName);
038: else if (url.startsWith("http")) {
039: downloadWebDavFile(url, ftype, siteName);
040: } else
041: downloadFile(url, type);
042:
043: }
044: } catch (Exception e) {
045: Log.logException(e);
046: }
047:
048: return null;
049: }
050:
051: protected void downloadFile(String filePath, String type)
052: throws Exception {
053: try {
054: FileDownloadBO theBO = new FileDownloadBO(
055: new File(filePath), comms);
056: theBO.setContentType(type);
057: theBO.download();
058: } catch (Exception e) {
059: Log.logException(e);
060: }
061: }
062:
063: public void downloadFtpFile(String id, String type, String siteName) {
064: try {
065: Download dw = DownloadFactory
066: .getDownload("org.enhydra.snapperAdmin.business.DownloadImpl");
067: File tempFile = dw.downloadFtpFile(id, type, siteName);
068: if (tempFile != null) {
069: FileDownloadBO theBO = new FileDownloadBO(tempFile,
070: comms);
071: theBO.setContentType(manageType(type));
072: theBO.download();
073: tempFile.delete();
074: } else {
075: return;
076: }
077: } catch (Exception e) {
078: Log.logException(e);
079: }
080: }
081:
082: public void downloadWebDavFile(String id, String type,
083: String siteName) {
084: try {
085: Download dw = DownloadFactory
086: .getDownload("org.enhydra.snapperAdmin.business.DownloadImpl");
087: File tempFile = dw.downloadWebDavFile(id, type, siteName);
088:
089: if (tempFile != null) {
090: FileDownloadBO theBO = new FileDownloadBO(tempFile,
091: comms);
092: theBO.setContentType(manageType(type));
093: theBO.download();
094: tempFile.delete();
095: } else {
096: return;
097: }
098: } catch (Exception e) {
099: Log.logException(e);
100: }
101: }
102:
103: public boolean checkIsGrantedDownload(String siteName) {
104: if (siteName == null)
105: return false;
106: try {
107: SiteList sl = SiteListFactory
108: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
109:
110: Site site = sl.findSiteByName(siteName);
111:
112: if (site != null)
113: return site.getDOWNLOAD();
114: else
115: return false;
116:
117: } catch (Exception e) {
118: Log.logException(e);
119: return false;
120: }
121:
122: }
123:
124: protected String manageType(String type) {
125: String result;
126: if (type.equalsIgnoreCase("html"))
127: result = FileDownloadBO.HTML_CONTENT_TYPE;
128: else if (type.equalsIgnoreCase("pdf"))
129: result = FileDownloadBO.PDF_CONTENT_TYPE;
130: else if (type.equalsIgnoreCase("xls"))
131: result = FileDownloadBO.EXCEL_CONTENT_TYPE;
132: else if (type.equalsIgnoreCase("doc"))
133: result = FileDownloadBO.WORD_CONTENT_TYPE;
134: else if (type.equalsIgnoreCase("rtf"))
135: result = FileDownloadBO.RTF_CONTENT_TYPE;
136: else if (type.equalsIgnoreCase("sxw"))
137: result = FileDownloadBO.SXW_CONTENT_TYPE;
138: else if (type.equalsIgnoreCase("stw"))
139: result = FileDownloadBO.STW_CONTENT_TYPE;
140: else if (type.equalsIgnoreCase("sxg"))
141: result = FileDownloadBO.SXG_CONTENT_TYPE;
142: else if (type.equalsIgnoreCase("sxc"))
143: result = FileDownloadBO.SXC_CONTENT_TYPE;
144: else if (type.equalsIgnoreCase("stc"))
145: result = FileDownloadBO.STC_CONTENT_TYPE;
146: else if (type.equalsIgnoreCase("sxi"))
147: result = FileDownloadBO.SXI_CONTENT_TYPE;
148: else if (type.equalsIgnoreCase("sti"))
149: result = FileDownloadBO.STI_CONTENT_TYPE;
150: else if (type.equalsIgnoreCase("sxd"))
151: result = FileDownloadBO.SXD_CONTENT_TYPE;
152: else if (type.equalsIgnoreCase("std"))
153: result = FileDownloadBO.STD_CONTENT_TYPE;
154: else if (type.equalsIgnoreCase("sxm"))
155: result = FileDownloadBO.SXM_CONTENT_TYPE;
156: else if (type.equalsIgnoreCase("msg"))
157: result = FileDownloadBO.EML_CONTENT_TYPE;
158: else if (type.equalsIgnoreCase("pst"))
159: result = FileDownloadBO.EML_CONTENT_TYPE;
160: else if (type.equalsIgnoreCase("ppt"))
161: result = FileDownloadBO.PPT_CONTENT_TYPE;
162: else if (type.equalsIgnoreCase("pps"))
163: result = FileDownloadBO.PPS_CONTENT_TYPE;
164: else if (type.equalsIgnoreCase("zip"))
165: result = FileDownloadBO.ZIP_CONTENT_TYPE;
166: else if (type.equalsIgnoreCase("eml"))
167: result = FileDownloadBO.EML_CONTENT_TYPE;
168: else if (type.equalsIgnoreCase("txt"))
169: result = FileDownloadBO.HTML_CONTENT_TYPE;
170: else if (type.equalsIgnoreCase("ico"))
171: result = "image/x-icon";
172: else if (type.equalsIgnoreCase("xlc"))
173: result = FileDownloadBO.EXCEL_CONTENT_TYPE;
174: else if (type.equalsIgnoreCase("xlt"))
175: result = FileDownloadBO.EXCEL_CONTENT_TYPE;
176: else if (type.equalsIgnoreCase("xla"))
177: result = FileDownloadBO.EXCEL_CONTENT_TYPE;
178: else if (type.equalsIgnoreCase("text"))
179: result = "text/plain";
180: else if (type.equalsIgnoreCase("bib"))
181: result = "text/plain";
182: else if (type.equalsIgnoreCase("err"))
183: result = "text/plain";
184: else if (type.equalsIgnoreCase("faq"))
185: result = "text/plain";
186: else if (type.equalsIgnoreCase("log"))
187: result = "text/plain";
188: else if (type.equalsIgnoreCase("csv"))
189: result = "text/plain";
190: else if (type.equalsIgnoreCase("sql"))
191: result = "text/plain";
192: else if (type.equalsIgnoreCase("xml"))
193: result = "application/xml";
194: else if (type.equalsIgnoreCase("xsl"))
195: result = "application/xml";
196: else if (type.equalsIgnoreCase("xslt"))
197: result = "application/xml";
198: else if (type.equalsIgnoreCase("js"))
199: result = "text/plain";
200: else if (type.equalsIgnoreCase("jsp"))
201: result = "text/plain";
202: else if (type.equalsIgnoreCase("jspx"))
203: result = "text/plain";
204: else if (type.equalsIgnoreCase("css"))
205: result = "text/plain";
206: else if (type.equalsIgnoreCase("php"))
207: result = "text/plain";
208: else if (type.equalsIgnoreCase("php3"))
209: result = "text/plain";
210: else if (type.equalsIgnoreCase("php4"))
211: result = "text/plain";
212: else if (type.equalsIgnoreCase("php5"))
213: result = "text/plain";
214: else if (type.equalsIgnoreCase("asp"))
215: result = "text/plain";
216: else if (type.equalsIgnoreCase("aspx"))
217: result = "text/plain";
218: else if (type.equalsIgnoreCase("cfm"))
219: result = "text/plain";
220: else if (type.equalsIgnoreCase("htx"))
221: result = "text/plain";
222: else if (type.equalsIgnoreCase("java"))
223: result = "text/plain";
224: else if (type.equalsIgnoreCase("properties"))
225: result = "text/plain";
226: else if (type.equalsIgnoreCase("c"))
227: result = "text/plain";
228: else if (type.equalsIgnoreCase("cpp"))
229: result = "text/plain";
230: else if (type.equalsIgnoreCase("h"))
231: result = "text/plain";
232: else if (type.equalsIgnoreCase("cgi"))
233: result = "text/plain";
234: else if (type.equalsIgnoreCase("dtd"))
235: result = "text/plain";
236: else if (type.equalsIgnoreCase("pl"))
237: result = "text/plain";
238: else if (type.equalsIgnoreCase("rar"))
239: result = FileDownloadBO.ZIP_CONTENT_TYPE;
240: else if (type.equalsIgnoreCase("gz"))
241: result = FileDownloadBO.ZIP_CONTENT_TYPE;
242: else if (type.equalsIgnoreCase("bz2"))
243: result = FileDownloadBO.ZIP_CONTENT_TYPE;
244: else
245: result = "";
246: return result;
247:
248: }
249:
250: }
|