KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminModuleAdminEdit.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
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
30 package com.opencms.workplace;
31
32 import org.opencms.file.CmsObject;
33 import org.opencms.main.CmsException;
34 import org.opencms.main.CmsLog;
35
36 import com.opencms.core.I_CmsSession;
37 import com.opencms.legacy.CmsXmlTemplateLoader;
38 import com.opencms.template.CmsXmlTemplateFile;
39
40 import java.util.Hashtable JavaDoc;
41 import java.util.Vector JavaDoc;
42
43 /**
44  * Template class for displaying the conflicting Files for a new Module.
45  * Creation date: (06.09.00 09:30:25)
46  * @author Hanjo Riege
47  *
48  * @deprecated Will not be supported past the OpenCms 6 release.
49  */

50 public class CmsAdminModuleAdminEdit extends CmsWorkplaceDefault {
51
52     /**
53      * Checks if the name is correct.
54      * @param name the name to check..
55      */

56     private boolean checkName(String JavaDoc name) {
57         if(name == null || name.length() == 0 || name.trim().length() == 0) {
58             return false;
59         }
60         for(int i = 0;i < name.length();i++) {
61             char c = name.charAt(i);
62             if(((c < 'a') || (c > 'z')) && ((c < '0') || (c > '9')) && ((c < 'A') || (c > 'Z')) && (c != '-') && (c != '.') && (c != '_') && (c != '~')) {
63                 return false;
64             }
65         }
66         return true;
67     }
68
69     /**
70      * Checks if the type of the value is correct and returns the converted value or null.
71      * @param type the type that the value should have..
72      * @param value the value to check.
73      */

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

145     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
146         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
147             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
148             CmsLog.getLog(this).debug("Template file is: " + templateFile);
149             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
150         }
151         CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
152         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
153         Hashtable JavaDoc sessionData = (Hashtable JavaDoc)session.getValue(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_DATA);
154         String JavaDoc module = (String JavaDoc)sessionData.get(CmsWorkplaceDefault.C_MODULE_PACKETNAME);
155         xmlTemplateDocument.setData("packetname", module);
156         Vector JavaDoc paraNames = (Vector JavaDoc)sessionData.get(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_NAMES);
157         Vector JavaDoc paraDescr = (Vector JavaDoc)sessionData.get(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_DESCR);
158         Vector JavaDoc paraTyp = (Vector JavaDoc)sessionData.get(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_TYP);
159         Vector JavaDoc paraVal = (Vector JavaDoc)sessionData.get(CmsWorkplaceDefault.C_SESSION_MODULE_ADMIN_PROP_VAL);
160         String JavaDoc prop = (String JavaDoc)parameters.get("prop");
161         String JavaDoc delete = (String JavaDoc)parameters.get("delete");
162         String JavaDoc ok = (String JavaDoc)parameters.get("ok");
163         String JavaDoc step = (String JavaDoc)parameters.get("step");
164         if((prop == null) || ("".equals(prop))) {
165
166             // new property
167
if((ok != null) && (!"".equals(ok))) {
168
169                 // read new prop
170
String JavaDoc name = getStringValue((String JavaDoc)parameters.get("NAME"));
171                 String JavaDoc description = getStringValue((String JavaDoc)parameters.get("BESCHREIBUNG"));
172                 String JavaDoc type = "string";
173                 String JavaDoc value = (String JavaDoc)parameters.get("WERT");
174
175                 // check if all fields are filled out and if the value is correct
176
String JavaDoc newValue = checkType(type, value);
177                 if((checkName(name)) && (newValue != null)) {
178                     paraNames.addElement(name);
179                     paraDescr.addElement(description);
180                     paraTyp.addElement(type);
181                     paraVal.addElement(newValue);
182                     templateSelector = "done";
183                 }
184                 else {
185                     session.putValue("parametername", name);
186                     session.putValue("description", description);
187                     session.putValue("parametertype", type);
188                     session.putValue("parametervalue", value);
189                     templateSelector = "errornew";
190                 }
191             }
192             else {
193                 if((step == null) || ("".equals(step))) {
194                     xmlTemplateDocument.setData("paraname", "");
195                     xmlTemplateDocument.setData("paranameok", "");
196                     xmlTemplateDocument.setData("value", "");
197                     xmlTemplateDocument.setData("description", "");
198                     xmlTemplateDocument.setData("delybutton", " ");
199                 }
200                 else {
201
202                     // from Errorpage
203
xmlTemplateDocument.setData("paraname", "");
204                     xmlTemplateDocument.setData("paranameok", (String JavaDoc)session.getValue("parametername"));
205                     xmlTemplateDocument.setData("value", (String JavaDoc)session.getValue("parametervalue"));
206                     xmlTemplateDocument.setData((String JavaDoc)session.getValue("parametertype"), "selected");
207                     xmlTemplateDocument.setData("description", (String JavaDoc)session.getValue("description"));
208                     xmlTemplateDocument.setData("delybutton", " ");
209                     session.removeValue("packagename");
210                     session.removeValue("parametervalue");
211                     session.removeValue("parametertype");
212                     session.removeValue("description");
213                 }
214             }
215         }else {
216             if((ok != null) && (!"".equals(ok))) {
217
218                 // set property
219
String JavaDoc type = "string";
220                 String JavaDoc value = getStringValue((String JavaDoc)parameters.get("WERT"));
221                 String JavaDoc newValue = checkType(type, value);
222                 if(newValue != null) {
223                     int i = paraNames.indexOf(prop);
224                     paraNames.removeElementAt(i);
225                     paraDescr.removeElementAt(i);
226                     paraTyp.removeElementAt(i);
227                     paraVal.removeElementAt(i);
228                     paraNames.addElement(prop);
229                     paraDescr.addElement(getStringValue((String JavaDoc)parameters.get("BESCHREIBUNG")));
230                     paraTyp.addElement(type);
231                     paraVal.addElement(newValue);
232                     templateSelector = "done";
233                 }else {
234                     session.putValue("parametername", prop);
235                     session.putValue("description", getStringValue((String JavaDoc)parameters.get("BESCHREIBUNG")));
236                     session.putValue("parametertype", type);
237                     session.putValue("parametervalue", value);
238                     templateSelector = "errorold";
239                 }
240             }else {
241                 if((delete != null) && (!"".equals(delete))) {
242
243                     // delete property
244
int i = paraNames.indexOf(prop);
245                     paraNames.removeElementAt(i);
246                     paraDescr.removeElementAt(i);
247                     paraTyp.removeElementAt(i);
248                     paraVal.removeElementAt(i);
249                     templateSelector = "done";
250                 }else {
251
252                     // prepare for change property
253
if((step == null) || ("".equals(step))) {
254                         int i = paraNames.indexOf(prop);
255                         xmlTemplateDocument.setData("paraname", prop);
256                         xmlTemplateDocument.setData("nameentry", prop);
257                         xmlTemplateDocument.setData("value", (String JavaDoc)paraVal.elementAt(i));
258                         xmlTemplateDocument.setData("description", (String JavaDoc)paraDescr.elementAt(i));
259                         xmlTemplateDocument.setData("string", "selected");
260                         xmlTemplateDocument.setData("delybutton", xmlTemplateDocument.getProcessedDataValue("deletebutton"));
261                     }else {
262
263                         // from errorpage errorold
264
prop = (String JavaDoc)session.getValue("parametername");
265                         xmlTemplateDocument.setData("paraname", prop);
266                         xmlTemplateDocument.setData("nameentry", prop);
267                         xmlTemplateDocument.setData("value", (String JavaDoc)session.getValue("parametervalue"));
268                         xmlTemplateDocument.setData("description", (String JavaDoc)session.getValue("description"));
269                         xmlTemplateDocument.setData((String JavaDoc)session.getValue("parametertype"), "selected");
270                         xmlTemplateDocument.setData("delybutton", xmlTemplateDocument.getProcessedDataValue("deletebutton"));
271                         session.removeValue("packagename");
272                         session.removeValue("parametervalue");
273                         session.removeValue("parametertype");
274                         session.removeValue("description");
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      * returns the String or "" if it is null.
285      * Creation date: (29.10.00 16:05:38)
286      * @return java.lang.String
287      * @param param java.lang.String
288      */

289     private String JavaDoc getStringValue(String JavaDoc param) {
290         if(param == null) {
291             return "";
292         }
293         return param;
294     }
295
296     /**
297      * Indicates if the results of this class are cacheable.
298      *
299      * @param cms CmsObject Object for accessing system resources
300      * @param templateFile Filename of the template file
301      * @param elementName Element name of this template in our parent template.
302      * @param parameters Hashtable with all template class parameters.
303      * @param templateSelector template section that should be processed.
304      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
305      */

306     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
307         return false;
308     }
309 }
310
Popular Tags