KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > defaults > A_CmsBackoffice


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/A_CmsBackoffice.java,v $
3 * Date : $Date: 2005/06/27 23:22:23 $
4 * Version: $Revision: 1.9 $
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.defaults;
30
31 import org.opencms.db.CmsUserSettings;
32 import org.opencms.file.CmsGroup;
33 import org.opencms.file.CmsObject;
34 import org.opencms.file.CmsProject;
35 import org.opencms.file.CmsResource;
36 import org.opencms.file.CmsUser;
37 import org.opencms.i18n.CmsEncoder;
38 import org.opencms.main.CmsException;
39 import org.opencms.main.CmsLog;
40 import org.opencms.util.CmsDateUtil;
41 import org.opencms.util.CmsUUID;
42
43 import com.opencms.core.I_CmsSession;
44 import com.opencms.defaults.master.CmsPlausibilizationException;
45 import com.opencms.legacy.CmsLegacyException;
46 import com.opencms.legacy.CmsXmlTemplateLoader;
47 import com.opencms.template.A_CmsXmlContent;
48 import com.opencms.template.CmsXmlTemplateFile;
49 import com.opencms.workplace.CmsWorkplaceDefault;
50 import com.opencms.workplace.CmsXmlLanguageFile;
51 import com.opencms.workplace.CmsXmlWpTemplateFile;
52
53 import java.lang.reflect.Constructor JavaDoc;
54 import java.lang.reflect.InvocationTargetException JavaDoc;
55 import java.lang.reflect.Method JavaDoc;
56 import java.util.Enumeration JavaDoc;
57 import java.util.Hashtable JavaDoc;
58 import java.util.List JavaDoc;
59 import java.util.Vector JavaDoc;
60
61 /**
62  * Abstract class for generic backoffice display. It automatically
63  * generates the <ul><li>head section with filters and buttons,</li>
64  * <li>body section with the table data,</li>
65  * <li>lock states of the entries. if there are any,</li>
66  * <li>delete dialog,</li>
67  * <li>lock dialog.</li></ul>
68  * calls the <ul><li>edit dialog of the calling backoffice class</li>
69  * <li>new dialog of the calling backoffice class</li></ul>
70  * using the content definition class defined by the getContentDefinition method.
71  * The methods and data provided by the content definition class
72  * is accessed by reflection. This way it is possible to re-use
73  * this class for any content definition class, that just has
74  * to extend the A_CmsContentDefinition class!
75  * Creation date: (27.10.00 10:04:42)
76  *
77  * @author Michael Knoll
78  * @author Michael Emmerich
79  * @version $Revision: 1.9 $
80  *
81  * @deprecated Will not be supported past the OpenCms 6 release.
82  */

83 public abstract class A_CmsBackoffice extends CmsWorkplaceDefault {
84
85     /** Value for state: not locked. */
86     public static int C_NOT_LOCKED = -1;
87     
88     /** Value for no access. */
89     public static int C_NO_ACCESS = -2;
90
91     private static String JavaDoc C_DEFAULT_SELECTOR = "(default)";
92     private static String JavaDoc C_DONE_SELECTOR = "done";
93
94     /** The style for unchanged files or folders. */
95     private static final String JavaDoc C_STYLE_UNCHANGED = "dateingeandert";
96
97     /** The style for files or folders not in project. */
98     private static final String JavaDoc C_STYLE_NOTINPROJECT = "dateintprojekt";
99
100     /** The style for new files or folders. */
101     private static final String JavaDoc C_STYLE_NEW = "dateineu";
102
103     /** The style for deleted files or folders. */
104     private static final String JavaDoc C_STYLE_DELETED = "dateigeloescht";
105
106     /** The style for changed files or folders. */
107     private static final String JavaDoc C_STYLE_CHANGED = "dateigeaendert";
108
109     /** Default value of permission.*/
110     protected static final int C_DEFAULT_PERMISSIONS = 383;
111
112     /** Possible accessflags. */
113     protected static final String JavaDoc[] C_ACCESS_FLAGS = {"1", "2", "4", "8", "16", "32", "64", "128", "256"};
114
115     /**
116     * Gets the backoffice url of the module.
117     *
118     * @param cms the cms object
119     * @param tagcontent the tag body content
120     * @param doc the xml document
121     * @param userObject additional parameter values
122     * @return A string with the backoffice url
123     * @throws Exception if something goes wrong
124     */

125     public abstract String JavaDoc getBackofficeUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc;
126     /**
127     * Gets the create url of the module.
128     *
129     * @param cms the cms object
130     * @param tagcontent the tag body content
131     * @param doc the xml document
132     * @param userObject additional parameter values
133     * @return a string with the create url
134     * @throws Exception if something goes wrong
135     */

136     public abstract String JavaDoc getCreateUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc;
137
138     /**
139     * Gets the edit url of the module.
140     *
141     * @param cms the cms object
142     * @param tagcontent the tag body content
143     * @param doc the xml document
144     * @param userObject additional parameter values
145     * @return A string with the edit url
146     * @throws Exception if something goes wrong
147     */

148     public abstract String JavaDoc getEditUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc;
149
150     /**
151     * Gets the edit url of the module.
152     *
153     * @param cms the cms object
154     * @param tagcontent the tag body content
155     * @param doc the xml document
156     * @param userObject additional parameter values
157     * @return A string with the edit url
158     * @throws Exception if something goes wrong
159     */

160     public String JavaDoc getDeleteUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
161
162         return getBackofficeUrl(cms, tagcontent, doc, userObject);
163     }
164
165     /**
166     * Gets the undelete url of the module.
167     *
168     * @param cms the cms object
169     * @param tagcontent the tag body content
170     * @param doc the xml document
171     * @param userObject additional parameter values
172     * @return A string with the undelete url
173     * @throws Exception if something goes wrong
174     */

175     public String JavaDoc getUndeleteUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
176
177         return getBackofficeUrl(cms, tagcontent, doc, userObject);
178     }
179
180     /**
181     * Gets the publish url of the module.
182     *
183     * @param cms the cms object
184     * @param tagcontent the tag body content
185     * @param doc the xml document
186     * @param userObject additional parameter values
187     * @return A string with the publish url
188     * @throws Exception if something goes wrong
189     */

190     public String JavaDoc getPublishUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
191
192         return getBackofficeUrl(cms, tagcontent, doc, userObject);
193     }
194
195     /**
196     * Gets the history url of the module.
197     *
198     * @param cms the cms object
199     * @param tagcontent the tag body content
200     * @param doc the xml document
201     * @param userObject additional parameter values
202     * @return A string with the history url
203     * @throws Exception if something goes wrong
204     */

205     public String JavaDoc getHistoryUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
206
207         return getBackofficeUrl(cms, tagcontent, doc, userObject);
208     }
209
210     /**
211     * Gets the redirect url of the module. This URL is called, when an entry of the file list is selected.
212     *
213     * @param cms the cms object
214     * @param tagcontent the tag body content
215     * @param doc the xml document
216     * @param userObject additional parameter values
217     * @return a string with the url
218     * @throws Exception if something goes wrong
219     */

220     public String JavaDoc getUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
221         return "";
222     }
223
224     /**
225     * Gets the setup url of the module. This is the url of the setup page for this module.
226     *
227     * @param cms the cms object
228     * @param tagcontent the tag body content
229     * @param doc the xml document
230     * @param userObject additional parameter values
231     * @return a string with the setup url
232     * @throws Exception if something goes wrong
233     */

234     public String JavaDoc getSetupUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
235         return "";
236     }
237
238     /**
239     * Gets the preview url of the module. This is the url of the preview page for this module.
240     *
241     * @param cms the cms object
242     * @param tagcontent the tag body content
243     * @param doc the xml document
244     * @param userObject additional parameter values
245     * @return a string with the setup url
246     * @throws Exception if something goes wrong
247     */

248     public String JavaDoc getPreviewUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
249         return "";
250     }
251
252     /**
253      * Gets the content of a given template file.
254      * This method displays any content provided by a content definition
255      * class on the template. The used backoffice class does not need to use a
256      * special getContent method. It just has to extend the methods of this class!
257      * Using reflection, this method creates the table headline and table content
258      * with the layout provided by the template automatically!
259      *
260      * @param cms A_CmsObject Object for accessing system resources
261      * @param templateFile Filename of the template file
262      * @param elementName <em>not used here</em>.
263      * @param parameters <em>not used here</em>.
264      * @param templateSelector template section that should be processed.
265      * @return Processed content of the given template file.
266      * @throws CmsException if something goes wrong
267      */

268
269     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
270
271         //return var
272
byte[] returnProcess = null;
273
274         // the CD to be used
275
A_CmsContentDefinition cd = null;
276
277         // session will be created or fetched
278
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
279         session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
280         //create new workplace templatefile object
281
CmsXmlWpTemplateFile template = new CmsXmlWpTemplateFile(cms, templateFile);
282         //get parameters
283
String JavaDoc selectBox = (String JavaDoc)parameters.get("selectbox");
284         String JavaDoc filterParam = (String JavaDoc)parameters.get("filterparameter");
285         String JavaDoc id = (String JavaDoc)parameters.get("id");
286         String JavaDoc idlock = (String JavaDoc)parameters.get("idlock");
287         String JavaDoc iddelete = (String JavaDoc)parameters.get("iddelete");
288         String JavaDoc idedit = (String JavaDoc)parameters.get("idedit");
289         String JavaDoc action = (String JavaDoc)parameters.get("action");
290         String JavaDoc parentId = (String JavaDoc)parameters.get("parentId");
291         String JavaDoc ok = (String JavaDoc)parameters.get("ok");
292         String JavaDoc setaction = (String JavaDoc)parameters.get("setaction");
293         String JavaDoc idundelete = (String JavaDoc)parameters.get("idundelete");
294         String JavaDoc idpublish = (String JavaDoc)parameters.get("idpublish");
295         String JavaDoc idhistory = (String JavaDoc)parameters.get("idhistory");
296         String JavaDoc idpermissions = (String JavaDoc)parameters.get("idpermissions");
297         String JavaDoc idcopy = (String JavaDoc)parameters.get("idcopy");
298         // debug-code
299
/*
300                 System.err.println("### "+this.getContentDefinitionClass().getName());
301                 System.err.println("### PARAMETERS");
302                 Enumeration enu=parameters.keys();
303                 while (enu.hasMoreElements()) {
304                   String a=(String)enu.nextElement();
305                   String b=parameters.get(a).toString();
306                   System.err.println("## "+a+" -> "+b);
307                 }
308         
309                 System.err.println("");
310                 System.err.println("+++ SESSION");
311                 String[] ses=session.getValueNames();
312                 for (int i=0;i<ses.length;i++) {
313                   String a=ses[i];
314                   String b=session.getValue(a).toString();
315                   System.err.println("++ "+a+" -> "+b);
316                 }
317                 System.err.println("");
318                 System.err.println("-------------------------------------------------");
319         */

320
321         String JavaDoc hasFilterParam = (String JavaDoc)session.getValue("filterparameter");
322         template.setData("filternumber", "0");
323
324         //change filter
325
if ((hasFilterParam == null) && (filterParam == null) && (setaction == null)) {
326             if (selectBox != null) {
327                 session.putValue("filter", selectBox);
328                 template.setData("filternumber", selectBox);
329             }
330         } else {
331             template.setData("filternumber", (String JavaDoc)session.getValue("filter"));
332         }
333
334         //move id values to id, remove old markers
335
if (idlock != null) {
336             id = idlock;
337             session.putValue("idlock", idlock);
338             session.removeValue("idedit");
339             session.removeValue("idnew");
340             session.removeValue("iddelete");
341             session.removeValue("idundelete");
342             session.removeValue("idpublish");
343             session.removeValue("idhistory");
344             session.removeValue("idpermissions");
345             session.removeValue("idcopy");
346         }
347         if (idedit != null) {
348             id = idedit;
349             session.putValue("idedit", idedit);
350             session.removeValue("idlock");
351             session.removeValue("idnew");
352             session.removeValue("iddelete");
353             session.removeValue("idundelete");
354             session.removeValue("idpublish");
355             session.removeValue("idhistory");
356             session.removeValue("idpermissions");
357             session.removeValue("idcopy");
358         }
359         if (iddelete != null) {
360             id = iddelete;
361             session.putValue("iddelete", iddelete);
362             session.removeValue("idedit");
363             session.removeValue("idnew");
364             session.removeValue("idlock");
365             session.removeValue("idundelete");
366             session.removeValue("idpublish");
367             session.removeValue("idhistory");
368             session.removeValue("idpermissions");
369             session.removeValue("idcopy");
370         }
371         if (idundelete != null) {
372             id = idundelete;
373             session.putValue("idundelete", idundelete);
374             session.removeValue("idedit");
375             session.removeValue("idnew");
376             session.removeValue("idlock");
377             session.removeValue("iddelete");
378             session.removeValue("idpublish");
379             session.removeValue("idhistory");
380             session.removeValue("idpermissions");
381             session.removeValue("idcopy");
382         }
383         if (idpublish != null) {
384             id = idpublish;
385             session.putValue("idpublish", idpublish);
386             session.removeValue("idedit");
387             session.removeValue("idnew");
388             session.removeValue("idlock");
389             session.removeValue("iddelete");
390             session.removeValue("idundelete");
391             session.removeValue("idhistory");
392             session.removeValue("idpermissions");
393             session.removeValue("idcopy");
394         }
395
396         if (idhistory != null) {
397             id = idhistory;
398             session.putValue("idhistory", idhistory);
399             session.removeValue("idedit");
400             session.removeValue("idnew");
401             session.removeValue("idlock");
402             session.removeValue("iddelete");
403             session.removeValue("idundelete");
404             session.removeValue("idpublish");
405             session.removeValue("idpermissions");
406             session.removeValue("idcopy");
407         }
408
409         if (idpermissions != null) {
410             id = idpermissions;
411             session.putValue("idpermissions", idpermissions);
412             session.removeValue("idedit");
413             session.removeValue("idnew");
414             session.removeValue("idlock");
415             session.removeValue("iddelete");
416             session.removeValue("idundelete");
417             session.removeValue("idpublish");
418             session.removeValue("idhistory");
419             session.removeValue("idcopy");
420         }
421
422         if (idcopy != null) {
423             id = idcopy;
424             session.putValue("idcopy", idcopy);
425             session.removeValue("idedit");
426             session.removeValue("idnew");
427             session.removeValue("idlock");
428             session.removeValue("iddelete");
429             session.removeValue("idundelete");
430             session.removeValue("idpublish");
431             session.removeValue("idhistory");
432             session.removeValue("idpermissions");
433         }
434
435         if ((id != null) && (id.equals("new"))) {
436             session.putValue("idnew", id);
437             session.removeValue("idedit");
438             session.removeValue("iddelete");
439             session.removeValue("idlock");
440             session.removeValue("idundelete");
441             session.removeValue("idpublish");
442             session.removeValue("idhistory");
443             session.removeValue("idpermissions");
444             session.removeValue("idcopy");
445         }
446         //get marker id from session
447
String JavaDoc idsave = (String JavaDoc)session.getValue("idsave");
448         if (ok == null) {
449
450             idsave = null;
451         }
452
453         if (parentId != null) {
454             session.putValue("parentId", parentId);
455         }
456
457         //get marker for accessing the new dialog
458

459         // --- This is the part when getContentNew is called ---
460
//access to new dialog
461
if ((id != null) && (id.equals("new")) || ((idsave != null) && (idsave.equals("new")))) {
462             if (idsave != null) {
463                 parameters.put("id", idsave);
464             }
465             if (id != null) {
466                 parameters.put("id", id);
467                 session.putValue("idsave", id);
468             }
469             return getContentNewInternal(cms, id, cd, session, template, elementName, parameters, templateSelector);
470
471             // --- This was the part when getContentNew is called ---
472
}
473         //go to the appropriate getContent methods
474
if ((id == null) && (idsave == null) && (action == null) && (idlock == null) && (iddelete == null) && (idedit == null) && (idundelete == null) && (idpublish == null) && (idhistory == null) && (idpermissions == null) && (idcopy == null)) {
475             //process the head frame containing the filter
476
returnProcess = getContentHead(cms, template, elementName, parameters, templateSelector);
477             //finally return processed data
478
return returnProcess;
479         } else {
480             //process the body frame containing the table
481
if (action == null) {
482                 action = "";
483             }
484             if (action.equalsIgnoreCase("list")) {
485                 //process the list output
486
// clear "idsave" here in case user verification of data failed and input has to be shown again ...
487
session.removeValue("idsave");
488                 if (isExtendedList()) {
489                     returnProcess = getContentExtendedList(cms, template, elementName, parameters, templateSelector);
490                 } else {
491                     returnProcess = getContentList(cms, template, elementName, parameters, templateSelector);
492                 }
493                 //finally return processed data
494
return returnProcess;
495             } else {
496                 // --- This is the part where getContentEdit is called ---
497

498                 //get marker for accessing the edit dialog
499
String JavaDoc ideditsave = (String JavaDoc)session.getValue("idedit");
500                 //go to the edit dialog
501
if ((idedit != null) || (ideditsave != null)) {
502                     if (idsave != null) {
503                         parameters.put("id", idsave);
504                     }
505                     if (id != null) {
506                         parameters.put("id", id);
507                         session.putValue("idsave", id);
508                     }
509                     return getContentEditInternal(cms, id, cd, session, template, elementName, parameters, templateSelector);
510
511                     // --- This was the part where getContentEdit is called ---
512

513                 } else {
514                     //store id parameters for delete and lock
515
if (idsave != null) {
516                         parameters.put("id", idsave);
517                         session.removeValue("idsave");
518                     } else {
519                         parameters.put("id", id);
520                         session.putValue("idsave", id);
521                     }
522                     //check if the cd should be undeleted
523
if (idundelete != null) {
524                         returnProcess = getContentUndelete(cms, template, elementName, parameters, templateSelector);
525                         return returnProcess;
526                     }
527                     //get marker for accessing the publish dialog
528
//check if the cd should be published
529
String JavaDoc idpublishsave = (String JavaDoc)session.getValue("idpublish");
530                     if (idpublish != null || idpublishsave != null) {
531                         returnProcess = getContentDirectPublish(cms, template, elementName, parameters, templateSelector);
532                         return returnProcess;
533                     }
534                     //get marker for accessing the history dialog
535
//check if the history of cd should be dispayed
536
String JavaDoc idhistorysave = (String JavaDoc)session.getValue("idhistory");
537                     if (idhistory != null || idhistorysave != null) {
538                         returnProcess = getContentHistory(cms, template, elementName, parameters, templateSelector);
539                         return returnProcess;
540                     }
541
542                     //get marker for accessing the change permissions dialog
543
//check if the permissions of cd should be dispayed
544
String JavaDoc idpermissionssave = (String JavaDoc)session.getValue("idpermissions");
545                     if (idpermissions != null || idpermissionssave != null) {
546                         returnProcess = getContentPermissions(cms, template, elementName, parameters, templateSelector);
547                         return returnProcess;
548                     }
549
550                     //get marker for accessing the copy dialog
551
//check if the permissions of cd should be dispayed
552
String JavaDoc idcopysave = (String JavaDoc)session.getValue("idcopy");
553                     if (idcopy != null || idcopysave != null) {
554                         returnProcess = getContentCopy(cms, template, elementName, parameters, templateSelector);
555                         return returnProcess;
556                     }
557
558                     //get marker for accessing the delete dialog
559
String JavaDoc iddeletesave = (String JavaDoc)session.getValue("iddelete");
560                     //access delete dialog
561
if (((iddelete != null) || (iddeletesave != null)) && (idlock == null)) {
562                         returnProcess = getContentDelete(cms, template, elementName, parameters, templateSelector);
563                         return returnProcess;
564                     } else {
565                         //access lock dialog
566
returnProcess = getContentLock(cms, template, elementName, parameters, templateSelector);
567                         //finally return processed data
568
return returnProcess;
569                     }
570                 }
571             }
572         }
573     }
574
575     /**
576     * Gets the content definition class
577     * @return class content definition class
578     * Must be implemented in the extending backoffice class!
579     */

