KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > extensions > ExtensionUploadHandler


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.extensions;
21
22 import java.io.IOException JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.struts.Globals;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMessages;
30 import org.apache.struts.upload.FormFile;
31
32 import com.sslexplorer.core.BundleActionMessage;
33 import com.sslexplorer.core.CoreException;
34 import com.sslexplorer.core.CoreUtil;
35 import com.sslexplorer.core.GlobalWarning;
36 import com.sslexplorer.core.PopupException;
37 import com.sslexplorer.core.UploadHandler;
38 import com.sslexplorer.extensions.store.ExtensionStore;
39 import com.sslexplorer.vfs.UploadDetails;
40
41 public class ExtensionUploadHandler implements UploadHandler {
42
43     public static final String JavaDoc TYPE_EXTENSION = "EXTENSION";
44
45     public ActionForward performUpload(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, UploadDetails fileUpload,
46                                         FormFile file) throws IOException JavaDoc, Exception JavaDoc {
47         String JavaDoc id = file.getFileName().replaceAll(".zip", "");
48         ExtensionBundle bundle = null;
49         try {
50             bundle = ExtensionStore.getInstance().getExtensionBundle(id);
51         } catch (Exception JavaDoc e) {
52             // do nothing as there is no extention with the name.
53
}
54         if (bundle == null) {
55             bundle = ExtensionStore.getInstance().installExtension(id, file.getInputStream());
56             ExtensionStore.getInstance().licenseCheck(bundle, request, fileUpload.getUploadedForward());
57             ExtensionStore.getInstance().postInstallExtension(bundle, request);
58         } else {
59             bundle = ExtensionStore.getInstance().updateExtension(id, file.getInputStream(), request, file.getFileSize());
60             if (bundle.isContainsPlugin())
61                 CoreUtil.addMultipleGlobalWarning(GlobalWarning.MANAGEMENT_USERS, new BundleActionMessage("extensions",
62                                 "extensionStore.message.extensionUpdatedRestartRequired"));
63         }
64
65         return fileUpload.getUploadedForward();
66
67     }
68
69     public boolean checkFileToUpload(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, UploadDetails fileUpload,
70                                         FormFile file) throws IOException JavaDoc, Exception JavaDoc {
71         // TODO Auto-generated method stub
72
return false;
73     }
74
75 }
76
Popular Tags