KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsProjectlist.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.CmsObject;
33 import org.opencms.file.CmsProject;
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.main.CmsException;
36 import org.opencms.util.CmsDateUtil;
37
38 import com.opencms.legacy.CmsLegacyException;
39 import com.opencms.template.A_CmsXmlContent;
40
41 import java.lang.reflect.InvocationTargetException JavaDoc;
42 import java.lang.reflect.Method JavaDoc;
43 import java.util.Hashtable JavaDoc;
44 import java.util.Vector JavaDoc;
45
46 import org.w3c.dom.Element JavaDoc;
47
48 /**
49  * Class for building workplace icons. <BR>
50  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;ICON&gt;</code>.
51  *
52  * @author Andreas Schouten
53  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
54  * @see com.opencms.workplace.CmsXmlWpTemplateFile
55  *
56  * @deprecated Will not be supported past the OpenCms 6 release.
57  */

58
59 public class CmsProjectlist extends A_CmsWpElement {
60     
61     
62     /**
63      * Javascriptmethod, to call for contextlink
64      */

65     private static final String JavaDoc C_PROJECT_LOCK = "project_lock";
66     
67     
68     /**
69      * Javascriptmethod, to call for contextlink
70      */

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

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

187     
188     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
189             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
190         return false;
191     }
192     
193     /**
194      * Method to set details about a project into xml-datas.
195      * @param cms The cms-object.
196      * @param lang The language-file.
197      * @param xmlFile The file to set the xml-data into.
198      * @param project The project to get the data from.
199      * @throws CmsException is thrown if something goes wrong.
200      */

201     
202     public static void setListEntryData(CmsObject cms, CmsXmlLanguageFile lang,
203             CmsXmlWpTemplateFile xmlFile, CmsProject project) throws CmsException {
204         String JavaDoc state;
205         
206         // get the correckt state
207
if(cms.countLockedResources(project.getId()) == 0) {
208             state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_UNLOCKED;
209         }
210         else {
211             state = CmsWorkplaceDefault.C_PROJECTLIST_STATE_LOCKED;
212         }
213         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME, project.getName());
214         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_NAME_ESCAPED, CmsEncoder.escape(project.getName(),
215             cms.getRequestContext().getEncoding()));
216         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTID, project.getId() + "");
217         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DESCRIPTION, project.getDescription());
218         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_STATE, lang.getLanguageValue(state));
219         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTMANAGER, cms.readManagerGroup(project).getName());
220         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_PROJECTWORKER, cms.readGroup(project).getName());
221         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_DATECREATED, CmsDateUtil.getDateTimeShort(project.getDateCreated()));
222         xmlFile.setData(CmsWorkplaceDefault.C_PROJECTLIST_OWNER, cms.readOwner(project).getName());
223     }
224 }
225
Popular Tags