KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsExplorerHead.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.main.CmsException;
34
35 import com.opencms.core.I_CmsSession;
36 import com.opencms.legacy.CmsXmlTemplateLoader;
37
38 import java.util.Hashtable JavaDoc;
39
40 /**
41  * Template class for displaying the explorer head of the OpenCms workplace.<P>
42  * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
43  *
44  * @author Michael Emmerich
45  * @version $Revision: 1.2 $ $Date: 2005/06/27 23:22:07 $
46  *
47  * @deprecated Will not be supported past the OpenCms 6 release.
48  */

49
50 public class CmsExplorerHead extends CmsWorkplaceDefault {
51
52
53     /** Definition of the Datablock PARENT */
54     private final static String JavaDoc C_PARENT = "PARENT";
55
56
57     /** Definition of the Datablock PARENT_ENABLED */
58     private final static String JavaDoc C_PARENT_ENABLED = "PARENT_ENABLED";
59
60
61     /** Definition of the Datablock PARENT_DISABLED */
62     private final static String JavaDoc C_PARENT_DISABLED = "PARENT_DISABLED";
63
64
65     /** Definition of the Datablock PREVIOUS */
66     private final static String JavaDoc C_PREVIOUS = "PREVIOUS";
67
68
69     /** Definition of the Datablock PREVIOUS_ENABLED */
70     private final static String JavaDoc C_PREVIOUS_ENABLED = "PREVIOUS_ENABLED";
71
72
73     /** Definition of the Datablock PREVIOUS_DISABLED */
74     private final static String JavaDoc C_PREVIOUS_DISABLED = "PREVIOUS_DISABLED";
75
76
77     /** Definition of the Datablock NEW */
78     private final static String JavaDoc C_NEW = "NEW";
79
80
81     /** Definition of the Datablock NEW_ENABLED */
82     private final static String JavaDoc C_NEW_ENABLED = "NEW_ENABLED";
83
84
85     /** Definition of the Datablock NEW_DISABLED */
86     private final static String JavaDoc C_NEW_DISABLED = "NEW_DISABLED";
87
88
89     /** Definition of the Datablock FILELIST */
90     private final static String JavaDoc C_FILELIST = "FILELIST";
91
92
93     /** Definition of the Datablock PREVIOUSLIST */
94     private final static String JavaDoc C_PREVIOUSLIST = "PREVIOUSLIST";
95
96
97     /** Definition of the Datablock STARTUP */
98     private final static String JavaDoc C_STARTUP = "STARTUP";
99
100
101     /** Definition of the Datablock STARTUP_FILE */
102     private final static String JavaDoc C_STARTUP_FILE = "STARTUP_FILE";
103
104
105     /** Definition of the Datablock STARTUP_FOLDER */
106     private final static String JavaDoc C_STARTUP_FOLDER = "STARTUP_FOLDER";
107
108
109     /** Definition of the Datablock LINK_VALUE */
110     private final static String JavaDoc C_LINK_VALUE = "LINK_VALUE";
111
112     /**
113      * Overwrties the getContent method of the CmsWorkplaceDefault.<br>
114      * The explorer head works in three different modes that are selected by
115      * different parameters in the request:
116      * <ul>
117      * <li>Normal mode: No parameter is given, in this mode address input field and the
118      * navigation buttons are displayed. </li>
119      * <li>View mode: This mode is used wehn the "viewfile" parameter is set. It is used
120      * when a file is displayed in the main explorer window and only includes a back button
121      * in the explorer head. </li>
122      * <li>URL mode: This mode is activated when a file or folder is given in the address input
123      * field. It is used to determine the file or fodler to be displayed. </li>
124      * </ul>
125      *
126      * @param cms The CmsObject.
127      * @param templateFile The login template file
128      * @param elementName not used
129      * @param parameters Parameters of the request and the template.
130      * @param templateSelector Selector of the template tag to be displayed.
131      * @return Bytearre containgine the processed data of the template.
132      * @throws Throws CmsException if something goes wrong.
133      */

134
135     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
136             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
137         String JavaDoc viewfile = null;
138         String JavaDoc filelist = null;
139         String JavaDoc previous = null;
140         String JavaDoc url = null;
141         String JavaDoc currentFilelist = null;
142         String JavaDoc previousFilelist = null;
143         String JavaDoc newFilelist = null;
144
145         // the template to be displayed
146
String JavaDoc template = null;
147
148         // get session and servlet root
149
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
150         String JavaDoc servlets = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl();
151         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
152
153         // if the viewfile value is included in the request, exchange the explorer
154
// read with a back button to the file list
155
viewfile = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_VIEWFILE);
156         if(viewfile != null) {
157             template = "viewfile";
158         }
159         else {
160
161             // Check if the URL parameter was included in the request. It is set when
162
// a folder or file is entered in the address input field.
163
url = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_URL);
164             if(url == null) {
165                 xmlTemplateDocument.clearStartup();
166             }
167             else {
168
169                 // check if the requested url is a file or a folder.
170
if(url.endsWith("/")) {
171
172                     // the url is a folder, so prepare to update the file list and tree
173
xmlTemplateDocument.setData(C_FILELIST, url);
174                     xmlTemplateDocument.setData(C_STARTUP, xmlTemplateDocument.getProcessedDataValue(C_STARTUP_FOLDER, this));
175                     // currentFilelist = (String)session.getValue(C_PARA_FILELIST);
176
currentFilelist = CmsWorkplaceAction.getCurrentFolder(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest());
177                     if(currentFilelist == null) {
178                         currentFilelist = cms.getSitePath(cms.readFolder("/"));
179                     }
180                     session.putValue(CmsWorkplaceDefault.C_PARA_PREVIOUSLIST, currentFilelist);
181                     // session.putValue(C_PARA_FILELIST, url);
182
CmsWorkplaceAction.setCurrentFolder(url, CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest());
183                     session.putValue(CmsWorkplaceDefault.C_PARA_FOLDER, url);
184                 }
185                 else {
186
187                     // the url is a file, so show the requested document
188
xmlTemplateDocument.setData(C_LINK_VALUE, servlets + url);
189                     xmlTemplateDocument.setData(C_STARTUP, xmlTemplateDocument.getProcessedDataValue(C_STARTUP_FILE, this));
190
191                 // the url is a file
192
}
193             }
194
195             // check if a previous filelist parameter was included in the request.
196
// if a previous filelist was included, overwrite the value in the session for later use.
197
previous = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_PREVIOUSLIST);
198             if(previous != null) {
199                 session.putValue(CmsWorkplaceDefault.C_PARA_PREVIOUSLIST, previous);
200             }
201
202             // get the previous current filelist to calculate the link for the back button.
203
previousFilelist = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_PREVIOUSLIST);
204
205             //check if a filelist parameter was included in the request.
206
//if a filelist was included, overwrite the value in the session for later use.
207
filelist = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getParameter(CmsWorkplaceDefault.C_PARA_FILELIST);
208             if(filelist != null) {
209                 // session.putValue(C_PARA_FILELIST, filelist);
210
CmsWorkplaceAction.setCurrentFolder(filelist, CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest());
211             }
212
213             // get the current filelist to calculate its patent
214
// currentFilelist = (String)session.getValue(C_PARA_FILELIST);
215
currentFilelist = CmsWorkplaceAction.getCurrentFolder(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest());
216             
217             // if no filelist parameter was given, use the current folder
218
if(currentFilelist == null) {
219                 currentFilelist = cms.getSitePath(cms.readFolder("/"));
220             }
221             if(!currentFilelist.equals("/")) {
222
223                 // cut off last "/"
224
newFilelist = currentFilelist.substring(0, currentFilelist.length() - 1);
225
226                 // now get the partent folder
227
int end = newFilelist.lastIndexOf("/");
228                 if(end > -1) {
229                     newFilelist = newFilelist.substring(0, end + 1);
230                 }
231             }
232             else {
233                 newFilelist = currentFilelist;
234             }
235
236             // put the refereences to the filelist and the previous filelist into the
237
// template.
238
xmlTemplateDocument.setData(C_FILELIST, newFilelist);
239             xmlTemplateDocument.setData(C_PREVIOUSLIST, previousFilelist);
240
241             // update the value for the back link.
242
// this is required that for the explorer head after the back link is used.
243
// session.putValue(C_PARA_PREVIOUSLIST,currentFilelist);
244
// set the parent button to enabled if not on the root folder
245
if(currentFilelist.equals("/")) {
246                 xmlTemplateDocument.setData(C_PARENT, xmlTemplateDocument.getProcessedDataValue(C_PARENT_DISABLED, this));
247             }
248             else {
249                 xmlTemplateDocument.setData(C_PARENT, xmlTemplateDocument.getProcessedDataValue(C_PARENT_ENABLED, this));
250             }
251
252             // set the parent button to enabled if not on the root folder
253
if(previousFilelist == null) {
254                 xmlTemplateDocument.setData(C_PREVIOUS, xmlTemplateDocument.getProcessedDataValue(C_PREVIOUS_DISABLED, this));
255             }
256             else {
257                 xmlTemplateDocument.setData(C_PREVIOUS, xmlTemplateDocument.getProcessedDataValue(C_PREVIOUS_ENABLED, this));
258             }
259
260             // check if the new resource button must be enabeld.
261
// this is only done if the project is not the online project.
262
if(cms.getRequestContext().currentProject().isOnlineProject()) {
263                 xmlTemplateDocument.setData(C_NEW, xmlTemplateDocument.getProcessedDataValue(C_NEW_DISABLED, this));
264             }
265             else {
266                 xmlTemplateDocument.setData(C_NEW, xmlTemplateDocument.getProcessedDataValue(C_NEW_ENABLED, this));
267             }
268         }
269
270         // process the selected template
271
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
272     }
273
274     /**
275      * Indicates if the results of this class are cacheable.
276      *
277      * @param cms CmsObject Object for accessing system resources
278      * @param templateFile Filename of the template file
279      * @param elementName Element name of this template in our parent template.
280      * @param parameters Hashtable with all template class parameters.
281      * @param templateSelector template section that should be processed.
282      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
283      */

284
285     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
286             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
287         return false;
288     }
289
290     /**
291      * Sets the value of the address input filed of the file header.
292      * This method is directly called by the content definiton.
293      * @param Cms The CmsObject.
294      * @param lang The language file.
295      * @param parameters User parameters.
296      * @return Value that is set into the adress field.
297      * @throws CmsExeption if something goes wrong.
298      */

299
300     public String JavaDoc setValue(CmsObject cms, CmsXmlLanguageFile lang, Hashtable JavaDoc parameters) throws CmsException {
301         // I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
302

303         // get the current filelist to display it in the address input field.
304
// String currentFilelist = (String)session.getValue(C_PARA_FILELIST);
305
String JavaDoc currentFilelist = CmsWorkplaceAction.getCurrentFolder(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest());
306
307         // if no filelist parameter was given, use the current folder
308
if(currentFilelist == null) {
309             currentFilelist = cms.getSitePath(cms.readFolder("/"));
310         }
311         return currentFilelist;
312     }
313 }
314
Popular Tags