KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsRadioButtons.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 import java.util.Vector JavaDoc;
42
43 import org.w3c.dom.Element JavaDoc;
44
45 /**
46  * Class for building workplace radio buttons. <BR>
47  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;RADIOBUTTON&gt;</code>.
48  *
49  * @author Michael Emmerich
50  * @author Alexander Lucas
51  * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:07 $
52  * @see com.opencms.workplace.CmsXmlWpTemplateFile
53  *
54  * @deprecated Will not be supported past the OpenCms 6 release.
55  */

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

77     
78     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
79             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
80         
81         /** StringBuffer for the generated output */
82         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
83         
84         /** Here the different select box options will be stored */
85         Vector JavaDoc values = new Vector JavaDoc();
86         Vector JavaDoc names = new Vector JavaDoc();
87         Vector JavaDoc descriptions = new Vector JavaDoc();
88         Integer JavaDoc returnObject = null;
89         String JavaDoc radioName = n.getAttribute(CmsWorkplaceDefault.C_RADIO_NAME);
90         String JavaDoc radioMethod = n.getAttribute(CmsWorkplaceDefault.C_RADIO_METHOD);
91         String JavaDoc radioOrder = n.getAttribute(CmsWorkplaceDefault.C_RADIO_ORDER);
92         if(radioOrder == null || ((!"row".equals(radioOrder)) && (!"col".equals(radioOrder)))) {
93             radioOrder = "col";
94         }
95         
96         // call the method for generating listbox elements
97
Method JavaDoc groupsMethod = null;
98         int selectedOption = 0;
99         try {
100             groupsMethod = callingObject.getClass().getMethod(radioMethod, new Class JavaDoc[] {
101                 CmsObject.class, CmsXmlLanguageFile.class, Vector JavaDoc.class,
102                 Vector JavaDoc.class, Vector JavaDoc.class, Hashtable JavaDoc.class
103             });
104             returnObject = (Integer JavaDoc)groupsMethod.invoke(callingObject, new Object JavaDoc[] {
105                 cms, lang, names, values, descriptions, parameters
106             });
107         }
108         catch(NoSuchMethodException JavaDoc exc) {
109             
110             // The requested method was not found.
111
throwException("Could not find radio button method " + radioMethod
112                     + " in calling class " + callingObject.getClass().getName()
113                     + " for generating select box content.", CmsLegacyException.C_NOT_FOUND);
114         }
115         catch(InvocationTargetException JavaDoc targetEx) {
116             
117             // the method could be invoked, but throwed a exception
118
// itself. Get this exception and throw it again.
119
Throwable JavaDoc e = targetEx.getTargetException();
120             if(!(e instanceof CmsException)) {
121                 
122                 throwException("Radio button method " + radioMethod + " in calling class "
123                         + callingObject.getClass().getName() + " throwed an exception. "
124                         + e);
125             }
126             else {
127                 
128                 // This is a CmsException
129
// Error printing should be done previously.
130
throw (CmsException)e;
131             }
132         }
133         catch(Exception JavaDoc exc2) {
134             throwException("Radio button method " + radioMethod + " in calling class " + callingObject.getClass().getName()
135                     + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
136         }
137         
138         // If the radio button method returned a value, use it for preselecting an option
139
if(returnObject != null) {
140             selectedOption = returnObject.intValue();
141         }
142         
143         // process the vectors with the elelmetns of the radio buttons to be displayed.
144
int numValues = values.size();
145         CmsXmlWpTemplateFile radiodef = getRadioDefinitions(cms);
146         for(int i = 0;i < numValues;i++) {
147             
148             // Set values for this radiobutton entry
149
radiodef.setData(CmsWorkplaceDefault.C_RADIO_RADIONAME, radioName);
150             radiodef.setData(CmsWorkplaceDefault.C_RADIO_NAME, (String JavaDoc)descriptions.elementAt(i));
151             radiodef.setData(CmsWorkplaceDefault.C_RADIO_LINK, (String JavaDoc)values.elementAt(i));
152             
153             // Check, if an image should be displayed
154
if((String JavaDoc)names.elementAt(i) == null || "".equals(names.elementAt(i))) {
155                 radiodef.setData(CmsWorkplaceDefault.C_RADIO_IMAGEENTRY, "");
156             }
157             else {
158                 radiodef.setData(CmsWorkplaceDefault.C_RADIO_IMAGENAME, "ic_" + (String JavaDoc)names.elementAt(i) + ".gif");
159                 radiodef.setData(CmsWorkplaceDefault.C_RADIO_IMAGEENTRY, radiodef.getProcessedDataValue("radiobuttons."
160                         + CmsWorkplaceDefault.C_RADIO_IMAGEOPTION, callingObject));
161             }
162             
163             // Check, if this should be the preselected option
164
if(i == selectedOption) {
165                 radiodef.setData(CmsWorkplaceDefault.C_RADIO_SELECTEDENTRY, radiodef.getDataValue("radiobuttons." + CmsWorkplaceDefault.C_RADIO_SELECTEDOPTION));
166             }
167             else {
168                 radiodef.setData(CmsWorkplaceDefault.C_RADIO_SELECTEDENTRY, "");
169             }
170             
171             // Now get output for this option
172
if(radioOrder.equals("col")) {
173                 
174                 // Buttons should be displayed in one column
175
result.append(radiodef.getProcessedDataValue("radiobuttons.colentry", callingObject));
176             }
177             else {
178                 
179                 // Buttons should be displayed in a row.
180
result.append(radiodef.getProcessedDataValue("radiobuttons.rowentry", callingObject));
181             }
182         }
183         return result.toString();
184     }
185 }
186
Popular Tags