580     public abstract Class JavaDoc getContentDefinitionClass();
581
582     /**
583     * Gets the content definition class method constructor
584     *
585     * @param cms the cms object
586     * @param contentClass the content class
587     * @param contentId the id of the content
588     * @return content definition object
589     */

590     protected Object JavaDoc getContentDefinition(CmsObject cms, Class JavaDoc contentClass, CmsUUID contentId) {
591         Object JavaDoc o = null;
592         try {
593             Constructor JavaDoc c = contentClass.getConstructor(new Class JavaDoc[] {CmsObject.class, CmsUUID.class});
594             o = c.newInstance(new Object JavaDoc[] {cms, contentId});
595         } catch (InvocationTargetException JavaDoc ite) {
596             if (CmsLog.getLog(this).isWarnEnabled()) {
597                 CmsLog.getLog(this).warn("Invocation target exception", ite);
598             }
599         } catch (NoSuchMethodException JavaDoc nsm) {
600             if (CmsLog.getLog(this).isWarnEnabled()) {
601                 CmsLog.getLog(this).warn("Requested method was not found", nsm);
602             }
603         } catch (InstantiationException JavaDoc ie) {
604             if (CmsLog.getLog(this).isWarnEnabled()) {
605                 CmsLog.getLog(this).warn("The reflected class is abstract", ie);
606             }
607         } catch (Exception JavaDoc e) {
608             if (CmsLog.getLog(this).isWarnEnabled()) {
609                 CmsLog.getLog(this).warn("Other exception", e);
610             }
611         }
612         return o;
613     }
614
615     /**
616      * Gets the content definition class method constructor.<p>
617      *
618      * @param cms the cms object
619      * @param cdClass the content definition class
620      * @return content definition object
621      */

622     protected Object JavaDoc getContentDefinition(CmsObject cms, Class JavaDoc cdClass) {
623         Object JavaDoc o = null;
624         try {
625             //Constructor c = cdClass.getConstructor(new Class[] {CmsObject.class, String.class});
626
Constructor JavaDoc c = cdClass.getConstructor(new Class JavaDoc[] {CmsObject.class});
627             o = c.newInstance(new Object JavaDoc[] {cms});
628         } catch (InvocationTargetException JavaDoc ite) {
629             if (CmsLog.getLog(this).isWarnEnabled()) {
630                 CmsLog.getLog(this).warn("Invocation target exception", ite);
631             }
632         } catch (NoSuchMethodException JavaDoc nsm) {
633             if (CmsLog.getLog(this).isWarnEnabled()) {
634                 CmsLog.getLog(this).warn("Requested method was not found", nsm);
635             }
636         } catch (InstantiationException JavaDoc ie) {
637             if (CmsLog.getLog(this).isWarnEnabled()) {
638                 CmsLog.getLog(this).warn("The reflected class is abstract", ie);
639             }
640         } catch (Exception JavaDoc e) {
641             if (CmsLog.getLog(this).isWarnEnabled()) {
642                 CmsLog.getLog(this).warn("Other exception", e);
643             }
644         }
645         return o;
646     }
647
648     /**
649     * Gets the content definition class method constructor.<p>
650     *
651     * @param cms the cms object
652     * @param cdClass the content definition class
653     * @param id the id of the content
654     * @return content definition object
655     */

656     protected Object JavaDoc getContentDefinition(CmsObject cms, Class JavaDoc cdClass, String JavaDoc id) {
657         Object JavaDoc o = null;
658         try {
659             Constructor JavaDoc c = cdClass.getConstructor(new Class JavaDoc[] {CmsObject.class, String JavaDoc.class});
660             o = c.newInstance(new Object JavaDoc[] {cms, id});
661         } catch (InvocationTargetException JavaDoc ite) {
662             if (CmsLog.getLog(this).isWarnEnabled()) {
663                 CmsLog.getLog(this).warn("Invocation target exception", ite);
664             }
665         } catch (NoSuchMethodException JavaDoc nsm) {
666             if (CmsLog.getLog(this).isWarnEnabled()) {
667                 CmsLog.getLog(this).warn("Requested method was not found", nsm);
668             }
669         } catch (InstantiationException JavaDoc ie) {
670             if (CmsLog.getLog(this).isWarnEnabled()) {
671                 CmsLog.getLog(this).warn("The reflected class is abstract", ie);
672             }
673         } catch (Exception JavaDoc e) {
674             if (CmsLog.getLog(this).isWarnEnabled()) {
675                 CmsLog.getLog(this).warn("Other exception", e);
676             }
677         }
678         return o;
679     }
680
681     /**
682      * @param cms A CmsObject to read the user with
683      * @param userId The id of the user to read
684      * @return The name of the user, or the id (as a String) in case the user has been deleted
685      */

686     public String JavaDoc readSaveUserName(CmsObject cms, CmsUUID userId) {
687         String JavaDoc userName = null;
688         try {
689             userName = cms.readUser(userId).getName();
690         } catch (Exception JavaDoc e) {
691             userName = "" + userId;
692         }
693         return userName;
694     }
695
696     /**
697     * @param cms A CmsObject to read the group with
698     * @param groupId The id of the group to read
699     * @return The name of the group, or the id (as a String) in case the group has been deleted
700     */

701     public String JavaDoc readSaveGroupName(CmsObject cms, CmsUUID groupId) {
702         String JavaDoc groupName = null;
703         try {
704             groupName = cms.readGroup(groupId).getName();
705         } catch (Exception JavaDoc e) {
706             groupName = "" + groupId;
707         }
708         return groupName;
709     }
710
711     /**
712     * Gets the content of a given template file.
713     * <P>
714     * While processing the template file the table entry
715     * <code>entryTitle<code> will be displayed in the delete dialog
716     *
717     * @param cms A_CmsObject Object for accessing system resources
718     * @param template the template file
719     * @param elementName not used here
720     * @param parameters get the parameters action for the button activity
721     * and id for the used content definition instance object
722     * @param templateSelector template section that should be processed.
723     * @return Processed content of the given template file.
724     * @throws CmsException if something goes wrong
725     */

726
727     public byte[] getContentDelete(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
728         // return var
729
byte[] processResult = null;
730
731         // session will be created or fetched
732
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
733         //get the class of the content definition
734
Class JavaDoc cdClass = getContentDefinitionClass();
735
736         //get (stored) id parameter
737
String JavaDoc id = (String JavaDoc)parameters.get("id");
738         if (id == null) {
739             id = "";
740         }
741
742         // get value of hidden input field action
743
String JavaDoc action = (String JavaDoc)parameters.get("action");
744
745         //no button pressed, go to the default section!
746
//delete dialog, displays the title of the entry to be deleted
747
if (action == null || action.equals("")) {
748             if (id != "") {
749                 //set template section
750
templateSelector = "delete";
751
752                 //create new language file object
753
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
754
755                 //get the dialog from the language file and set it in the template
756
template.setData("deletetitle", lang.getLanguageValue("title.delete"));
757                 template.setData("deletedialog", lang.getLanguageValue("messagebox.delete"));
758                 template.setData("newsentry", id);
759                 template.setData("setaction", "default");
760             }
761             // confirmation button pressed, process data!
762
} else {
763             //set template section
764
templateSelector = "done";
765             //remove marker
766
session.removeValue("iddelete");
767             //delete the content definition instance
768
CmsUUID contentId = new CmsUUID(id);
769             // try {
770
// idInteger = Integer.valueOf(id);
771
// } catch (Exception e) {
772
// //access content definition constructor by reflection
773
// Object o = null;
774
// o = getContentDefinition(cms, cdClass, id);
775
// //get delete method and delete content definition instance
776
// try {
777
// ((A_CmsContentDefinition) o).delete(cms);
778
// } catch (Exception e1) {
779
// if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
780
// A_OpenCms.log(this);
781
// }
782
// templateSelector = "deleteerror";
783
// template.setData("deleteerror", e1.getMessage());
784
// }
785
// //finally start the processing
786
// processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
787
// return processResult;
788
// }
789

790             //access content definition constructor by reflection
791
Object JavaDoc o = null;
792             o = getContentDefinition(cms, cdClass, contentId);
793             //get delete method and delete content definition instance
794
try {
795                 ((A_CmsContentDefinition)o).delete(cms);
796             } catch (Exception JavaDoc e) {
797                 templateSelector = "deleteerror";
798                 template.setData("deleteerror", e.getMessage());
799             }
800         }
801
802         //finally start the processing
803
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
804         return processResult;
805     }
806
807     /**
808      * Gets the content of a given template file.
809      * <P>
810      * While processing the template file the table entry
811      * <code>entryTitle<code> will be displayed in the delete dialog
812      *
813      * @param cms A_CmsObject Object for accessing system resources
814      * @param template the template
815      * @param elementName not used here
816      * @param parameters get the parameters action for the button activity
817      * and id for the used content definition instance object
818      * @param templateSelector template section that should be processed.
819      * @return Processed content of the given template file.
820      * @throws CmsException if something goes wrong
821      */

822     public byte[] getContentUndelete(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
823         //return var
824
byte[] processResult = null;
825
826         // session will be created or fetched
827
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
828         //get the class of the content definition
829
Class JavaDoc cdClass = getContentDefinitionClass();
830
831         //get (stored) id parameter
832
String JavaDoc id = (String JavaDoc)parameters.get("id");
833         if (id == null) {
834             id = "";
835         }
836
837         //set template section
838
templateSelector = "done";
839         //remove marker
840
session.removeValue("idundelete");
841         //undelete the content definition instance
842
CmsUUID contentId = new CmsUUID(id);
843         // Integer idInteger = null;
844
// try {
845
// idInteger = Integer.valueOf(id);
846
// } catch (Exception e) {
847
// //access content definition constructor by reflection
848
// Object o = null;
849
// o = getContentDefinition(cms, cdClass, id);
850
// //get undelete method and undelete content definition instance
851
// try {
852
// ((I_CmsExtendedContentDefinition) o).undelete(cms);
853
// } catch (Exception e1) {
854
// if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
855
// A_OpenCms.log(this);
856
// }
857
// templateSelector = "undeleteerror";
858
// template.setData("undeleteerror", e1.getMessage());
859
// }
860
// //finally start the processing
861
// processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
862
// return processResult;
863
// }
864
//access content definition constructor by reflection
865
Object JavaDoc o = null;
866         o = getContentDefinition(cms, cdClass, contentId);
867         //get undelete method and undelete content definition instance
868
try {
869             ((I_CmsExtendedContentDefinition)o).undelete(cms);
870         } catch (Exception JavaDoc e) {
871             templateSelector = "undeleteerror";
872             template.setData("undeleteerror", e.getMessage());
873         }
874
875         //finally start the processing
876
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
877         return processResult;
878     }
879
880     /**
881      * Gets the content of a given template file.
882      * <P>
883      * While processing the template file the table entry
884      * <code>entryTitle<code> will be displayed in the delete dialog
885      *
886      * @param cms A_CmsObject Object for accessing system resources
887      * @param template the template file
888      * @param elementName not used here
889      * @param parameters get the parameters action for the button activity
890      * and id for the used content definition instance object
891      * @param templateSelector template section that should be processed.
892      * @return Processed content of the given template file.
893      * @throws CmsException if something goes wrong
894      */

895     public byte[] getContentCopy(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
896         //return var
897
byte[] processResult = null;
898
899         // session will be created or fetched
900
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
901         //get the class of the content definition
902
Class JavaDoc cdClass = getContentDefinitionClass();
903
904         //get (stored) id parameter
905
String JavaDoc id = (String JavaDoc)parameters.get("id");
906         if (id == null) {
907             id = "";
908         }
909         // get value of hidden input field action
910
String JavaDoc action = (String JavaDoc)parameters.get("action");
911
912         //no button pressed, go to the default section!
913
//copy dialog, displays information of the entry to be copy
914
if (action == null || action.equals("")) {
915             if (id != "") {
916                 //access content definition constructor by reflection
917
Object JavaDoc o = getContentDefinition(cms, cdClass, new CmsUUID(id));
918                 // get owner and group of content definition
919
String JavaDoc curOwner = readSaveUserName(cms, ((I_CmsExtendedContentDefinition)o).getOwner());
920                 String JavaDoc curGroup = readSaveGroupName(cms, ((I_CmsExtendedContentDefinition)o).getGroupId());
921
922                 //set template section
923
templateSelector = "copy";
924
925                 //get the dialog from the language file and set it in the template
926
template.setData("username", curOwner);
927                 template.setData("groupname", curGroup);
928                 template.setData("id", id);
929                 template.setData("setaction", "default");
930             }
931             // confirmation button pressed, process data!
932
} else {
933             //set template section
934
templateSelector = "done";
935             //remove marker
936
session.removeValue("idcopy");
937             //copy the content definition instance
938
CmsUUID contentId = new CmsUUID(id);
939             Object JavaDoc o = getContentDefinition(cms, cdClass, contentId);
940
941             // Integer contentId = null;
942
// Object o = null;
943
// try {
944
// contentId = Integer.valueOf(id);
945
// //access content definition constructor by reflection
946
// o = getContentDefinition(cms, cdClass, contentId);
947
// } catch (Exception e) {
948
// //access content definition constructor by reflection
949
// o = getContentDefinition(cms, cdClass, id);
950
// }
951

952             //get copy method and copy content definition instance
953
try {
954                 ((I_CmsExtendedContentDefinition)o).copy(cms);
955             } catch (Exception JavaDoc e) {
956                 templateSelector = "copyerror";
957                 template.setData("copyerror", e.getMessage());
958             }
959         }
960         //finally start the processing
961
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
962         return processResult;
963     }
964
965     /**
966      * Gets the content of a given template file.
967      * <P>
968      * While processing the template file the table entry
969      * <code>entryTitle<code> will be displayed in the direct publish dialog
970      *
971      * @param cms A_CmsObject Object for accessing system resources
972      * @param template the template
973      * @param elementName not used here
974      * @param parameters get the parameters action for the button activity
975      * and id for the used content definition instance object
976      * @param templateSelector template section that should be processed.
977      * @return Processed content of the given template file.
978      * @throws CmsException if something goes wrong
979      */

980     public byte[] getContentDirectPublish(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
981         //return var
982
byte[] processResult = null;
983
984         //create new language file object
985
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
986
987         if (cms.isAdmin() || cms.isManagerOfProject()) {
988             // session will be created or fetched
989
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
990             //get the class of the content definition
991
Class JavaDoc cdClass = getContentDefinitionClass();
992
993             //get (stored) id parameter
994
String JavaDoc id = (String JavaDoc)parameters.get("id");
995             if (id == null) {
996                 id = "";
997             }
998
999             // get value of hidden input field action
1000
String JavaDoc action = (String JavaDoc)parameters.get("action");
1001
1002            //no button pressed, go to the default section!
1003
//publish dialog, displays the title of the entry to be published
1004
if (action == null || action.equals("")) {
1005                if (id != "") {
1006                    //set template section
1007
templateSelector = "publish";
1008
1009                    //get the dialog from the langauge file and set it in the template
1010
template.setData("publishtitle", lang.getLanguageValue("messagebox.title.publishresource"));
1011                    template.setData("publishdialog1", lang.getLanguageValue("messagebox.message1.publishresource"));
1012                    template.setData("newsentry", id);
1013                    template.setData("publishdialog2", lang.getLanguageValue("messagebox.message4.publishresource"));
1014                    template.setData("setaction", "default");
1015                }
1016                // confirmation button pressed, process data!
1017
} else {
1018                //set template section
1019
templateSelector = "done";
1020                //remove marker
1021
session.removeValue("idsave");
1022                //publish the content definition instance
1023
CmsUUID contentId = new CmsUUID(id);
1024                // Integer contentId = null;
1025
// try {
1026
// contentId = Integer.valueOf(id);
1027
// } catch (Exception e) {
1028
// //access content definition constructor by reflection
1029
// Object o = null;
1030
// o = getContentDefinition(cms, cdClass, id);
1031
// //get publish method and publish content definition instance
1032
// try {
1033
// ((I_CmsExtendedContentDefinition) o).publishResource(cms);
1034
// } catch (Exception e1) {
1035
// if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
1036
// A_OpenCms.log(this);
1037
// }
1038
// templateSelector = "publisherror";
1039
// template.setData("publisherror", e1.getMessage());
1040
// }
1041
// //finally start the processing
1042
// processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
1043
// return processResult;
1044
// }
1045

1046                //access content definition constructor by reflection
1047
Object JavaDoc o = null;
1048                o = getContentDefinition(cms, cdClass, contentId);
1049                //get publish method and publish content definition instance
1050
try {
1051                    ((I_CmsExtendedContentDefinition)o).publishResource(cms);
1052                } catch (Exception JavaDoc e) {
1053                    templateSelector = "publisherror";
1054                    template.setData("publisherror", e.getMessage());
1055                }
1056            }
1057        } else {
1058            templateSelector = "publisherror";
1059            template.setData("publisherror", lang.getLanguageValue("error.message.publishresource") + "<br>" + lang.getLanguageValue("error.reason.publishresource"));
1060        }
1061
1062        //finally start the processing
1063
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
1064        return processResult;
1065    }
1066
1067    /**
1068     * Gets the content of a given template file.
1069     * <P>
1070     * While processing the template file the table entry
1071     * <code>entryTitle<code> will be displayed in the history dialog
1072     *
1073     * @param cms A_CmsObject Object for accessing system resources
1074     * @param template the template
1075     * @param elementName not used here
1076     * @param parameters get the parameters action for the button activity
1077     * and id for the used content definition instance object
1078     * @param templateSelector template section that should be processed.
1079     * @return Processed content of the given template file.
1080     * @throws CmsException if something goes wrong
1081     */

