KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsPrefsScroller.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 preferences scroller windows. <BR>
46  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;PREFSSCROLLER&gt;</code>.
47  *
48  * @author Alexander Lucas
49  * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:07 $
50  *
51  * @deprecated Will not be supported past the OpenCms 6 release.
52  */

53
54 public class CmsPrefsScroller extends A_CmsWpElement {
55     
56     
57     /** XML tag attribute used for the filling method */
58     private static final String JavaDoc C_WPTAG_ATTR_METHOD = "method";
59     
60     
61     /** XML tag attribute used for the title */
62     private static final String JavaDoc C_WPTAG_ATTR_TITLE = "title";
63     
64     
65     /** XML datablock tag used for setting the title */
66     private static final String JavaDoc C_TAG_PREFSSCROLLER_TITLE = "scrollertitle";
67     
68     
69     /** XML datablock tag used for setting the title */
70     private static final String JavaDoc C_TAG_PREFSSCROLLER_CONTENT = "scrollercontent";
71     
72     
73     /** XML datablock tag used for processing and getting the complete prefs scroller */
74     private static final String JavaDoc C_TAG_PREFSSCROLLER_COMPLETE = "scrollerwin";
75     
76     /**
77      * Handling of the <CODE>&lt;PREFSSCROLLER&gt;</CODE> tags.
78      * <P>
79      * Reads the code of a preferences scroller from the prefsscroller definition file
80      * and returns the processed code with the actual elements.
81      * <P>
82      * Preferences scroller windows can be created in any workplace template by <br>
83      * <code>&lt;PREFSSCROLLER method="..." title="..."&gt;</code><br>
84      *
85      * The given method will be looked up in the calling object and then
86      * called using reflection API. The preferences scroller will be filled
87      * with the return value of this method.
88      * <P>
89      * The title of the preferences scroller will be looked up in the
90      * "title" section of the current language file using the given
91      * tag name.
92      *
93      * @param cms CmsObject Object for accessing resources.
94      * @param n XML element containing the <code>&lt;INPUT&gt;</code> tag.
95      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
96      * @param callingObject reference to the calling object.
97      * @param parameters Hashtable containing all user parameters.
98      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
99      * @return Processed button.
100      * @throws CmsException
101      */

102     
103     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
104             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
105         String JavaDoc methodName = n.getAttribute(C_WPTAG_ATTR_METHOD);
106         String JavaDoc title = n.getAttribute(C_WPTAG_ATTR_TITLE);
107         
108         // prefs scroller definition file
109
CmsXmlWpTemplateFile prefsscrollerdef = getPrefsScrollerDefinitions(cms);
110         
111         // call the method for generating listbox elements
112
Method JavaDoc fillMethod = null;
113         String JavaDoc fillResult = null;
114         try {
115             fillMethod = callingObject.getClass().getMethod(methodName, new Class JavaDoc[] {
116                 CmsObject.class, A_CmsXmlContent.class, CmsXmlLanguageFile.class,
117                 Hashtable JavaDoc.class, Object JavaDoc.class
118             });
119             fillResult = (String JavaDoc)fillMethod.invoke(callingObject, new Object JavaDoc[] {
120                 cms, doc, lang, parameters, callingObject
121             });
122         }
123         catch(NoSuchMethodException JavaDoc exc) {
124             
125             // The requested method was not found.
126
throwException("Could not find prefs scroller fill method " + methodName
127                     + " in calling class " + callingObject.getClass().getName() + " for generating select box content.",
128                     CmsLegacyException.C_NOT_FOUND);
129         }
130         catch(InvocationTargetException JavaDoc targetEx) {
131             
132             // the method could be invoked, but throwed a exception
133
// itself. Get this exception and throw it again.
134
Throwable JavaDoc e = targetEx.getTargetException();
135             if(!(e instanceof CmsException)) {
136                 
137                 throwException("Prefs scroller fill method " + methodName + " in calling class "
138                         + callingObject.getClass().getName() + " throwed an exception. " + e);
139             }
140             else {
141                 
142                 // This is a CmsException
143
// Error printing should be done previously.
144
throw (CmsException)e;
145             }
146         }
147         catch(Exception JavaDoc exc2) {
148             throwException("Prefs scroller fill method " + methodName + " in calling class "
149                     + callingObject.getClass().getName() + " was found but could not be invoked. "
150                     + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
151         }
152         prefsscrollerdef.setData(C_TAG_PREFSSCROLLER_TITLE, lang.getLanguageValue(CmsWorkplaceDefault.C_LANG_TITLE + "." + title));
153         prefsscrollerdef.setData(C_TAG_PREFSSCROLLER_CONTENT, fillResult);
154         return prefsscrollerdef.getProcessedDataValue(C_TAG_PREFSSCROLLER_COMPLETE, callingObject, parameters);
155     }
156 }
157
Popular Tags