KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/A_CmsGalleryBrowser.java,v $
3  * Date : $Date: 2005/06/27 23:22:07 $
4  * Version: $Revision: 1.3 $
5  *
6  * This library is part of OpenCms - the Open Source Content Mananagement
7  * System
8  *
9  * Copyright (C) 2002 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License as published by the
13  * Free Software Foundation; either version 2.1 of the License, or (at your
14  * option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
19  * for more details.
20  *
21  * For further information about Alkacon Software, please see the company
22  * website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the project website:
25  * http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with this library; if not, write to the Free Software Foundation,
29  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package com.opencms.workplace;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsResource;
36 import org.opencms.main.CmsException;
37 import org.opencms.security.CmsPermissionSet;
38
39 import com.opencms.core.I_CmsSession;
40 import com.opencms.legacy.CmsXmlTemplateLoader;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.Hashtable JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.StringTokenizer JavaDoc;
46 import java.util.Vector JavaDoc;
47
48 /**
49  * An abstract gallery browser.<p>
50  *
51  * Each {download|picture|HTML} gallery workplace class has to extend this
52  * browser class.<p>
53  *
54  * @author Thomas Weckert
55  * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:07 $
56  *
57  * @deprecated Will not be supported past the OpenCms 6 release.
58  */

59 public abstract class A_CmsGalleryBrowser extends CmsWorkplaceDefault {
60
61     /**
62      * Reads the names of all galleries for a specified gallery path.
63      * <P>
64      *
65      * The vectors <code>names</code> and <code>values</code> will be
66      * filled with the information to be used for building a select box. The
67      * values will are the paths of the galleries.
68      * <p>
69      *
70      * @param cms the current user's CmsObject instance
71      * @param galleryPath the VFS paath of the gallery, e.g. /system/galleries/pics/
72      * @param lang XML language file for internationalization, <em>(not used here)</em>
73      * @param names filled with the URIs of the galleries
74      * @param values filled with the names of the galleries
75      * @param parameters contains user parameters, <em>(not used here)</em>
76      * @return the number of galleries
77      * @throws CmsException if something goes wrong
78      */

79     public Integer JavaDoc getGalleryNames(CmsObject cms, String JavaDoc galleryPath, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
80         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
81         String JavaDoc ident = "";
82         int ret = -1;
83         // which folder is the gallery?
84
String JavaDoc chosenFolder = (String JavaDoc) parameters.get(CmsWorkplaceDefault.C_PARA_FOLDER);
85         if (chosenFolder == null) {
86             chosenFolder = (String JavaDoc) session.getValue(CmsWorkplaceDefault.C_PARA_FOLDER);
87         }
88         if (chosenFolder == null) {
89             chosenFolder = "";
90         }
91         List JavaDoc folders = getGallerySubFolders(cms, new ArrayList JavaDoc(), galleryPath);
92         int numFolders = folders.size();
93         for (int i = 0; i < numFolders; i++) {
94             CmsResource currFolder = (CmsResource) folders.get(i);
95             ident = "";
96             String JavaDoc name = currFolder.getName();
97             if (chosenFolder.equals(currFolder.getRootPath())) {
98                 ret = i;
99             }
100             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(currFolder.getRootPath(), "/");
101             for (int j = 0; j < (tokenizer.countTokens() - 4); j++) {
102                 ident = ident + "-";
103             }
104             values.addElement(currFolder.getRootPath());
105             names.addElement(ident + name);
106         }
107         return new Integer JavaDoc(ret);
108     }
109
110     /**
111      * Reads all subfolders of a gallery recursively.<p>
112      *
113      * @param cms the current user's CmsObject instance
114      * @param folders filled with the appropriate values in this method.
115      * @param foldername String the folder to start from.
116      * @return all folders
117      * @throws CmsException
118      */

119     protected List JavaDoc getGallerySubFolders(CmsObject cms, List JavaDoc folders, String JavaDoc foldername) throws CmsException {
120         List JavaDoc tempFolders = cms.getSubFolders(foldername);
121         for (int i = 0; i < tempFolders.size(); i++) {
122             CmsResource currFolder = (CmsResource) tempFolders.get(i);
123             if (this.checkAccess(cms, currFolder)) {
124                 folders.add(tempFolders.get(i));
125             }
126             getGallerySubFolders(cms, folders, currFolder.getRootPath());
127         }
128         return folders;
129     }
130
131     /**
132      * Checks if a resource should be displayed in the gallery selection.<p>
133      *
134      * @param cms the current user's CmsObject instance
135      * @param res the resource
136      * @return true if a resource should be displayed in the gallery selection
137      * @throws CmsException if something goes wrong.
138      */

139     protected boolean checkAccess(CmsObject cms, CmsResource res) throws CmsException {
140         return cms.hasPermissions(res, CmsPermissionSet.ACCESS_VIEW);
141     }
142     
143     /**
144      * Checks, if the given filename matches the filter string.<p>
145      *
146      * @param filename filename to be checked
147      * @param filter filter to be checked
148      * @return <code>true</code> if the filename matches the filter, <code>false</code> otherwise.
149      */

150     protected boolean inFilter(String JavaDoc filename, String JavaDoc filter) {
151         String JavaDoc compareName = filename.toLowerCase();
152         String JavaDoc compareFilter = filter.toLowerCase();
153         
154         return ("".equals(compareFilter) || (compareName.indexOf(compareFilter) != -1));
155     }
156
157 }
158
Popular Tags