KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.opencms.workplace;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.file.CmsRequestContext;
33 import org.opencms.main.CmsException;
34 import org.opencms.main.OpenCms;
35 import org.opencms.module.CmsModule;
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 modulelist. <BR>
50  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;MODULELIST&gt;</code>.
51  *
52  * Creation date: (31.08.00 15:16:10)
53  * @author Hanjo Riege
54  * @version $Revision: 1.3 $
55  * @see com.opencms.workplace.CmsXmlWpTemplateFile
56  *
57  * @deprecated Will not be supported past the OpenCms 6 release.
58  */

59
60 public class CmsModulelist extends A_CmsWpElement {
61     
62     /**
63      * Handling of the special workplace <CODE>&lt;MODULELIST&gt;</CODE> tags.
64      * <P>
65      * Returns the processed code with the actual elements.
66      * <P>
67      * Projectlists can be referenced in any workplace template by <br>
68      * <CODE>&lt;MODULELIST /&gt;</CODE>
69      *
70      * @param cms CmsObject Object for accessing resources.
71      * @param n XML element containing the <code>&lt;MODULELIST&gt;</code> tag.
72      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
73      * @param callingObject reference to the calling object <em>(not used here)</em>.
74      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
75      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
76      * @return Processed button.
77      * @throws CmsException
78      */

79     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
80             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
81         
82         // Read projectlist parameters
83
String JavaDoc listMethod = n.getAttribute(CmsWorkplaceDefault.C_MODULELIST_METHOD);
84         
85         // Get list definition and language values
86
CmsXmlWpTemplateFile listdef = getModulelistDefinitions(cms);
87         
88         // call the method for generating projectlist elements
89
Method JavaDoc callingMethod = null;
90         Vector JavaDoc list = new Vector JavaDoc();
91         try {
92             callingMethod = callingObject.getClass().getMethod(listMethod, new Class JavaDoc[] {
93                 CmsObject.class, CmsXmlLanguageFile.class
94             });
95             list = (Vector JavaDoc)callingMethod.invoke(callingObject, new Object JavaDoc[] {
96                 cms, lang
97             });
98         }
99         catch(NoSuchMethodException JavaDoc exc) {
100             
101             // The requested method was not found.
102
throwException("Could not find method " + listMethod + " in calling class "
103                     + callingObject.getClass().getName()
104                     + " for generating projectlist content.", CmsLegacyException.C_NOT_FOUND);
105         }
106         catch(InvocationTargetException JavaDoc targetEx) {
107             
108             // the method could be invoked, but throwed a exception
109
// itself. Get this exception and throw it again.
110
Throwable JavaDoc e = targetEx.getTargetException();
111             if(!(e instanceof CmsException)) {
112                 
113                 // Only print an error if this is NO CmsException
114
throwException("User method " + listMethod + " in calling class "
115                         + callingObject.getClass().getName() + " throwed an exception. "
116                         + e);
117             }
118             else {
119                 
120                 // This is a CmsException
121
// Error printing should be done previously.
122
throw (CmsException)e;
123             }
124         }
125         catch(Exception JavaDoc exc2) {
126             throwException("User method " + listMethod + " in calling class "
127                     + callingObject.getClass().getName()
128                     + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
129         }
130         
131         // check if we are in the onlineProject
132
CmsRequestContext reqCont = cms.getRequestContext();
133         if(reqCont.currentProject().isOnlineProject()) {
134             listdef.setData("menue", "menueonline");
135         }
136         else {
137             listdef.setData("menue", "modulemenue");
138         }
139         
140         // StringBuffer for the generated output
141
StringBuffer JavaDoc result = new StringBuffer JavaDoc();
142         for(int i = 0;i < list.size();i++) {
143             String JavaDoc currentModule = (String JavaDoc)list.elementAt(i);
144             listdef.setData(CmsWorkplaceDefault.C_MODULELIST_NAME, currentModule);
145             listdef.setData(CmsWorkplaceDefault.C_MODULELIST_NICE_NAME, OpenCms.getModuleManager().getModule(currentModule).getNiceName());
146             listdef.setData(CmsWorkplaceDefault.C_MODULELIST_VERSION, OpenCms.getModuleManager().getModule(currentModule).getVersion().toString());
147             listdef.setData(CmsWorkplaceDefault.C_MODULELIST_AUTHOR, OpenCms.getModuleManager().getModule(currentModule).getAuthorName());
148             listdef.setData(CmsWorkplaceDefault.C_MODULELIST_DATECREATED, CmsDateUtil.getDateShort(OpenCms.getModuleManager().getModule(currentModule).getDateCreated()));
149             if(OpenCms.getModuleManager().getModule(currentModule).getDateInstalled() == CmsModule.DEFAULT_DATE) {
150                 listdef.setData(CmsWorkplaceDefault.C_MODULELIST_DATEUPLOADED, " - ");
151             }
152             else {
153                 listdef.setData(CmsWorkplaceDefault.C_MODULELIST_DATEUPLOADED, CmsDateUtil.getDateShort(OpenCms.getModuleManager().getModule(currentModule).getDateInstalled()));
154             }
155             listdef.setData(CmsWorkplaceDefault.C_MODULELIST_IDX, new Integer JavaDoc(i).toString());
156             result.append(listdef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_MODULELIST_DEFAULT, callingObject, parameters));
157         }
158         return result.toString();
159     }
160     
161     /**
162      * Indicates if the results of this class are cacheable.
163      *
164      * @param cms CmsObject Object for accessing system resources
165      * @param templateFile Filename of the template file
166      * @param elementName Element name of this template in our parent template.
167      * @param parameters Hashtable with all template class parameters.
168      * @param templateSelector template section that should be processed.
169      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
170      */

171     
172     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
173             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
174         return false;
175     }
176 }
177
Free Books   Free Magazines  
Popular Tags