KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsPanel.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
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.file.CmsObject;
33 import org.opencms.file.CmsRequestContext;
34 import org.opencms.main.CmsException;
35
36 import com.opencms.legacy.CmsXmlTemplateLoader;
37 import com.opencms.template.A_CmsXmlContent;
38
39 import java.util.Hashtable JavaDoc;
40 import java.util.Vector JavaDoc;
41
42 import org.w3c.dom.Element JavaDoc;
43 import org.w3c.dom.Node JavaDoc;
44 import org.w3c.dom.NodeList JavaDoc;
45
46 /**
47  * Class for building workplace panel bars. <BR>
48  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;PANELBAR&gt;</code>.
49  *
50  * @author Alexander Lucas
51  * @version $Revision: 1.2 $ $Date: 2005/06/27 23:22:07 $
52  *
53  * @deprecated Will not be supported past the OpenCms 6 release.
54  */

55
56 public class CmsPanel extends A_CmsWpElement {
57
58
59     /** Workplace tag used for each panel in <code>&lt;PANELBAR&gt;</code> */
60     public static final String JavaDoc C_WPTAG_PANEL = "panel";
61
62
63     /** Attribute used for panelnames <code>C_WPTAG_PANEL</code> */
64     public static final String JavaDoc C_WPTAG_ATTR_PANELNAME = "name";
65
66     /**
67      * Handling of the <CODE>&lt;PANELBAR&gt;</CODE> tags.
68      * <P>
69      * Reads the code of a panel from the panel definition file
70      * and returns the processed code with the actual elements.
71      * <P>
72      * Panel bars can be referenced in any workplace template by <br>
73      * <code>&lt;PANELBAR&gt;<br>
74      * &lt;PANEL&gt; name="..."/&gt;<br>
75      * &lt;PANEL&gt; name="..."/&gt;<br>
76      * ...
77      * </code>
78      * For each <code>&lt;PANEL&gt;</code> element one panel will be created.
79      * The text for this panel will be taken from the language file's
80      * <code>&lt;PANEL&gt;</code> section using the panel name.
81      * <p>
82      * Each panel will be linked to the currently requested URL,
83      * extended by the <code>?panel=name</code> parameter.
84      *
85      * @param cms CmsObject Object for accessing resources.
86      * @param n XML element containing the <code>&lt;INPUT&gt;</code> tag.
87      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
88      * @param callingObject reference to the calling object.
89      * @param parameters Hashtable containing all user parameters.
90      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
91      * @return Processed button.
92      * @throws CmsException
93      */

94
95     public Object JavaDoc handleSpecialWorkplaceTag(CmsObject cms, Element JavaDoc n, A_CmsXmlContent doc,
96             Object JavaDoc callingObject, Hashtable JavaDoc parameters, CmsXmlLanguageFile lang) throws CmsException {
97
98         // Currently requested panel
99
String JavaDoc selectedPanel = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_PANEL);
100         if(selectedPanel == null) {
101             selectedPanel = "";
102         }
103
104         // panel definition file
105
CmsXmlWpTemplateFile paneldef = getPanelDefinitions(cms);
106
107         // base URL of the page, each panel is linked to.
108

109         // This URL will be extendeb by "?panel=panelname" or "&panel=panelname"
110
CmsRequestContext reqCont = cms.getRequestContext();
111         String JavaDoc url = CmsXmlTemplateLoader.getRequest(reqCont).getServletUrl() + reqCont.getUri();
112         if(url.indexOf("?") >= 0) {
113             url = url + "&panel=";
114         }
115         else {
116             url = url + "?panel=";
117         }
118
119         // Node reference used in loops
120
Node JavaDoc nodeLoop;
121
122         // Name of the currently processed panel
123
String JavaDoc panelName = null;
124
125         // Some StringBuffer for storing the results
126
StringBuffer JavaDoc resultBg = new StringBuffer JavaDoc();
127         StringBuffer JavaDoc resultTxt = new StringBuffer JavaDoc();
128         StringBuffer JavaDoc resultAll = new StringBuffer JavaDoc();
129
130         // Collect all available panels and put them into
131
// the Vector panels
132
NodeList JavaDoc nl = n.getChildNodes();
133         Vector JavaDoc panels = new Vector JavaDoc();
134         for(int i = 0;i < nl.getLength();i++) {
135             Element JavaDoc tempElem = null;
136             nodeLoop = nl.item(i);
137             if(nodeLoop.getNodeType() == Node.ELEMENT_NODE) {
138                 tempElem = (Element JavaDoc)nodeLoop;
139                 if(tempElem.getNodeName().toLowerCase().equals(C_WPTAG_PANEL)) {
140                     panelName = tempElem.getAttribute(C_WPTAG_ATTR_PANELNAME);
141                     if(panelName != null && !panelName.equals("")) {
142                         panels.addElement(panelName);
143                     }
144                 }
145             }
146         }
147
148         // Get the index of the currently requested panel
149
int currentPanelNo = panels.indexOf(selectedPanel);
150
151         // Generate the output for each panel.
152

153         // Panel background and text will be written separately
154
for(int i = 0;i < panels.size();i++) {
155             panelName = (String JavaDoc)panels.elementAt(i);
156             paneldef.setData(CmsWorkplaceDefault.C_PANEL_LINK, panelName);
157             paneldef.setData(CmsWorkplaceDefault.C_PANEL_NAME, lang.getLanguageValue("panel." + panelName));
158             if(i == currentPanelNo) {
159                 resultBg.append(paneldef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PANEL_BGACTIVE, callingObject, null));
160                 resultTxt.append(paneldef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PANEL_TEXTACTIVE));
161             }
162             else {
163                 resultBg.append(paneldef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PANEL_BGINACTIVE, callingObject, null));
164                 resultTxt.append(paneldef.getProcessedDataValue(CmsWorkplaceDefault.C_TAG_PANEL_TEXTINACTIVE));
165             }
166         }
167
168         // Now build the end result
169
resultAll.append(paneldef.getDataValue(CmsWorkplaceDefault.C_TAG_PANEL_STARTSEQ));
170         resultAll.append(resultBg.toString());
171         resultAll.append(paneldef.getDataValue(CmsWorkplaceDefault.C_TAG_PANEL_SEPBGTEXT));
172         resultAll.append(resultTxt.toString());
173         resultAll.append(paneldef.getDataValue(CmsWorkplaceDefault.C_TAG_PANEL_ENDSEQ));
174         return resultAll.toString();
175     }
176 }
177
Popular Tags