KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminHtmlGalleries.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.3 $
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 package com.opencms.workplace;
30
31 import org.opencms.file.CmsFolder;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsPropertyDefinition;
34 import org.opencms.file.CmsResource;
35 import org.opencms.file.types.CmsResourceTypeFolder;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.OpenCms;
38 import org.opencms.workplace.CmsWorkplace;
39
40 import com.opencms.core.I_CmsSession;
41 import com.opencms.legacy.CmsXmlTemplateLoader;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.Collections JavaDoc;
45 import java.util.Hashtable JavaDoc;
46 import java.util.List JavaDoc;
47
48 /**
49  * Template Class for administration of html galleries
50  * <p>
51  *
52  * @author simmeu
53  * @version $Revision: 1.3 $ $Date: 2005/06/27 23:22:07 $
54  * @see com.opencms.workplace.CmsXmlWpTemplateFile
55  *
56  * @deprecated Will not be supported past the OpenCms 6 release.
57  */

58
59 public class CmsAdminHtmlGalleries extends CmsAdminGallery {
60
61     /**
62      * This method must be implemented by all galleries.
63      * It must return the path to the gallery root folder.<p>
64      */

65     public String JavaDoc getGalleryPath() {
66         return CmsWorkplaceDefault.C_VFS_GALLERY_HTML;
67     }
68     
69     /**
70      * This method must return the path to the gallery icon.<p>
71      *
72      * The gallery image is displayed in the list of available galleries.
73      *
74      * @param cms The current CmsObject
75      * @return The path to the gallery icon
76      * @throws CmsException In case of problem accessing system resources
77      */

78     public String JavaDoc getGalleryIconPath(CmsObject cms) throws CmsException {
79         CmsXmlWpConfigFile config = this.getConfigFile(cms);
80         return config.getWpPicturePath() + "ic_file_htmlgallery.gif";
81     }
82         
83     /**
84      * Default XMLTemplate method called to build the output,
85      *
86      * @param cms CmsObject for accessing system resources
87      * @param templateFile Filename of the template file
88      * @param elementName Element name of this template in our parent template
89      * @param parameters Hashtable with all template class parameters
90      * @param templateSelector template section that should be processed
91      *
92      * @return A HTML String converted to bytes that contains the generated output
93      */

94     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
95             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
96
97         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
98         CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
99                 templateFile, elementName, parameters, templateSelector);
100
101         // Get the URL to which we need to return when we're done
102
String JavaDoc lasturl = getLastUrl(cms, parameters);
103         
104         // Check if this is the inital call to the page
105
getInitial(session, parameters);
106                         
107         // Get the folder for the gallery
108
String JavaDoc foldername = getGalleryPath(cms, session, parameters);
109         CmsFolder thefolder = cms.readFolder(foldername);
110
111         // Check if we must redirect to head_1
112
if(foldername.equals(CmsWorkplaceDefault.C_VFS_GALLERY_HTML) && templateFile.endsWith("administration_head_htmlgalleries2")) {
113             // we are in the wrong head - use the first one
114
xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms, CmsWorkplace.VFS_PATH_WORKPLACE + "administration/htmlgallery/administration_head_htmlgalleries1", elementName, parameters, templateSelector);
115         }
116
117         // Check if we must redirect to head_2
118
try {
119             String JavaDoc parent = CmsResource.getParentFolder(cms.getSitePath(thefolder));
120             if(foldername.startsWith(CmsWorkplaceDefault.C_VFS_GALLERY_HTML) && (parent.equals(CmsWorkplaceDefault.C_VFS_GALLERY_HTML)) && templateFile.endsWith("administration_head_htmlgalleries1")) {
121                 // we are in the wrong head - use the second one
122
xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms, CmsWorkplace.VFS_PATH_WORKPLACE + "administration/htmlgallery/administration_head_htmlgalleries2", elementName, parameters, templateSelector);
123             }
124         }
125         catch(Exception JavaDoc e) {}
126
127         // Now read further parameters
128
String JavaDoc action = (String JavaDoc)parameters.get("action");
129         String JavaDoc title = (String JavaDoc)parameters.get("TITLE"); // both for gallery and upload file
130

