KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsInput.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 input fields. <BR>
46  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;INPUT&gt;</code>.
47  *
48  * @author Michael Emmerich
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 CmsInput extends A_CmsWpElement {
55     
56     /**
57      * Handling of the <CODE>&lt;INPUT&gt;</CODE> tags.
58      * <P>
59      * Reads the code of a input field from the input definition file
60      * and returns the processed code with the actual elements.
61      * <P>
62      * Input fields can be referenced in any workplace template by <br>
63      * <CODE>&lt;INPUT name="..." action="..." alt="..."/&gt;</CODE>
64      *
65      * @param cms CmsObject Object for accessing resources.
66      * @param n XML element containing the <code>&lt;INPUT&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.
69      * @param parameters Hashtable containing all user parameters.
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         String JavaDoc styleClass = n.getAttribute(CmsWorkplaceDefault.C_INPUT_CLASS);
78         String JavaDoc name = n.getAttribute(CmsWorkplaceDefault.C_INPUT_NAME);
79         String JavaDoc size = n.getAttribute(CmsWorkplaceDefault.C_INPUT_SIZE);
80         String JavaDoc length = n.getAttribute(CmsWorkplaceDefault.C_INPUT_LENGTH);
81         String JavaDoc value = n.getAttribute(CmsWorkplaceDefault.C_INPUT_VALUE);
82         String JavaDoc method = n.getAttribute(CmsWorkplaceDefault.C_INPUT_METHOD);
83         String JavaDoc action = n.getAttribute(CmsWorkplaceDefault.C_INPUT_ACTION);
84         if((method != null) && (method.length() != 0)) {
85             
86             // call the method for generating value
87
Method JavaDoc valueMethod = null;
88             try {
89                 valueMethod = callingObject.getClass().getMethod(method, new Class JavaDoc[] {
90                     CmsObject.class, CmsXmlLanguageFile.class, Hashtable JavaDoc.class
91                 });
92                 value = (String JavaDoc)valueMethod.invoke(callingObject, new Object JavaDoc[] {
93                     cms, lang, parameters
94                 });
95             }
96             catch(NoSuchMethodException JavaDoc exc) {
97                 
98                 // The requested method was not found.
99
throwException("Could not find method " + method + " in calling class "
100                         + callingObject.getClass().getName()
101                         + " for generating input value content.", CmsLegacyException.C_NOT_FOUND);
102             }
103             catch(InvocationTargetException JavaDoc targetEx) {
104                 
105                 // the method could be invoked, but throwed a exception
106
// itself. Get this exception and throw it again.
107
Throwable JavaDoc e = targetEx.getTargetException();
108                 if(!(e instanceof CmsException)) {
109                     
110                     throwException("User method " + method + " in calling class "
111                             + callingObject.getClass().getName() + " throwed an exception. "
112                             + e);
113                 }
114                 else {
115                     
116                     // This is a CmsException
117
// Error printing should be done previously.
118
throw (CmsException)e;
119                 }
120             }
121             catch(Exception JavaDoc exc2) {
122                 throwException("User method " + method + " in calling class "
123                         + callingObject.getClass().getName()
124                         + " was found but could not be invoked. "
125                         + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
126             }
127         }
128         if(value == null) {
129             value = "";
130         }
131         CmsXmlWpInputDefFile inputdef = getInputDefinitions(cms);
132         String JavaDoc result = inputdef.getInput(styleClass, name, size, length, value, action);
133         return result;
134     }
135 }
136
Popular Tags