1082    public byte[] getContentHistory(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
1083        //return var
1084
byte[] processResult = null;
1085
1086        // session will be created or fetched
1087
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
1088        //get the class of the content definition
1089
Class JavaDoc cdClass = getContentDefinitionClass();
1090
1091        //get (stored) id parameter
1092
String JavaDoc id = (String JavaDoc)parameters.get("id");
1093        if (id == null) {
1094            id = "";
1095        }
1096
1097        // get value of hidden input field action
1098
String JavaDoc action = (String JavaDoc)parameters.get("action");
1099        //no button pressed, go to the default section!
1100
//history dialog, displays the versions of the cd in the history
1101
if (action == null || action.equals("")) {
1102            if (id != "") {
1103                //set template section
1104
templateSelector = "history";
1105                //create new language file object
1106
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
1107                //get the dialog from the langauge file and set it in the template
1108
template.setData("historytitle", lang.getLanguageValue("messagebox.title.history"));
1109                // build the history list
1110
template.setData("id", id);
1111                template.setData("setaction", "detail");
1112            } else {
1113                //set template section
1114
templateSelector = "done";
1115                //remove marker
1116
session.removeValue("idhistory");
1117            }
1118            // confirmation button pressed, process data!
1119
} else if (action.equalsIgnoreCase("detail")) {
1120            String JavaDoc versionId = (String JavaDoc)parameters.get("version");
1121            if (versionId != null && !"".equals(versionId)) {
1122                templateSelector = "historydetail";
1123                //access content definition constructor by reflection
1124
Object JavaDoc o = null;
1125                o = getContentDefinition(cms, cdClass, new CmsUUID(id));
1126                //get the version from history
1127
try {
1128                    I_CmsExtendedContentDefinition curVersion = (I_CmsExtendedContentDefinition) ((I_CmsExtendedContentDefinition)o).getVersionFromHistory(cms, Integer.parseInt(versionId));
1129                    String JavaDoc projectName = "";
1130                    String JavaDoc projectDescription = "";
1131                    String JavaDoc userName = "";
1132                    try {
1133                        CmsProject theProject = cms.readBackupProject(curVersion.getLockedInProject());
1134                        projectName = theProject.getName();
1135                        projectDescription = theProject.getDescription();
1136                    } catch (CmsException ex) {
1137                        projectName = "";
1138                    }
1139                    try {
1140                        CmsUser theUser = cms.readUser(curVersion.getLastModifiedBy());
1141                        userName = theUser.getName() + " " + theUser.getFirstname() + " " + theUser.getLastname();
1142                    } catch (CmsException ex) {
1143                        userName = curVersion.getLastModifiedByName();
1144                    }
1145                    template.setData("histproject", projectName);
1146                    template.setData("version", versionId);
1147                    template.setData("id", id);
1148                    template.setData("histid", curVersion.getId().toString());
1149                    template.setData("histtitle", curVersion.getTitle());
1150                    template.setData("histlastmodified", CmsDateUtil.getDateTimeShort(curVersion.getDateLastModified()));
1151                    template.setData("histpublished", CmsDateUtil.getDateTimeShort(curVersion.getDateCreated()));
1152                    template.setData("histmodifiedby", userName);
1153                    template.setData("histdescription", projectDescription);
1154                    CmsUUID curUser = cms.getRequestContext().currentUser().getId();
1155                    int curProject = cms.getRequestContext().currentProject().getId();
1156                    if (((A_CmsContentDefinition)o).getLockstate().equals(curUser) && ((I_CmsExtendedContentDefinition)o).getLockedInProject() == curProject) {
1157                        // enable restore button
1158
template.setData("BUTTONRESTORE", template.getProcessedDataValue("ENABLERESTORE", this));
1159                        template.setData("setaction", "restore");
1160                    } else {
1161                        template.setData("BUTTONRESTORE", template.getProcessedDataValue("DISABLERESTORE", this));
1162                        template.setData("setaction", "");
1163                    }
1164                } catch (Exception JavaDoc e) {
1165                    if (CmsLog.getLog(this).isWarnEnabled()) {
1166                        CmsLog.getLog(this).warn("Backoffice: history method caused an exception", e);
1167                    }
1168                    templateSelector = "historyerror";
1169                    template.setData("historyerror", e.getMessage());
1170                    //remove marker
1171
session.removeValue("idhistory");
1172                }
1173            } else {
1174                // no version selected
1175
//set template section
1176
templateSelector = "history";
1177                //create new language file object
1178
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
1179                //get the dialog from the langauge file and set it in the template
1180
template.setData("historytitle", lang.getLanguageValue("messagebox.title.history"));
1181                // build the history list
1182
template.setData("id", id);
1183                template.setData("setaction", "detail");
1184            }
1185        } else if (action.equalsIgnoreCase("restore")) {
1186            String JavaDoc versionId = (String JavaDoc)parameters.get("version");
1187            //set template section
1188
templateSelector = "history";
1189            //create new language file object
1190
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
1191            //get the dialog from the langauge file and set it in the template
1192
template.setData("historytitle", lang.getLanguageValue("messagebox.title.history"));
1193            // build the history list
1194
template.setData("id", id);
1195            template.setData("setaction", "detail");
1196            if (versionId != null && !"".equals(versionId)) {
1197                //access content definition constructor by reflection
1198
Object JavaDoc o = null;
1199                o = getContentDefinition(cms, cdClass, new CmsUUID(id));
1200                //get restore method and restore content definition instance
1201
try {
1202                    ((I_CmsExtendedContentDefinition)o).restore(cms, Integer.parseInt(versionId));
1203                } catch (Exception JavaDoc e) {
1204                    if (CmsLog.getLog(this).isWarnEnabled()) {
1205                        CmsLog.getLog(this).warn("Restore method caused an exception", e);
1206                    }
1207                    templateSelector = "historyerror";
1208                    template.setData("historyerror", e.getMessage());
1209                    //remove marker
1210
session.removeValue("idhistory");
1211                }
1212            }
1213        }
1214        //finally start the processing
1215
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
1216        return processResult;
1217    }
1218
1219    /**
1220     * Gets all versions of the resource from the history.
1221     * <P>
1222     * The given vectors <code>names</code> and <code>values</code> will
1223     * be filled with the appropriate information to be used for building
1224     * a select box.
1225     *
1226     * @param cms CmsObject Object for accessing system resources.
1227     * @param lang the language file
1228     * @param names Vector to be filled with the appropriate values in this method.
1229     * @param values Vector to be filled with the appropriate values in this method.
1230     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
1231     * @return Index representing the current value in the vectors.
1232     * @throws CmsException if something goes wrong
1233     */

1234
1235    public Integer JavaDoc getHistory(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
1236        CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
1237        String JavaDoc id = (String JavaDoc)parameters.get("id");
1238        if (id != null && !"".equals(id)) {
1239            Vector JavaDoc cdHistory = new Vector JavaDoc();
1240            //get the class of the content definition
1241
Class JavaDoc cdClass = getContentDefinitionClass();
1242            //access content definition constructor by reflection
1243
Object JavaDoc o = null;
1244            o = getContentDefinition(cms, cdClass, new CmsUUID(id));
1245            //get history method and return the vector of the versions
1246
try {
1247                cdHistory = ((I_CmsExtendedContentDefinition)o).getHistory(cms);
1248            } catch (Exception JavaDoc e) {
1249                if (CmsLog.getLog(this).isErrorEnabled()) {
1250                    CmsLog.getLog(this).error("History reading history for class " + cdClass.getName(), e);
1251                }
1252            }
1253            // fill the names and values
1254
for (int i = 0; i < cdHistory.size(); i++) {
1255                try {
1256                    I_CmsExtendedContentDefinition curCd = ((I_CmsExtendedContentDefinition)cdHistory.elementAt(i));
1257                    long updated = curCd.getDateCreated();
1258                    String JavaDoc userName = readSaveUserName(cms, curCd.getLastModifiedBy());
1259                    long lastModified = curCd.getDateLastModified();
1260                    String JavaDoc output = CmsDateUtil.getDateTimeShort(lastModified) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + CmsDateUtil.getDateTimeShort(updated) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + userName;
1261                    names.addElement(output);
1262                    values.addElement(curCd.getVersionId() + "");
1263                } catch (Exception JavaDoc e) {
1264                    if (CmsLog.getLog(this).isErrorEnabled()) {
1265                        CmsLog.getLog(this).error(e);
1266                    }
1267                }
1268            }
1269        }
1270        return new Integer JavaDoc(-1);
1271    }
1272
1273    /**
1274     * Gets the content of a given template file.
1275     * <P>
1276     * While processing the template file the table entry
1277     * <code>entryTitle<code> will be displayed in the delete dialog
1278     *
1279     * @param cms A_CmsObject Object for accessing system resources
1280     * @param template the template
1281     * @param elementName not used here
1282     * @param parameters get the parameters action for the button activity
1283     * and id for the used content definition instance object
1284     * @param templateSelector template section that should be processed.
1285     * @return Processed content of the given template file.
1286     * @throws CmsException if something goes wrong
1287     */

1288    public byte[] getContentPermissions(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
1289        //return var
1290
byte[] processResult = null;
1291        Object JavaDoc o = null;
1292        // session will be created or fetched
1293
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
1294        //get the class of the content definition
1295
Class JavaDoc cdClass = getContentDefinitionClass();
1296
1297        // get mode of permission changing
1298
String JavaDoc mode = (String JavaDoc)parameters.get("chmode");
1299        if (mode == null || "".equals(mode)) {
1300            mode = "";
1301        }
1302        //get (stored) id parameter
1303
String JavaDoc id = (String JavaDoc)parameters.get("id");
1304        if (id == null) {
1305            id = "";
1306        }
1307        // get value of hidden input field action
1308
String JavaDoc action = (String JavaDoc)parameters.get("action");
1309        // get values of input fields
1310
CmsUUID newOwner = CmsUUID.getNullUUID();
1311        CmsUUID newGroup = CmsUUID.getNullUUID();
1312        String JavaDoc newOwnerString = (String JavaDoc)parameters.get("owner");
1313        if (newOwnerString != null && !"".equals(newOwnerString)) {
1314            newOwner = new CmsUUID(newOwnerString);
1315        }
1316        String JavaDoc newGroupString = (String JavaDoc)parameters.get("groupId");
1317        if (newGroupString != null && !"".equals(newGroupString)) {
1318            newGroup = new CmsUUID(newGroupString);
1319        }
1320        int newAccessFlags = getAccessValue(parameters);
1321        //no button pressed, go to the default section!
1322
//change permissions dialog, displays owner, group and access flags of the entry to be changed
1323
if (action == null || action.equals("")) {
1324            if (id != "" && mode != "") {
1325                //access content definition constructor by reflection
1326
o = getContentDefinition(cms, cdClass, new CmsUUID(id));
1327                //set template section
1328
templateSelector = mode;
1329                CmsUUID curOwner = ((I_CmsExtendedContentDefinition)o).getOwner();
1330                CmsUUID curGroup = ((I_CmsExtendedContentDefinition)o).getGroupId();
1331                int curAccessFlags = ((I_CmsExtendedContentDefinition)o).getAccessFlags();
1332                // set the values in the dialog
1333
this.setOwnerSelectbox(cms, template, curOwner);
1334                this.setGroupSelectbox(cms, template, curGroup);
1335                this.setAccessValue(template, curAccessFlags);
1336                template.setData("id", id);
1337                template.setData("setaction", mode);
1338            }
1339            // confirmation button pressed, process data!
1340
} else {
1341            //set template section
1342
templateSelector = "done";
1343            //remove marker
1344
session.removeValue("idpermissions");
1345            //change the content definition instance
1346
CmsUUID contentId = new CmsUUID(id);
1347            o = getContentDefinition(cms, cdClass, contentId);
1348            // try {
1349
// contentId = Integer.valueOf(id);
1350
// //access content definition constructor by reflection
1351
// o = getContentDefinition(cms, cdClass, contentId);
1352
// } catch (Exception e) {
1353
// //access content definition constructor by reflection
1354
// o = getContentDefinition(cms, cdClass, id);
1355
// }
1356

1357            //get change method and change content definition instance
1358
try {
1359                if ("chown".equalsIgnoreCase(action) && !newOwner.isNullUUID()) {
1360                    ((I_CmsExtendedContentDefinition)o).chown(cms, newOwner);
1361                } else if ("chgrp".equalsIgnoreCase(action) && !newGroup.isNullUUID()) {
1362                    ((I_CmsExtendedContentDefinition)o).chgrp(cms, newGroup);
1363                } else if ("chmod".equalsIgnoreCase(action)) {
1364                    ((I_CmsExtendedContentDefinition)o).chmod(cms, newAccessFlags);
1365                }
1366            } catch (Exception JavaDoc e) {
1367                if (CmsLog.getLog(this).isWarnEnabled()) {
1368                    CmsLog.getLog(this).warn("Changing permissions method caused an exception", e);
1369                }
1370                templateSelector = "permissionserror";
1371                template.setData("permissionserror", e.getMessage());
1372            }
1373        }
1374        //finally start the processing
1375
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
1376        return processResult;
1377    }
1378
1379    /**
1380    * Gets the content of a given template file.
1381    * <P>
1382    *
1383    * @param cms A_CmsObject Object for accessing system resources
1384    * @param template the template
1385    * @param elementName not used here
1386    * @param parameters get the parameters action for the button activity
1387    * and id for the used content definition instance object
1388    * and the author, title, text content for setting the new/changed data
1389    * @param templateSelector template section that should be processed.
1390    * @return Processed content of the given template file.
1391    * @throws CmsException if something goes wrong
1392    */

1393
1394    private byte[] getContentHead(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
1395
1396        //return var
1397
byte[] processResult = null;
1398        //get the class of the content definition
1399

1400        //init vars
1401

1402        //create new or fetch existing session
1403
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
1404        String JavaDoc uri = cms.getRequestContext().getUri();
1405        String JavaDoc sessionSelectBoxValue = uri + "selectBoxValue";
1406        //get filter method from session
1407
String JavaDoc selectBoxValue = (String JavaDoc)parameters.get("selectbox");
1408        if (selectBoxValue == null) {
1409            // set default value
1410
if ((String JavaDoc)session.getValue(sessionSelectBoxValue) != null) {
1411                // came back from edit or something ... redisplay last filter
1412
selectBoxValue = (String JavaDoc)session.getValue(sessionSelectBoxValue);
1413            } else {
1414                // the very first time here...
1415
selectBoxValue = "0";
1416            }
1417        }
1418        boolean filterChanged = true;
1419        if (selectBoxValue.equals(session.getValue(sessionSelectBoxValue))) {
1420            filterChanged = false;
1421        } else {
1422            filterChanged = true;
1423        }
1424
1425        //get vector of filter names from the content definition
1426
Vector JavaDoc filterMethods = getFilterMethods(cms);
1427
1428        if (Integer.parseInt(selectBoxValue) >= filterMethods.size()) {
1429            // the stored seclectBoxValue is does not exist any more, ...
1430
selectBoxValue = "0";
1431        }
1432
1433        session.putValue(sessionSelectBoxValue, selectBoxValue); // store in session for Selectbox!
1434
session.putValue("filter", selectBoxValue); // store filter in session for getContentList!
1435

1436        String JavaDoc filterParam = (String JavaDoc)parameters.get("filterparameter");
1437        // create the key for the filterparameter in the session ... should be unique to avoid problems...
1438
String JavaDoc sessionFilterParam = uri + selectBoxValue + "filterparameter";
1439        //store filterparameter in the session, new enty for every filter of every url ...
1440
if (filterParam != null) {
1441            session.putValue(sessionFilterParam, filterParam);
1442        }
1443
1444        //create appropriate class name with underscores for labels
1445
String JavaDoc moduleName = "";
1446        moduleName = getClass().toString(); //get name
1447
moduleName = moduleName.substring(5); //remove 'class' substring at the beginning
1448
moduleName = moduleName.trim();
1449        moduleName = moduleName.replace('.', '_'); //replace dots with underscores
1450

1451        //create new language file object
1452
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
1453        //set labels in the template
1454
template.setData("filterlabel", lang.getLanguageValue(moduleName + ".label.filter"));
1455        template.setData("filterparameterlabel", lang.getLanguageValue(moduleName + ".label.filterparameter"));
1456
1457        //no filter selected so far, store a default filter in the session
1458
if (selectBoxValue == null) {
1459            CmsFilterMethod defaultFilter = (CmsFilterMethod)filterMethods.firstElement();
1460            session.putValue("selectbox", defaultFilter.getFilterName());
1461        }
1462
1463        // show param box ?
1464
CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(Integer.parseInt(selectBoxValue));
1465        if (currentFilter.hasUserParameter()) {
1466            if (filterChanged) {
1467                template.setData("filterparameter", currentFilter.getDefaultFilterParam());
1468                // access default in getContentList() ....
1469
session.putValue(sessionFilterParam, currentFilter.getDefaultFilterParam());
1470            } else if (filterParam != null) {
1471                template.setData("filterparameter", filterParam);
1472            } else {
1473                // redisplay after edit or something like this ...
1474
template.setData("filterparameter", (String JavaDoc)session.getValue(sessionFilterParam));
1475            }
1476            // check if there is only one filtermethod, do not show the selectbox then
1477
if (filterMethods.size() < 2) {
1478                // replace the selectbox with a simple text output
1479
CmsFilterMethod defaultFilter = (CmsFilterMethod)filterMethods.firstElement();
1480                template.setData("filtername", defaultFilter.getFilterName());
1481                template.setData("insertFilter", template.getProcessedDataValue("noSelectboxWithParam", this, parameters));
1482            } else {
1483                template.setData("insertFilter", template.getProcessedDataValue("selectboxWithParam", this, parameters));
1484            }
1485            template.setData("setfocus", template.getDataValue("focus"));
1486        } else {
1487            // check if there is only one filtermethod, do not show the selectbox then
1488
if (filterMethods.size() < 2) {
1489                // replace the selectbox with a simple text output
1490
CmsFilterMethod defaultFilter = (CmsFilterMethod)filterMethods.firstElement();
1491                template.setData("filtername", defaultFilter.getFilterName());
1492                template.setData("insertFilter", template.getProcessedDataValue("noSelectbox", this, parameters));
1493            } else {
1494                template.setData("insertFilter", template.getProcessedDataValue("singleSelectbox", this, parameters));
1495            }
1496        }
1497
1498        //if getCreateUrl equals null, the "create new entry" button
1499
//will not be displayed in the template
1500
String JavaDoc createButton = null;
1501        try {
1502            createButton = getCreateUrl(cms, null, null, null);
1503        } catch (Exception JavaDoc e) { }
1504        if (createButton == null) {
1505            String JavaDoc cb = template.getDataValue("nowand");
1506            template.setData("createbutton", cb);
1507        } else {
1508            boolean buttonActiv = true;
1509            if (isExtendedList() && (cms.getRequestContext().currentProject().isOnlineProject())) {
1510                buttonActiv = false;
1511            }
1512            if (buttonActiv) {
1513                String JavaDoc cb = template.getProcessedDataValue("wand", this, parameters);
1514                template.setData("createbutton", cb);
1515            } else {
1516                String JavaDoc cb = template.getProcessedDataValue("deactivwand", this, parameters);
1517                template.setData("createbutton", cb);
1518            }
1519        }
1520
1521        //if getSetupUrl is empty, the module setup button will not be displayed in the template.
1522
String JavaDoc setupButton = null;
1523        try {
1524            setupButton = getSetupUrl(cms, null, null, null);
1525        } catch (Exception JavaDoc e) { }
1526        if ((setupButton == null) || (setupButton.equals(""))) {
1527            String JavaDoc sb = template.getDataValue("nosetup");
1528            template.setData("setupbutton", sb);
1529        } else {
1530            String JavaDoc sb = template.getProcessedDataValue("setup", this, parameters);
1531            template.setData("setupbutton", sb);
1532        }
1533
1534        //finally start the processing
1535
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
1536        return processResult;
1537    }
1538    /**
1539     * Gets the content of a given template file.
1540     * This method displays any content provided by a content definition
1541     * class on the template. The used backoffice class does not need to use a
1542     * special getContent method. It just has to extend the methods of this class!
1543     * Using reflection, this method creates the table headline and table content
1544     * with the layout provided by the template automatically!
1545     * @param cms CmsObjectfor accessing system resources
1546     * @param template the template
1547     * @param elementName <em>not used here</em>.
1548     * @param parameters <em>not used here</em>.
1549     * @param templateSelector template section that should be processed.
1550     * @return Processed content of the given template file.
1551     * @throws CmsException if something goes wrong
1552     */

