KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminModuleProperties.java,v $
3 * Date : $Date: 2005/05/31 15:51:19 $
4 * Version: $Revision: 1.3 $
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.main.CmsException;
33 import org.opencms.main.CmsLog;
34 import org.opencms.main.OpenCms;
35 import org.opencms.module.CmsModule;
36 import org.opencms.module.CmsModuleDependency;
37 import org.opencms.util.CmsDateUtil;
38
39 import com.opencms.core.I_CmsSession;
40 import com.opencms.legacy.CmsXmlTemplateLoader;
41 import com.opencms.template.CmsXmlTemplateFile;
42
43 import java.util.HashMap JavaDoc;
44 import java.util.Hashtable JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47 import java.util.Map JavaDoc;
48
49 /**
50  * Template class for displaying the properties of a module.
51  * Creation date: (07.09.00 11:30:26)
52  * @author Hanjo Riege
53  *
54  * @deprecated Will not be supported past the OpenCms 6 release.
55  */

56 public class CmsAdminModuleProperties extends CmsWorkplaceDefault {
57     
58     /**
59      * the different template views.
60      */

61     private final String JavaDoc C_DESCRIPTION = "description";
62     private final String JavaDoc C_VIEW = "view";
63     private final String JavaDoc C_MODULENAME = "module";
64     private final String JavaDoc C_PARAMETER = "parameter";
65     private final String JavaDoc C_CHANGE_PARAMETER = "changeparameter";
66     private final String JavaDoc C_NEW_VALUE = "newvalue";
67     private final String JavaDoc C_FROMERRORPAGE = "fromerrorpage";
68     
69     // sessionentry
70
private final String JavaDoc C_SESSION_MODULENAME = "modulename_error";
71     private final String JavaDoc C_SESSION_PARAMETER = "moduleparameter_error";
72     
73     /**
74      * Checks if the type of the value is correct and returns the converted value or null.
75      * @param type the type that the value should have..
76      * @param value the value to check.
77      */

78     private String JavaDoc checkType(String JavaDoc type, String JavaDoc value) {
79         type = type.toLowerCase();
80         try {
81             if("string".equals(type)) {
82                 if((value != null) && (value.indexOf("\"") < 0)) {
83                     return value;
84                 }
85                 else {
86                     return null;
87                 }
88             }
89             else {
90                 if("int".equals(type) || "integer".equals(type)) {
91                     value = "" + Integer.parseInt(value);
92                     return value;
93                 }
94                 else {
95                     if("float".equals(type)) {
96                         value = "" + Float.valueOf(value);
97                         return value;
98                     }
99                     else {
100                         if("boolean".equals(type)) {
101                             value = "" + Boolean.valueOf(value);
102                             return value;
103                         }
104                         else {
105                             if("long".equals(type)) {
106                                 value = "" + Long.valueOf(value);
107                                 return value;
108                             }
109                             else {
110                                 if("double".equals(type)) {
111                                     value = "" + Double.valueOf(value);
112                                     return value;
113                                 }
114                                 else {
115                                     if("byte".equals(type)) {
116                                         value = "" + Byte.valueOf(value);
117                                         return value;
118                                     }
119                                     else {
120                                         
121                                         // the type dosen't exist
122
return null;
123                                     }
124                                 }
125                             }
126                         }
127                     }
128                 }
129             }
130         }
131         catch(Exception JavaDoc exc) {
132             
133             // the type of the value was wrong
134
return null;
135         }
136     }
137     
138     /**
139      * Gets the content of a defined section in a given template file and its subtemplates
140      * with the given parameters.
141      *
142      * @see #getContent(CmsObject, String, String, Hashtable, String)
143      * @param cms CmsObject Object for accessing system resources.
144      * @param templateFile Filename of the template file.
145      * @param elementName Element name of this template in our parent template.
146      * @param parameters Hashtable with all template class parameters.
147      * @param templateSelector template section that should be processed.
148      */

149     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
150         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
151             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
152             CmsLog.getLog(this).debug("Template file is: " + templateFile);
153             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
154         }
155         CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
156         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
157         String JavaDoc view = (String JavaDoc)parameters.get(C_VIEW);
158         String JavaDoc module = (String JavaDoc)parameters.get(C_MODULENAME);
159         if((view != null) && (C_DESCRIPTION.equals(view))) {
160             
161             // set the values in the template "description"
162
xmlTemplateDocument.setData("name", module);
163             xmlTemplateDocument.setData("version", "" + OpenCms.getModuleManager().getModule(module).getVersion());
164             xmlTemplateDocument.setData("descriptiontext", OpenCms.getModuleManager().getModule(module).getDescription());
165             xmlTemplateDocument.setData("author", OpenCms.getModuleManager().getModule(module).getAuthorName());
166             xmlTemplateDocument.setData("email", OpenCms.getModuleManager().getModule(module).getAuthorEmail());
167             xmlTemplateDocument.setData("createdate", CmsDateUtil.getDateTimeShort(OpenCms.getModuleManager().getModule(module).getDateCreated()));
168             xmlTemplateDocument.setData("uploadfrom", OpenCms.getModuleManager().getModule(module).getUserInstalled());
169             xmlTemplateDocument.setData("uploaddate", CmsDateUtil.getDateTimeShort(OpenCms.getModuleManager().getModule(module).getDateInstalled()));
170             xmlTemplateDocument.setData("view", "");
171             xmlTemplateDocument.setData("documentation", "");
172             String JavaDoc dependences = "";
173             List JavaDoc moduleDependencies = OpenCms.getModuleManager().getModule(module).getDependencies();
174             for (int i=0; i<moduleDependencies.size(); i++) {
175                 CmsModuleDependency dep = (CmsModuleDependency)moduleDependencies.get(i);
176                 dependences += dep.getName() + " " + dep.getVersion() + " - " + "*" + "\n";
177             }
178             xmlTemplateDocument.setData("dependences", dependences);
179             String JavaDoc outputRep = "";
180             xmlTemplateDocument.setData("repository", outputRep);
181             
182             // set the correct templateselector
183
templateSelector = C_DESCRIPTION;
184         }
185         else {
186             if((view != null) && (C_PARAMETER.equals(view))) {
187                 
188                 // set the values in the template "parameter"
189
xmlTemplateDocument.setData("name", module);
190                 xmlTemplateDocument.setData("version", "" + OpenCms.getModuleManager().getModule(module).getVersion());
191                 Map JavaDoc moduleParameters = OpenCms.getModuleManager().getModule(module).getParameters();
192                 String JavaDoc allParameter = "";
193                 Iterator JavaDoc it = moduleParameters.keySet().iterator();
194                 while (it.hasNext()) {
195                     String JavaDoc key = (String JavaDoc)it.next();
196                     xmlTemplateDocument.setData("paraname", key);
197                     xmlTemplateDocument.setData("paravalue", (String JavaDoc)moduleParameters.get(key));
198                     allParameter += xmlTemplateDocument.getProcessedDataValue("parameterentry");
199                 }
200                 xmlTemplateDocument.setData("allparameter", allParameter);
201                 
202                 // set the correct templateselector
203
templateSelector = C_PARAMETER;
204             }
205             else {
206                 if((view != null) && (C_CHANGE_PARAMETER.equals(view))) {
207                     
208                     // set the values in the template "changeparameter"
209
String JavaDoc parameter = (String JavaDoc)parameters.get("selectpara");
210                     String JavaDoc fromError = (String JavaDoc)parameters.get(C_FROMERRORPAGE);
211                     if(fromError != null) {
212                         module = (String JavaDoc)session.getValue(C_SESSION_MODULENAME);
213                         parameter = (String JavaDoc)session.getValue(C_SESSION_PARAMETER);
214                         session.removeValue(C_SESSION_MODULENAME);
215                         session.removeValue(C_SESSION_PARAMETER);
216                     }
217                     Map JavaDoc moduleParameters = OpenCms.getModuleManager().getModule(module).getParameters();
218                     xmlTemplateDocument.setData("name", module);
219                     xmlTemplateDocument.setData("version", "" + OpenCms.getModuleManager().getModule(module).getVersion());
220                     xmlTemplateDocument.setData("paraname", parameter);
221                     xmlTemplateDocument.setData("paratext", "");
222                     xmlTemplateDocument.setData("paratype", "String");
223                     xmlTemplateDocument.setData("paravalue", (String JavaDoc)moduleParameters.get(parameter));
224                     
225                     // set the correct templateselector
226
templateSelector = C_CHANGE_PARAMETER;
227                 }
228                 else {
229                     if((view != null) && (C_NEW_VALUE.equals(view))) {
230                         
231                         // Now we can finaly change the value.
232
String JavaDoc parameter = (String JavaDoc)parameters.get("parameter");
233                         String JavaDoc value = (String JavaDoc)parameters.get("parawert");
234                         xmlTemplateDocument.setData("name", module);
235                         templateSelector = "done";
236                         if(value != null) {
237                             CmsModule oldModule = OpenCms.getModuleManager().getModule(module);
238                             Map JavaDoc moduleParameters = new HashMap JavaDoc(oldModule.getParameters());
239                             moduleParameters.put(parameter, value);
240                             
241                             CmsModule updatedModule =
242                                 new CmsModule(
243                                     oldModule.getName(),
244                                     oldModule.getNiceName(),
245                                     oldModule.getGroup(),
246                                     oldModule.getActionClass(),
247                                     oldModule.getDescription(),
248                                     oldModule.getVersion(),
249                                     oldModule.getAuthorName(),
250                                     oldModule.getAuthorEmail(),
251                                     oldModule.getDateCreated(),
252                                     oldModule.getUserInstalled(),
253                                     oldModule.getDateInstalled(),
254                                     oldModule.getDependencies(),
255                                     oldModule.getExportPoints(),
256                                     oldModule.getResources(),
257                                     moduleParameters);
258                             
259                             updatedModule.setResourceTypes(oldModule.getResourceTypes());
260                             updatedModule.setExplorerTypes(oldModule.getExplorerTypes());
261                             
262                             OpenCms.getModuleManager().updateModule(cms, updatedModule);
263                             
264                         }
265                         else {
266                             
267                             // wrong value
268
session.putValue(C_SESSION_MODULENAME, module);
269                             session.putValue(C_SESSION_PARAMETER, parameter);
270                             templateSelector = "error";
271                             xmlTemplateDocument.setData("paraname", parameter);
272                             xmlTemplateDocument.setData("DETAILS", "");
273                         }
274                     }
275                 }
276             }
277         }
278         
279         // Now load the template file and start the processing
280
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
281     }
282     
283     /**
284      * Indicates if the results of this class are cacheable.
285      *
286      * @param cms CmsObject Object for accessing system resources
287      * @param templateFile Filename of the template file
288      * @param elementName Element name of this template in our parent template.
289      * @param parameters Hashtable with all template class parameters.
290      * @param templateSelector template section that should be processed.
291      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
292      */

293     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
294         return false;
295     }
296 }
297
Popular Tags