KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsXmlWpTemplateFile.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.CmsFile;
33 import org.opencms.file.CmsObject;
34 import org.opencms.main.CmsException;
35 import org.opencms.main.CmsLog;
36
37 import com.opencms.template.CmsTemplateClassManager;
38 import com.opencms.template.CmsXmlTemplateFile;
39
40 import java.util.Hashtable JavaDoc;
41
42 import org.w3c.dom.Element JavaDoc;
43
44 /**
45  * Content definition for Workplace template files.
46  *
47  * @author Alexander Lucas
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 CmsXmlWpTemplateFile extends CmsXmlTemplateFile {
55
56     private Hashtable JavaDoc m_wpTags = new Hashtable JavaDoc();
57
58     /** Reference to the actual language file. */
59     private CmsXmlLanguageFile m_languageFile = null;
60
61     /**
62      * Default constructor.
63      */

64     public CmsXmlWpTemplateFile() throws CmsException {
65         super();
66         registerMyTags();
67     }
68
69     /**
70      * Constructor for creating a new object containing the content
71      * of the given filename.
72      *
73      * @param cms CmsObject object for accessing system resources.
74      * @param filename Name of the body file that shoul be read.
75      */

76     public CmsXmlWpTemplateFile(CmsObject cms, CmsFile file) throws CmsException {
77         super();
78         registerMyTags();
79         init(cms, file);
80     }
81
82     /**
83      * Constructor for creating a new object containing the content
84      * of the given filename.
85      *
86      * @param cms CmsObject object for accessing system resources.
87      * @param filename Name of the body file that shoul be read.
88      */

89     public CmsXmlWpTemplateFile(CmsObject cms, String JavaDoc filename) throws CmsException {
90         super();
91         registerMyTags();
92         init(cms, filename);
93     }
94
95     /**
96      * Clears the startup tag that can be used in workplace documents.
97      */

98     public void clearStartup() {
99         setData(CmsWorkplaceDefault.C_TAG_STARTUP, "");
100     }
101
102     /**
103      * Fast method to replace a datablock.
104      * <P>
105      * <b>USE WITH CARE!</b>
106      * <P>
107      * Using this method only if
108      * <ul>
109      * <li>The tag name is given in lowercase</li>
110      * <li>The datablock already exists (it may be empty)</li>
111      * <li>Neither tag nor data are <code>null</code></li>
112      * <li>You are sure, there will occurr no errors</li>
113      * </ul>
114      *
115      * @param tag Key for this datablock.
116      * @param data String to be put in the datablock.
117      */

118     public void fastSetXmlData(String JavaDoc tag, String JavaDoc data) {
119         fastSetData(tag, data);
120     }
121
122     /**
123      * Gets the actual instance of the language file.
124      * @return Language file.
125      */

126     public CmsXmlLanguageFile getLanguageFile() {
127         return m_languageFile;
128     }
129
130     /**
131      * Gets the text and CDATA content of a processed datablock from the
132      * datablock hashtable.
133      *
134      * @param tag Key for the datablocks hashtable.
135      * @return Processed datablock for the given key.
136      * @deprecated Use getProcessedDataValue instead.
137      * @throws CmsException
138      */

139     public String JavaDoc getProcessedXmlDataValue(String JavaDoc tag) throws CmsException {
140         return getProcessedDataValue(tag);
141     }
142
143     /**
144      * Gets the text and CDATA content of a processed datablock from the
145      * datablock hashtable.
146      *
147      * @param tag Key for the datablocks hashtable.
148      * @param callingObject Object that should be used to look up user methods.
149      * @return Processed datablock for the given key.
150      * @deprecated Use getProcessedDataValue instead.
151      * @throws CmsException
152      */

153     public String JavaDoc getProcessedXmlDataValue(String JavaDoc tag, Object JavaDoc callingObject) throws CmsException {
154         return getProcessedDataValue(tag, callingObject);
155     }
156
157     /**
158      * Gets the text and CDATA content of a processed datablock from the
159      * datablock hashtable.
160      * <P>
161      * The userObj Object is passed to all called user methods.
162      * By using this, the initiating class can pass customized data to its methods.
163      *
164      * @param tag Key for the datablocks hashtable.
165      * @param callingObject Object that should be used to look up user methods.
166      * @param userObj any object that should be passed to user methods
167      * @return Processed datablock for the given key.
168      * @deprecated Use getProcessedDataValue instead.
169      * @throws CmsException
170      */

