KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsAdminModuleAdmin


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminModuleAdmin.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.4 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.workplace;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.file.types.CmsResourceTypeFolder;
33 import org.opencms.main.CmsException;
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.OpenCms;
36 import org.opencms.module.CmsModule;
37 import org.opencms.module.CmsModuleDependency;
38 import org.opencms.module.CmsModuleVersion;
39 import org.opencms.util.CmsDateUtil;
40
41 import com.opencms.core.I_CmsSession;
42 import com.opencms.legacy.CmsXmlTemplateLoader;
43 import com.opencms.template.CmsXmlTemplateFile;
44
45 import java.text.SimpleDateFormat JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.Date JavaDoc;
48 import java.util.HashMap JavaDoc;
49 import java.util.Hashtable JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Map JavaDoc;
53 import java.util.StringTokenizer JavaDoc;
54 import java.util.Vector JavaDoc;
55
56 /**
57  * Template class for displaying OpenCms workplace administration module administration.
58  *
59  * Creation date: (29.10.00 10:28:08)
60  * @author Hanjo Riege
61  * @author Thomas Weckert
62  *
63  * @deprecated Will not be supported past the OpenCms 6 release.
64  */

65 public class CmsAdminModuleAdmin extends CmsWorkplaceDefault {
66     private final String JavaDoc C_FROM = "from";
67     private final String JavaDoc C_VERSION = "version";
68     private final String JavaDoc C_GROUP = "group";
69     private final String JavaDoc C_MODULENAME = "modulename";
70     private final String JavaDoc C_DESCRIPTION = "description";
71     private final String JavaDoc C_MAINTENANCE = "maintenance";
72     private final String JavaDoc C_PUBLISHCLASS = "publishclass";
73     private final String JavaDoc C_AUTHOR = "author";
74     private final String JavaDoc C_EMAIL = "email";
75     private final String JavaDoc C_DATE = "date";
76     private final String JavaDoc C_DEPENDENCY = "dependencies";
77     private final String JavaDoc C_ALLDEPS = "alldeps";
78     private final String JavaDoc C_ONEDEP = "dependentry";
79     private final String JavaDoc C_OPTIONENTRY = "optionentry";
80     private final String JavaDoc C_NAME_PARAMETER = "module";
81
82     /**
83      * fills the data from the module in the hashtable.
84      * Creation date: (30.10.00 14:22:22)
85      * @param param java.lang.String
86      * @return java.util.Hashtable
87      */

88     private void fillHashtable(CmsObject cms, Hashtable JavaDoc table, String JavaDoc module) {
89         table.put(CmsWorkplaceDefault.C_MODULE_PACKETNAME, module);
90         table.put(C_VERSION, getStringValue(OpenCms.getModuleManager().getModule(module).getVersion().toString()));
91         table.put(C_GROUP, getStringValue(OpenCms.getModuleManager().getModule(module).getGroup()));
92         table.put(C_MODULENAME, getStringValue(OpenCms.getModuleManager().getModule(module).getNiceName()));
93         table.put(C_DESCRIPTION, getStringValue(OpenCms.getModuleManager().getModule(module).getDescription()));
94         table.put(C_MAINTENANCE, getStringValue(OpenCms.getModuleManager().getModule(module).getActionClass()));
95         table.put(C_PUBLISHCLASS, getStringValue(OpenCms.getModuleManager().getModule(module).getActionClass()));
96         table.put(C_AUTHOR, getStringValue(OpenCms.getModuleManager().getModule(module).getAuthorName()));
97         table.put(C_EMAIL, getStringValue(OpenCms.getModuleManager().getModule(module).getAuthorEmail()));
98         table.put(C_DATE, getStringValue(CmsDateUtil.getDateShort(OpenCms.getModuleManager().getModule(module).getDateCreated())));
99
100         // get the dependencies
101
Vector JavaDoc stringDeps = new Vector JavaDoc();
102         List JavaDoc moduleDependencies = OpenCms.getModuleManager().getModule(module).getDependencies();
103         for (int i=0; i<moduleDependencies.size(); i++) {
104             CmsModuleDependency dep = (CmsModuleDependency)moduleDependencies.get(i);
105             stringDeps.addElement(dep.getName() + " Version:" + dep.getVersion() + " - *");
106         }
107         table.put(C_DEPENDENCY, stringDeps);
108
109         // handle the properties
110
Vector JavaDoc paraNames = new Vector JavaDoc();
111         Vector JavaDoc paraDescr = new Vector JavaDoc();
112         Vector JavaDoc paraTyp = new Vector JavaDoc();
113         Vector JavaDoc paraVal = new Vector JavaDoc();
114         Map JavaDoc params = OpenCms.getModuleManager().getModule(module).getParameters();
115         Iterator JavaDoc it = params.keySet().iterator();
116         while(it.hasNext()) {
117             String JavaDoc key = (String JavaDoc)it.next();
118             String JavaDoc value = (String JavaDoc)params.get(key);
119             paraNames.addElement(key);
120             paraDescr.addElement("");
121             paraVal.addElement(getStringValue(value));
122             paraTyp.addElement("");
123         }
124         table.put(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_NAMES, paraNames);
125         table.put(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_DESCR, paraDescr);
126         table.put(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_TYP, paraTyp);
127         table.put(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_VAL, paraVal);
128     }
129
130     /**
131      * Gets the content of a defined section in a given template file and its subtemplates
132      * with the given parameters.
133      *
134      * @see #getContent(CmsObject, String, String, Hashtable, String)
135      * @param cms CmsObject Object for accessing system resources.
136      * @param templateFile Filename of the template file.
137      * @param elementName Element name of this template in our parent template.
138      * @param parameters Hashtable with all template class parameters.
139      * @param templateSelector template section that should be processed.
140      */

141     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
142         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
143             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
144             CmsLog.getLog(this).debug("Template file is: " + templateFile);
145             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
146         }
147         CmsXmlTemplateFile templateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
148         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
149         String JavaDoc stepTo = "";
150         String JavaDoc from = (String JavaDoc)parameters.get(C_FROM);
151         String JavaDoc packetName = (String JavaDoc)parameters.get(C_NAME_PARAMETER);
152         Hashtable JavaDoc sessionData = new Hashtable JavaDoc();
153         if((from == null) || "".equals(from)) {
154
155             // first call; clear session
156
session.removeValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA);
157             fillHashtable(cms, sessionData, packetName);
158             session.putValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA, sessionData);
159             stepTo = "firstpage";
160         }else {
161             sessionData = (Hashtable JavaDoc)session.getValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA);
162             if("first".equals(from)) {
163
164                 // put the data in the session
165
sessionData.put(C_VERSION, getStringValue((String JavaDoc)parameters.get(C_VERSION)));
166                 sessionData.put(C_MODULENAME, getStringValue((String JavaDoc)parameters.get(C_MODULENAME)));
167                 sessionData.put(C_DESCRIPTION, getStringValue((String JavaDoc)parameters.get(C_DESCRIPTION)));
168                 sessionData.put(C_MAINTENANCE, getStringValue((String JavaDoc)parameters.get(C_MAINTENANCE)));
169                 sessionData.put(C_PUBLISHCLASS, getStringValue((String JavaDoc)parameters.get(C_PUBLISHCLASS)));
170                 sessionData.put(C_AUTHOR, getStringValue((String JavaDoc)parameters.get(C_AUTHOR)));
171                 sessionData.put(C_EMAIL, getStringValue((String JavaDoc)parameters.get(C_EMAIL)));
172                 sessionData.put(C_DATE, getStringValue((String JavaDoc)parameters.get(C_DATE)));
173     
174                 session.putValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA, sessionData);
175                 stepTo = "deps";
176             }
177             if("deps".equals(from)) {
178
179                 // put the data in the session
180
String JavaDoc allData = (String JavaDoc)parameters.get(C_ALLDEPS);
181                 Vector JavaDoc allDeps = new Vector JavaDoc();
182                 allDeps = parseAllDeps(getStringValue(allData));
183                 sessionData.put(C_DEPENDENCY, allDeps);
184                 session.putValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA, sessionData);
185
186                 // decide if we are going back or forward => set stepTo
187
String JavaDoc back = (String JavaDoc)parameters.get("back");
188                 if((back == null) || ("".equals(back))) {
189                     stepTo = "props";
190                 }
191                 else {
192                     stepTo = "firstpage";
193                 }
194             }
195             if("props".equals(from)) {
196                 stepTo = "deps";
197             }
198             if("edit".equals(from)) {
199                 stepTo = "props";
200             }
201             if("propsready".equals(from)) {
202
203                 // ready; save changes in registry
204
updateTheModule(cms, sessionData, packetName);
205                 session.removeValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA);
206                 templateSelector = "done";
207             }
208         }
209         if("firstpage".equals(stepTo)) {
210
211             // show the first page
212
templateDocument.setData(CmsWorkplaceDefault.C_MODULE_PACKETNAME, (String JavaDoc)sessionData.get(CmsWorkplaceDefault.C_MODULE_PACKETNAME));
213             templateDocument.setData(C_VERSION, (String JavaDoc)sessionData.get(C_VERSION));
214             templateDocument.setData(C_MODULENAME, (String JavaDoc)sessionData.get(C_MODULENAME));
215             templateDocument.setData(C_DESCRIPTION, (String JavaDoc)sessionData.get(C_DESCRIPTION));
216             templateDocument.setData(C_MAINTENANCE, (String JavaDoc)sessionData.get(C_MAINTENANCE));
217             templateDocument.setData(C_PUBLISHCLASS, (String JavaDoc)sessionData.get(C_PUBLISHCLASS));
218             templateDocument.setData(C_AUTHOR, (String JavaDoc)sessionData.get(C_AUTHOR));
219             templateDocument.setData(C_EMAIL, (String JavaDoc)sessionData.get(C_EMAIL));
220             templateDocument.setData(C_DATE, (String JavaDoc)sessionData.get(C_DATE));
221             
222             templateDocument.setData("moduletype", "checked");
223             templateSelector = "";
224         }
225         if("deps".equals(stepTo)) {
226
227             // show the dependencies
228
templateDocument.setData(CmsWorkplaceDefault.C_MODULE_PACKETNAME, (String JavaDoc)sessionData.get(CmsWorkplaceDefault.C_MODULE_PACKETNAME));
229             Vector JavaDoc deps = (Vector JavaDoc)sessionData.get(C_DEPENDENCY);
230             String JavaDoc entrys = "";
231             for(int i = 0;i < deps.size();i++) {
232                 templateDocument.setData(C_ONEDEP, (String JavaDoc)deps.elementAt(i));
233                 entrys += templateDocument.getProcessedDataValue(C_OPTIONENTRY);
234             }
235             templateDocument.setData(C_ALLDEPS, entrys);
236             templateSelector = "dependencies";
237         }
238         if("props".equals(stepTo)) {
239
240             // prepare the properties page
241
templateSelector = "properties";
242         }
243
244         // Now load the template file and start the processing
245
return startProcessing(cms, templateDocument, elementName, parameters, templateSelector);
246     }
247
248     /**
249      * returns the String or "" if it is null.
250      * Creation date: (29.10.00 16:05:38)
251      * @return java.lang.String
252      * @param param java.lang.String
253      */