1553    private byte[] getContentList(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
1554        //return var
1555
byte[] processResult = null;
1556        // session will be created or fetched
1557
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
1558        //get the class of the content definition
1559
Class JavaDoc cdClass = getContentDefinitionClass();
1560
1561        //read value of the selected filter
1562
String JavaDoc filterMethodName = (String JavaDoc)session.getValue("filter");
1563        if (filterMethodName == null) {
1564            filterMethodName = "0";
1565        }
1566
1567        String JavaDoc uri = cms.getRequestContext().getUri();
1568        String JavaDoc sessionFilterParam = uri + filterMethodName + "filterparameter";
1569        //read value of the inputfield filterparameter
1570
String JavaDoc filterParam = (String JavaDoc)session.getValue(sessionFilterParam);
1571        if (filterParam == "") {
1572            filterParam = null;
1573        }
1574
1575        //change template to list section for data list output
1576
templateSelector = "list";
1577
1578        //init vars
1579
String JavaDoc tableHead = "";
1580        String JavaDoc singleRow = "";
1581        String JavaDoc allEntrys = "";
1582        String JavaDoc entry = "";
1583        String JavaDoc url = "";
1584        int columns = 0;
1585
1586        // get number of columns
1587
Vector JavaDoc columnsVector = new Vector JavaDoc();
1588        String JavaDoc fieldNamesMethod = "getFieldNames";
1589        Class JavaDoc paramClasses[] = {CmsObject.class};
1590        Object JavaDoc params[] = {cms};
1591        columnsVector = (Vector JavaDoc)getContentMethodObject(cms, cdClass, fieldNamesMethod, paramClasses, params);
1592        columns = columnsVector.size();
1593
1594        //create appropriate class name with underscores for labels
1595
String JavaDoc moduleName = "";
1596        moduleName = getClass().toString(); //get name
1597
moduleName = moduleName.substring(5); //remove 'class' substring at the beginning
1598
moduleName = moduleName.trim();
1599        moduleName = moduleName.replace('.', '_'); //replace dots with underscores
1600

1601        //create new language file object
1602
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
1603
1604        //create tableheadline
1605
for (int i = 0; i < columns; i++) {
1606            tableHead += (template.getDataValue("tabledatabegin")) + lang.getLanguageValue(moduleName + ".label." + columnsVector.elementAt(i).toString().toLowerCase().trim()) + (template.getDataValue("tabledataend"));
1607        }
1608        //set template data for table headline content
1609
template.setData("tableheadline", tableHead);
1610
1611        // get vector of filterMethods and select the appropriate filter method,
1612
// if no filter is appropriate, select a default filter get number of rows for output
1613
Vector JavaDoc tableContent = new Vector JavaDoc();
1614        try {
1615            Vector JavaDoc filterMethods = (Vector JavaDoc)cdClass.getMethod("getFilterMethods", new Class JavaDoc[] {CmsObject.class}).invoke(null, new Object JavaDoc[] {cms});
1616            CmsFilterMethod filterMethod = null;
1617            CmsFilterMethod filterName = (CmsFilterMethod)filterMethods.elementAt(Integer.parseInt(filterMethodName));
1618            filterMethodName = filterName.getFilterName();
1619            //loop trough the filter methods and set the chosen one
1620
for (int i = 0; i < filterMethods.size(); i++) {
1621                CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(i);
1622                if (currentFilter.getFilterName().equals(filterMethodName)) {
1623                    filterMethod = currentFilter;
1624                    break;
1625                }
1626            }
1627
1628            // the chosen filter does not exist, use the first one!
1629
if (filterMethod == null) {
1630                filterMethod = (CmsFilterMethod)filterMethods.firstElement();
1631            }
1632            // now apply the filter with the cms object, the filter method and additional user parameters
1633
tableContent = (Vector JavaDoc)cdClass.getMethod("applyFilter", new Class JavaDoc[] {CmsObject.class, CmsFilterMethod.class, String JavaDoc.class}).invoke(null, new Object JavaDoc[] {cms, filterMethod, filterParam});
1634        } catch (InvocationTargetException JavaDoc ite) {
1635            //error occured while applying the filter
1636
if (CmsLog.getLog(this).isWarnEnabled()) {
1637                CmsLog.getLog(this).warn("Apply filter caused an InvocationTargetException", ite);
1638            }
1639            templateSelector = "error";
1640            template.setData("filtername", filterMethodName);
1641            while (ite.getTargetException() instanceof InvocationTargetException JavaDoc) {
1642                ite = ((InvocationTargetException JavaDoc)ite.getTargetException());
1643            }
1644            template.setData("filtererror", ite.getTargetException().getMessage());
1645            session.removeValue(sessionFilterParam);
1646            //session.removeValue("filter");
1647
} catch (NoSuchMethodException JavaDoc nsm) {
1648            if (CmsLog.getLog(this).isWarnEnabled()) {
1649                CmsLog.getLog(this).warn("Apply filter method was not found", nsm);
1650            }
1651            templateSelector = "error";
1652            template.setData("filtername", filterMethodName);
1653            template.setData("filtererror", nsm.getMessage());
1654            session.removeValue(sessionFilterParam);
1655            //session.removeValue("filterparameter");
1656
} catch (Exception JavaDoc e) {
1657            if (CmsLog.getLog(this).isWarnEnabled()) {
1658                CmsLog.getLog(this).warn("Apply filter: Other Exception", e);
1659            }
1660            templateSelector = "error";
1661            template.setData("filtername", filterMethodName);
1662            template.setData("filtererror", e.getMessage());
1663            session.removeValue(sessionFilterParam);
1664            //session.removeValue("filterparameter");
1665
}
1666
1667        //get the number of rows
1668
int rows = tableContent.size();
1669
1670        // get the field methods from the content definition
1671
Vector JavaDoc fieldMethods = new Vector JavaDoc();
1672        try {
1673            fieldMethods = (Vector JavaDoc)cdClass.getMethod("getFieldMethods", new Class JavaDoc[] {CmsObject.class}).invoke(null, new Object JavaDoc[] {cms});
1674        } catch (Exception JavaDoc exc) {
1675            if (CmsLog.getLog(this).isWarnEnabled()) {
1676                CmsLog.getLog(this).warn("getFieldMethods caused an exception", exc);
1677            }
1678            templateSelector = "error";
1679            template.setData("filtername", filterMethodName);
1680            template.setData("filtererror", exc.getMessage());
1681        }
1682
1683        // create output from the table data
1684
String JavaDoc fieldEntry = "";
1685        String JavaDoc id = "";
1686        for (int i = 0; i < rows; i++) {
1687            //init
1688
entry = "";
1689            singleRow = "";
1690            Object JavaDoc entryObject = new Object JavaDoc();
1691            entryObject = tableContent.elementAt(i); //cd object in row #i
1692

1693            //set data of single row
1694
for (int j = 0; j < columns; j++) {
1695                fieldEntry = "+++ NO VALUE FOUND +++";
1696                // call the field methods
1697
Method JavaDoc getMethod = null;
1698                try {
1699                    getMethod = (Method JavaDoc)fieldMethods.elementAt(j);
1700
1701                } catch (Exception JavaDoc e) {
1702                    if (CmsLog.getLog(this).isWarnEnabled()) {
1703                        CmsLog.getLog(this).warn("Could not get field method for " + (String JavaDoc)columnsVector.elementAt(j) + " - check for correct spelling", e);
1704                    }
1705                }
1706                try {
1707                    //apply methods on content definition object
1708
Object JavaDoc fieldEntryObject = null;
1709
1710                    fieldEntryObject = getMethod.invoke(entryObject, new Object JavaDoc[0]);
1711
1712                    if (fieldEntryObject != null) {
1713                        fieldEntry = fieldEntryObject.toString();
1714                    } else {
1715                        fieldEntry = null;
1716                    }
1717                } catch (InvocationTargetException JavaDoc ite) {
1718                    if (CmsLog.getLog(this).isWarnEnabled()) {
1719                        CmsLog.getLog(this).warn("Backoffice content definition object caused an InvocationTargetException", ite);
1720                    }
1721                } catch (Exception JavaDoc e) {
1722                    if (CmsLog.getLog(this).isWarnEnabled()) {
1723                        CmsLog.getLog(this).warn("Backoffice content definition object: Other exception", e);
1724                    }
1725                }
1726
1727                try {
1728                    id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms);
1729                } catch (Exception JavaDoc e) {
1730                    if (CmsLog.getLog(this).isWarnEnabled()) {
1731                        CmsLog.getLog(this).warn("Backoffice: getUniqueId caused an Exception, e");
1732                    }
1733                }
1734
1735                //insert unique id in contextmenue
1736
if (id != null) {
1737                    template.setData("uniqueid", id);
1738                }
1739                //insert table entry
1740
if (fieldEntry != null) {
1741                    try {
1742                        Vector JavaDoc v = new Vector JavaDoc();
1743                        v.addElement(new CmsUUID(id));
1744                        v.addElement(template);
1745                        url = getUrl(cms, null, null, v);
1746                    } catch (Exception JavaDoc e) {
1747                        if (CmsLog.getLog(this).isErrorEnabled()) {
1748                            CmsLog.getLog(this).error("Error getting URL for ID " + id, e);
1749                        }
1750                        
1751                        url = "";
1752                    }
1753                    if (!url.equals("")) {
1754                        // enable url
1755
entry += (template.getDataValue("tabledatabegin")) + (template.getProcessedDataValue("url", this, parameters)) + fieldEntry + (template.getDataValue("tabledataend"));
1756                    } else {
1757                        // disable url
1758
entry += (template.getDataValue("tabledatabegin")) + fieldEntry + (template.getDataValue("tabledataend"));
1759                    }
1760                } else {
1761                    entry += (template.getDataValue("tabledatabegin")) + "" + (template.getDataValue("tabledataend"));
1762                }
1763            }
1764            //get the unique id belonging to an entry
1765
try {
1766                id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms);
1767            } catch (Exception JavaDoc e) {
1768                if (CmsLog.getLog(this).isWarnEnabled()) {
1769                    CmsLog.getLog(this).warn("Backoffice: getUniqueId caused an Exception", e);
1770                }
1771            }
1772
1773            //insert unique id in contextmenue
1774
if (id != null) {
1775                template.setData("uniqueid", id);
1776            }
1777
1778            //set the lockstates for the actual entry
1779
setLockstates(cms, template, cdClass, entryObject, parameters);
1780
1781            //insert single table row in template
1782
template.setData("entry", entry);
1783
1784            // processed row from template
1785
singleRow = template.getProcessedDataValue("singlerow", this, parameters);
1786            allEntrys += (template.getDataValue("tablerowbegin")) + singleRow + (template.getDataValue("tablerowend"));
1787        }
1788
1789        //insert tablecontent in template
1790
template.setData("tablecontent", "" + allEntrys);
1791
1792        //save select box value into session
1793
session.putValue("selectbox", filterMethodName);
1794
1795        //finally start the processing
1796
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
1797        return processResult;
1798    }
1799
1800    /**
1801     * Gets the content of a given template file.
1802     * This method displays any content provided by a content definition
1803     * class on the template. The used backoffice class does not need to use a
1804     * special getContent method. It just has to extend the methods of this class!
1805     * Using reflection, this method creates the table headline and table content
1806     * with the layout provided by the template automatically!
1807     * @param cms CmsObjectfor accessing system resources
1808     * @param template the template
1809     * @param elementName <em>not used here</em>.
1810     * @param parameters <em>not used here</em>.
1811     * @param templateSelector template section that should be processed.
1812     * @return Processed content of the given template file.
1813     * @throws CmsException if something goes wrong
1814     */

