KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminGallery.java,v $
3  * Date : $Date: 2005/06/27 23:22:07 $
4  * Version: $Revision: 1.4 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 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  * First created on 16. October 2002
29  */

30
31 package com.opencms.workplace;
32
33 import org.opencms.db.CmsUserSettings;
34 import org.opencms.file.CmsFolder;
35 import org.opencms.file.CmsGroup;
36 import org.opencms.file.CmsObject;
37 import org.opencms.file.CmsPropertyDefinition;
38 import org.opencms.file.CmsResource;
39 import org.opencms.main.CmsException;
40 import org.opencms.main.OpenCms;
41 import org.opencms.workplace.CmsWorkplace;
42
43 import com.opencms.core.I_CmsSession;
44 import com.opencms.legacy.CmsXmlTemplateLoader;
45 import com.opencms.template.A_CmsXmlContent;
46
47 import java.util.ArrayList JavaDoc;
48 import java.util.Hashtable JavaDoc;
49 import java.util.List JavaDoc;
50 import java.util.Vector JavaDoc;
51
52 /**
53  * This class provides some common functions and methods shared among all
54  * workplace gallery implementations.
55  *
56  * @author Alexander Kandzior
57  * @version $Revision: 1.4 $
58  *
59  * @deprecated Will not be supported past the OpenCms 6 release.
60  */

61 public abstract class CmsAdminGallery extends CmsWorkplaceDefault implements I_CmsFileListUsers {
62      
63      /**
64       * This method checks if C_PARA_INITIAL is present with the requst parameters
65       * and clears the session variables if this it true,
66       *
67       * @return The value of the parameter C_PARA_INITIAL
68       */

69      public String JavaDoc getInitial(I_CmsSession session, Hashtable JavaDoc parameters) {
70         // clear session values on first load
71
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
72         if(initial != null) {
73             // remove all session values
74
session.removeValue(CmsWorkplaceDefault.C_PARA_FOLDER);
75             session.removeValue("lasturl");
76             session.removeValue("lastgallery");
77             session.removeValue("galleryRootFolder");
78         }
79         return initial;
80      }
81            
82     /**
83      * This methods looks up the folder information for the gallery.
84      * It also sets some required session information.
85      *
86      * @param cms The current CmsObject
87      * @param session The current session
88      * @param parameters The current set of request parameters
89      * @return The path to the current gallery
90      */

91     public String JavaDoc getGalleryPath(CmsObject cms, I_CmsSession session, Hashtable JavaDoc parameters) {
92         // read the parameters
93
String JavaDoc foldername = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_FOLDER);
94         String JavaDoc galleryPath = getGalleryPath();
95
96         if (foldername != null) {
97             try {
98                 CmsFolder fold = cms.readFolder(foldername);
99                 String JavaDoc parent = CmsResource.getParentFolder(cms.getSitePath(fold));
100                 if (!(parent.equals(galleryPath))) {
101                     foldername = galleryPath;
102                 }
103                 if (fold.getState() == CmsResource.STATE_DELETED) {
104                     foldername = galleryPath;
105                 }
106             } catch (CmsException exc) {
107                 // couldn't read the folder - switch to default path
108
foldername = galleryPath;
109             }
110             session.putValue("lastgallery", foldername);
111             parameters.put(CmsWorkplaceDefault.C_PARA_FOLDER, foldername);
112         } else {
113             foldername = (String JavaDoc) session.getValue(CmsWorkplaceDefault.C_PARA_FOLDER);
114             String JavaDoc tmpFolder = (String JavaDoc) session.getValue("lastgallery");
115
116             if (foldername == null) {
117
118                 if (tmpFolder != null) {
119                     try {
120                         // check if tmpfolder exists
121
cms.readFolder(tmpFolder);
122                         foldername = tmpFolder;
123                     } catch (CmsException e) {
124                         foldername = galleryPath;
125                     }
126                 } else {
127                     foldername = galleryPath;
128                 }
129             }
130         }
131
132         // need the foldername in the session in case of an exception in the dialog
133
session.putValue(CmsWorkplaceDefault.C_PARA_FOLDER, foldername);
134         return foldername;
135     }
136     
137     /**
138      * This method is reuired by the XMLTemplate mechanism to indicate
139      * if the results of this class are cacheable.
140      * This is always false for all galleries.
141      *
142      * @param cms CmsObject for accessing system resources
143      * @param templateFile Filename of the template file
144      * @param elementName Element name of this template in our parent template
145      * @param parameters Hashtable with all template class parameters
146      * @param templateSelector template section that should be processed
147      * @return Always false for all gelleries
148      */

149     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
150             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
151         return false;
152     }
153        
154     /**
155      * From interface <code>I_CmsFileListUsers</code><p>
156      *
157      * Used to modify the bit pattern for hiding and showing columns in
158      * the file list.
159      * This is usually the same for all galleries.
160      *
161      * @param cms CmsObject for accessing system resources
162      * @param prefs Old bit pattern
163      * @return New modified bit pattern
164      *
165      * @see I_CmsFileListUsers
166      */