254     private String JavaDoc getStringValue(String JavaDoc param) {
255         if(param == null) {
256             return "";
257         }
258         return param;
259     }
260
261     /**
262      * Indicates if the results of this class are cacheable.
263      *
264      * @param cms CmsObject Object for accessing system resources
265      * @param templateFile Filename of the template file
266      * @param elementName Element name of this template in our parent template.
267      * @param parameters Hashtable with all template class parameters.
268      * @param templateSelector template section that should be processed.
269      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
270      */

271     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
272         return false;
273     }
274
275     /** Parse the string which holds all dependencies
276      *
277      * @param resources containts the full pathnames of all the resources, separated by semicolons
278      * @return A vector with the same resources
279      */

280     private Vector JavaDoc parseAllDeps(String JavaDoc resources) {
281         Vector JavaDoc ret = new Vector JavaDoc();
282         if(resources != null) {
283             StringTokenizer JavaDoc resTokenizer = new StringTokenizer JavaDoc(resources, ";");
284             while(resTokenizer.hasMoreElements()) {
285                 String JavaDoc path = (String JavaDoc)resTokenizer.nextElement();
286                 ret.addElement(path);
287             }
288         }
289         return ret;
290     }
291
292     /**
293      * Insert the method's description here.
294      * Creation date: (03.11.00 08:23:13)
295      * @param param org.opencms.file.CmsObject
296      * @param folder java.lang.String
297      * @param newFolder java.lang.String
298      */

