KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > modules > CmsModulesUploadFromHttp


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsModulesUploadFromHttp.java,v $
3  * Date : $Date: 2006/03/28 13:54:48 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.modules;
33
34 import org.opencms.configuration.CmsConfigurationException;
35 import org.opencms.i18n.CmsMessageContainer;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsIllegalStateException;
39 import org.opencms.main.CmsLog;
40 import org.opencms.main.CmsSystemInfo;
41 import org.opencms.main.OpenCms;
42 import org.opencms.module.CmsModule;
43 import org.opencms.module.CmsModuleDependency;
44 import org.opencms.module.CmsModuleImportExportHandler;
45 import org.opencms.module.CmsModuleManager;
46 import org.opencms.workplace.administration.A_CmsImportFromHttp;
47 import org.opencms.workplace.tools.CmsToolDialog;
48 import org.opencms.workplace.tools.CmsToolManager;
49
50 import java.io.File JavaDoc;
51 import java.io.IOException JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.HashMap JavaDoc;
54 import java.util.Iterator JavaDoc;
55 import java.util.List JavaDoc;
56 import java.util.Map JavaDoc;
57
58 import javax.servlet.ServletException JavaDoc;
59 import javax.servlet.http.HttpServletRequest JavaDoc;
60 import javax.servlet.http.HttpServletResponse JavaDoc;
61 import javax.servlet.jsp.PageContext JavaDoc;
62
63 import org.apache.commons.logging.Log;
64
65 /**
66  * Class to upload a module with HTTP upload.<p>
67  *
68  * @author Michael Emmerich
69  *
70  * @version $Revision: 1.12 $
71  *
72  * @since 6.0.0
73  */

74 public class CmsModulesUploadFromHttp extends A_CmsImportFromHttp {
75
76     /** The dialog URI. */
77     public static final String JavaDoc DIALOG_URI = PATH_WORKPLACE + "admin/modules/modules_import.jsp";
78
79     /** Modulename parameter. */
80     public static final String JavaDoc PARAM_MODULE = "module";
81
82     /** The log object for this class. */
83     private static final Log LOG = CmsLog.getLog(CmsModulesUploadFromHttp.class);
84
85     /**
86      * Public constructor with JSP action element.<p>
87      *
88      * @param jsp an initialized JSP action element
89      */

90     public CmsModulesUploadFromHttp(CmsJspActionElement jsp) {
91
92         super(jsp);
93     }
94
95     /**
96      * Public constructor with JSP variables.<p>
97      *
98      * @param context the JSP page context
99      * @param req the JSP request
100      * @param res the JSP response
101      */

102     public CmsModulesUploadFromHttp(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
103
104         this(new CmsJspActionElement(context, req, res));
105     }
106
107     /**
108      * @see org.opencms.workplace.administration.A_CmsImportFromHttp#actionCommit()
109      */

110     public void actionCommit() throws IOException JavaDoc, ServletException JavaDoc {
111
112         try {
113             copyFileToServer(OpenCms.getSystemInfo().getPackagesRfsPath()
114                 + File.separator
115                 + CmsSystemInfo.FOLDER_MODULES);
116         } catch (CmsException e) {
117             // error copying the file to the OpenCms server
118
setException(e);
119             return;
120         }
121         /// copied
122
List JavaDoc errors = new ArrayList JavaDoc();
123         CmsModule module = null;
124         try {
125             String JavaDoc importpath = OpenCms.getSystemInfo().getPackagesRfsPath();
126             importpath = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
127                 importpath + "modules/" + getParamImportfile());
128             module = CmsModuleImportExportHandler.readModuleFromImport(importpath);
129
130             // check if all dependencies are fulfilled
131
List JavaDoc dependencies = OpenCms.getModuleManager().checkDependencies(
132                 module,
133                 CmsModuleManager.DEPENDENCY_MODE_IMPORT);
134             if (!dependencies.isEmpty()) {
135                 StringBuffer JavaDoc dep = new StringBuffer JavaDoc(32);
136                 for (int i = 0; i < dependencies.size(); i++) {
137                     CmsModuleDependency dependency = (CmsModuleDependency)dependencies.get(i);
138                     dep.append("\n - ");
139                     dep.append(dependency.getName());
140                     dep.append(" (Version: ");
141                     dep.append(dependency.getVersion());
142                     dep.append(")");
143                 }
144                 errors.add(Messages.get().container(
145                     Messages.ERR_ACTION_MODULE_DEPENDENCY_2,
146                     getParamImportfile(),
147                     new String JavaDoc(dep)));
148             }
149
150         } catch (CmsConfigurationException e) {
151             errors.add(Messages.get().container(Messages.ERR_ACTION_MODULE_UPLOAD_1, getParamImportfile()));
152         }
153
154         if (errors.isEmpty()) {
155
156             // refresh the list
157
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
158             if (objects != null) {
159                 objects.remove(CmsModulesList.class.getName());
160             }
161
162             // redirect
163
Map JavaDoc param = new HashMap JavaDoc();
164             param.put(CmsModulesList.PARAM_MODULE, getParamImportfile());
165             param.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
166             param.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/modules"));
167             if (OpenCms.getModuleManager().hasModule(module.getName())) {
168                 param.put(CmsModulesUploadFromServer.PARAM_MODULENAME, module.getName());
169                 getToolManager().jspForwardPage(this, CmsModulesUploadFromServer.REPLACE_ACTION_REPORT, param);
170             } else {
171                 getToolManager().jspForwardPage(this, CmsModulesUploadFromServer.IMPORT_ACTION_REPORT, param);
172             }
173         } else {
174             // log it
175
Iterator JavaDoc it = errors.iterator();
176             CmsMessageContainer msg;
177             while (it.hasNext()) {
178                 // only one
179
msg = (CmsMessageContainer)it.next();
180                 if (LOG.isErrorEnabled()) {
181                     LOG.error(msg.key(getLocale()));
182                 }
183                 // then throw to avoid blank page telling nothing due to missing forward
184
throw new CmsIllegalStateException(msg);
185             }
186
187         }
188
189     }
190
191     /**
192      * @see org.opencms.workplace.administration.A_CmsImportFromHttp#getDialogReturnUri()
193      */

194     public String JavaDoc getDialogReturnUri() {
195
196         return DIALOG_URI;
197     }
198
199     /**
200      * @see org.opencms.workplace.administration.A_CmsImportFromHttp#getImportMessage()
201      */

202     public String JavaDoc getImportMessage() {
203
204         return key(Messages.GUI_MODULES_IMPORT_FILE_0);
205     }
206
207     /**
208      * @see org.opencms.workplace.administration.A_CmsImportFromHttp#getStarttext()
209      */

210     public String JavaDoc getStarttext() {
211
212         return key(Messages.GUI_MODULES_IMPORT_BLOCK_0);
213     }
214
215     /**
216      * @see org.opencms.workplace.CmsWorkplace#initMessages()
217      */

218     protected void initMessages() {
219
220         // add specific dialog resource bundle
221
addMessages(Messages.get().getBundleName());
222         // add default resource bundles
223
addMessages(org.opencms.workplace.Messages.get().getBundleName());
224         addMessages(org.opencms.workplace.tools.Messages.get().getBundleName());
225     }
226 }
Popular Tags