KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

54
55 public class CmsButton extends A_CmsWpElement {
56     
57     /**
58      * Handling of the special workplace <CODE>&lt;BUTTON&gt;</CODE> tags.
59      * <P>
60      * Reads the code of a button from the buttons definition file
61      * and returns the processed code with the actual elements.
62      * <P>
63      * Buttons can be referenced in any workplace template by <br>
64      * <CODE>&lt;BUTTON name="..." action="..." alt="..."/&gt;</CODE>
65      *
66      * @param cms CmsObject Object for accessing resources.
67      * @param n XML element containing the <code>&lt;BUTTON&gt;</code> tag.
68      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
69      * @param callingObject reference to the calling object <em>(not used here)</em>.
70      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
71      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
72      * @return Processed button.
73      * @throws CmsException
74      */

75     
76     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
77             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
78         
79         // Read button parameters
80
String JavaDoc buttonName = n.getAttribute(CmsWorkplaceDefault.C_BUTTON_NAME);
81         String JavaDoc buttonAction = n.getAttribute(CmsWorkplaceDefault.C_BUTTON_ACTION);
82         String JavaDoc buttonAlt = n.getAttribute(CmsWorkplaceDefault.C_BUTTON_ALT);
83         String JavaDoc buttonHref = n.getAttribute(CmsWorkplaceDefault.C_BUTTON_HREF);
84         String JavaDoc buttonMethod = n.getAttribute(CmsWorkplaceDefault.C_BUTTON_METHOD);
85         if(buttonHref == null || "".equals(buttonHref)) {
86             buttonHref = "";
87         }
88         
89         // call the method for activation decision
90
boolean activate = true;
91         if(buttonMethod != null && !"".equals(buttonMethod)) {
92             Method JavaDoc callMethod = null;
93             try {
94                 callMethod = callingObject.getClass().getMethod(buttonMethod, new Class JavaDoc[] {
95                     CmsObject.class, CmsXmlLanguageFile.class, Hashtable JavaDoc.class
96                 });
97                 activate = ((Boolean JavaDoc)callMethod.invoke(callingObject, new Object JavaDoc[] {
98                     cms, lang, parameters
99                 })).booleanValue();
100             }
101             catch(NoSuchMethodException JavaDoc exc) {
102                 
103                 // The requested method was not found.
104
throwException("Could not find button activation method " + buttonMethod
105                         + " in calling class " + callingObject.getClass().getName()
106                         + " for generating icon.", CmsLegacyException.C_NOT_FOUND);
107             }
108             catch(InvocationTargetException JavaDoc targetEx) {
109                 
110                 // the method could be invoked, but throwed a exception
111
// itself. Get this exception and throw it again.
112
Throwable JavaDoc e = targetEx.getTargetException();
113                 if(!(e instanceof CmsException)) {
114                     
115                     throwException("Button activation method " + buttonMethod
116                             + " in calling class " + callingObject.getClass().getName()
117                             + " throwed an exception. " + e);
118                 }
119                 else {
120                     
121                     // This is a CmsException
122
// Error printing should be done previously.
123
throw (CmsException)e;
124                 }
125             }
126             catch(Exception JavaDoc exc2) {
127                 throwException("Button activation method " + buttonMethod
128                         + " in calling class " + callingObject.getClass().getName()
129                         + " was found but could not be invoked. " + exc2);
130             }
131         }
132         
133         // Get button definition and language values
134
CmsXmlWpButtonsDefFile buttondef = getButtonDefinitions(cms);
135         buttonAlt = lang.getLanguageValue(CmsWorkplaceDefault.C_LANG_BUTTON + "." + buttonAlt);
136         
137         // get the processed button.
138
if(activate) {
139             return buttondef.getButton(buttonName, buttonAction, buttonAlt, buttonHref,
140                     callingObject);
141         }
142         else {
143             return buttondef.getDeactivatedButton(buttonName, buttonAction, buttonAlt,
144                     buttonHref, callingObject);
145         }
146     }
147 }
148
Popular Tags