299     private void tryToCreateFolder(CmsObject cms, String JavaDoc folder, String JavaDoc newFolder) {
300         try {
301             cms.createResource(folder + newFolder, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
302         }catch(Exception JavaDoc e) {
303         }
304     }
305
306     /**
307      * fills the data from the hashtable in the module.
308      * Creation date: (30.10.00 14:22:22)
309      * @param param java.lang.String
310      * @return java.util.Hashtable
311      */

312     private void updateTheModule(CmsObject cms, Hashtable JavaDoc table, String JavaDoc module) {
313         SimpleDateFormat JavaDoc dateFormat = new java.text.SimpleDateFormat JavaDoc("dd.MM.yyyy");
314         String JavaDoc name = (String JavaDoc)table.get(CmsWorkplaceDefault.C_MODULE_PACKETNAME);
315
316         try {
317         
318             // set the module version
319
CmsModuleVersion version = new CmsModuleVersion((String JavaDoc)table.get(C_VERSION));
320         
321             // the easy values
322
String JavaDoc niceName = (String JavaDoc)table.get(C_MODULENAME);
323             String JavaDoc group = (String JavaDoc)table.get(C_GROUP);
324             String JavaDoc description = (String JavaDoc)table.get(C_DESCRIPTION);
325             String JavaDoc moduleClass = (String JavaDoc)table.get(C_PUBLISHCLASS);
326             String JavaDoc moduleAuthor = (String JavaDoc)table.get(C_AUTHOR);
327             String JavaDoc moduleEmail = (String JavaDoc)table.get(C_EMAIL);
328
329             // set the date, if the value is not correct set the current date
330
String JavaDoc date = (String JavaDoc)table.get(C_DATE);
331             long moduleDateCreated = 0;
332             try {
333                 moduleDateCreated = dateFormat.parse(date).getTime();
334             }catch(Exception JavaDoc exc) {
335                 moduleDateCreated = (new Date JavaDoc()).getTime();
336             }
337
338             // now the dependnecies
339
Vector JavaDoc stringDeps = (Vector JavaDoc)table.get(C_DEPENDENCY);
340             List JavaDoc dependencies = new ArrayList JavaDoc();
341             
342             for(int i = 0;i < stringDeps.size();i++) {
343                 String JavaDoc complString = (String JavaDoc)stringDeps.elementAt(i);
344                 complString = complString.substring(0, complString.lastIndexOf("-") - 1);
345                 String JavaDoc min = complString.substring(complString.lastIndexOf(":") + 1);
346                 String JavaDoc depName = (complString.substring(0, complString.lastIndexOf("Version:") - 1)).trim();
347                 
348                 dependencies.add(new CmsModuleDependency(depName, new CmsModuleVersion(String.valueOf(min))));
349             }
350
351             // last not least: the properties
352
Vector JavaDoc paraNames = (Vector JavaDoc)table.get(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_NAMES);
353             Vector JavaDoc paraVal = (Vector JavaDoc)table.get(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_VAL);
354             
355             Map JavaDoc parameters = new HashMap JavaDoc();
356             for (int i=0; i<paraNames.size(); i++) {
357                 String JavaDoc key = (String JavaDoc)paraNames.get(i);
358                 parameters.put(key, paraVal.get(i));
359             }
360             
361             CmsModule currentModule = OpenCms.getModuleManager().getModule(name);
362
363             CmsModule updatedModule =
364                 new CmsModule(
365                     name,
366                     niceName,
367                     group,
368                     moduleClass,
369                     description,
370                     version,
371                     moduleAuthor,
372                     moduleEmail,
373                     moduleDateCreated,
374                     currentModule.getUserInstalled(),
375                     currentModule.getDateInstalled(),
376                     dependencies,
377                     currentModule.getExportPoints(),
378                     currentModule.getResources(),
379                     parameters);
380             
381                 updatedModule.setResourceTypes(currentModule.getResourceTypes());
382                 updatedModule.setExplorerTypes(currentModule.getExplorerTypes());
383             
384             OpenCms.getModuleManager().updateModule(cms, updatedModule);
385
386         } catch (CmsException e) {
387              if(CmsLog.getLog(this).isErrorEnabled()) {
388                  CmsLog.getLog(this).error("Error in module administration", e);
389              }
390         }
391     }
392 }
393
Popular Tags