1815    private byte[] getContentExtendedList(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
1816
1817        //return var
1818
byte[] processResult = null;
1819        // session will be created or fetched
1820
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
1821        //get the class of the content definition
1822
Class JavaDoc cdClass = getContentDefinitionClass();
1823
1824        //read value of the selected filter
1825
String JavaDoc filterMethodName = (String JavaDoc)session.getValue("filter");
1826        if (filterMethodName == null) {
1827            filterMethodName = "0";
1828        }
1829        String JavaDoc uri = cms.getRequestContext().getUri();
1830        String JavaDoc sessionFilterParam = uri + filterMethodName + "filterparameter";
1831        //read value of the inputfield filterparameter
1832
String JavaDoc filterParam = (String JavaDoc)session.getValue(sessionFilterParam);
1833        if (filterParam == "") {
1834            filterParam = null;
1835        }
1836        //change template to list section for data list output
1837
templateSelector = "list";
1838
1839        //init vars
1840
StringBuffer JavaDoc tableHead = new StringBuffer JavaDoc();
1841        String JavaDoc singleRow = new String JavaDoc();
1842        StringBuffer JavaDoc allEntrys = new StringBuffer JavaDoc();
1843        StringBuffer JavaDoc entry = new StringBuffer JavaDoc();
1844        String JavaDoc url = "";
1845        int columns = 0;
1846        String JavaDoc style = ">";
1847        String JavaDoc url_style = "";
1848        String JavaDoc tabledatabegin = template.getDataValue("tabledatabegin");
1849        String JavaDoc tabledataend = template.getDataValue("tabledataend");
1850        String JavaDoc tablerowbegin = template.getDataValue("tablerowbegin");
1851        String JavaDoc tablerowend = template.getDataValue("tablerowend");
1852
1853        // get number of columns
1854
Vector JavaDoc columnsVector = new Vector JavaDoc();
1855        String JavaDoc fieldNamesMethod = "getFieldNames";
1856        Class JavaDoc paramClasses[] = {CmsObject.class};
1857        Object JavaDoc params[] = {cms};
1858        columnsVector = (Vector JavaDoc)getContentMethodObject(cms, cdClass, fieldNamesMethod, paramClasses, params);
1859        columns = columnsVector.size();
1860        //create appropriate class name with underscores for labels
1861
String JavaDoc moduleName = "";
1862        moduleName = getClass().toString(); //get name
1863
moduleName = moduleName.substring(5); //remove 'class' substring at the beginning
1864
moduleName = moduleName.trim();
1865        moduleName = moduleName.replace('.', '_'); //replace dots with underscores
1866

1867        //create new language file object
1868
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
1869        //create tableheadline
1870
for (int i = 0; i < columns; i++) {
1871            tableHead.append(tabledatabegin);
1872            tableHead.append(style);
1873            tableHead.append(lang.getLanguageValue(moduleName + ".label." + columnsVector.elementAt(i).toString().toLowerCase().trim()));
1874            tableHead.append(tabledataend);
1875        }
1876        //set template data for table headline content
1877
template.setData("tableheadline", tableHead.toString());
1878        // get vector of filterMethods and select the appropriate filter method,
1879
// if no filter is appropriate, select a default filter get number of rows for output
1880
Vector JavaDoc tableContent = new Vector JavaDoc();
1881        try {
1882            Vector JavaDoc filterMethods = (Vector JavaDoc)cdClass.getMethod("getFilterMethods", new Class JavaDoc[] {CmsObject.class}).invoke(null, new Object JavaDoc[] {cms});
1883            CmsFilterMethod filterMethod = null;
1884            CmsFilterMethod filterName = (CmsFilterMethod)filterMethods.elementAt(Integer.parseInt(filterMethodName));
1885            filterMethodName = filterName.getFilterName();
1886            //loop trough the filter methods and set the chosen one
1887
for (int i = 0; i < filterMethods.size(); i++) {
1888                CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(i);
1889                if (currentFilter.getFilterName().equals(filterMethodName)) {
1890                    filterMethod = currentFilter;
1891                    break;
1892                }
1893            }
1894            // the chosen filter does not exist, use the first one!
1895
if (filterMethod == null) {
1896                filterMethod = (CmsFilterMethod)filterMethods.firstElement();
1897            }
1898
1899            // now apply the filter with the cms object, the filter method and additional user parameters
1900
tableContent = (Vector JavaDoc)cdClass.getMethod("applyFilter", new Class JavaDoc[] {CmsObject.class, CmsFilterMethod.class, String JavaDoc.class}).invoke(null, new Object JavaDoc[] {cms, filterMethod, filterParam});
1901        } catch (InvocationTargetException JavaDoc ite) {
1902            //error occured while applying the filter
1903
if (CmsLog.getLog(this).isWarnEnabled()) {
1904                CmsLog.getLog(this).warn("Apply filter caused an InvocationTargetException", ite);
1905            }
1906            templateSelector = "error";
1907            template.setData("filtername", filterMethodName);
1908            while (ite.getTargetException() instanceof InvocationTargetException JavaDoc) {
1909                ite = ((InvocationTargetException JavaDoc)ite.getTargetException());
1910            }
1911            template.setData("filtererror", ite.getTargetException().getMessage());
1912            session.removeValue(sessionFilterParam);
1913            //session.removeValue("filter");
1914
} catch (NoSuchMethodException JavaDoc nsm) {
1915            if (CmsLog.getLog(this).isWarnEnabled()) {
1916                CmsLog.getLog(this).warn("Apply filter method was not found", nsm);
1917            }
1918            templateSelector = "error";
1919            template.setData("filtername", filterMethodName);
1920            template.setData("filtererror", nsm.getMessage());
1921            session.removeValue(sessionFilterParam);
1922            //session.removeValue("filterparameter");
1923
} catch (Exception JavaDoc e) {
1924            if (CmsLog.getLog(this).isWarnEnabled()) {
1925                CmsLog.getLog(this).warn("Apply filter caused an Exception", e);
1926            }
1927            templateSelector = "error";
1928            template.setData("filtername", filterMethodName);
1929            template.setData("filtererror", e.getMessage());
1930            session.removeValue(sessionFilterParam);
1931            //session.removeValue("filterparameter");
1932
}
1933
1934        //get the number of rows
1935
int rows = tableContent.size();
1936        // get the field methods from the content definition
1937
Vector JavaDoc fieldMethods = new Vector JavaDoc();
1938        try {
1939            fieldMethods = (Vector JavaDoc)cdClass.getMethod("getFieldMethods", new Class JavaDoc[] {CmsObject.class}).invoke(null, new Object JavaDoc[] {cms});
1940        } catch (Exception JavaDoc exc) {
1941            if (CmsLog.getLog(this).isWarnEnabled()) {
1942                CmsLog.getLog(this).warn("getFieldMethods caused an exception", exc);
1943            }
1944            templateSelector = "error";
1945            template.setData("filtername", filterMethodName);
1946            template.setData("filtererror", exc.getMessage());
1947        }
1948
1949        // create output from the table data
1950
String JavaDoc fieldEntry = "";
1951        String JavaDoc id = "";
1952
1953        for (int i = 0; i < rows; i++) {
1954            //init
1955
entry = new StringBuffer JavaDoc();
1956            singleRow = new String JavaDoc();
1957            Object JavaDoc entryObject = new Object JavaDoc();
1958            entryObject = tableContent.elementAt(i); //cd object in row #i
1959

1960            // set the fontformat of the current row
1961
// each entry is formated depending on the state of the cd object
1962
style = this.getStyle(cms, template, entryObject) + ">";
1963            //style entry for backoffice with getUrl method
1964
url_style = this.getStyle(cms, template, entryObject);
1965            //style = ">";
1966
//set data of single row
1967
for (int j = 0; j < columns; j++) {
1968                fieldEntry = "+++ NO VALUE FOUND +++";
1969                // call the field methods
1970
Method JavaDoc getMethod = null;
1971                try {
1972                    getMethod = (Method JavaDoc)fieldMethods.elementAt(j);
1973                } catch (Exception JavaDoc e) {
1974                    if (CmsLog.getLog(this).isWarnEnabled()) {
1975                        CmsLog.getLog(this).warn("Could not get field method for " + (String JavaDoc)columnsVector.elementAt(j) + " - check for correct spelling", e);
1976                    }
1977                }
1978                try {
1979                    //apply methods on content definition object
1980
Object JavaDoc fieldEntryObject = null;
1981                    fieldEntryObject = getMethod.invoke(entryObject, new Object JavaDoc[0]);
1982                    if (fieldEntryObject != null) {
1983                        fieldEntry = fieldEntryObject.toString();
1984                    } else {
1985                        fieldEntry = null;
1986                    }
1987                } catch (InvocationTargetException JavaDoc ite) {
1988                    if (CmsLog.getLog(this).isWarnEnabled()) {
1989                        CmsLog.getLog(this).warn("Backoffice content definition object caused an InvocationTargetException", ite);
1990                    }
1991                } catch (Exception JavaDoc e) {
1992                    if (CmsLog.getLog(this).isWarnEnabled()) {
1993                        CmsLog.getLog(this).warn("Backoffice content definition object: Other exception", e);
1994                    }
1995                }
1996                try {
1997                    id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms);
1998                } catch (Exception JavaDoc e) {
1999                    if (CmsLog.getLog(this).isWarnEnabled()) {
2000                        CmsLog.getLog(this).warn("Backoffice getUniqueId caused an Exception", e);
2001                    }
2002                }
2003
2004                //insert unique id in contextmenue
2005
if (id != null) {
2006                    template.setData("uniqueid", id);
2007                }
2008                //insert table entry
2009
if (fieldEntry != null) {
2010                    try {
2011                        Vector JavaDoc v = new Vector JavaDoc();
2012                        v.addElement(new Integer JavaDoc(id));
2013                        v.addElement(template);
2014                        url = getUrl(cms, null, null, v);
2015                    } catch (Exception JavaDoc e) {
2016                        url = "";
2017                    }
2018                    if (!url.equals("")) {
2019                        // enable url
2020
template.setData("url_style", url_style);
2021                        entry.append(tabledatabegin);
2022                        entry.append(style);
2023                        entry.append(template.getProcessedDataValue("url", this, parameters));
2024                        entry.append(fieldEntry);
2025                        entry.append(tabledataend);
2026                    } else {
2027                        // disable url
2028
entry.append(tabledatabegin);
2029                        entry.append(style);
2030                        entry.append(fieldEntry);
2031                        entry.append(tabledataend);
2032                    }
2033                } else {
2034                    entry.append(tabledatabegin);
2035                    entry.append("");
2036                    entry.append(tabledataend);
2037                }
2038            }
2039            //get the unique id belonging to an entry
2040
try {
2041                id = ((A_CmsContentDefinition)entryObject).getUniqueId(cms);
2042            } catch (Exception JavaDoc e) {
2043                if (CmsLog.getLog(this).isWarnEnabled()) {
2044                    CmsLog.getLog(this).warn("Backoffice: getUniqueId caused an Exception", e);
2045                }
2046            }
2047
2048            //insert unique id in contextmenue
2049
if (id != null) {
2050                template.setData("uniqueid", id);
2051            }
2052
2053            //set the lockstates for the current entry
2054
setExtendedLockstates(cms, template, cdClass, entryObject, parameters);
2055            //set the projectflag for the current entry
2056
setProjectFlag(cms, template, cdClass, entryObject, parameters);
2057            // set the context menu of the current entry
2058
setContextMenu(cms, template, entryObject);
2059            //insert single table row in template
2060
template.setData("entry", entry.toString());
2061            // processed row from template
2062
singleRow = template.getProcessedDataValue("singlerow", this, parameters);
2063            allEntrys.append(tablerowbegin);
2064            allEntrys.append(singleRow);
2065            allEntrys.append(tablerowend);
2066
2067        }
2068
2069        //insert tablecontent in template
2070
template.setData("tablecontent", allEntrys.toString());
2071
2072        //save select box value into session
2073
session.putValue("selectbox", filterMethodName);
2074
2075        //finally start the processing
2076
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
2077        return processResult;
2078    }
2079
2080    /**
2081    * Gets the content of a given template file.
2082    * <P>
2083    * While processing the template file the table entry
2084    * <code>entryTitle<code> will be displayed in the delete dialog
2085    *
2086    * @param cms A_CmsObject Object for accessing system resources
2087    * @param template the template
2088    * @param elementName not used here
2089    * @param parameters get the parameters action for the button activity
2090    * and id for the used content definition instance object
2091    * @param templateSelector template section that should be processed.
2092    * @return Processed content of the given template file.
2093    * @throws CmsException if something goes wrong
2094    */

2095
2096    private byte[] getContentLock(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
2097
2098        byte[] processResult = null;
2099
2100        // now check if the "do you really want to lock" dialog should be shown.
2101
CmsUserSettings settings = new CmsUserSettings(cms);
2102
2103        if (!settings.getDialogShowLock()) {
2104            parameters.put("action", "go");
2105        }
2106
2107        // session will be created or fetched
2108
CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
2109        //get the class of the content definition
2110
Class JavaDoc cdClass = getContentDefinitionClass();
2111
2112        CmsUUID actUserId = cms.getRequestContext().currentUser().getId();
2113        //get (stored) id parameter
2114
String JavaDoc id = (String JavaDoc)parameters.get("id");
2115        if (id == null)
2116            id = "";
2117        /*if (id != "") {
2118            session.putValue("idsave", id);
2119        } else {
2120            String idsave = (String) session.getValue("idsave");
2121            if (idsave == null)
2122                idsave = "";
2123            id = idsave;
2124            session.removeValue("idsave");
2125        } */

2126
2127        parameters.put("idlock", id);
2128
2129        // get value of hidden input field action
2130
String JavaDoc action = (String JavaDoc)parameters.get("action");
2131        //no button pressed, go to the default section!
2132
if (action == null || action.equals("")) {
2133            //lock dialog, displays the title of the entry to be changed in lockstate
2134
templateSelector = "lock";
2135            CmsUUID contentId = new CmsUUID(id);
2136
2137            CmsUUID lockedByUserId = CmsUUID.getNullUUID();
2138
2139            // try {
2140
// contentId = Integer.valueOf(id);
2141
// } catch (Exception e) {
2142
// lockedByUserId = CmsUUID.getNullUUID();
2143
// //access content definition object specified by id through reflection
2144
// Object o = null;
2145
// o = getContentDefinition(cms, cdClass, id);
2146
// try {
2147
// lockedByUserId = ((A_CmsContentDefinition) o).getLockstate();
2148
// /*Method getLockstateMethod = (Method) cdClass.getMethod("getLockstate", new Class[] {});
2149
// ls = (int) getLockstateMethod.invoke(o, new Object[0]); */
2150
// } catch (Exception exc) {
2151
// exc.printStackTrace();
2152
// }
2153
// }
2154

2155            //access content definition object specified by id through reflection
2156
Object JavaDoc o = null;
2157            if (contentId != null) {
2158                o = getContentDefinition(cms, cdClass, contentId);
2159                try {
2160                    lockedByUserId = ((A_CmsContentDefinition)o).getLockstate();
2161                } catch (Exception JavaDoc e) {
2162                    if (CmsLog.getLog(this).isWarnEnabled()) {
2163                        CmsLog.getLog(this).warn(e.getMessage());
2164                    }
2165                }
2166            } else {
2167                o = getContentDefinition(cms, cdClass, id);
2168                try {
2169                    lockedByUserId = ((A_CmsContentDefinition)o).getLockstate();
2170                } catch (Exception JavaDoc e) {
2171                    if (CmsLog.getLog(this).isWarnEnabled()) {
2172                        CmsLog.getLog(this).warn(e.getMessage());
2173                    }
2174                }
2175            }
2176            //create appropriate class name with underscores for labels
2177
String JavaDoc moduleName = "";
2178            moduleName = getClass().toString(); //get name
2179
moduleName = moduleName.substring(5); //remove 'class' substring at the beginning
2180
moduleName = moduleName.trim();
2181            moduleName = moduleName.replace('.', '_'); //replace dots with underscores
2182
//create new language file object
2183
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
2184            //get the dialog from the langauge file and set it in the template
2185
if (!lockedByUserId.isNullUUID() && !lockedByUserId.equals(actUserId)) {
2186                // "lock"
2187
template.setData("locktitle", lang.getLanguageValue("messagebox.title.lockchange"));
2188                template.setData("lockstate", lang.getLanguageValue("messagebox.message1.lockchange"));
2189            }
2190            if (lockedByUserId.isNullUUID()) {
2191                // "nolock"
2192
template.setData("locktitle", lang.getLanguageValue("messagebox.title.lock"));
2193                template.setData("lockstate", lang.getLanguageValue("messagebox.message1.lock"));
2194            }
2195            if (lockedByUserId.equals(actUserId)) {
2196                template.setData("locktitle", lang.getLanguageValue("messagebox.title.unlock"));
2197                template.setData("lockstate", lang.getLanguageValue("messagebox.message1.unlock"));
2198            }
2199
2200            //set the title of the selected entry
2201
template.setData("newsentry", id);
2202
2203            //go to default template section
2204
template.setData("setaction", "default");
2205            parameters.put("action", "done");
2206
2207            // confirmation button pressed, process data!
2208
} else {
2209            templateSelector = "done";
2210
2211            //access content definition constructor by reflection
2212
CmsUUID contentId = new CmsUUID(id);
2213
2214            CmsUUID lockedByUserId = CmsUUID.getNullUUID();
2215
2216            //call the appropriate content definition constructor
2217
Object JavaDoc o = null;
2218            o = getContentDefinition(cms, cdClass, contentId);
2219            try {
2220                lockedByUserId = ((A_CmsContentDefinition)o).getLockstate();
2221            } catch (Exception JavaDoc e) {
2222                if (CmsLog.getLog(this).isWarnEnabled()) {
2223                    CmsLog.getLog(this).warn(e.getMessage());
2224                }
2225            }
2226
2227            try {
2228                lockedByUserId = ((A_CmsContentDefinition)o).getLockstate();
2229            } catch (Exception JavaDoc e) {
2230                if (CmsLog.getLog(this).isWarnEnabled()) {
2231                    CmsLog.getLog(this).warn("Method getLockstate caused an exception", e);
2232                }
2233            }
2234
2235            //show the possible cases of a lockstate in the template
2236
//and change lockstate in content definition (and in DB or VFS)
2237
if (lockedByUserId.equals(actUserId)) {
2238                if (isExtendedList()) {
2239                    // if its an extended list check if the current project is the same as the
2240
// project, in which the resource is locked
2241
int curProjectId = cms.getRequestContext().currentProject().getId();
2242                    int lockedInProject = -1;
2243                    try {
2244                        lockedInProject = ((I_CmsExtendedContentDefinition)o).getLockedInProject();
2245                    } catch (Exception JavaDoc e) {
2246                        if (CmsLog.getLog(this).isWarnEnabled()) {
2247                            CmsLog.getLog(this).warn("Method getLockstate caused an exception", e);
2248                        }
2249                    }
2250                    if (curProjectId == lockedInProject) {
2251                        //unlock project
2252
try {
2253                            ((A_CmsContentDefinition)o).setLockstate(CmsUUID.getNullUUID());
2254                        } catch (Exception JavaDoc e) {
2255                            if (CmsLog.getLog(this).isWarnEnabled()) {
2256                                CmsLog.getLog(this).warn("Method setLockstate caused an exception", e);
2257                            }
2258                        }
2259                    } else {
2260                        //steal lock
2261
try {
2262                            ((A_CmsContentDefinition)o).setLockstate(actUserId);
2263                        } catch (Exception JavaDoc e) {
2264                            if (CmsLog.getLog(this).isWarnEnabled()) {
2265                                CmsLog.getLog(this).warn("Method setLockstate caused an exception", e);
2266                            }
2267                        }
2268                    }
2269                } else {
2270                    // this is not the extended list
2271
//steal lock (userlock -> nolock)
2272
try {
2273                        ((A_CmsContentDefinition)o).setLockstate(CmsUUID.getNullUUID());
2274                    } catch (Exception JavaDoc e) {
2275                        if (CmsLog.getLog(this).isWarnEnabled()) {
2276                            CmsLog.getLog(this).warn("Method setLockstate caused an exception", e);
2277                        }
2278                    }
2279                }
2280                //write to DB
2281
try {
2282                    ((A_CmsContentDefinition)o).write(cms); // reflection is not neccessary!
2283
} catch (Exception JavaDoc e) {
2284                    if (CmsLog.getLog(this).isWarnEnabled()) {
2285                        CmsLog.getLog(this).warn("Method write caused an exception", e);
2286                    }
2287                }
2288                templateSelector = "done";
2289            } else {
2290                if ((!lockedByUserId.isNullUUID()) && (!lockedByUserId.equals(actUserId))) {
2291                    //unlock (lock -> userlock)
2292
try {
2293                        ((A_CmsContentDefinition)o).setLockstate(actUserId);
2294                    } catch (Exception JavaDoc e) {
2295                        if (CmsLog.getLog(this).isWarnEnabled()) {
2296                            CmsLog.getLog(this).warn("Could not set lockstate", e);
2297                        }
2298                    }
2299                    //write to DB
2300
try {
2301                        ((A_CmsContentDefinition)o).write(cms);
2302                    } catch (Exception JavaDoc e) {
2303                        if (CmsLog.getLog(this).isWarnEnabled()) {
2304                            CmsLog.getLog(this).warn("Could not set lockstate", e);
2305                        }
2306                    }
2307                    templateSelector = "done";
2308                } else {
2309                    //lock (nolock -> userlock)
2310
try {
2311                        ((A_CmsContentDefinition)o).setLockstate(actUserId);
2312                    } catch (Exception JavaDoc e) {
2313                        if (CmsLog.getLog(this).isWarnEnabled()) {
2314                            CmsLog.getLog(this).warn("Could not set lockstate", e);
2315                        }
2316                    }
2317                    //write to DB/VFS
2318
try {
2319                        ((A_CmsContentDefinition)o).write(cms);
2320                    } catch (Exception JavaDoc e) {
2321                        if (CmsLog.getLog(this).isWarnEnabled()) {
2322                            CmsLog.getLog(this).warn("Could not write to content definition", e);
2323                        }
2324                    }
2325                }
2326            }
2327        }
2328        //finally start the processing
2329
processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
2330        return processResult;
2331    }
2332    /**
2333     * gets the content definition class method object.<p>
2334     *
2335     * @param cms the cms object
2336     * @param cdClass the content definition class
2337     * @param method a method name of the class
2338     * @param paramClasses the parameter classes
2339     * @param params the parameter values
2340     * @return object content definition class method object
2341     */

2342
2343    private Object JavaDoc getContentMethodObject(CmsObject cms, Class JavaDoc cdClass, String JavaDoc method, Class JavaDoc paramClasses[], Object JavaDoc params[]) {
2344
2345        //return value
2346
Object JavaDoc retObject = null;
2347        if (method != "") {
2348            try {
2349                retObject = cdClass.getMethod(method, paramClasses).invoke(null, params);
2350            } catch (InvocationTargetException JavaDoc ite) {
2351                if (CmsLog.getLog(this).isWarnEnabled()) {
2352                    CmsLog.getLog(this).warn(method + " caused an InvocationTargetException", ite);
2353                }
2354                ite.getTargetException().printStackTrace();
2355            } catch (NoSuchMethodException JavaDoc nsm) {
2356                if (CmsLog.getLog(this).isWarnEnabled()) {
2357                    CmsLog.getLog(this).warn(method + ": Requested method was not found", nsm);
2358                }
2359            } catch (Exception JavaDoc e) {
2360                if (CmsLog.getLog(this).isWarnEnabled()) {
2361                    CmsLog.getLog(this).warn(method + ": Other Exception", e);
2362                }
2363            }
2364        }
2365        return retObject;
2366    }
2367
2368    /**
2369    * The old version of the getContentNew methos. Only available for compatilibility resons.
2370    * Per default, it uses the edit dialog. If you want to use a seperate input form, you have to create
2371    * a new one and write your own getContentNew method in your backoffice class.<p>
2372    *
2373    * @param cms ths cms object
2374    * @param templateFile the template
2375    * @param elementName the element name
2376    * @param parameters the parameters
2377    * @param templateSelector the template selector
2378    * @return the content as byte array
2379    * @throws CmsException if something goes wrong
2380    */

2381    public byte[] getContentNew(CmsObject cms, CmsXmlWpTemplateFile templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
2382        parameters.put("id", "new");
2383        return getContentEdit(cms, templateFile, elementName, parameters, templateSelector);
2384    }
2385
2386    /**
2387    * The new version of the getContentNew methos. Only this one should be used from now on.
2388    * Per default, it uses the edit dialog. If you want to use a seperate input form, you have to create
2389    * a new one and write your own getContentNew method in your backoffice class.<p>
2390    *
2391    * @param cms ths cms object
2392    * @param template the template
2393    * @param cd the content definition
2394    * @param elementName name of an element
2395    * @param keys the parameter keys
2396    * @param parameters the parameters
2397    * @param templateSelector the template selector
2398    * @return the content
2399    * @throws CmsException if something goes wrong
2400    */

