KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsContextmenue.java,v $
3 * Date : $Date: 2005/06/25 11:19:03 $
4 * Version: $Revision: 1.2 $
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.db.CmsUserSettings;
33 import org.opencms.file.CmsObject;
34 import org.opencms.main.CmsException;
35
36 import com.opencms.template.A_CmsXmlContent;
37
38 import java.util.Hashtable JavaDoc;
39
40 import org.w3c.dom.Element JavaDoc;
41 import org.w3c.dom.Node JavaDoc;
42 import org.w3c.dom.NodeList JavaDoc;
43
44 /**
45  * Class for building workplace icons. <BR>
46  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;ICON&gt;</code>.
47  *
48  * @author Andreas Schouten
49  * @version $Revision: 1.2 $ $Date: 2005/06/25 11:19:03 $
50  * @see com.opencms.workplace.CmsXmlWpTemplateFile
51  *
52  * @deprecated Will not be supported past the OpenCms 6 release.
53  */

54
55 public class CmsContextmenue extends A_CmsWpElement implements I_CmsWpElement {
56
57
58     /** Storage for contextmenue */
59     private Hashtable JavaDoc m_storage = new Hashtable JavaDoc();
60
61     /**
62      * Handling of the special workplace <CODE>&lt;Contextmenue&gt;</CODE> tags.
63      * <P>
64      * Returns the processed code with the actual elements.
65      * <P>
66      * Contextmenue can be referenced in any workplace template by <br>
67      * <CODE>&lt;Contextmenue /&gt;</CODE>
68      *
69      * @param cms CmsObject Object for accessing resources.
70      * @param n XML element containing the <code>&lt;ICON&gt;</code> tag.
71      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
72      * @param callingObject reference to the calling object <em>(not used here)</em>.
73      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
74      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
75      * @return Processed button.
76      * @throws CmsException
77      */

78
79     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
80             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
81
82         // Read Contextmenue parameters
83
String JavaDoc name = n.getAttribute("name");
84         String JavaDoc output = "++ missing context ++";
85         if(name != null) {
86
87             // get the current langueag
88
String JavaDoc currentLocale = null;
89
90             CmsUserSettings settings = new CmsUserSettings(cms);
91             currentLocale = settings.getLocale().toString();
92             // create the result
93
StringBuffer JavaDoc result = new StringBuffer JavaDoc();
94
95             // check if this contextmenu is already cached
96
output = (String JavaDoc)m_storage.get(currentLocale + name + cms.getRequestContext().getUri());
97             if(output == null) {
98
99                 // Get list definition and language values
100
CmsXmlWpTemplateFile context = getContextmenueDefinitions(cms);
101
102                 // set the name (id) of the contextmenu
103
context.setData("name", name);
104                 result.append(context.getProcessedDataValue("CONTEXTHEAD", callingObject,
105                         parameters));
106                 NodeList JavaDoc nl = n.getChildNodes();
107
108                 // get each childnode
109
for(int i = 0;i < nl.getLength();i++) {
110                     Node JavaDoc actualNode = nl.item(i);
111                     if(actualNode.getNodeType() != Node.TEXT_NODE) {
112                         Element JavaDoc e = (Element JavaDoc)actualNode;
113
114                         // this is not a text node, process it
115
if(e.getTagName().toLowerCase().equals("contextspacer")) {
116
117                             // append a spacer
118
result.append(context.getProcessedDataValue("CONTEXTSPACER",
119                                     callingObject, parameters));
120                         }
121                         else {
122                             if(e.getTagName().toLowerCase().equals("contextentry")) {
123
124                                 // append a entry
125
context.setData("name", lang.getLanguageValue(e.getAttribute("name")));
126                                 context.setData("href", e.getAttribute("href"));
127                                 result.append(context.getProcessedDataValue("CONTEXTENTRY",
128                                         callingObject, parameters));
129                             }
130                             else {
131                                 if(e.getTagName().toLowerCase().equals("contextdisabled")) {
132
133                                     // append a entry
134
context.setData("name", lang.getLanguageValue(e.getAttribute("name")));
135                                     result.append(context.getProcessedDataValue("CONTEXTDISABLED", callingObject, parameters));
136                                 }
137                             }
138                         }
139                     }
140                 }
141                 result.append(context.getProcessedDataValue("CONTEXTFOOT", callingObject,
142                         parameters));
143                 output = result.toString();
144                 m_storage.put(currentLocale + name + cms.getRequestContext().getUri(), output);
145             }
146         }
147
148         // rerun the result
149
return output;
150     }
151 }
152
Popular Tags