171     public String JavaDoc getProcessedXmlDataValue(String JavaDoc tag, Object JavaDoc callingObject,
172             Object JavaDoc userObj) throws CmsException {
173         return getProcessedDataValue(tag, callingObject, userObj);
174     }
175
176     /**
177      * Gets the text and CDATA content of a datablock from the
178      * datablock hashtable.
179      *
180      * @param tag Key for the datablocks hashtable.
181      * @return Datablock content for the given key or null if no datablock
182      * @deprecated Use getDataValue instead.
183      * is found for this key.
184      */

185     public String JavaDoc getXmlDataValue(String JavaDoc tag) throws CmsException {
186         return getDataValue(tag);
187     }
188
189     /**
190      * Gets the expected tagname for the XML documents of this content type
191      * @return Expected XML tagname.
192      */

193     public String JavaDoc getXmlDocumentTagName() {
194         return "WORKPLACE";
195     }
196
197     /**
198      * Handles any occurence of any special workplace XML tag like <code>&lt;BUTTON&gt;</code> or
199      * <code>&lt;LABEL&gt;</code>. Looks up the appropriate workplace element class for the current
200      * tag and calls the <code>handleSpecialWorkplaceTag()</code> method of this class.
201      * <P>
202      * Every workplace element class used by this method has to implement the interface
203      * <code>I_CmsWpElement</code>
204      *
205      * @param n XML element containing the current special workplace tag.
206      * @param callingObject reference to the calling object.
207      * @param userObj hashtable containig all user parameters.
208      * @throws CmsException
209      * @see com.opencms.workplace.I_CmsWpElement
210      */

211     public Object JavaDoc handleAnyTag(Element JavaDoc n, Object JavaDoc callingObject, Object JavaDoc userObj) throws CmsException {
212         Object JavaDoc result = null;
213         I_CmsWpElement workplaceObject = null;
214         String JavaDoc tagname = n.getTagName().toLowerCase();
215         String JavaDoc classname = null;
216         classname = (String JavaDoc)m_wpTags.get(tagname);
217         if(classname == null || "".equals(classname)) {
218             throwException("Don't know which class handles " + tagname + " tags.");
219         }
220         Object JavaDoc loadedClass = CmsTemplateClassManager.getClassInstance(classname);
221         if(!(loadedClass instanceof I_CmsWpElement)) {
222             throwException("Loaded class " + classname + " is not implementing I_CmsWpElement");
223         }
224         processNode(n, m_mainProcessTags, null, callingObject, userObj);
225         workplaceObject = (I_CmsWpElement)loadedClass;
226         try {
227             result = workplaceObject.handleSpecialWorkplaceTag(m_cms, n, this, callingObject,
228                     (Hashtable JavaDoc)userObj, m_languageFile);
229         }catch(Exception JavaDoc e) {
230             String JavaDoc errorMessage = "Error while building workplace element \"" + tagname + "\": " + e;
231             if(e instanceof CmsException) {
232                 if(CmsLog.getLog(this).isWarnEnabled()) {
233                     CmsLog.getLog(this).warn(errorMessage, e);
234                 }
235                 throw (CmsException)e;
236             }else {
237                 throwException(errorMessage, e);
238             }
239         }
240         return result;
241     }
242
243     /**
244      * Checks if this Template owns a datablock with the given key.
245      * @param key Datablock key to be checked.
246      * @deprecated Use hasData instead.
247      * @return true if a datablock is found, false otherwise.
248      */

249
250     public boolean hasXmlData(String JavaDoc tag) throws CmsException {
251         return hasData(tag);
252     }
253
254     /**
255      * Overridden init method of A_CmsXmlContent.
256      * This method is now extended to get an actual instance of the
257      * language file.
258      * @param cms CmsObject Object for accessing resources.
259      * @param file CmsFile object of the file to be loaded and parsed.
260      * @throws CmsException
261      */

262     public void init(CmsObject cms, CmsFile file) throws CmsException {
263         m_languageFile = new CmsXmlLanguageFile(cms);
264         String JavaDoc encoding = m_languageFile.getEncoding();
265         if (encoding != null) {
266             cms.getRequestContext().setEncoding(encoding);
267         }
268         super.init(cms, file);
269     }
270
271     /**
272      * Overridden init method of A_CmsXmlContent.
273      * This method is now extended to get an actual instance of the
274      * language file.
275      * @param cms CmsObject Object for accessing resources.
276      * @param file CmsFile object of the file to be loaded and parsed.
277      * @throws CmsException
278      */

