KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsSelectBox.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.main.CmsException;
33
34 import com.opencms.legacy.CmsLegacyException;
35 import com.opencms.template.A_CmsXmlContent;
36
37 import java.lang.reflect.InvocationTargetException JavaDoc;
38 import java.lang.reflect.Method JavaDoc;
39 import java.util.Hashtable JavaDoc;
40 import java.util.Vector 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  * @author Michael Emmerich
50  * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:07 $
51  * @see com.opencms.workplace.CmsXmlWpTemplateFile
52  *
53  * @deprecated Will not be supported past the OpenCms 6 release.
54  */

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

76     
77     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc, Object JavaDoc callingObject,
78             Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
79         
80         /** Here the different select box options will be stored */
81         Vector JavaDoc values = new Vector JavaDoc();
82         Vector JavaDoc names = new Vector JavaDoc();
83         
84         /** StringBuffer for the generated output */
85         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
86         
87         // Read selectbox parameters
88
String JavaDoc selectClass = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_CLASS);
89         String JavaDoc selectName = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_NAME);
90         String JavaDoc selectMethod = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_METHOD);
91         String JavaDoc selectWidth = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_WIDTH);
92         String JavaDoc selectOnchange = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_ONCHANGE);
93         String JavaDoc selectSize = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_SIZE);
94         String JavaDoc selectDiv = n.getAttribute(CmsWorkplaceDefault.C_SELECTBOX_DIV);
95         if((selectSize == null) || (selectSize.length() == 0)) {
96             selectSize = "1";
97         }
98         
99         // Get input definition file
100
CmsXmlWpInputDefFile inputdef = getInputDefinitions(cms);
101         if((selectDiv == null) || (selectDiv.length() == 0)) {
102             
103             // get the processed selectbox start.
104
result.append(inputdef.getSelectBoxStart(selectClass, selectName, selectWidth, selectOnchange, selectSize));
105         }
106         else {
107             result.append(inputdef.getSelectBoxStartDiv(selectClass, selectName, selectWidth, selectOnchange, selectSize));
108         }
109         
110         // call the method for generating listbox elements
111
Method JavaDoc groupsMethod = null;
112         int selectedOption = 0;
113         try {
114             groupsMethod = callingObject.getClass().getMethod(selectMethod, new Class JavaDoc[] {
115                 CmsObject.class, CmsXmlLanguageFile.class, Vector JavaDoc.class,
116                 Vector JavaDoc.class, Hashtable JavaDoc.class
117             });
118             selectedOption = ((Integer JavaDoc)groupsMethod.invoke(callingObject, new Object JavaDoc[] {
119                 cms, lang, values, names, parameters
120             })).intValue();
121         }
122         catch(NoSuchMethodException JavaDoc exc) {
123             
124             // The requested method was not found.
125
throwException("Could not find method " + selectMethod + " in calling class " + callingObject.getClass().getName()
126                     + " for generating select box content.", CmsLegacyException.C_NOT_FOUND);
127         }
128         catch(InvocationTargetException JavaDoc targetEx) {
129             
130             // the method could be invoked, but throwed a exception
131
// itself. Get this exception and throw it again.
132
Throwable JavaDoc e = targetEx.getTargetException();
133             if(!(e instanceof CmsException)) {
134                 
135                 // Only print an error if this is NO CmsException
136
throwException("User method " + selectMethod + " in calling class " + callingObject.getClass().getName()
137                         + " throwed an exception. " + e);
138             }
139             else {
140                 
141                 // This is a CmsException
142
// Error printing should be done previously.
143
throw (CmsException)e;
144             }
145         }
146         catch(Exception JavaDoc exc2) {
147             throwException("User method " + selectMethod + " in calling class " + callingObject.getClass().getName()
148                     + " was found but could not be invoked. " + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
149         }
150         
151         // check the returned elements and put them into option tags.
152
// The element with index "selectedOption" has to get the "selected" tag.
153
int numValues = values.size();
154         
155         for(int i = 0;i < numValues;i++) {
156             if(i == selectedOption) {
157                 result.append(inputdef.getSelectBoxSelOption((String JavaDoc)values.elementAt(i), (String JavaDoc)names.elementAt(i)));
158             }
159             else {
160                 result.append(inputdef.getSelectBoxOption((String JavaDoc)values.elementAt(i), (String JavaDoc)names.elementAt(i)));
161             }
162         }
163         
164         // get the processed selectbox end sequence.
165
result.append(inputdef.getSelectBoxEnd());
166         return result.toString();
167     }
168 }
169
Popular Tags