167
168     public int modifyDisplayedColumns(CmsObject cms, int prefs) {
169         prefs = ((prefs & CmsUserSettings.FILELIST_NAME) == 0) ? prefs : (prefs - CmsUserSettings.FILELIST_NAME);
170         prefs = ((prefs & CmsUserSettings.FILELIST_TITLE) == 0) ? prefs : (prefs - CmsUserSettings.FILELIST_TITLE);
171         prefs = ((prefs & CmsUserSettings.FILELIST_TYPE) == 0) ? prefs : (prefs - CmsUserSettings.FILELIST_TYPE);
172         prefs = ((prefs & CmsUserSettings.FILELIST_SIZE) == 0) ? prefs : (prefs - CmsUserSettings.FILELIST_SIZE);
173         return prefs;
174     }
175
176     /**
177      * Gets all groups for the select box in the "create a new gallery" dialog.<p>
178      *
179      * The given vectors <code>names</code> and <code>values</code> will
180      * be filled with the appropriate information to be used for building
181      * a select box.<p>
182      *
183      * This functionality is usually the same for all galleries.
184      *
185      * @param cms CmsObject for accessing system resources
186      * @param names Vector to be filled with the appropriate values in this method
187      * @param values Vector to be filled with the appropriate values in this method
188      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
189      * @return Index representing the current value in the vectors
190      * @throws CmsException In case there were problems accessing the language resources
191      */

192     public Integer JavaDoc getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
193             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
194
195         // get all groups
196
List JavaDoc groups = cms.getGroups();
197         int retValue = 0;
198
199         // fill the names and values
200
String JavaDoc prompt = lang.getLanguageValue("input.promptgroup");
201         names.addElement(prompt);
202         values.addElement("Aufforderung"); // without significance for the user
203
for(int z = 0;z < groups.size();z++) {
204             String JavaDoc name = ((CmsGroup)groups.get(z)).getName();
205             if(! OpenCms.getDefaultUsers().getGroupGuests().equals(name)){
206                 names.addElement(name);
207                 values.addElement(name);
208             }
209         }
210         return new Integer JavaDoc(retValue);
211     }
212     
213     /**
214      * This method must return the path to the gallery root folder.<p>
215      *
216      * The root folder names are usually defined as constants in
217      * the I_CmsWpConstants interface.
218      *
219      * @return The path to the gallery root folder
220      */

221     public abstract String JavaDoc getGalleryPath();
222     
223     /**
224      * Collect all folders and files that should be displayed in the
225      * list of galleries of this gallery type.<p>
226      *
227      * @param cms The current CmsObject
228      * @return A vector of folder and file objects
229      * @throws CmsException In case of trouble accessing the VFS
230      *
231      * @see I_CmsFileListUsers
232      */

233     public List JavaDoc getFiles(CmsObject cms) throws CmsException {
234         List JavaDoc galleries = (List JavaDoc) new ArrayList JavaDoc();
235         List JavaDoc folders = cms.getSubFolders(getGalleryPath());
236         int numFolders = folders.size();
237         for(int i = 0;i < numFolders;i++) {
238             CmsResource currFolder = (CmsResource)folders.get(i);
239             galleries.add(currFolder);
240         }
241         return galleries;
242     }
243     
244     /**
245      * This method is used in the gallery templates in the onLoad Javascript
246      * page handler. It returns a location string to the current folder.
247      */

248     public Object JavaDoc onLoad(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObj) throws CmsException {
249         Hashtable JavaDoc parameters = (Hashtable JavaDoc) userObj;
250         String JavaDoc folder = (String JavaDoc)parameters.get("folder");
251
252         if(folder != null) {
253             String JavaDoc servletUrl = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl();
254             return "window.top.body.admin_content.location.href='" + servletUrl + CmsWorkplace.VFS_PATH_WORKPLACE + "action/explorer_files.html?mode=listonly&folder=" + folder + "'";
255         } else {
256             return "";
257         }
258     }
259     
260     /**
261      * This method must return the path to the gallery icon.<p>
262      *
263      * The gallery image is displayed in the list of available galleries.
264      *
265      * @param cms The current CmsObject
266      * @return The path to the gallery icon
267      * @throws CmsException In case of problem accessing system resources
268      */

269     public abstract String JavaDoc getGalleryIconPath(CmsObject cms) throws CmsException;
270     
271     /**
272      * This method builds the customized gallery file list.<p>
273      *
274      * @param cms CmsObject for accessing system resources
275      * @param filelist Template file containing the definitions for the file list together with
276      * the included customized defintions
277      * @param res CmsResource Object of the current file list entry
278      * @param lang Current language file
279      * @throws CmsException if access to system resources failed.
280      *
281      * @see I_CmsFileListUsers
282      */

283     public void getCustomizedColumnValues(CmsObject cms, CmsXmlWpTemplateFile filelistTemplate,
284             CmsResource res, CmsXmlLanguageFile lang) throws CmsException {
285         getConfigFile(cms);
286         filelistTemplate.fastSetXmlData(CmsWorkplaceDefault.C_FILELIST_ICON_VALUE,
287             CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl() + getGalleryIconPath(cms) );
288         filelistTemplate.setData(CmsWorkplaceDefault.C_FILELIST_NAME_VALUE, res.getName());
289         filelistTemplate.setData(CmsWorkplaceDefault.C_FILELIST_TITLE_VALUE, cms.readProperty(cms.getSitePath(res),
290                 CmsPropertyDefinition.PROPERTY_TITLE));
291     }
292                     
293 }
294
Popular Tags