KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsIcon.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.4 $
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 icons. <BR>
46  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;ICON&gt;</code>.
47  *
48  * @author Andreas Schouten
49  * @version $Revision: 1.4 $ $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 CmsIcon extends A_CmsWpElement {
56     
57     /**
58      * Handling of the special workplace <CODE>&lt;ICON&gt;</CODE> tags.
59      * <P>
60      * Returns the processed code with the actual elements.
61      * <P>
62      * Icons can be referenced in any workplace template by <br>
63      * <CODE>&lt;ICON name="..." label="..." action="..." HREF="..." target="..."/&gt;</CODE>
64      *
65      * @param cms CmsObject Object for accessing resources.
66      * @param n XML element containing the <code>&lt;ICON&gt;</code> tag.
67      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
68      * @param callingObject reference to the calling object <em>(not used here)</em>.
69      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
70      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
71      * @return Processed button.
72      * @throws CmsException
73      */

74     
75     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
76             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
77         
78         // Read button parameters
79
String JavaDoc iconName = n.getAttribute(CmsWorkplaceDefault.C_ICON_NAME);
80         String JavaDoc iconLabel = n.getAttribute(CmsWorkplaceDefault.C_ICON_LABEL);
81         String JavaDoc iconAction = n.getAttribute(CmsWorkplaceDefault.C_ICON_ACTION);
82         String JavaDoc iconHref = n.getAttribute(CmsWorkplaceDefault.C_ICON_HREF);
83         String JavaDoc iconTarget = n.getAttribute(CmsWorkplaceDefault.C_ICON_TARGET);
84         String JavaDoc iconActiveMethod = n.getAttribute(CmsWorkplaceDefault.C_ICON_ACTIVE_METHOD);
85         String JavaDoc iconVisibleMethod = n.getAttribute(CmsWorkplaceDefault.C_ICON_VISIBLE_METHOD);
86         if(iconHref == null || "".equals(iconHref)) {
87             iconHref = "";
88         }
89         
90         // call the method for activation decision
91
boolean activate = true;
92         if(iconActiveMethod != null && !"".equals(iconActiveMethod)) {
93             Method JavaDoc groupsMethod = null;
94             try {
95                 groupsMethod = callingObject.getClass().getMethod(iconActiveMethod,
96                         new Class JavaDoc[] {
97                     CmsObject.class, CmsXmlLanguageFile.class, Hashtable JavaDoc.class
98                 });
99                 activate = ((Boolean JavaDoc)groupsMethod.invoke(callingObject, new Object JavaDoc[] {
100                     cms, lang, parameters
101                 })).booleanValue();
102             }
103             catch(NoSuchMethodException JavaDoc exc) {
104                 
105                 // The requested method was not found.
106
throwException("Could not find icon activation method " + iconActiveMethod
107                 + " in calling class " + callingObject.getClass().getName()
108                 + " for generating icon.", CmsLegacyException.C_NOT_FOUND);
109             }
110             catch(InvocationTargetException JavaDoc targetEx) {
111                 
112                 // the method could be invoked, but throwed a exception
113
// itself. Get this exception and throw it again.
114
Throwable JavaDoc e = targetEx.getTargetException();
115                 if(!(e instanceof CmsException)) {
116                     
117                     throwException("Icon activation method " + iconActiveMethod
118                             + " in calling class " + callingObject.getClass().getName()
119                             + " throwed an exception. " + e);
120                 }
121                 else {
122                     
123                     // This is a CmsException
124
// Error printing should be done previously.
125
throw (CmsException)e;
126                 }
127             }
128             catch(Exception JavaDoc exc2) {
129                 throwException("Icon activation method " + iconActiveMethod
130                         + " in calling class " + callingObject.getClass().getName()
131                         + " was found but could not be invoked. " + exc2);
132             }
133         }
134         
135         // call the method for the visibility decision
136
boolean visible = true;
137         if(iconVisibleMethod != null && !"".equals(iconVisibleMethod)) {
138             Method JavaDoc groupsMethod = null;
139             try {
140                 groupsMethod = callingObject.getClass().getMethod(iconVisibleMethod, new Class JavaDoc[] {
141                     CmsObject.class, CmsXmlLanguageFile.class, Hashtable JavaDoc.class
142                 });
143                 visible = ((Boolean JavaDoc)groupsMethod.invoke(callingObject, new Object JavaDoc[] {
144                     cms, lang, parameters
145                 })).booleanValue();
146             }
147             catch(NoSuchMethodException JavaDoc exc) {
148                 
149                 // The requested method was not found.
150
throwException("Could not find icon activation method " + iconVisibleMethod
151                         + " in calling class " + callingObject.getClass().getName()
152                         + " for generating icon.", CmsLegacyException.C_NOT_FOUND);
153             }
154             catch(InvocationTargetException JavaDoc targetEx) {
155                 
156                 // the method could be invoked, but throwed a exception
157
// itself. Get this exception and throw it again.
158
Throwable JavaDoc e = targetEx.getTargetException();
159                 if(!(e instanceof CmsException)) {
160                     
161                     throwException("Icon activation method " + iconVisibleMethod
162                             + " in calling class " + callingObject.getClass().getName()
163                             + " throwed an exception. " + e);
164                 }
165                 else {
166                     
167                     // This is a CmsException
168
// Error printing should be done previously.
169
throw (CmsException)e;
170                 }
171             }
172             catch(Exception JavaDoc exc2) {
173                 throwException("Icon activation method " + iconVisibleMethod
174                     + " in calling class " + callingObject.getClass().getName()
175                     + " was found but could not be invoked. " + exc2);
176             }
177         }
178         
179         // Get button definition and language values
180
CmsXmlWpTemplateFile icondef = getIconDefinitions(cms);
181         StringBuffer JavaDoc iconLabelBuffer = new StringBuffer JavaDoc(lang.getLanguageValue(CmsWorkplaceDefault.C_LANG_ICON + "." + iconLabel));
182         
183         // Insert a html-break, if needed
184
if(iconLabelBuffer.toString().indexOf("- ") != -1) {
185             iconLabelBuffer.insert(iconLabelBuffer.toString().indexOf("- ") + 2, "<BR>");
186         }
187         
188         // get the processed button.
189
icondef.setData(CmsWorkplaceDefault.C_ICON_NAME, iconName);
190         icondef.setData(CmsWorkplaceDefault.C_ICON_LABEL, iconLabelBuffer.toString());
191         icondef.setData(CmsWorkplaceDefault.C_ICON_ACTION, iconAction);
192         icondef.setData(CmsWorkplaceDefault.C_ICON_HREF, iconHref);
193         icondef.setData(CmsWorkplaceDefault.C_ICON_TARGET, iconTarget);
194         if(visible) {
195             if(activate) {
196                 return icondef.getProcessedDataValue("defaulticon", callingObject);
197             }
198             else {
199                 return icondef.getProcessedDataValue("deactivatedicon", callingObject);
200             }
201         }
202         else {
203             return icondef.getProcessedDataValue("noicon", callingObject);
204         }
205     }
206 }
207
Popular Tags