KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > defaults > master > CmsChannelBackoffice


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/master/CmsChannelBackoffice.java,v $
3 * Date : $Date: 2005/06/27 23:22:25 $
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 package com.opencms.defaults.master;
30
31 import org.opencms.db.CmsDbUtil;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsUser;
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.main.CmsException;
36 import org.opencms.util.CmsUUID;
37 import org.opencms.workplace.CmsWorkplace;
38
39 import com.opencms.core.I_CmsSession;
40 import com.opencms.defaults.A_CmsBackoffice;
41 import com.opencms.legacy.CmsXmlTemplateLoader;
42 import com.opencms.template.A_CmsXmlContent;
43 import com.opencms.workplace.CmsXmlLanguageFile;
44 import com.opencms.workplace.CmsXmlWpTemplateFile;
45
46 import java.util.Hashtable JavaDoc;
47 import java.util.List JavaDoc;
48
49 /**
50  * @deprecated Will not be supported past the OpenCms 6 release.
51  */

52 public class CmsChannelBackoffice extends A_CmsBackoffice{
53     
54     /**
55      * The COS channel.
56      */

57     private CmsChannelContent m_channel;
58     
59     /**
60      * The ID of the channel which is set as a property on the folder representing the channel.
61      */

62     private String JavaDoc m_channelId = "0";
63     
64     /**
65      * The resource ID of the folder representing the channel.
66      */

67     private CmsUUID m_folderId;
68
69     public Class JavaDoc getContentDefinitionClass() {
70         return CmsChannelContent.class;
71     }
72
73     public String JavaDoc getCreateUrl(CmsObject cms, String JavaDoc tagcontent,
74                              A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc{
75         return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/EditBackoffice.html";
76     }
77
78     public String JavaDoc getBackofficeUrl(CmsObject cms, String JavaDoc tagcontent,
79                                  A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
80         return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/Backoffice.html";
81     }
82
83     public String JavaDoc getEditUrl(CmsObject cms, String JavaDoc tagcontent,
84                            A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
85         return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/EditBackoffice.html";
86     }
87
88     public String JavaDoc getPublishUrl(CmsObject cms, String JavaDoc tagcontent,
89                                  A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
90         return CmsWorkplace.VFS_PATH_WORKPLACE.substring(1) + "administration/channels/Backoffice.html";
91     }
92
93     // removed for testing
94
public String JavaDoc getSetupUrl(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObject) throws Exception JavaDoc {
95         return "";
96     }
97
98     /**
99      * Gets the content of a given template file.
100      * <P>
101      *
102      * @param cms A_CmsObject Object for accessing system resources
103      * @param templateFile Filename of the template file
104      * @param elementName not used here
105      * @param parameters get the parameters action for the button activity
106      * and id for the used content definition instance object
107      * and the author, title, text content for setting the new/changed data
108      * @param templateSelector template section that should be processed.
109      * @return Processed content of the given template file.
110      * @throws CmsException
111      */

112     public byte[] getContentEdit(CmsObject cms, CmsXmlWpTemplateFile template, String JavaDoc elementName,
113                              Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
114         //get the Languagedata
115
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
116         //create appropriate class name with underscores for labels
117
String JavaDoc moduleName = "";
118         moduleName = getClass().toString(); //get name
119
moduleName = moduleName.substring(5); //remove 'class' substring at the beginning
120
moduleName = moduleName.trim();
121         moduleName = moduleName.replace('.', '_'); //replace dots with underscores
122
//session
123
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
124         //default error
125
String JavaDoc error="";
126         //get values of all fields
127
//gets the parameter action from the hashtable.
128
String JavaDoc action = (String JavaDoc) parameters.get("action");
129         if (action == null){
130             action="";
131         } else if (action.equals("exit")){
132             clearSession(session);
133             templateSelector= "done";
134             return startProcessing(cms, template, "", parameters, templateSelector);
135         }
136
137         // Get the parameter values
138

139         // get value of id
140
String JavaDoc id = (String JavaDoc) parameters.get("id");
141         String JavaDoc channelId = (String JavaDoc) parameters.get("channelId");
142         String JavaDoc resourceId = (String JavaDoc) parameters.get("resourceid");
143         String JavaDoc nullUUIDStr = CmsUUID.getNullUUID().toString();
144         
145         // get value of parentId
146
String JavaDoc parentName = (String JavaDoc) parameters.get("parentName");
147         if(parentName == null || parentName.equals("")){
148             parentName="/";
149         }
150         
151         // channelname
152
String JavaDoc channelname = (String JavaDoc) parameters.get("channelName");
153         if(channelname == null){
154             channelname = "";
155         }
156         
157         // plausibility check
158
if(!action.equals("") && channelname.trim().equals("")){
159             error = lang.getLanguageValue(moduleName+".error.message2");
160         }
161         
162         // title of channel
163
String JavaDoc title = (String JavaDoc) parameters.get("title");
164
165         String JavaDoc owner=(String JavaDoc) parameters.get("owner");
166         owner=(owner!=null?owner.trim():"");
167         String JavaDoc group=(String JavaDoc) parameters.get("groupId");
168         group=(group!=null?group.trim():"");
169
170         int accessFlags = this.getAccessValue(parameters);
171
172         //new channel
173
if (id == null || id.equals("")){
174             id = "new";
175         }
176         if(channelId==null || channelId.trim().equals("")){
177             channelId="-1";
178         }
179         if(resourceId==null || resourceId.trim().equals("")){
180             resourceId=nullUUIDStr;
181         }
182         if(id.equals("new")){
183             if(resourceId.equals(nullUUIDStr)){
184                 m_channel=null;
185             }else{
186                 id=resourceId;
187             }
188         }
189         // for the first call check if the id exist, i.e. if the category is to edit
190
// and it is not created new one then read the information of category
191
if (action.equals("") && !id.equals("new")) {
192 // try {
193
// Integer.parseInt(id);
194
// } catch (Exception err) {
195
// throw new CmsException(err.getMessage());
196
// }
197
// gets the already existing ouputchannel's content definition.
198
m_channel = new CmsChannelContent(cms,new CmsUUID(id));
199             parentName=m_channel.getParentName();
200             m_channelId=m_channel.getChannelId();
201             m_folderId = m_channel.getId();
202             channelname=m_channel.getChannelName();
203             title=m_channel.getTitle();
204             owner=m_channel.getOwner().toString();
205             group=m_channel.getGroupId().toString();
206             accessFlags=m_channel.getAccessFlags();
207         }else if(m_channel==null){
208             //create a new ouputchannels content definition.
209
m_channel = new CmsChannelContent(cms);
210             m_channelId = CmsDbUtil.UNKNOWN_ID+"";
211             m_folderId = CmsUUID.getNullUUID();
212         }
213         //put parentId in session for user method
214
session.putValue("parentName",parentName);
215         session.putValue("id",m_folderId.toString());
216         //set data in CD when data is correct
217
if(error.equals("") && !action.equals("")) {
218             m_channel.setChannelId(m_channelId);
219             m_channel.setParentName(parentName);
220             m_channel.setChannelName(channelname);
221             m_channel.setTitle(title);
222             m_channel.setGroup(new CmsUUID(group));
223             m_channel.setOwner(new CmsUUID(owner));
224             m_channel.setAccessFlags(accessFlags);
225         }
226         //get values of the user for new entry
227
// String defaultGroup=cms.getRequestContext().currentGroup().getName();
228
String JavaDoc defaultUser=cms.getRequestContext().currentUser().getName();
229         //get all groups
230
// Vector cmsGroups=cms.getGroups();
231
// select box of group
232
String JavaDoc groupOptions="";
233 // for (int i=0; i<cmsGroups.size(); i++) {
234
// String groupName=((CmsGroup)cmsGroups.elementAt(i)).getName();
235
// CmsUUID groupId=((CmsGroup)cmsGroups.elementAt(i)).getId();
236
// template.setData("name",groupName);
237
// template.setData("value",groupId.toString());
238
// if (!group.equals("") && (cms.readGroup(new CmsUUID(group)).getName()).equals(groupName)) {
239
// template.setData("check","selected");
240
// }else if(m_channelId.equals(I_CmsConstants.UNKNOWN_ID+"") && groupName.equals(defaultGroup)){
241
// template.setData("check","selected");
242
// }else{
243
// template.setData("check","");
244
// }
245
// groupOptions=groupOptions+template.getProcessedDataValue("selectoption",this);
246
// }
247
template.setData("groups",groupOptions);
248         // select box of owner
249
String JavaDoc userOptions="";
250         List JavaDoc cmsUsers=cms.getUsers();
251         for (int i=0;i<cmsUsers.size();i++) {
252             String JavaDoc userName=((CmsUser)cmsUsers.get(i)).getName();
253             CmsUUID userId=((CmsUser)cmsUsers.get(i)).getId();
254             template.setData("name",userName);
255             template.setData("value",userId.toString());
256             if (!owner.equals("") && (cms.readUser(new CmsUUID(owner)).getName()).equals(userName)) {
257                 template.setData("check","selected");
258             }else if(m_channelId.equals(CmsDbUtil.UNKNOWN_ID+"") && userName.equals(defaultUser)){
259                 template.setData("check","selected");
260             }else{
261                 template.setData("check","");
262             }
263             userOptions=userOptions+template.getProcessedDataValue("selectoption",this);
264         }
265         template.setData("users",userOptions);
266         // set the access flags
267
this.setAccessValue(template, m_channel.getAccessFlags());
268         //set data in template
269
template.setData("channelId", ""+m_channel.getChannelId());
270         template.setData("resourceid", m_channel.getId().toString());
271         template.setData("channelName", m_channel.getChannelName());
272         template.setData("title", CmsEncoder.escape(m_channel.getTitle(),
273             cms.getRequestContext().getEncoding()));
274         template.setData("parentName", m_channel.getParentName());
275         template.setData("error", error);
276
277         //if the saveexit-button has been clicked.
278
if(action.equals("saveexit") && error.equals("")){
279             try{
280                 m_channel.setChannelId(channelId);
281                 //write/save
282
m_channel.write(cms);
283                 //exit
284
clearSession(session);
285                 templateSelector = "done";
286                 return startProcessing(cms, template, "", parameters, templateSelector);
287             }catch (CmsException exc){
288                 template.setData("channelId", channelId);
289                 template.setData("resourceid", m_channel.getId().toString());
290                 template.setData("channelName", channelname);
291                 template.setData("title", CmsEncoder.escape(title,
292                     cms.getRequestContext().getEncoding()));
293                 template.setData("parentName", parentName);
294                 error = lang.getLanguageValue(moduleName+".error.message3")+" "+exc.getMessage();
295                 template.setData("error", error);
296                 //log
297
exc.printStackTrace(System.err);
298             }catch (Exception JavaDoc e){
299                 template.setData("channelId", channelId);
300                 template.setData("resourceid", m_channel.getId().toString());
301                 template.setData("channelName", channelname);
302                 template.setData("title", CmsEncoder.escape(title,
303                     cms.getRequestContext().getEncoding()));
304                 template.setData("parentName", parentName);
305                 error = lang.getLanguageValue(moduleName+".error.message3")+" "+e.getMessage();
306                 template.setData("error", error);
307                 //log
308
e.printStackTrace(System.err);
309             }
310         }
311
312         //if the "save"-button has been clicked.
313
if(action.equals("save") && error.equals("")){
314             try{
315                 m_channel.setChannelId(channelId);
316                 //write
317
m_channel.write(cms);
318                 m_channelId=m_channel.getChannelId();
319                 template.setData("channelId", m_channelId);
320                 template.setData("resourceid", m_channel.getId().toString());
321                 //indicator for saved new entrys - the new id
322
template.setData("newChannelId", m_channelId);
323             }catch (CmsException exc){
324                 template.setData("channelId", channelId);
325                 template.setData("resourceid", m_channel.getId().toString());
326                 template.setData("channelName", channelname);
327                 template.setData("title", CmsEncoder.escape(title,
328                     cms.getRequestContext().getEncoding()));
329                 template.setData("parentName", parentName);
330                 error = lang.getLanguageValue(moduleName+".error.message3")+" "+exc.getMessage();
331                 template.setData("error", error);
332                 //log
333
exc.printStackTrace(System.err);
334             }catch (Exception JavaDoc e){
335                 e.printStackTrace(System.err);
336                 template.setData("channelId", channelId);
337                 template.setData("resourceid", m_channel.getId().toString());
338                 template.setData("channelName", channelname);
339                 template.setData("title", CmsEncoder.escape(title,
340                     cms.getRequestContext().getEncoding()));
341                 template.setData("parentName", parentName);
342                 error = lang.getLanguageValue(moduleName+".error.message3")+" "+e.getMessage();
343                 template.setData("error", error);
344             }
345         }
346         //finally start the processing
347
return startProcessing(cms, template, elementName, parameters, templateSelector);
348     }
349
350     /**
351      * get the accessFlags from the template
352      */

353     private int getAccessValue(Hashtable JavaDoc parameters){
354         int accessFlag = 0;
355         for(int i=0; i<=8; i++){
356             String JavaDoc permissionsAtI=(String JavaDoc)parameters.get("permissions"+i);
357             if(permissionsAtI != null) {
358                 if(permissionsAtI.equals("on")) {
359                     accessFlag += new Integer JavaDoc(C_ACCESS_FLAGS[i]).intValue();
360                 }
361             }
362         }
363         if(accessFlag == 0){
364             accessFlag = C_DEFAULT_PERMISSIONS;
365         }
366         return accessFlag;
367     }
368
369     /**
370      * Set the accessFlags in the template
371      */

372      private void setAccessValue(CmsXmlWpTemplateFile template, int accessFlags){
373         // permissions check boxes
374
for(int i=0; i<=8; i++) {
375             int accessValueAtI = new Integer JavaDoc(C_ACCESS_FLAGS[i]).intValue();
376             if ((accessFlags & accessValueAtI) > 0) {
377                 template.setData("permissions_check_"+i,"checked");
378             } else {
379                 template.setData("permissions_check_"+i,"");
380             }
381         }
382      }
383     /**
384      * remove all session values used by outputchannel Backoffice
385      */

386     private void clearSession(I_CmsSession session){
387         session.removeValue("parentName");
388         session.removeValue("id");
389     }
390     /**
391      *
392      */

393     public boolean isExtendedList(){
394         return true;
395     }
396 }
Popular Tags