2401    public String JavaDoc getContentNew(CmsObject cms, CmsXmlWpTemplateFile template, A_CmsContentDefinition cd, String JavaDoc elementName, Enumeration JavaDoc keys, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
2402        parameters.put("id", "new");
2403        return getContentEdit(cms, template, cd, elementName, keys, parameters, templateSelector);
2404    }
2405
2406    /**
2407    * Gets the content of a edited entry form.
2408    * Has to be overwritten in your backoffice class if the old way of writeing BackOffices is used.
2409    * Only available for compatibility reasons.<p>
2410    *
2411    * @param cms ths cms object
2412    * @param templateFile the template
2413    * @param elementName name of an element
2414    * @param parameters the parameters
2415    * @param templateSelector the template selector
2416    * @return the content
2417    * @throws CmsException if something goes wrong
2418    */

2419    public byte[] getContentEdit(CmsObject cms, CmsXmlWpTemplateFile templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
2420        return null;
2421    }
2422
2423    /**
2424    * Gets the content of a edited entry form.
2425    * Has to be overwritten in your backoffice class if the new way of writeing BackOffices is used.<p>
2426    *
2427    * @param cms ths cms object
2428    * @param templateFile the template
2429    * @param cd the content definition
2430    * @param elementName name of an element
2431    * @param keys the parameter keys
2432    * @param parameters the parameters
2433    * @param templateSelector the template selector
2434    * @return the content
2435    * @throws CmsException if something goes wrong
2436    */

2437    public String JavaDoc getContentEdit(CmsObject cms, CmsXmlWpTemplateFile templateFile, A_CmsContentDefinition cd, String JavaDoc elementName, Enumeration JavaDoc keys, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
2438        return null;
2439    }
2440
2441    /**
2442    * Set the correct lockstates in the list output.
2443    * Lockstates can be "unlocked", "locked", "locked by user" or "no access"
2444    * @param cms The current CmsObject.
2445    * @param template The actual template file.
2446    * @param cdClass The content defintion.
2447    * @param entryObject a content definition instance
2448    * @param parameters All template ands URL parameters.
2449    */

2450    private void setLockstates(CmsObject cms, CmsXmlWpTemplateFile template, Class JavaDoc cdClass, Object JavaDoc entryObject, Hashtable JavaDoc parameters) {
2451
2452        //init lock state vars
2453
String JavaDoc la = "false";
2454        Object JavaDoc laObject = new Object JavaDoc();
2455        CmsUUID lockedByUserId = CmsUUID.getNullUUID();
2456        String JavaDoc lockString = null;
2457        CmsUUID actUserId = cms.getRequestContext().currentUser().getId();
2458        String JavaDoc isLockedBy = null;
2459        boolean hasWriteAccess = false;
2460
2461        //is the content definition object (i.e. the table entry) lockable?
2462
try {
2463            //get the method
2464
Method JavaDoc laMethod = cdClass.getMethod("isLockable", new Class JavaDoc[] {});
2465            //get the returned object
2466
laObject = laMethod.invoke(null, null);
2467        } catch (InvocationTargetException JavaDoc ite) {
2468            if (CmsLog.getLog(this).isWarnEnabled()) {
2469                CmsLog.getLog(this).warn("Method isLockable caused an Invocation target exception", ite);
2470            }
2471        } catch (NoSuchMethodException JavaDoc nsm) {
2472            if (CmsLog.getLog(this).isWarnEnabled()) {
2473                CmsLog.getLog(this).warn("Requested method isLockable was not found", nsm);
2474            }
2475        } catch (Exception JavaDoc e) {
2476            if (CmsLog.getLog(this).isWarnEnabled()) {
2477                CmsLog.getLog(this).warn("Method isLockable caused an exception", e);
2478            }
2479        }
2480
2481        //cast the returned object to a string
2482
la = laObject.toString();
2483        if (la.equals("false")) {
2484            try {
2485                //the entry is not lockable: use standard contextmenue
2486
template.setData("backofficecontextmenue", "backofficeedit");
2487                template.setData("lockedby", template.getDataValue("nolock"));
2488            } catch (Exception JavaDoc e) {
2489                if (CmsLog.getLog(this).isWarnEnabled()) {
2490                    CmsLog.getLog(this).warn("Backoffice setLockstates:'not lockable' section caused an exception", e);
2491                }
2492            }
2493        } else {
2494            //...get the lockstate of an entry
2495
try {
2496                //get the method lockstate
2497
lockedByUserId = ((A_CmsContentDefinition)entryObject).getLockstate();
2498                hasWriteAccess = ((A_CmsContentDefinition)entryObject).hasWriteAccess(cms);
2499            } catch (Exception JavaDoc e) {
2500                if (CmsLog.getLog(this).isWarnEnabled()) {
2501                    CmsLog.getLog(this).warn("Method getLockstate caused an exception", e);
2502                }
2503            }
2504            try {
2505                //show the possible cases of a lockstate in the template
2506
if (lockedByUserId.equals(actUserId)) {
2507                    // lockuser
2508
isLockedBy = cms.getRequestContext().currentUser().getName();
2509                    template.setData("isLockedBy", isLockedBy); // set current users name in the template
2510
lockString = template.getProcessedDataValue("lockuser", this, parameters);
2511                    template.setData("lockedby", lockString);
2512                    template.setData("backofficecontextmenue", "backofficelockuser");
2513                } else {
2514                    if (!lockedByUserId.isNullUUID()) {
2515                        // lock
2516
// set the name of the user who locked the file in the template ...
2517
if (!hasWriteAccess) {
2518                            lockString = template.getProcessedDataValue("noaccess", this, parameters);
2519                            template.setData("lockedby", lockString);
2520                            template.setData("backofficecontextmenue", "backofficenoaccess");
2521                        } else {
2522                            isLockedBy = readSaveUserName(cms, lockedByUserId);
2523                            template.setData("isLockedBy", isLockedBy);
2524                            lockString = template.getProcessedDataValue("lock", this, parameters);
2525                            template.setData("lockedby", lockString);
2526                            template.setData("backofficecontextmenue", "backofficelock");
2527                        }
2528                    } else {
2529                        // nolock
2530
lockString = template.getProcessedDataValue("nolock", this, parameters);
2531                        template.setData("lockedby", lockString);
2532                        template.setData("backofficecontextmenue", "backofficenolock");
2533                    }
2534                }
2535            } catch (Exception JavaDoc e) {
2536                if (CmsLog.getLog(this).isWarnEnabled()) {
2537                    CmsLog.getLog(this).warn("Backoffice setLockstates caused an exception", e);
2538                }
2539            }
2540        }
2541    }
2542
2543    /**
2544    * Set the correct lockstates in the list output for the extended list.
2545    * Lockstates can be "unlocked", "locked", "locked by user" or "no access"
2546    * @param cms The current CmsObject.
2547    * @param template The actual template file.
2548    * @param cdClass The content defintion.
2549    * @param entryObject a content definition instance
2550    * @param parameters All template ands URL parameters.
2551    */

2552    private void setExtendedLockstates(CmsObject cms, CmsXmlWpTemplateFile template, Class JavaDoc cdClass, Object JavaDoc entryObject, Hashtable JavaDoc parameters) {
2553
2554        //init lock state vars
2555
String JavaDoc la = "false";
2556        Object JavaDoc laObject = new Object JavaDoc();
2557        CmsUUID lockedByUserId = CmsUUID.getNullUUID();
2558        String JavaDoc lockString = null;
2559        CmsUUID actUserId = cms.getRequestContext().currentUser().getId();
2560        String JavaDoc isLockedBy = null;
2561        int lockedInProject = -1;
2562        int curProjectId = cms.getRequestContext().currentProject().getId();
2563        boolean hasWriteAccess = false;
2564
2565        //is the content definition object (i.e. the table entry) lockable?
2566
try {
2567            //get the method
2568
Method JavaDoc laMethod = cdClass.getMethod("isLockable", new Class JavaDoc[] {});
2569            //get the returned object
2570
laObject = laMethod.invoke(null, null);
2571        } catch (InvocationTargetException JavaDoc ite) {
2572            if (CmsLog.getLog(this).isWarnEnabled()) {
2573                CmsLog.getLog(this).warn("Method isLockable caused an Invocation target exception", ite);
2574            }
2575        } catch (NoSuchMethodException JavaDoc nsm) {
2576            if (CmsLog.getLog(this).isWarnEnabled()) {
2577                CmsLog.getLog(this).warn("Requested method isLockable was not found", nsm);
2578            }
2579        } catch (Exception JavaDoc e) {
2580            if (CmsLog.getLog(this).isWarnEnabled()) {
2581                CmsLog.getLog(this).warn("Method isLockable caused an exception", e);
2582            }
2583        }
2584
2585        //cast the returned object to a string
2586
la = laObject.toString();
2587        if (la.equals("false")) {
2588            try {
2589                //the entry is not lockable: use standard contextmenue
2590
template.setData("backofficecontextmenue", "backofficeedit");
2591                template.setData("lockedby", template.getDataValue("nolock"));
2592            } catch (Exception JavaDoc e) {
2593                if (CmsLog.getLog(this).isWarnEnabled()) {
2594                    CmsLog.getLog(this).warn("Backoffice setLockstates:'not lockable' section caused an exception", e);
2595                }
2596            }
2597        } else {
2598            //...get the lockstate of an entry
2599
try {
2600                //get the method lockstate
2601
lockedByUserId = ((A_CmsContentDefinition)entryObject).getLockstate();
2602                hasWriteAccess = ((A_CmsContentDefinition)entryObject).hasWriteAccess(cms);
2603            } catch (Exception JavaDoc e) {
2604                if (CmsLog.getLog(this).isWarnEnabled()) {
2605                    CmsLog.getLog(this).warn("Method getLockstate caused an exception", e);
2606                }
2607            }
2608            try {
2609                //show the possible cases of a lockstate in the template
2610
if (lockedByUserId.equals(actUserId)) {
2611                    // lockuser
2612
isLockedBy = cms.getRequestContext().currentUser().getName();
2613                    template.setData("isLockedBy", isLockedBy); // set current users name in the template
2614
// check if the resource is locked in another project
2615
try {
2616                        //get the method lockstate
2617
lockedInProject = ((I_CmsExtendedContentDefinition)entryObject).getLockedInProject();
2618                    } catch (Exception JavaDoc e) {
2619                        if (CmsLog.getLog(this).isWarnEnabled()) {
2620                            CmsLog.getLog(this).warn("Method getLockedInProject caused an exception", e);
2621                        }
2622                    }
2623                    if (lockedInProject == curProjectId) {
2624                        lockString = template.getProcessedDataValue("lockuser", this, parameters);
2625                    } else {
2626                        lockString = template.getProcessedDataValue("lock", this, parameters);
2627                    }
2628                    template.setData("lockedby", lockString);
2629                } else {
2630                    if (!lockedByUserId.isNullUUID()) {
2631                        // lock
2632
// set the name of the user who locked the file in the template ...
2633
if (!hasWriteAccess) {
2634                            lockString = template.getProcessedDataValue("noaccess", this, parameters);
2635                            template.setData("lockedby", lockString);
2636                        } else {
2637                            isLockedBy = readSaveUserName(cms, lockedByUserId);
2638                            template.setData("isLockedBy", isLockedBy);
2639                            lockString = template.getProcessedDataValue("lock", this, parameters);
2640                            template.setData("lockedby", lockString);
2641                        }
2642                    } else {
2643                        // nolock
2644
lockString = template.getProcessedDataValue("nolock", this, parameters);
2645                        template.setData("lockedby", lockString);
2646                    }
2647                }
2648            } catch (Exception JavaDoc e) {
2649                if (CmsLog.getLog(this).isWarnEnabled()) {
2650                    CmsLog.getLog(this).warn("Backoffice setLockstates caused an exception", e);
2651                }
2652            }
2653        }
2654    }
2655    /**
2656     * Set the correct project flag in the list output.
2657     * Lockstates can be "unlocked", "locked", "locked by user" or "no access"
2658     * @param cms The current CmsObject.
2659     * @param template The actual template file.
2660     * @param cdClass The content defintion.
2661     * @param entryObject a content definition instance
2662     * @param parameters All template ands URL parameters.
2663     */

2664    private void setProjectFlag(CmsObject cms, CmsXmlWpTemplateFile template, Class JavaDoc cdClass, Object JavaDoc entryObject, Hashtable JavaDoc parameters) {
2665
2666        //init project flag vars
2667
int state = 0;
2668        int projectId = 1;
2669        String JavaDoc projectFlag = null;
2670        int actProjectId = cms.getRequestContext().currentProject().getId();
2671        String JavaDoc isInProject = null;
2672        // set the default projectflag
2673
try {
2674            template.setData("projectflag", template.getDataValue("noproject"));
2675        } catch (Exception JavaDoc e) {
2676            if (CmsLog.getLog(this).isWarnEnabled()) {
2677                CmsLog.getLog(this).warn("Backoffice setProjectFlag:'no project' section caused an exception", e);
2678            }
2679        }
2680
2681        // get the state of an entry: if its unchanged do not show the flag
2682
try {
2683            state = ((I_CmsExtendedContentDefinition)entryObject).getState();
2684        } catch (Exception JavaDoc e) {
2685            if (CmsLog.getLog(this).isWarnEnabled()) {
2686                CmsLog.getLog(this).warn("Method getState caused an exception", e);
2687            }
2688        }
2689
2690        if (state == 0) {
2691            try {
2692                //the entry is not changed, so do not set the project flag
2693
template.setData("projectflag", template.getDataValue("noproject"));
2694            } catch (Exception JavaDoc e) {
2695                if (CmsLog.getLog(this).isWarnEnabled()) {
2696                    CmsLog.getLog(this).warn("Backoffice setProjectFlag:'no project' section caused an exception", e);
2697                }
2698            }
2699        } else {
2700            // the entry is new, changed or deleted
2701
//...get the project of the entry
2702
try {
2703                projectId = ((I_CmsExtendedContentDefinition)entryObject).getLockedInProject();
2704            } catch (Exception JavaDoc e) {
2705                if (CmsLog.getLog(this).isWarnEnabled()) {
2706                    CmsLog.getLog(this).warn("Method getLockedInProject caused an exception", e);
2707                }
2708            }
2709            try {
2710                //show the possible cases of a lockstate in the template
2711
try {
2712                    isInProject = cms.readProject(projectId).getName();
2713                } catch (CmsException e) {
2714                    isInProject = "";
2715                }
2716                // set project name in the template
2717
template.setData("isInProject", isInProject);
2718                if (projectId == actProjectId) {
2719                    // changed in this project
2720
projectFlag = template.getProcessedDataValue("thisproject", this, parameters);
2721                    template.setData("projectflag", projectFlag);
2722                } else {
2723                    // changed in another project
2724
projectFlag = template.getProcessedDataValue("otherproject", this, parameters);
2725                    template.setData("projectflag", projectFlag);
2726                }
2727            } catch (Exception JavaDoc e) {
2728                if (CmsLog.getLog(this).isWarnEnabled()) {
2729                    CmsLog.getLog(this).warn("Backoffice setLockstates caused an exception", e);
2730                }
2731            }
2732        }
2733    }
2734
2735    /**
2736     * Return the format for the list output.
2737     * States can be "not in project", "unchanged", "changed", "new" or "deleted"
2738     *
2739     * @param cms The current CmsObject
2740     * @param template the template
2741     * @param entryObject a content definition instance
2742     * @return String The format tag for the entry
2743     */

2744    private String JavaDoc getStyle(CmsObject cms, CmsXmlWpTemplateFile template, Object JavaDoc entryObject) {
2745
2746        //init project flag vars
2747
int state = 0;
2748        int projectId = 1;
2749        int actProjectId = cms.getRequestContext().currentProject().getId();
2750        String JavaDoc style = new String JavaDoc();
2751
2752        // get the projectid of the entry
2753
try {
2754            projectId = ((I_CmsExtendedContentDefinition)entryObject).getProjectId();
2755        } catch (Exception JavaDoc e) {
2756            if (CmsLog.getLog(this).isWarnEnabled()) {
2757                CmsLog.getLog(this).warn("Method getProjectId caused an exception", e);
2758            }
2759        }
2760
2761        if (actProjectId == CmsProject.ONLINE_PROJECT_ID) {
2762            style = C_STYLE_UNCHANGED;
2763        } else if (projectId != actProjectId) {
2764            // not is in this project
2765
style = C_STYLE_NOTINPROJECT;
2766        } else {
2767            // get the lockstate of an entry: if its unlocked and changed enable direct publish
2768
try {
2769                ((A_CmsContentDefinition)entryObject).getLockstate();
2770            } catch (Exception JavaDoc e) {
2771                if (CmsLog.getLog(this).isWarnEnabled()) {
2772                    CmsLog.getLog(this).warn("Method getLockstate caused an exception", e);
2773                }
2774            }
2775            // get the state of an entry: if its unchanged do not change the font
2776
try {
2777                state = ((I_CmsExtendedContentDefinition)entryObject).getState();
2778            } catch (Exception JavaDoc e) {
2779                if (CmsLog.getLog(this).isWarnEnabled()) {
2780                    CmsLog.getLog(this).warn("Method getState caused an exception", e);
2781                }
2782            }
2783
2784            switch (state) {
2785                case CmsResource.STATE_NEW :
2786                    style = C_STYLE_NEW;
2787                    break;
2788                case CmsResource.STATE_CHANGED :
2789                    style = C_STYLE_CHANGED;
2790                    break;
2791                case CmsResource.STATE_DELETED :
2792                    style = C_STYLE_DELETED;
2793                    break;
2794                default :
2795                    style = C_STYLE_UNCHANGED;
2796                    break;
2797            }
2798        }
2799        // if there was an exception return an empty string
2800
return style;
2801    }
2802
2803    /**
2804     * Set the context menu for the current list entry.<p>
2805     *
2806     * @param cms The current CmsObject
2807     * @param template The current template
2808     * @param entryObject a content definition instance
2809     */