279     public void init(CmsObject cms, String JavaDoc filename) throws CmsException {
280         m_languageFile = new CmsXmlLanguageFile(cms);
281         String JavaDoc encoding = m_languageFile.getEncoding();
282         if (encoding != null) {
283             cms.getRequestContext().setEncoding(encoding);
284         }
285         super.init(cms, filename);
286     }
287
288     /**
289      * Registers the special tags for processing with
290      * processNode().
291      */

292
293     private void registerMyTags() {
294         registerTag("BUTTON", "com.opencms.workplace.CmsButton");
295         registerTag("ICON", "com.opencms.workplace.CmsIcon");
296         registerTag("BUTTONSEPARATOR", "com.opencms.workplace.CmsButtonSeparator");
297
298         // registerTag("ERRORBOX", "com.opencms.workplace.CmsErrorbox");
299
registerTag("ERRORPAGE", "com.opencms.workplace.CmsErrorpage");
300         registerTag("FILELIST", "com.opencms.workplace.CmsFileList");
301         registerTag("FILETYPELIST", "com.opencms.workplace.CmsFileTypeList");
302         registerTag("INPUTFIELD", "com.opencms.workplace.CmsInput");
303         registerTag("JAVASCRIPTBUTTON", "com.opencms.workplace.CmsButtonJavascript");
304         registerTag("LABEL", "com.opencms.workplace.CmsLabel");
305         registerTag("PASSWORD", "com.opencms.workplace.CmsInputPassword");
306         registerTag("SUBMITBUTTON", "com.opencms.workplace.CmsButtonSubmit");
307         registerTag("TEXTBUTTON", "com.opencms.workplace.CmsButtonText");
308         registerTag("SELECT", "com.opencms.workplace.CmsSelectBox");
309         registerTag("PROJECTLIST", "com.opencms.workplace.CmsProjectlist");
310         registerTag("PROJECTHISTORY", "com.opencms.workplace.CmsProjecthistory");
311         registerTag("MODULELIST", "com.opencms.workplace.CmsModulelist");
312         registerTag("CONTEXTMENUE", "com.opencms.workplace.CmsContextmenue");
313         registerTag("MESSAGEBOX", "com.opencms.workplace.CmsMessagebox");
314         registerTag("RADIOBUTTON", "com.opencms.workplace.CmsRadioButtons");
315         registerTag("PANELBAR", "com.opencms.workplace.CmsPanel");
316         registerTag("TASKLIST", "com.opencms.workplace.CmsTaskList");
317         registerTag("TASKDOCU", "com.opencms.workplace.CmsTaskDocu");
318         registerTag("PREFSSCROLLER", "com.opencms.workplace.CmsPrefsScroller");
319         registerTag("BACKBUTTON", "com.opencms.workplace.CmsBackbutton");
320         // just to be sure this is in the workplace view always aktiv
321
registerTag("ELEMENT", CmsXmlTemplateFile.class, "handleElementTag", C_REGISTER_MAIN_RUN);
322     }
323
324     /**
325      * Special registerTag method for this content definition class.
326      * Any workplace XML tag will be registered with the superclass for handling with
327      * the method <code>handleAnyTag()</code> in this class.
328      * Then the tagname together with the name of the class for the template
329      * element (e.g. <code>CmsButton</code> or <code>CmsLabel</code>) will be put in an internal Hashtable.
330      * <P>
331      * Every workplace element class used by this method has to implement the interface
332      * <code>I_CmsWpElement</code>
333      *
334      * @param tagname XML tag to be registered as a special workplace tag.
335      * @param elementClassName Appropriate workplace element class name for this tag.
336      * @see com.opencms.workplace.I_CmsWpElement
337      */

338     private void registerTag(String JavaDoc tagname, String JavaDoc elementClassName) {
339         super.registerTag(tagname, CmsXmlWpTemplateFile.class, "handleAnyTag", C_REGISTER_MAIN_RUN);
340         m_wpTags.put(tagname.toLowerCase(), elementClassName);
341     }
342
343     /**
344      * Removes a datablock from the internal hashtable and
345      * from the XML document
346      * @param tag Key of the datablock to delete.
347      * @deprecated Use removeData instead.
348      */

349     public void removeXmlData(String JavaDoc tag) {
350         removeData(tag);
351     }
352
353     /**
354      * Creates a datablock consisting of a single TextNode containing
355      * data and stores this block into the datablock-hashtable.
356      *
357      * @param tag Key for this datablock.
358      * @param data String to be put in the datablock.
359      * @deprecated Use setData instead.
360      */

361     public void setXmlData(String JavaDoc tag, String JavaDoc data) {
362         setData(tag, data);
363     }
364 }
365
Popular Tags