KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29
30 package com.opencms.workplace;
31
32 import org.opencms.file.CmsBackupProject;
33 import org.opencms.file.CmsObject;
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.main.CmsException;
36 import org.opencms.util.CmsDateUtil;
37 import org.opencms.workplace.CmsWorkplace;
38
39 import com.opencms.legacy.CmsLegacyException;
40 import com.opencms.template.A_CmsXmlContent;
41
42 import java.lang.reflect.InvocationTargetException JavaDoc;
43 import java.lang.reflect.Method JavaDoc;
44 import java.util.ArrayList JavaDoc;
45 import java.util.Hashtable JavaDoc;
46 import java.util.List JavaDoc;
47
48 import org.w3c.dom.Element JavaDoc;
49
50 /**
51  * Class for building workplace icons. <BR>
52  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;ICON&gt;</code>.
53  *
54  * @author Edna Falkenhan
55  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
56  * @see com.opencms.workplace.CmsXmlWpTemplateFile
57  *
58  * @deprecated Will not be supported past the OpenCms 6 release.
59  */

60
61 public class CmsProjecthistory extends A_CmsWpElement {
62
63     /**
64      * Javascriptmethod, to call for contextlink
65      */

66     private static final String JavaDoc C_PROJECT_UNLOCK = "project_unlock";
67
68     /**
69      * Handling of the special workplace <CODE>&lt;PROJECTHISTORY&gt;</CODE> tags.
70      * <P>
71      * Returns the processed code with the actual elements.
72      * <P>
73      * Projectlists can be referenced in any workplace template by <br>
74      * <CODE>&lt;PROJECTHISTORY /&gt;</CODE>
75      *
76      * @param cms CmsObject Object for accessing resources.
77      * @param n XML element containing the <code>&lt;ICON&gt;</code> tag.
78      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
79      * @param callingObject reference to the calling object <em>(not used here)</em>.
80      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
81      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
82      * @return Processed button.
83      * @throws CmsException
84      */

85
86     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc, Object JavaDoc callingObject,
87             Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
88
89         // Read projectlist parameters
90
String JavaDoc listMethod = n.getAttribute(CmsWorkplaceDefault.C_PROJECTLIST_METHOD);
91
92         // Get list definition and language values
93
CmsXmlWpTemplateFile listdef = getProjectlistDefinitions(cms);
94
95         // call the method for generating projectlist elements
96
Method JavaDoc callingMethod = null;
97         List JavaDoc list = new ArrayList JavaDoc();
98         try {
99             callingMethod = callingObject.getClass().getMethod(listMethod, new Class JavaDoc[] {
100                 CmsObject.class, CmsXmlLanguageFile.class
101             });
102             list = (List JavaDoc)callingMethod.invoke(callingObject, new Object JavaDoc[] {
103                 cms, lang
104             });
105         }
106         catch(NoSuchMethodException JavaDoc exc) {
107
108             // The requested method was not found.
109
throwException("Could not find method " + listMethod + " in calling class "
110                     + callingObject.getClass().getName() + " for generating projectlist content.",
111                     CmsLegacyException.C_NOT_FOUND);
112         }
113         catch(InvocationTargetException JavaDoc targetEx) {
114
115             // the method could be invoked, but throwed a exception
116
// itself. Get this exception and throw it again.
117
Throwable JavaDoc e = targetEx.getTargetException();
118             if(!(e instanceof CmsException)) {
119
120                 // Only print an error if this is NO CmsException
121
throwException("User method " + listMethod + " in calling class "
122                         + callingObject.getClass().getName() + " throwed an exception. "
123                         + e);
124             }
125             else {
126
127                 // This is a CmsException
128
// Error printing should be done previously.
129
throw (CmsException)e;
130             }
131         }
132         catch(Exception JavaDoc exc2) {
133             throwException("User method " + listMethod + " in calling class "
134                     + callingObject.getClass().getName() + " was found but could not be invoked. "
135                     + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
136         }
137
138         /** StringBuffer for the generated output */
139         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
140         listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PROJECTLIST_SNAPLOCK, callingObject, parameters);
141         for(int i = 0;i < list.size();i++) {
142
143             // get the actual project
144
CmsBackupProject project = (CmsBackupProject)list.get(i);
145
146             // get the processed list.
147
setListEntryData(cms, lang, listdef, project);
148             listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_LOCKSTATE, "");
149             listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_MENU, C_PROJECT_UNLOCK);
150
151             listdef.setData(CmsWorkplaceDefault.C_PROJECTLIST_IDX, new Integer JavaDoc(i).toString());
152             result.append(listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PROJECTLIST_DEFAULT, callingObject,
153                     parameters));
154         }
155         return result.toString();
156     }
157
158     /**
159      * Indicates if the results of this class are cacheable.
160      *
161      * @param cms CmsObject Object for accessing system resources
162      * @param templateFile Filename of the template file
163      * @param elementName Element name of this template in our parent template.
164      * @param parameters Hashtable with all template class parameters.
165      * @param templateSelector template section that should be processed.
166      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
167      */

168
169     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
170             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
171         return false;
172     }
173
174     /**
175      * Method to set details about a project into xml-datas.
176      * @param cms The cms-object.
177      * @param lang The language-file.
178      * @param xmlFile The file to set the xml-data into.
179      * @param project The project to get the data from.
180      * @throws CmsException is thrown if something goes wrong.
181      */

182
183     public static void setListEntryData(CmsObject cms, CmsXmlLanguageFile lang,
184             CmsXmlWpTemplateFile xmlFile, CmsBackupProject project) throws CmsException {
185
186         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME, project.getName());
187         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DESCRIPTION, project.getDescription());
188         // get the resources in the project
189
List JavaDoc resources = project.getProjectResources();
190         String JavaDoc reslist = new String JavaDoc();
191         for(int i=0; i < resources.size(); i++){
192             reslist = reslist+(String JavaDoc)resources.get(i);
193             if(i < (resources.size()-1)){
194                 reslist = reslist+"<br>";
195             }
196         }
197         xmlFile.setData("resources", reslist);
198         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTWORKER, project.getGroupName());
199         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTMANAGER, project.getManagerGroupName());
200         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DATECREATED, CmsDateUtil.getDateTimeShort(project.getDateCreated()));
201         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_OWNER, project.getOwnerName());
202         xmlFile.setData("publishdate", CmsDateUtil.getDateTimeShort(project.getPublishingDate()));
203         xmlFile.setData("publishedby", project.getPublishedByName());
204         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME_ESCAPED, CmsEncoder.escape(project.getName(),
205             cms.getRequestContext().getEncoding()));
206         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTID, project.getId() + "");
207         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_STATE, lang.getLanguageValue(CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED));
208     }
209
210     /**
211      * Reads the projectlist definition file.
212      * @param cms The actual cms object
213      * @return Reference to the list defintion file.
214      * @throws CmsException
215      */

216
217     public CmsXmlWpTemplateFile getProjectlistDefinitions(CmsObject cms) throws CmsException {
218         String JavaDoc templatePath = CmsWorkplace.VFS_PATH_WORKPLACE + "administration/project/historyprojects/";
219         m_projectlistdef = new CmsXmlWpTemplateFile(cms, templatePath+"projectlist");
220         return m_projectlistdef;
221     }
222 }
223
Popular Tags