131         if("new".equals(action)) {
132             String JavaDoc galleryname = (String JavaDoc)parameters.get("NAME");
133             String JavaDoc group = (String JavaDoc)parameters.get("GROUP");
134             if(galleryname != null && group != null && galleryname != "" && group != "") {
135 // boolean read = parameters.get("READ") != null;
136
// boolean write = parameters.get("WRITE") != null;
137
try {
138
139                     // create the folder
140

141                     // get the path from the workplace.ini
142
String JavaDoc superfolder = getConfigFile(cms).getHtmlGalleryPath();
143                     CmsResource folder = cms.createResource(superfolder + galleryname, CmsResourceTypeFolder.RESOURCE_TYPE_ID);
144                     if(title != null) {
145                         cms.writeProperty(cms.getSitePath(folder), CmsPropertyDefinition.PROPERTY_TITLE, title);
146                     }
147 // TODO: check how to set the appropriate access using acl
148
/*
149                     cms.chgrp(cms.readAbsolutePath(folder), group);
150                     int flag = folder.getAccessFlags();
151
152                     // set the access rights for 'other' users
153                     if(read != ((flag & C_ACCESS_PUBLIC_READ) != 0)) {
154                         flag ^= C_ACCESS_PUBLIC_READ;
155                     }
156                     if(write != ((flag & C_ACCESS_PUBLIC_WRITE) != 0)) {
157                         flag ^= C_ACCESS_PUBLIC_WRITE;
158                     }
159                     if((flag & C_ACCESS_GROUP_READ) == 0){
160                         flag ^= C_ACCESS_GROUP_READ;
161                     }
162                     if((flag & C_ACCESS_GROUP_WRITE) == 0){
163                         flag ^= C_ACCESS_GROUP_WRITE;
164                     }
165                     if((flag & C_ACCESS_GROUP_VISIBLE) == 0){
166                         flag ^= C_ACCESS_GROUP_VISIBLE;
167                     }
168                     if((flag & C_PERMISSION_READ ) == 0){
169                         flag ^= C_PERMISSION_READ;
170                     }
171                     if((flag & C_PERMISSION_WRITE) == 0){
172                         flag ^= C_PERMISSION_WRITE;
173                     }
174                     if((flag & C_PERMISSION_VIEW) == 0){
175                         flag ^= C_PERMISSION_VIEW;
176                     }
177                     if((flag & C_ACCESS_PUBLIC_VISIBLE) == 0){
178                         flag ^= C_ACCESS_PUBLIC_VISIBLE;
179                     }
180                     cms.chmod(cms.readAbsolutePath(folder), flag);
181                     */

182                     try {
183                       cms.unlockResource(cms.getSitePath(folder));
184                     }
185                     catch (CmsException e) {
186                       String JavaDoc parent = CmsResource.getParentFolder(cms.getSitePath(folder));
187                       cms.unlockResource(parent);
188                       cms.unlockResource(cms.getSitePath(folder));
189
190                     }
191                 }
192                 catch(CmsException ex) {
193                     xmlTemplateDocument.setData("ERRORDETAILS", CmsException.getStackTraceAsString(ex));
194                     templateSelector = "error";
195                 }
196             }
197             else {
198                 templateSelector = "datamissing";
199             }
200         }
201
202         else if ("snippet".equalsIgnoreCase(action)) {
203             if (foldername != null) {
204                 String JavaDoc filename = (String JavaDoc) parameters.get("NEUNAME");
205                 String JavaDoc pagetitle = (String JavaDoc) parameters.get("NEUTITEL");
206                 String JavaDoc type = (String JavaDoc) parameters.get("type");
207
208                 if (filename != null && !"".equals(filename)) {
209                     // create the new file
210

211                     List JavaDoc properties = null;
212                     if (pagetitle != null) {
213                         properties = new ArrayList JavaDoc();
214                         properties.add(new org.opencms.file.CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, pagetitle, null));
215                     } else {
216                         properties = Collections.EMPTY_LIST;
217                     }
218
219                     int t = OpenCms.getResourceManager().getResourceType(type).getTypeId();
220                     cms.createResource(foldername + filename, t, new byte[0], properties);
221                 }
222             }
223         }
224
225         xmlTemplateDocument.setData("link_value", foldername);
226         xmlTemplateDocument.setData("lasturl", lasturl);
227         xmlTemplateDocument.setData("galleryRootFolder", CmsWorkplaceDefault.C_VFS_GALLERY_HTML);
228
229         // Finally start the processing
230
return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
231                 templateSelector);
232     }
233 }
234
Popular Tags