2810    private void setContextMenu(CmsObject cms, CmsXmlWpTemplateFile template, Object JavaDoc entryObject) {
2811
2812        //init project flag vars
2813
int state = 0;
2814        CmsUUID lockedByUserId = CmsUUID.getNullUUID();
2815        int projectId = 1;
2816        int lockedInProject = -1;
2817        int actProjectId = cms.getRequestContext().currentProject().getId();
2818
2819        // get the projectid of the entry
2820
try {
2821            projectId = ((I_CmsExtendedContentDefinition)entryObject).getProjectId();
2822        } catch (Exception JavaDoc e) {
2823            if (CmsLog.getLog(this).isWarnEnabled()) {
2824                CmsLog.getLog(this).warn("Method getProjectId caused an exception", e);
2825            }
2826        }
2827
2828        if (actProjectId == CmsProject.ONLINE_PROJECT_ID) {
2829            template.setData("backofficecontextmenue", "backofficeonline");
2830        } else if (projectId != actProjectId) {
2831            // not is in this project
2832
template.setData("backofficecontextmenue", "backofficenoaccess");
2833        } else {
2834            // get the lockstate of an entry: if its unlocked and changed enable direct publish
2835
try {
2836                lockedByUserId = ((A_CmsContentDefinition)entryObject).getLockstate();
2837            } catch (Exception JavaDoc e) {
2838                if (CmsLog.getLog(this).isWarnEnabled()) {
2839                    CmsLog.getLog(this).warn("Method getLockstate caused an exception", e);
2840                }
2841            }
2842            // get the state of an entry: if its unchanged do not change the font
2843
try {
2844                state = ((I_CmsExtendedContentDefinition)entryObject).getState();
2845            } catch (Exception JavaDoc e) {
2846                if (CmsLog.getLog(this).isWarnEnabled()) {
2847                    CmsLog.getLog(this).warn("Method getState caused an exception", e);
2848                }
2849            }
2850            if (lockedByUserId.isNullUUID()) {
2851                if (state == CmsResource.STATE_UNCHANGED) {
2852                    template.setData("backofficecontextmenue", "backofficenolock");
2853                } else if (state == CmsResource.STATE_DELETED) {
2854                    template.setData("backofficecontextmenue", "backofficedeleted");
2855                } else {
2856                    template.setData("backofficecontextmenue", "backofficenolockchanged");
2857                }
2858            } else if (lockedByUserId.equals(cms.getRequestContext().currentUser().getId())) {
2859                // check if the resource is locked in another project
2860
try {
2861                    lockedInProject = ((I_CmsExtendedContentDefinition)entryObject).getLockedInProject();
2862                } catch (Exception JavaDoc e) {
2863                    if (CmsLog.getLog(this).isWarnEnabled()) {
2864                        CmsLog.getLog(this).warn("Method getLockedInProject caused an exception", e);
2865                    }
2866                }
2867                if (lockedInProject == actProjectId) {
2868                    template.setData("backofficecontextmenue", "backofficelockuser");
2869                } else {
2870                    template.setData("backofficecontextmenue", "backofficelock");
2871                }
2872            } else {
2873                template.setData("backofficecontextmenue", "backofficelock");
2874            }
2875        }
2876    }
2877
2878    /**
2879     * Checks if the extended list should be used for displaying the cd
2880     *
2881     * @return boolean Is true the extended list should be used
2882     */

2883    public boolean isExtendedList() {
2884        return false;
2885    }
2886
2887    /**
2888     * This method creates the selectbox in the head-frame
2889     *
2890     * @param cms the cms object
2891     * @param lang the language file
2892     * @param names the names in the select box
2893     * @param values the values
2894     * @param parameters additional paramters
2895     * @return the current entry
2896     * @throws CmsException if something goes wrong
2897     */

2898    public Integer JavaDoc getFilter(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
2899        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
2900        int returnValue = 0;
2901        String JavaDoc uri = cms.getRequestContext().getUri();
2902        String JavaDoc sessionSelectBoxValue = uri + "selectBoxValue";
2903        Vector JavaDoc filterMethods = getFilterMethods(cms);
2904        String JavaDoc tmp = (String JavaDoc)session.getValue(sessionSelectBoxValue);
2905        if (tmp != null) {
2906            returnValue = Integer.parseInt(tmp);
2907        }
2908        for (int i = 0; i < filterMethods.size(); i++) {
2909            CmsFilterMethod currentFilter = (CmsFilterMethod)filterMethods.elementAt(i);
2910            //insert filter in the template selectbox
2911
names.addElement(currentFilter.getFilterName());
2912            values.addElement("" + i);
2913        }
2914        return new Integer JavaDoc(returnValue);
2915    }
2916
2917    /**
2918     * User method that handles a checkbox in the input form of the backoffice.<p>
2919     *
2920     * @param cms the cms object
2921     * @param tagcontent the body content of the tag
2922     * @param doc the xml document
2923     * @param userObject additional data
2924     * @return the checkbox definition
2925     * @throws CmsException if something goes wrong
2926     */

2927    public Object JavaDoc handleCheckbox(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException {
2928        Hashtable JavaDoc parameters = (Hashtable JavaDoc)userObject;
2929        String JavaDoc returnValue = "";
2930        String JavaDoc selected = (String JavaDoc)parameters.get(tagcontent);
2931        if (selected != null && selected.equals("on")) {
2932            returnValue = "checked";
2933        }
2934        return returnValue;
2935    }
2936
2937    /**
2938    * Get the all available filter methods.
2939    * @param cms The actual CmsObject
2940    * @return Vector of Filter Methods
2941    */

2942    private Vector JavaDoc getFilterMethods(CmsObject cms) {
2943        Vector JavaDoc filterMethods = new Vector JavaDoc();
2944        Class JavaDoc cdClass = getContentDefinitionClass();
2945        try {
2946            filterMethods = (Vector JavaDoc)cdClass.getMethod("getFilterMethods", new Class JavaDoc[] {CmsObject.class}).invoke(null, new Object JavaDoc[] {cms});
2947        } catch (InvocationTargetException JavaDoc ite) {
2948            //error occured while applying the filter
2949
if (CmsLog.getLog(this).isWarnEnabled()) {
2950                CmsLog.getLog(this).warn("InvocationTargetException", ite);
2951            }
2952        } catch (NoSuchMethodException JavaDoc nsm) {
2953            if (CmsLog.getLog(this).isWarnEnabled()) {
2954                CmsLog.getLog(this).warn("Requested method was not found", nsm);
2955            }
2956        } catch (Exception JavaDoc e) {
2957            if (CmsLog.getLog(this).isWarnEnabled()) {
2958                CmsLog.getLog(this).warn("Problem occured with your filter methods", e);
2959            }
2960        }
2961        return filterMethods;
2962    }
2963
2964    /**
2965     * This method creates the selectbox with all avaiable Pages to select from.
2966     *
2967     * @param cms the cms object
2968     * @param lang the language file
2969     * @param names the names of the options
2970     * @param values the values ogf the options
2971     * @param parameters additional parameters
2972     * @return the selected entry
2973     * @throws CmsException if something goes wrong
2974     */

2975    public Integer JavaDoc getSelectedPage(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
2976
2977        int returnValue = 0;
2978        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
2979        // get all aviable template selectors
2980
Vector JavaDoc templateSelectors = (Vector JavaDoc)session.getValue("backofficepageselectorvector");
2981        // get the actual template selector
2982
String JavaDoc selectedPage = (String JavaDoc)parameters.get("backofficepage");
2983        if (selectedPage == null) {
2984            selectedPage = "";
2985        }
2986
2987        // now build the names and values for the selectbox
2988
if (templateSelectors != null) {
2989            for (int i = 0; i < templateSelectors.size(); i++) {
2990                String JavaDoc selector = (String JavaDoc)templateSelectors.elementAt(i);
2991                names.addElement(selector);
2992                values.addElement(selector);
2993                // check for the selected item
2994
if (selectedPage.equals(selector)) {
2995                    returnValue = i;
2996                }
2997            }
2998        }
2999        session.putValue("backofficeselectortransfer", values);
3000        session.putValue("backofficeselectedtransfer", new Integer JavaDoc(returnValue));
3001        return new Integer JavaDoc(returnValue);
3002    }
3003
3004    /**
3005    * This method contains the code used by the getContent method when the new form of the backoffice is processed.
3006    * It automatically gets all the data from the "getXYZ" methods and sets it in the correct datablock of the
3007    * template.<p>
3008    *
3009    * @param cms The actual CmsObject.
3010    * @param id The id of the content definition object to be edited.
3011    * @param cd the content definition.
3012    * @param session The current user session.
3013    * @param template The template file.
3014    * @param elementName The emelentName of the template mechanism.
3015    * @param parameters All parameters of this request.
3016    * @param templateSelector The template selector.
3017    * @return Content of the template, as an array of bytes.
3018    * @throws CmsException if something goes wrong
3019    */

3020    private byte[] getContentNewInternal(CmsObject cms, String JavaDoc id, A_CmsContentDefinition cd, I_CmsSession session, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
3021
3022        //return varlue
3023
byte[] returnProcess = null;
3024        //error storage
3025
String JavaDoc error = "";
3026        // action value of backoffice buttons
3027
String JavaDoc action = (String JavaDoc)parameters.get("action");
3028
3029        // get the correct template selector
3030
templateSelector = getTemplateSelector(cms, template, parameters, templateSelector);
3031
3032        //process the template for entering the data
3033
// first try to do it in the old way to be compatible to the existing modules.
3034
returnProcess = getContentNew(cms, template, elementName, parameters, templateSelector);
3035
3036        // there was no returnvalue, so the BO uses the new getContentNew method
3037
if (returnProcess == null) {
3038
3039            //try to get the CD form the session
3040
cd = (A_CmsContentDefinition)session.getValue(this.getContentDefinitionClass().getName());
3041            if (cd == null) {
3042                //get a new, empty content definition
3043
cd = (A_CmsContentDefinition)this.getContentDefinition(cms, this.getContentDefinitionClass());
3044            }
3045            //get all existing parameters
3046
Enumeration JavaDoc keys = parameters.keys();
3047
3048            //call the new getContentEdit method
3049
error = getContentNew(cms, template, cd, elementName, keys, parameters, templateSelector);
3050
3051            // get all getXVY methods to automatically get the data from the CD
3052
Vector JavaDoc methods = this.getGetMethods(cd);
3053            // get all setXVY methods to automatically set the data into the CD
3054
Hashtable JavaDoc setMethods = this.getSetMethods(cd);
3055            //set all data from the parameters into the CD
3056
this.fillContentDefinition(cms, cd, parameters, setMethods);
3057
3058            // store the modified CD in the session
3059
session.putValue(this.getContentDefinitionClass().getName(), cd);
3060
3061            // check if there was an error found in the input form
3062
if (!error.equals("")) {
3063                template.setData("error", template.getProcessedDataValue("errormsg") + error);
3064            } else {
3065                template.setData("error", "");
3066            }
3067
3068            // now check if one of the exit buttons is used
3069
templateSelector = getContentButtonsInternal(cms, cd, session, template, parameters, templateSelector, action, error);
3070
3071            //now set all the data from the CD into the template
3072
this.setDatablocks(cms, template, cd, methods);
3073
3074            returnProcess = startProcessing(cms, template, "", parameters, templateSelector);
3075        }
3076
3077        //finally retrun processed data
3078
return returnProcess;
3079    }
3080
3081    /**
3082     * This method contains the code used by the getContent method when the edit form of the backoffice is processed.
3083     * It automatically gets all the data from the "getXYZ" methods and sets it in the correct datablock of the
3084     * template.
3085     * @param cms The actual CmsObject.
3086     * @param id The id of the content definition object to be edited.
3087     * @param cd the content definition.
3088     * @param session The current user session.
3089     * @param template The template file.
3090     * @param elementName The emelentName of the template mechanism.
3091     * @param parameters All parameters of this request.
3092     * @param templateSelector The template selector.
3093     * @return Content of the template, as an array of bytes.
3094     * @throws CmsException if something goes wrong
3095     */

3096    private byte[] getContentEditInternal(CmsObject cms, String JavaDoc id, A_CmsContentDefinition cd, I_CmsSession session, CmsXmlWpTemplateFile template, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
3097
3098        //return varlue
3099
byte[] returnProcess = null;
3100        //error storage
3101
String JavaDoc error = "";
3102        // action value of backoffice buttons
3103
String JavaDoc action = (String JavaDoc)parameters.get("action");
3104
3105        // get the correct template selector
3106
templateSelector = getTemplateSelector(cms, template, parameters, templateSelector);
3107
3108        //process the template for editing the data
3109
// first try to do it in the old way to be compatible to the existing modules.
3110
returnProcess = getContentEdit(cms, template, elementName, parameters, templateSelector);
3111
3112        // there was no returnvalue, so the BO uses the new getContentEdit method
3113
if (returnProcess == null) {
3114            //try to get the CD form the session
3115
cd = (A_CmsContentDefinition)session.getValue(this.getContentDefinitionClass().getName());
3116            if (cd == null) {
3117                // not successful, so read new content definition with given id
3118
CmsUUID contentId = new CmsUUID(id);
3119                cd = (A_CmsContentDefinition)this.getContentDefinition(cms, this.getContentDefinitionClass(), contentId);
3120            }
3121
3122            //get all existing parameters
3123
Enumeration JavaDoc keys = parameters.keys();
3124            //call the new getContentEdit method
3125
error = getContentEdit(cms, template, cd, elementName, keys, parameters, templateSelector);
3126
3127            // get all getXVY methods to automatically get the data from the CD
3128
Vector JavaDoc getMethods = this.getGetMethods(cd);
3129
3130            // get all setXVY methods to automatically set the data into the CD
3131
Hashtable JavaDoc setMethods = this.getSetMethods(cd);
3132
3133            //set all data from the parameters into the CD
3134
this.fillContentDefinition(cms, cd, parameters, setMethods);
3135
3136            // store the modified CD in the session
3137
session.putValue(this.getContentDefinitionClass().getName(), cd);
3138
3139            //care about the previewbutten, if getPreviewUrl is empty, the preview button will not be displayed in the template
3140
String JavaDoc previewButton = null;
3141            try {
3142                previewButton = getPreviewUrl(cms, null, null, null);
3143            } catch (Exception JavaDoc e) { }
3144            if (!((previewButton == null) || (previewButton.equals("")))) {
3145                session.putValue("weShallDisplayThePreviewButton", previewButton + "?id=" + cd.getUniqueId(cms));
3146            }
3147
3148            // check if there was an error found in the input form
3149
if (!error.equals("")) {
3150                template.setData("error", template.getProcessedDataValue("errormsg") + error);
3151            } else {
3152                template.setData("error", "");
3153            }
3154
3155            // now check if one of the exit buttons is used
3156
templateSelector = getContentButtonsInternal(cms, cd, session, template, parameters, templateSelector, action, error);
3157
3158            //now set all the data from the CD into the template
3159
this.setDatablocks(cms, template, cd, getMethods);
3160
3161            returnProcess = startProcessing(cms, template, "", parameters, templateSelector);
3162        }
3163
3164        //finally return processed data
3165
return returnProcess;
3166    }
3167
3168    /** This method checks the three function buttons on the backoffice edit/new template.
3169     * The following actions are excecuted: <ul>
3170     * <li>Save: Save the CD to the database if plausi shows no error, return to the edit/new template.</li>
3171     * <li>Save & Exit: Save the CD to the database if plausi shows no error, return to the list view. </li>
3172     * <li>Exit: Return to the list view without saving. </li>
3173     * </ul>
3174     *
3175     * @param cms The actual CmsObject.
3176     * @param cd The acutal content definition.
3177     * @param session The current user session.
3178     * @param template The template file.
3179     * @param parameters All parameters of this request.
3180     * @param templateSelector The template selector.
3181     * @param action the selected action
3182     * @param error an error message
3183     * @return The template selector.
3184     * @throws CmsException if something goes wrong
3185     */

3186    private String JavaDoc getContentButtonsInternal(CmsObject cms, A_CmsContentDefinition cd, I_CmsSession session, CmsXmlWpTemplateFile template, Hashtable JavaDoc parameters, String JavaDoc templateSelector, String JavaDoc action, String JavaDoc error) throws CmsException {
3187
3188        // storage for possible errors during plausibilization
3189
Vector JavaDoc errorCodes = null;
3190        // storage for a single error code
3191
String JavaDoc errorCode = null;
3192        // storage for the field where an error occured
3193
String JavaDoc errorField = null;
3194        // storage for the error type
3195
String JavaDoc errorType = null;
3196        // the complete error text displayed on the template
3197
//String error=null;
3198
// check if one of the exit buttons is used
3199

3200        if (action != null) {
3201            // there was no button selected, so the selectbox was used. Do a check of the input fileds.
3202
if ((!action.equals("save")) && (!action.equals("saveexit")) && (!action.equals("exit"))) {
3203                try {
3204                    cd.check(false);
3205                    // put value of last used templateselector in session
3206
session.putValue("backofficepagetemplateselector", templateSelector);
3207                } catch (CmsPlausibilizationException plex) {
3208                    // there was an error during plausibilization, so create an error text
3209
errorCodes = plex.getErrorCodes();
3210                    //loop through all errors
3211
for (int i = 0; i < errorCodes.size(); i++) {
3212                        errorCode = (String JavaDoc)errorCodes.elementAt(i);
3213                        // try to get an error message that fits thos this error code exactly
3214
if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode)) {
3215                            error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode);
3216                        } else {
3217                            // now check if there is a general error message for this field
3218
errorField = errorCode.substring(0, errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR));
3219                            if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField)) {
3220                                error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField);
3221                            } else {
3222                                // now check if there is at least a general error messace for the error type
3223
errorType = errorCode.substring(errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR) + 1, errorCode.length());
3224                                if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType)) {
3225                                    error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType);
3226                                } else {
3227                                    // no error dmessage was found, so generate a default one
3228
error += "[" + errorCode + "]";
3229                                }
3230                            }
3231                        }
3232                    }
3233                    //check if there is an introtext for the errors
3234
if (template.hasData("errormsg")) {
3235                        error = template.getProcessedDataValue("errormsg") + error;
3236                    }
3237                    template.setData("error", error);
3238                    if (session.getValue("backofficepagetemplateselector") != null) {
3239
3240                        templateSelector = (String JavaDoc)session.getValue("backofficepagetemplateselector");
3241                        parameters.put("backofficepage", templateSelector);
3242
3243                    } else {
3244                        templateSelector = null;
3245                    }
3246
3247                } // catch
3248
}
3249            // the same or save&exit button were pressed, so save the content definition to the
3250
// database
3251
if (((action.equals("save")) || (action.equals("saveexit"))) && (error.equals(""))) {
3252                try {
3253                    // first check if all plausibilization was ok
3254

3255                    cd.check(true);
3256
3257                    // unlock resource if save&exit was selected
3258
/* if (action.equals("saveexit")) {
3259                      cd.setLockstate(-1);
3260                    } */

3261
3262                    // write the data to the database
3263
cd.write(cms);
3264
3265                    //care about the previewbutten, if getPreviewUrl is empty, the preview button will not be displayed in the template
3266
String JavaDoc previewButton = null;
3267                    try {
3268                        previewButton = getPreviewUrl(cms, null, null, null);
3269                    } catch (Exception JavaDoc e) { }
3270                    if (!((previewButton == null) || (previewButton.equals("")))) {
3271                        session.putValue("weShallDisplayThePreviewButton", previewButton + "?id=" + cd.getUniqueId(cms));
3272                    }
3273
3274                } catch (CmsPlausibilizationException plex) {
3275
3276                    // there was an error during plausibilization, so create an error text
3277
errorCodes = plex.getErrorCodes();
3278
3279                    //loop through all errors
3280
for (int i = 0; i < errorCodes.size(); i++) {
3281                        errorCode = (String JavaDoc)errorCodes.elementAt(i);
3282
3283                        // try to get an error message that fits thos this error code exactly
3284
if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode)) {
3285                            error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorCode);
3286                        } else {
3287                            // now check if there is a general error message for this field
3288
errorField = errorCode.substring(0, errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR));
3289                            if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField)) {
3290                                error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorField);
3291                            } else {
3292                                // now check if there is at least a general error messace for the error type
3293
errorType = errorCode.substring(errorCode.indexOf(com.opencms.core.I_CmsConstants.C_ERRSPERATOR) + 1, errorCode.length());
3294                                if (template.hasData(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType)) {
3295                                    error += template.getProcessedDataValue(com.opencms.core.I_CmsConstants.C_ERRPREFIX + errorType);
3296                                } else {
3297                                    // no error dmessage was found, so generate a default one
3298
error += "[" + errorCode + "]";
3299                                }
3300                            }
3301                        }
3302
3303                    }
3304
3305                    //check if there is an introtext for the errors
3306
if (template.hasData("errormsg")) {
3307                        error = template.getProcessedDataValue("errormsg") + error;
3308                    }
3309                    template.setData("error", error);
3310
3311                } catch (Exception JavaDoc ex) {
3312                    // there was an error saving the content definition so remove all nescessary values from the
3313
// session
3314
session.removeValue(this.getContentDefinitionClass().getName());
3315                    session.removeValue("backofficepageselectorvector");
3316                    session.removeValue("backofficepagetemplateselector");
3317                    session.removeValue("media");
3318                    session.removeValue("selectedmediaCD");
3319                    session.removeValue("media_position");
3320                    session.removeValue("weShallDisplayThePreviewButton");
3321                    if (CmsLog.getLog(this).isErrorEnabled()) {
3322                        CmsLog.getLog(this).error("Error while saving data to Content Definition", ex);
3323                    }
3324                    throw new CmsLegacyException(ex.getMessage(), CmsLegacyException.C_UNKNOWN_EXCEPTION, ex);
3325                }
3326            } //if (save || saveexit)
3327

3328            // only exit the form if there was no error
3329
if (errorCodes == null) {
3330                // the exit or save&exit buttons were pressed, so return to the list
3331
if ((action.equals("exit")) || ((action.equals("saveexit")) && (error.equals("")))) {
3332                    try {
3333                        // cleanup session
3334
session.removeValue(this.getContentDefinitionClass().getName());
3335                        session.removeValue("backofficepageselectorvector");
3336                        session.removeValue("backofficepagetemplateselector");
3337                        session.removeValue("media");
3338                        session.removeValue("selectedmediaCD");
3339                        session.removeValue("media_position");
3340                        session.removeValue("weShallDisplayThePreviewButton");
3341
3342                        //do the redirect
3343
// to do: replace the getUri method with getPathInfo if aviable
3344
//String uri= cms.getRequestContext().getUri();
3345
//uri = "/"+uri.substring(1,uri.lastIndexOf("/"));
3346
//CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(uri);
3347
//return null;
3348
// EF 08.11.01: return the templateselector "done"
3349
// there the backoffice url of the module will be called
3350
return "done";
3351                    } catch (Exception JavaDoc e) {
3352                        if (CmsLog.getLog(this).isErrorEnabled()) {
3353                            CmsLog.getLog(this).error("Error while doing redirect ", e);
3354                        }
3355                        throw new CmsLegacyException(e.getMessage(), e);
3356                    }
3357                } // if (exit || saveexit)
3358
} // noerror
3359
} // if (action!=null)
3360
return templateSelector;
3361    }
3362
3363    /**
3364     * This methods collects all "getXYZ" methods of the actual content definition. This is used
3365     * to automatically preset the datablocks of the template with the values stored in the
3366     * content definition.
3367     * @param contentDefinition The actual Content Definition class
3368     * @return Vector of get-methods
3369     */

3370    private Vector JavaDoc getGetMethods(A_CmsContentDefinition contentDefinition) {
3371
3372        Vector JavaDoc getMethods = new Vector JavaDoc();
3373        //get all methods of the CD
3374
Method JavaDoc[] methods = this.getContentDefinitionClass().getMethods();
3375        for (int i = 0; i < methods.length; i++) {
3376            Method JavaDoc m = methods[i];
3377            String JavaDoc name = m.getName().toLowerCase();
3378
3379            //now extract all methods whose name starts with a "get"
3380
// TESTFIX Added "boignore" suffix to prevent BO from calling the method
3381
if (name.startsWith("get") && !(name.endsWith("boignore"))) {
3382                Class JavaDoc[] param = m.getParameterTypes();
3383                //only take those methods that have no parameter and return a String
3384
if (param.length == 0) {
3385
3386                    Class JavaDoc retType = m.getReturnType();
3387                    if (retType.equals(java.lang.String JavaDoc.class)) {
3388                        getMethods.addElement(m);
3389                    }
3390                }
3391            }
3392        } // for
3393
return getMethods;
3394    } //getGetMethods
3395

3396    /**
3397     * This methods collects all "setXYZ" methods of the actual content definition. This is used
3398     * to automatically insert the form parameters into the content definition.
3399     * @param contentDefinition The actual Content Definition class
3400     * @return Hashtable of set-methods.
3401     */

3402    private Hashtable JavaDoc getSetMethods(A_CmsContentDefinition contentDefinition) {
3403        Hashtable JavaDoc setMethods = new Hashtable JavaDoc();
3404        //get all methods of the CD
3405
Method JavaDoc[] methods = this.getContentDefinitionClass().getMethods();
3406        for (int i = 0; i < methods.length; i++) {
3407            Method JavaDoc m = methods[i];
3408            String JavaDoc name = m.getName().toLowerCase();
3409            //now extract all methods whose name starts with a "set"
3410
// TESTFIX Added "boignore" suffix to prevent BO from calling the method
3411
if (name.startsWith("set") && !(name.endsWith("boignore"))) {
3412                Class JavaDoc[] param = m.getParameterTypes();
3413                //only take those methods that have a single string parameter and return nothing
3414
if (param.length == 1) {
3415                    // check if the parameter is a string
3416
if (param[0].equals(java.lang.String JavaDoc.class)) {
3417                        Class JavaDoc retType = m.getReturnType();
3418                        // the return value must be void
3419
if (retType.toString().equals("void")) {
3420                            setMethods.put(m.getName().toLowerCase(), m);
3421                        }
3422                    }
3423                }
3424            }
3425        } // for
3426
return setMethods;
3427    } //getsetMethods
3428

3429    /**
3430     * This method austomatically fills all datablocks in the template that fit to a special name scheme.
3431     * A datablock named "xyz" is filled with the value of a "getXYZ" method form the content defintion.
3432     *
3433     * @param cms the cms object
3434     * @param template The template to set the datablocks in.
3435     * @param contentDefinition The actual content defintion.
3436     * @param methods A vector with all "getXYZ" methods to be used.
3437     * @throws CmsException if something goes wrong.
3438     */

3439    private void setDatablocks(CmsObject cms, CmsXmlWpTemplateFile template, A_CmsContentDefinition contentDefinition, Vector JavaDoc methods) throws CmsException {
3440        String JavaDoc methodName = "";
3441        String JavaDoc datablockName = "";
3442        String JavaDoc value = "";
3443        Method JavaDoc method;
3444
3445        for (int i = 0; i < methods.size(); i++) {
3446            // get the method name
3447
method = (Method JavaDoc)methods.elementAt(i);
3448            methodName = method.getName();
3449            //get the datablock name - the methodname without the leading "get"
3450
datablockName = (methodName.substring(3, methodName.length())).toLowerCase();
3451            //check if the datablock name ends with a "string" if so, remove it from the datablockname
3452
if (datablockName.endsWith("string")) {
3453                datablockName = datablockName.substring(0, datablockName.indexOf("string"));
3454            }
3455            //now call the method to get the value
3456
try {
3457                Object JavaDoc result = method.invoke(contentDefinition, new Object JavaDoc[] {});
3458                // check if the get method returns null (default value of the CD), set the datablock to
3459
// to "" then.
3460
if (result == null) {
3461                    value = "";
3462                } else {
3463                    // cast the result to a string, only strings can be set into datablocks.
3464
value = result + "";
3465                }
3466                template.setData(datablockName, value);
3467
3468                // set the escaped value into datablock for unescaping
3469
String JavaDoc escapedValue = value;
3470                if (!"".equals(escapedValue.trim())) {
3471                    escapedValue = CmsEncoder.escape(escapedValue, cms.getRequestContext().getEncoding());
3472                }
3473                template.setData(datablockName + "escaped", escapedValue);
3474            } catch (Exception JavaDoc e) {
3475                if (CmsLog.getLog(this).isErrorEnabled()) {
3476                    CmsLog.getLog(this).error("Error during automatic call method '" + methodName, e);
3477                }
3478            } // try
3479
} //for
3480
} //setDatablocks
3481

3482    /**
3483     * This method automatically fills the content definition with the values read from the template.
3484     * A method "setXYZ(value)" of the content defintion is automatically called and filled with the
3485     * value of a template input field named "xyz".
3486     * @param cms The current CmsObject.
3487     * @param contentDefinition The actual content defintion.
3488     * @param parameters A hashtable with all template and url parameters.
3489     * @param setMethods A hashtable with all "setXYZ" methods
3490     * @throws CmsException if something goes wrong
3491     */

3492    private void fillContentDefinition(CmsObject cms, A_CmsContentDefinition contentDefinition, Hashtable JavaDoc parameters, Hashtable JavaDoc setMethods) throws CmsException {
3493
3494        Enumeration JavaDoc keys = parameters.keys();
3495        // loop through all values that were returned
3496
while (keys.hasMoreElements()) {
3497            String JavaDoc key = (String JavaDoc)keys.nextElement();
3498            String JavaDoc value = parameters.get(key).toString();
3499
3500            // not check if this parameter might be an uploaded file
3501
boolean isFile = false;
3502            // loop through all uploaded files and check if one of those is equal to the value of
3503
// the tested parameter.
3504
Enumeration JavaDoc uploadedFiles = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getFileNames();
3505            byte[] content = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getFile(value);
3506            while (uploadedFiles.hasMoreElements()) {
3507                String JavaDoc filename = (String JavaDoc)uploadedFiles.nextElement();
3508                // there is a match, so this parameter represents a fileupload.
3509
if (filename.equals(value)) {
3510                    isFile = true;
3511                }
3512            }
3513            // try to find a set method for this parameter
3514
Method JavaDoc m = (Method JavaDoc)setMethods.get("set" + key);
3515
3516            // there was no method found with this name. So try the name "setXYZString" as an alternative.
3517
if (m == null) {
3518                m = (Method JavaDoc)setMethods.get("set" + key + "string");
3519            }
3520            // there was a method found
3521
if (m != null) {
3522                //now call the method to set the value
3523
try {
3524
3525                    m.invoke(contentDefinition, new Object JavaDoc[] {value});
3526
3527                    // this parameter was the name of an uploaded file. Now try to set the file content
3528
// too.
3529
if (isFile) {
3530                        // get the name of the method. It should be "setXYZContent"
3531
String JavaDoc methodName = m.getName() + "Content";
3532                        // now get the method itself.
3533
Method JavaDoc contentMethod = this.getContentDefinitionClass().getMethod(methodName, new Class JavaDoc[] {byte[].class});
3534                        //finally invoke it.
3535
contentMethod.invoke(contentDefinition, new Object JavaDoc[] {content});
3536                    }
3537                } catch (Exception JavaDoc e) {
3538                    if (CmsLog.getLog(this).isErrorEnabled()) {
3539                        CmsLog.getLog(this).error("Error during automatic call method '" + m.getName(), e);
3540                    }
3541                } // try
3542
} //if
3543
} // while
3544
} //fillContentDefiniton
3545

3546    /**
3547     * Checks how many template selectors are available in the backoffice template and selects the
3548     * correct one.
3549     * @param cms The current CmsObject.
3550     * @param template The current template.
3551     * @param parameters All template and URL parameters.
3552     * @param templateSelector The current template selector.
3553     * @return The new template selector.
3554     * @throws CmsException if something goes wrong.
3555     */

3556    private String JavaDoc getTemplateSelector(CmsObject cms, CmsXmlWpTemplateFile template, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
3557        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
3558        //store the old templateSelector in the session
3559
if (templateSelector != null) {
3560            session.putValue("backofficepagetemplateselector", templateSelector);
3561        }
3562        // Vector to store all template selectors in the template
3563
Vector JavaDoc selectors = new Vector JavaDoc();
3564        // Vector to store all useful template selectory in the template
3565
Vector JavaDoc filteredSelectors = new Vector JavaDoc();
3566        selectors = template.getAllSections();
3567        // loop through all templateseletors and find the useful ones
3568
for (int i = 0; i < selectors.size(); i++) {
3569            String JavaDoc selector = (String JavaDoc)selectors.elementAt(i);
3570            if ((!selector.equals(C_DEFAULT_SELECTOR)) && (!selector.equals(C_DONE_SELECTOR))) {
3571                filteredSelectors.addElement(selector);
3572            }
3573        }
3574
3575        String JavaDoc selectedPage = (String JavaDoc)parameters.get("backofficepage");
3576
3577        // check if there is more than one useful template selector. If not, do not display the selectbox.
3578
if (selectors.size() < 4) {
3579            template.setData("BOSELECTOR", "");
3580        }
3581
3582        if (selectedPage != null && selectedPage.length() > 0) {
3583
3584            templateSelector = selectedPage;
3585        } else if (filteredSelectors.size() > 0) {
3586            templateSelector = (String JavaDoc)filteredSelectors.elementAt(0);
3587            session.putValue("backofficepagetemplateselector", templateSelector);
3588        }
3589        session.putValue("backofficepageselectorvector", filteredSelectors);
3590
3591        return templateSelector;
3592    }
3593
3594    /**
3595     * get the accessFlags from the template
3596     *
3597     * @param parameters ??
3598     * @return the access value
3599     */

3600    private int getAccessValue(Hashtable JavaDoc parameters) {
3601        int accessFlag = 0;
3602        for (int i = 0; i <= 8; i++) {
3603            String JavaDoc permissionsAtI = (String JavaDoc)parameters.get("permission_" + i);
3604            if (permissionsAtI != null) {
3605                if (permissionsAtI.equals("on")) {
3606                    accessFlag += new Integer JavaDoc(C_ACCESS_FLAGS[i]).intValue();
3607                }
3608            }
3609        }
3610        if (accessFlag == 0) {
3611            accessFlag = C_DEFAULT_PERMISSIONS;
3612        }
3613        return accessFlag;
3614    }
3615
3616    /**
3617     * Set the accessFlags in the template
3618     *
3619     * @param template the template
3620     * @param accessFlags the access flags
3621     */

3622    private void setAccessValue(CmsXmlWpTemplateFile template, int accessFlags) {
3623        // permissions check boxes
3624
for (int i = 0; i <= 8; i++) {
3625            int accessValueAtI = new Integer JavaDoc(C_ACCESS_FLAGS[i]).intValue();
3626            if ((accessFlags & accessValueAtI) > 0) {
3627                template.setData("permission_" + i, "checked");
3628            } else {
3629                template.setData("permission_" + i, "");
3630            }
3631        }
3632    }
3633
3634    /**
3635     * Set the groups in the template
3636     *
3637     * @param cms the cms object
3638     * @param template the template
3639     * @param groupId id of the group
3640     * @throws CmsException if something goes wrong
3641     */

3642    private void setGroupSelectbox(CmsObject cms, CmsXmlWpTemplateFile template, CmsUUID groupId) throws CmsException {
3643        //get all groups
3644
List JavaDoc cmsGroups = cms.getGroups();
3645        // select box of group
3646
String JavaDoc groupOptions = "";
3647        // name of current group
3648
String JavaDoc groupName = readSaveGroupName(cms, groupId);
3649        for (int i = 0; i < cmsGroups.size(); i++) {
3650            String JavaDoc currentGroupName = ((CmsGroup)cmsGroups.get(i)).getName();
3651            CmsUUID currentGroupId = ((CmsGroup)cmsGroups.get(i)).getId();
3652            template.setData("name", currentGroupName);
3653            template.setData("value", currentGroupId.toString());
3654            if (!groupId.isNullUUID() && groupName.equals(currentGroupName)) {
3655                template.setData("check", "selected");
3656            } else {
3657                template.setData("check", "");
3658            }
3659            groupOptions = groupOptions + template.getProcessedDataValue("selectoption", this);
3660        }
3661        template.setData("groups", groupOptions);
3662        template.setData("groupname", groupName);
3663    }
3664
3665    /**
3666     * Set the owner in the template
3667     *
3668     * @param cms the cms object
3669     * @param template the template
3670     * @param ownerId the id of the owner
3671     * @throws CmsException if something goes wrong
3672     */

3673    private void setOwnerSelectbox(CmsObject cms, CmsXmlWpTemplateFile template, CmsUUID ownerId) throws CmsException {
3674        // select box of owner
3675
String JavaDoc userOptions = "";
3676        List JavaDoc cmsUsers = cms.getUsers();
3677        String JavaDoc ownerName = readSaveUserName(cms, ownerId);
3678        for (int i = 0; i < cmsUsers.size(); i++) {
3679            String JavaDoc currentUserName = ((CmsUser)cmsUsers.get(i)).getName();
3680            CmsUUID currentUserId = ((CmsUser)cmsUsers.get(i)).getId();
3681            template.setData("name", currentUserName);
3682            template.setData("value", currentUserId.toString());
3683            if (!ownerId.isNullUUID() && ownerName.equals(currentUserName)) {
3684                template.setData("check", "selected");
3685            } else {
3686                template.setData("check", "");
3687            }
3688            userOptions = userOptions + template.getProcessedDataValue("selectoption", this);
3689        }
3690        template.setData("users", userOptions);
3691        template.setData("username", ownerName);
3692    }
3693
3694    /**
3695    * user-method to create a checkbox with the according hidden field
3696    * @param cms the CmsObject
3697    * @param tagcontent params of the user-method
3698    * @param doc the xml document
3699    * @param userObject additional data
3700    * @return Object the checkbox definition
3701    * @throws CmsException if something goes wrong
3702    */

3703    public Object JavaDoc checkbox(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws CmsException {
3704        String JavaDoc name = null;
3705        String JavaDoc param = "";
3706        String JavaDoc value = "";
3707        String JavaDoc checked = null;
3708
3709        CmsXmlTemplateFile temp = (CmsXmlTemplateFile)doc;
3710        // separate name from other parameter (if given) ...
3711
int index = tagcontent.indexOf(",");
3712        if (index > -1 && index <= tagcontent.length()) {
3713            name = tagcontent.substring(0, index);
3714            param = tagcontent.substring(index + 1, tagcontent.length());
3715        } else {
3716            name = tagcontent;
3717        }
3718        // find out if the box was already selected ...
3719
value = temp.getDataValue(name);
3720        if (value.equals("on")) {
3721            checked = "checked";
3722        } else {
3723            checked = "";
3724        }
3725
3726        String JavaDoc buf = "<input type=hidden name=\"" + name + "\" value=\"off\">" + "<input type=checkbox name=\"" + name + "\" " + checked + " " + param + ">\n";
3727
3728        return buf.toString();
3729    }
3730}
3731
Popular Tags