KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/master/CmsChannelContent.java,v $
3 * Date : $Date: 2005/06/27 23:22:25 $
4 * Version: $Revision: 1.5 $
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 // TODO: remove group/user
29
package com.opencms.defaults.master;
30
31 import org.opencms.db.CmsDbUtil;
32 import org.opencms.file.CmsGroup;
33 import org.opencms.file.CmsObject;
34 import org.opencms.file.CmsProperty;
35 import org.opencms.file.CmsPropertyDefinition;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.file.types.CmsResourceTypeFolder;
39 import org.opencms.lock.CmsLock;
40 import org.opencms.main.CmsException;
41 import org.opencms.main.CmsLog;
42 import org.opencms.main.OpenCms;
43 import org.opencms.security.CmsPermissionSet;
44 import org.opencms.util.CmsUUID;
45
46 import com.opencms.defaults.A_CmsContentDefinition;
47 import com.opencms.defaults.CmsFilterMethod;
48 import com.opencms.defaults.I_CmsExtendedContentDefinition;
49 import com.opencms.legacy.CmsLegacyException;
50 import com.opencms.legacy.CmsXmlTemplateLoader;
51
52 import java.util.Hashtable JavaDoc;
53 import java.util.List JavaDoc;
54 import java.util.Map JavaDoc;
55 import java.util.Vector JavaDoc;
56
57 /**
58  * This class is the master of several Modules. It carries a lot of generic
59  * data-fileds which can be used for a special Module.
60  *
61  * The module creates a set of methods to support project-integration, history
62  * and import - export.
63  *
64  * @author E. Falkenhan $
65  * $Revision: 1.5 $
66  * $Date: 2005/06/27 23:22:25 $
67  *
68  * @deprecated Will not be supported past the OpenCms 6 release.
69  */

70 public class CmsChannelContent extends A_CmsContentDefinition implements I_CmsExtendedContentDefinition{
71
72     // definition of the error codes used by this content defintion
73
private static String JavaDoc C_CHANNELNAME_ERRFIELD="channelname";
74     private static String JavaDoc C_PARENT_ERRFIELD="channelparent";
75     //error code for empty inputs
76
private static String JavaDoc C_ERRCODE_EMPTY="empty";
77     //error code for no text input
78

79     /** The cms-object to get access to the cms-ressources */
80     protected CmsObject m_cms = null;
81
82     /**
83      * The channel ID
84      */

85     private String JavaDoc m_channelId;
86
87     /**
88      * The resource object that contains the information for the channel
89      */

90     private CmsResource m_channel;
91
92     /**
93      * The name of the channel
94      */

95     private String JavaDoc m_channelname;
96
97     /**
98      * The name of the parent channel
99      */

100     private String JavaDoc m_parentchannel;
101
102     /**
103      * The properties of the channel
104      */

105     private Map JavaDoc m_properties;
106
107     /**
108      * The groupid of the channel
109      */

110     // private CmsUUID m_GroupId;
111

112     /**
113      * The userid of the channel
114      */

115     // private CmsUUID m_UserId;
116

117     /**
118      * The accessflags of the channel
119      */

120     private int m_accessflags;
121
122     /**
123      * Constructor to create a new contentdefinition. You can set data with your
124      * set-Methods. After you have called the write-method this definition gets
125      * a unique id.
126      */

127     public CmsChannelContent(CmsObject cms) {
128         m_cms = cms;
129         initValues();
130     }
131
132     /**
133      * Constructor to read a existing contentdefinition from the database. The
134      * data read from the database will be filled into the member-variables.
135      * You can read them with the get- and modify them with the set-methods.
136      * Changes you have made must be written back to the database by calling
137      * the write-method.
138      * @param cms the cms-object for access to cms-resources.
139      * @param resourceid the resource id of the channel to read.
140      * @throws CmsException if the data couldn't be read from the database.
141      */

142     public CmsChannelContent(CmsObject cms, String JavaDoc channelId) throws CmsException {
143         new CmsChannelContent(cms, new CmsUUID(channelId));
144     }
145     /**
146      * Constructor to read a existing contentdefinition from the database. The
147      * data read from the database will be filled into the member-variables.
148      * You can read them with the get- and modify them with the set-methods.
149      * Changes you have made must be written back to the database by calling
150      * the write-method.
151      * @param cms the cms-object for access to cms-resources.
152      * @param channelname the name of the channel to read.
153      * @throws CmsException if the data couldn't be read from the database.
154      */

155     public CmsChannelContent(CmsObject cms, CmsUUID channelId) throws CmsException {
156         throw new RuntimeException JavaDoc("Method CmsChannelContent(CmsObject cms, CmsUUID channelId) not longer supported");
157     }
158
159     /**
160      * Constructor to create a new contentdefinition. You can set data with your
161      * set-Methods. After you have called the write-method this definition gets
162      * a unique id.
163      */

164     public CmsChannelContent(CmsObject cms, CmsResource resource) {
165         String JavaDoc channelId = CmsDbUtil.UNKNOWN_ID+"";
166         String JavaDoc fullName = cms.getSitePath(resource);
167         m_cms = cms;
168         m_channel = resource;
169         m_channelname = resource.getName();
170         m_parentchannel = CmsResource.getParentFolder(cms.getSitePath(resource));
171         // m_GroupId = resource.getGroupId();
172
// m_UserId = resource.getOwnerId();
173
// m_accessflags = resource.getAccessFlags();
174
try{
175             m_properties = cms.readProperties(fullName);
176             channelId = (String JavaDoc)m_properties.get(CmsPropertyDefinition.PROPERTY_CHANNELID);
177         } catch (CmsException exc){
178             m_properties = new Hashtable JavaDoc();
179             m_properties.put(CmsPropertyDefinition.PROPERTY_CHANNELID, CmsDbUtil.UNKNOWN_ID+"");
180         } finally {
181             if(channelId == null || "".equals(channelId)){
182                 channelId = CmsDbUtil.UNKNOWN_ID+"";
183             }
184             m_channelId = channelId;
185         }
186     }
187
188     /**
189      * This method initialises all needed members with default-values.
190      */

191     protected void initValues() {
192         m_channelId = CmsDbUtil.UNKNOWN_ID+"";
193         m_channelname = "";
194         m_parentchannel = "";
195         m_accessflags = com.opencms.core.I_CmsConstants.C_ACCESS_DEFAULT_FLAGS;
196         // create the resource object for the channel:
197
m_channel = new CmsResource(CmsUUID.getNullUUID(), CmsUUID.getNullUUID(),
198                                      "", CmsResourceTypeFolder.RESOURCE_TYPE_ID, true, 0,
199                                      m_cms.getRequestContext().currentProject().getId(),
200                                      1, System.currentTimeMillis(),
201                                      m_cms.getRequestContext().currentUser().getId(), System.currentTimeMillis(),
202                                      m_cms.getRequestContext().currentUser().getId(), CmsResource.DATE_RELEASED_DEFAULT,
203                                      CmsResource.DATE_EXPIRED_DEFAULT, 1, 0);
204         m_properties = new Hashtable JavaDoc();
205     }
206
207     /**
208      * delete method
209      * for delete instance of content definition
210      * @param cms the CmsObject to use.
211      */

212     public void delete(CmsObject cms) throws Exception JavaDoc {
213         cms.getRequestContext().saveSiteRoot();
214         cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
215         try{
216             cms.deleteResource(cms.getSitePath(m_channel), CmsResource.DELETE_PRESERVE_SIBLINGS);
217         } catch (CmsException exc){
218             throw exc;
219             /*
220             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
221                 A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not delete channel "+cms.readPath(m_channel));
222             }
223             */

224         } finally {
225             cms.getRequestContext().restoreSiteRoot();
226         }
227     }
228
229     /**
230      * undelete method
231      * for undelete instance of content definition
232      * @param cms the CmsObject to use.
233      */

234     public void undelete(CmsObject cms) throws Exception JavaDoc {
235         cms.getRequestContext().saveSiteRoot();
236         cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
237         try{
238             cms.undeleteResource(cms.getSitePath(m_channel));
239         } catch (CmsException exc){
240             if (CmsLog.getLog(this).isErrorEnabled() ) {
241                 CmsLog.getLog(this).error("Could not undelete channel " + cms.getSitePath(m_channel), exc);
242             }
243         } finally {
244             cms.getRequestContext().restoreSiteRoot();
245         }
246     }
247
248     /**
249      * publish method
250      * for publish instance of content definition
251      * @param cms the CmsObject to use.
252      */

253     public void publishResource(CmsObject cms) {
254         if (CmsLog.getLog(this).isWarnEnabled() ) {
255             CmsLog.getLog(this).warn("Channels can't be published directly");
256         }
257     }
258
259     /**
260      * restore method
261      * for restore instance of content definition from history
262      * @param cms the CmsObject to use.
263      * @param versionId The id of the version to restore
264      */

265     public void restore(CmsObject cms, int versionId) {
266         if (CmsLog.getLog(this).isWarnEnabled() ) {
267             CmsLog.getLog(this).warn("Channels can't be restored from history");
268         }
269     }
270
271     /**
272      * Change owner method
273      * for changing permissions of content definition
274      * @param cms the CmsObject to use.
275      * @param owner the new owner of the cd.
276      */

277     public void chown(CmsObject cms, CmsUUID owner) {
278         if (CmsLog.getLog(this).isWarnEnabled() ) {
279             CmsLog.getLog(this).warn("Permissions of Channels can be changed only in EditBackoffice");
280         }
281     }
282
283     /**
284      * Change group method
285      * for changing permissions of content definition
286      * @param cms the CmsObject to use.
287      * @param group the new group of the cd.
288      */

289     public void chgrp(CmsObject cms, CmsUUID group) {
290         if (CmsLog.getLog(this).isWarnEnabled() ) {
291             CmsLog.getLog(this).warn("Permissions of Channels can be changed only in EditBackoffice");
292         }
293     }
294
295     /**
296      * Change access flags method
297      * for changing permissions of content definition
298      * @param cms the CmsObject to use.
299      * @param accessflags the new access flags of the cd.
300      */

301     public void chmod(CmsObject cms, int accessflags) {
302         if (CmsLog.getLog(this).isWarnEnabled() ) {
303             CmsLog.getLog(this).warn("Permissions of Channels can be changed only in EditBackoffice");
304         }
305     }
306     /**
307      * Copy method
308      * for copying content definition
309      * @param cms the CmsObject to use.
310      * @return int The id of the new content definition
311      */

312     public CmsUUID copy(CmsObject cms) {
313         if (CmsLog.getLog(this).isWarnEnabled() ) {
314             CmsLog.getLog(this).warn("Channels can't be copied!");
315         }
316         return CmsUUID.getNullUUID();
317     }
318
319     /**
320      * write method
321      * to write the current content of the content definition to the database.
322      * @param cms the CmsObject to use.
323      */

324     public void write(CmsObject cms) throws Exception JavaDoc {
325         CmsResource newChannel = null;
326         CmsLock lock = null;
327         // is this a new row or an existing row?
328
cms.getRequestContext().saveSiteRoot();
329         cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
330         try{
331             if((CmsDbUtil.UNKNOWN_ID+"").equals(m_channelId)) {
332                 // this is a new row - call the create statement
333
// first set the new channelId
334
setNewChannelId();
335                 newChannel = cms.createResource(m_parentchannel + m_channelname, CmsResourceTypeFolder.RESOURCE_TYPE_ID, null, CmsProperty.toList(m_properties));
336                 cms.lockResource(cms.getSitePath(newChannel));
337             } else {
338                 if (!"".equals(m_channel.getName())) {
339                     newChannel = cms.readFolder(cms.getSitePath(m_channel));
340                 }
341                 
342                 if (newChannel!=null && !cms.getSitePath(newChannel).equals(m_parentchannel+m_channelname+"/")){
343                     // the parent and/or the channelname has changed,
344
// so move or rename the channel
345
String JavaDoc parent = CmsResource.getParentFolder(cms.getSitePath(newChannel));
346                     if(! parent.equals(m_parentchannel)){
347                         // move the channel to the new parent channel
348
cms.moveResource(cms.getSitePath(newChannel), m_parentchannel+m_channelname);
349                     } else if (!newChannel.getName().equals(m_channelname)){
350                         // only rename the channel, the parent has not changed
351
cms.renameResource(cms.getSitePath(newChannel), m_channelname);
352                     }
353                 }
354                 // read the changed channel
355
newChannel = cms.readFolder(m_parentchannel+m_channelname+"/");
356                 lock = cms.getLock(newChannel);
357                 // update the title of the channel
358
String JavaDoc propTitle = cms.readProperty(cms.getSitePath(newChannel), CmsPropertyDefinition.PROPERTY_TITLE);
359                 if (propTitle == null){
360                     propTitle = "";
361                 }
362                 if (!propTitle.equals(this.getTitle())){
363                     cms.writeProperty(cms.getSitePath(newChannel), CmsPropertyDefinition.PROPERTY_TITLE, this.getTitle());
364                 }
365                 // check if the lockstate has changed
366
if(!lock.getUserId().equals(this.getLockstate()) ||
367                     lock.getProjectId() != cms.getRequestContext().currentProject().getId()){
368                     if(this.getLockstate().isNullUUID()){
369                         // unlock the channel
370
cms.unlockResource(cms.getSitePath(newChannel));
371                     } else {
372                         // lock the channel
373
cms.lockResource(cms.getSitePath(newChannel));
374                     }
375                 }
376             }
377             // TODO: ACL's for COS
378
// // check if the owner has changed
379
// if(!newChannel.getOwnerId().equals(this.getOwner())){
380
// cms.chown(cms.readAbsolutePath(newChannel), this.getOwnerName());
381
// }
382
// // check if the group has changed
383
// if(!newChannel.getGroupId().equals(this.getGroupId())){
384
// cms.chgrp(cms.readAbsolutePath(newChannel), this.getGroup());
385
// }
386
// // check if the accessflags has changed
387
// if(newChannel.getAccessFlags() != this.getAccessFlags()){
388
// cms.chmod(cms.readAbsolutePath(newChannel), this.getAccessFlags());
389
// }
390
m_channel = cms.readFolder(cms.getSitePath(newChannel));
391         } catch (CmsException exc){
392             throw exc;
393             /*
394             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
395                 A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not write channel "+cms.readPath(m_channel));
396             }
397             */

398         } finally {
399             cms.getRequestContext().restoreSiteRoot();
400         }
401     }
402
403     /**
404      * gets the unique Id of a content definition instance
405      * @param cms the CmsObject to use.
406      * @return a string with the Id
407      */

408     public String JavaDoc getUniqueId(CmsObject cms) {
409         return m_channel.getStructureId().toString();
410     }
411
412     /**
413      * gets the unique Id of a content definition instance
414      *
415      * @return int The unique id
416      */

417     public CmsUUID getId() {
418         return m_channel.getStructureId();
419     }
420
421     /**
422      * Gets the projectId where the CD belongs to.
423      * This method is required for the use of the abstract backoffice.
424      * @return int with the projectId.
425      */

426     public int getLockedInProject() {
427         try {
428             return m_cms.getLock(m_channel).getProjectId();
429         } catch (CmsException e) {
430             return CmsDbUtil.UNKNOWN_ID;
431         }
432     }
433
434     /**
435      * Gets the state of a CD.
436      * This method is required for the use of the abstract backoffice.
437      * @return int with the state.
438      */

439     public int getState() {
440         return m_channel.getState();
441     }
442
443     /**
444      * Gets the projectId of a CD.
445      * This method is required for the use of the abstract backoffice.
446      * @return int with the projectId.
447      */

448     public int getProjectId() {
449         return m_channel.getProjectLastModified();
450     }
451
452     /**
453      * gets the unique channel Id of a content definition instance
454      * @return a string with the Id
455      */

456     public String JavaDoc getChannelId() {
457         return m_channelId;
458     }
459
460     /**
461      * sets the unique channel Id of a content definition instance
462      */

463     public void setChannelId(String JavaDoc id) {
464         m_properties.put(CmsPropertyDefinition.PROPERTY_CHANNELID, id);
465         m_channelId = id;
466     }
467
468     /**
469      * Gets the title of the channel
470      */

471     public String JavaDoc getTitle(){
472         String JavaDoc title = (String JavaDoc)m_properties.get(CmsPropertyDefinition.PROPERTY_TITLE);
473         if (title == null){
474             title = "";
475         }
476         return title;
477     }
478
479     /**
480      * sets the title of a content definition instance
481      */

482     public void setTitle(String JavaDoc title) {
483         m_properties.put(CmsPropertyDefinition.PROPERTY_TITLE, title);
484     }
485
486     /**
487      * Gets the lockstate.
488      * @return a int with the user who has locked the ressource.
489      */

490     public CmsUUID getLockstate() {
491         try {
492             return m_cms.getLock(m_channel).getUserId();
493         } catch (CmsException e) {
494             return CmsUUID.getNullUUID();
495         }
496     }
497
498     /**
499      * Sets the lockstates
500      * @param the lockstate for the actual entry.
501      */

502     public void setLockstate(CmsUUID lockstate) {
503         // m_channel.setLocked(lockstate);
504
}
505
506     /**
507      * Gets the ownername of this contentdefinition.
508      */

509     public String JavaDoc getOwnerName() {
510         String JavaDoc ownername = "";
511         try{
512             ownername = m_cms.readUser(getOwner()).getName();
513         } catch (CmsException exc){
514             //nothing to do, return empty string
515
}
516         return ownername;
517     }
518
519     /**
520      * Gets the owner of this contentdefinition.
521      */

522     public CmsUUID getOwner() {
523         return CmsUUID.getNullUUID();
524         // return m_UserId;
525
}
526
527     /**
528      * Sets the owner of this contentdefinition.
529      */

530     public void setOwner(CmsUUID id) {
531         // m_UserId = id;
532
}
533
534     /**
535      * Gets the groupname
536      */

537     public String JavaDoc getGroup() {
538         String JavaDoc groupname = "*NOT USED*";
539         // try{
540
// groupname = m_cms.readGroup(this.getGroupId()).getName();
541
// } catch (CmsException exc){
542
// nothing to do, return empty string
543
// }
544
return groupname;
545     }
546
547     /**
548      * Gets the groupid
549      */

550     public CmsUUID getGroupId() {
551         return CmsUUID.getNullUUID();
552         // return m_GroupId;
553
}
554
555     /**
556      * Sets the group.
557      */

558     public void setGroup(CmsUUID groupId) {
559         // m_GroupId = groupId;
560
}
561
562     /**
563      * Gets the channelname
564      */

565     public String JavaDoc getChannelPath() {
566         return m_cms.getSitePath(m_channel);
567     }
568
569     /**
570      * Gets the channelname
571      */

572     public String JavaDoc getChannelName() {
573         return m_channelname;
574     }
575
576     /**
577      * Sets the channelname.
578      */

579     public void setChannelName(String JavaDoc name) {
580         m_channelname = name;
581     }
582
583     /**
584      * Sets the parentname of the channel.
585      */

586     public void setParentName(String JavaDoc name) {
587         m_parentchannel = name;
588     }
589
590     /**
591      * Gets the name of the parent channel
592      */

593     public String JavaDoc getParentName() {
594         return m_parentchannel;
595     }
596
597     /**
598      * Sets the accessflags of the channel.
599      */

600     public void setAccessFlags(int flags) {
601         m_accessflags = flags;
602     }
603
604     /**
605      * Gets the accessflags of the channel
606      */

607     public int getAccessFlags() {
608         return m_accessflags;
609     }
610
611     /**
612      * Gets the date of the last modification of the channel
613      */

614     public long getDateLastModified(){
615         return m_channel.getDateLastModified();
616     }
617
618     /**
619      * Gets the date of the creation of the channel
620      */

621     public long getDateCreated(){
622         return m_channel.getDateCreated();
623     }
624
625     /**
626      * Gets the id of the user who has modified the channel
627      */

628     public CmsUUID getLastModifiedBy(){
629         return m_channel.getUserLastModified();
630     }
631
632     /**
633      * Gets the name of the user who has modified the channel
634      */

635     public String JavaDoc getLastModifiedByName(){
636         return "";
637     }
638
639     /**
640      * Gets the version id of version the channel
641      */

642     public int getVersionId(){
643         return CmsDbUtil.UNKNOWN_ID;
644     }
645
646     /**
647      * Gets all groups, that may work for a project.
648      * <P>
649      * The given vectors <code>names</code> and <code>values</code> will
650      * be filled with the appropriate information to be used for building
651      * a select box.
652      *
653      * @param cms CmsObject Object for accessing system resources.
654      * @param names Vector to be filled with the appropriate values in this method.
655      * @param values Vector to be filled with the appropriate values in this method.
656      * @return Index representing the current value in the vectors.
657      * @throws CmsException
658      */

659
660     public Integer JavaDoc getGroups(CmsObject cms, Vector JavaDoc names, Vector JavaDoc values) throws CmsException {
661
662         // get all groups
663
List JavaDoc groups = cms.getGroups();
664         int retValue = -1;
665         String JavaDoc defaultGroup = OpenCms.getDefaultUsers().getGroupUsers();
666         // make sure the user has a session
667
CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
668         String JavaDoc enteredGroup = this.getGroup();
669         if(enteredGroup != null && !enteredGroup.equals("")) {
670
671             // if an error has occurred before, take the previous entry of the user
672
defaultGroup = enteredGroup;
673         }
674
675         // fill the names and values
676
int n = 0;
677         for(int z = 0;z < groups.size();z++) {
678             if(((CmsGroup)groups.get(z)).getProjectCoWorker()) {
679                 String JavaDoc name = ((CmsGroup)groups.get(z)).getName();
680                 if(defaultGroup.equals(name)) {
681                     retValue = n;
682                 }
683                 names.addElement(name);
684                 values.addElement(name);
685                 n++; // count the number of ProjectCoWorkers
686
}
687         }
688         return new Integer JavaDoc(retValue);
689     }
690
691     /**
692      * history method
693      * returns the history of content definition
694      * @param cms the CmsObject to use.
695      * @return Vector The history of a cd
696      */

697     public Vector JavaDoc getHistory(CmsObject cms) {
698         if (CmsLog.getLog(this).isWarnEnabled() ) {
699             CmsLog.getLog(this).warn("Channels have no history");
700         }
701         return null;
702     }
703
704     /**
705      * History method
706      * returns the cd of the version with the given versionId
707      *
708      * @param cms The CmsObject
709      * @param versionId The version id
710      * @return Object The object with the version of the cd
711      */

712     public Object JavaDoc getVersionFromHistory(CmsObject cms, int versionId){
713         if (CmsLog.getLog(this).isWarnEnabled() ) {
714             CmsLog.getLog(this).warn("Channels have no history");
715         }
716         return null;
717     }
718     /**
719      * returns true if the CD is readable for the current user
720      * @return true
721      */

722     public boolean isReadable() {
723         m_cms.getRequestContext().saveSiteRoot();
724         m_cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
725         try {
726             return m_cms.hasPermissions(m_channel, CmsPermissionSet.ACCESS_READ);
727             // TODO: remove this later
728
// m_cms.accessRead();
729
} catch(CmsException exc) {
730             // there was a cms-exception - no read-access!
731
return false;
732         } finally {
733             m_cms.getRequestContext().restoreSiteRoot();
734         }
735     }
736
737     /**
738      * returns true if the CD is writeable for the current user
739      * @return true
740      */

741     public boolean isWriteable() {
742         m_cms.getRequestContext().saveSiteRoot();
743         m_cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
744         try {
745             // return m_cms.accessWrite(cms.readPath(m_channel));
746
return m_cms.hasPermissions(m_channel, CmsPermissionSet.ACCESS_WRITE);
747         } catch(CmsException exc) {
748             // there was a cms-exception - no write-access!
749
return false;
750         } finally {
751             m_cms.getRequestContext().restoreSiteRoot();
752         }
753     }
754
755     /**
756      * Returns the sub-id of this contentdefinition. You have to implement this
757      * method so it returns a unique sunb-id that describes the type of the
758      * contentdefinition. (E.g. article: sub-id=1; table: sub-id=2).
759      */

760     //abstract public int getSubId();
761

762     /**
763      * Returns a String representation of this instance.
764      * This can be used for debugging purposes.
765      */

766     public String JavaDoc toString() {
767         StringBuffer JavaDoc returnValue = new StringBuffer JavaDoc();
768         returnValue.append(this.getClass().getName() + "{");
769         returnValue.append("ChannelId=" + getChannelId() + ";");
770         returnValue.append("ChannelName=" + getChannelPath() + ";");
771         returnValue.append("Lockstate=" + getLockstate() + ";");
772         returnValue.append("AccessFlags=" + getAccessFlagsAsString() + ";");
773         returnValue.append(m_channel.toString() + "}");
774         return returnValue.toString();
775     }
776
777     /**
778      * Convenience method to get the access-Flags as String representation.
779      * @return String of access rights
780      */

781     public String JavaDoc getAccessFlagsAsString() {
782
783         int accessFlags = getAccessFlags();
784         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
785
786         buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_READ) > 0 ? "r" : "-"));
787         buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_WRITE) > 0 ? "w" : "-"));
788         buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_VIEW) > 0 ? "v" : "-"));
789         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_READ) > 0 ? "r" : "-"));
790         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_WRITE) > 0 ? "w" : "-"));
791         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_VISIBLE) > 0 ? "v" : "-"));
792         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_READ) > 0 ? "r" : "-"));
793         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_WRITE) > 0 ? "w" : "-"));
794         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE) > 0 ? "v" : "-"));
795         buf.append(((accessFlags & CmsResource.FLAG_INTERNAL) > 0 ? "i" : "-"));
796
797         return buf.toString();
798     }
799
800     /**
801      * Get the permissions of Channel
802      */

803     public void setAccessFlagsAsString(String JavaDoc permissions){
804         //change direction
805
String JavaDoc perm=permissions;
806         permissions="";
807         for(int x=9;x >= 0;x--) {
808             char temp=perm.charAt(x);
809             permissions+=temp;
810         }
811         setAccessFlags(Integer.parseInt(permissions,2));
812     }
813
814     /**
815      * Sets the channelId of a new channel
816      */

817     private void setNewChannelId() throws CmsException{
818         int newChannelId = org.opencms.db.CmsDbUtil.nextId(com.opencms.core.I_CmsConstants.C_TABLE_CHANNELID);
819         m_properties.put(CmsPropertyDefinition.PROPERTY_CHANNELID, newChannelId+"");
820         m_channelId = newChannelId+"";
821     }
822
823     /**
824      * This content definition is lockable. This class overwrited the isLockable method of the abstract
825      * backoffice to flag that this content definition uses the lock feature of the backoffice. *
826      */

827     public static boolean isLockable() {
828         return true;
829     }
830
831     /**
832      * Gets the names of the table columns displayed in the backoffice filelist.
833      * This method is needed for the abstract backoffice class only.
834      * @return Vector containing the columnnames.
835      */

836     public static Vector JavaDoc getFieldNames(CmsObject cms) {
837         Vector JavaDoc names = new Vector JavaDoc();
838         names.addElement("channelId");
839         names.addElement("channelPath");
840         names.addElement("title");
841         names.addElement("ownerName");
842         names.addElement("group");
843         names.addElement("accessFlagsAsString");
844         return names;
845     }
846
847     /**
848      * Gets the methods used to display the dava values in the backoffice filelist.
849      * This method is needed for the abstract backoffice class only.
850      * @return Vector with the nescessary get methods
851      */

852     public static Vector JavaDoc getFieldMethods(CmsObject cms) {
853         Vector JavaDoc methods = new Vector JavaDoc();
854         try {
855             methods.addElement(CmsChannelContent.class.getMethod("getChannelId", new Class JavaDoc[0]));
856             methods.addElement(CmsChannelContent.class.getMethod("getChannelPath", new Class JavaDoc[0]));
857             methods.addElement(CmsChannelContent.class.getMethod("getTitle", new Class JavaDoc[0]));
858             methods.addElement(CmsChannelContent.class.getMethod("getOwnerName", new Class JavaDoc[0]));
859             methods.addElement(CmsChannelContent.class.getMethod("getGroup", new Class JavaDoc[0]));
860             methods.addElement(CmsChannelContent.class.getMethod("getAccessFlagsAsString", new Class JavaDoc[0]));
861         } catch(NoSuchMethodException JavaDoc exc) {
862             // this exception should never occur. You know your own methods in this cd
863
}
864         return methods;
865     }
866
867     /**
868      * Gets the filter methods
869      * This method is needed for the abstract backoffice class only.
870      * @return a method array containing the methods
871      */

872     public static Vector JavaDoc getFilterMethods(CmsObject cms) {
873         Vector JavaDoc filterMethods = new Vector JavaDoc();
874         try {
875             CmsFilterMethod filterUp = new CmsFilterMethod("All Channels",
876                                       CmsChannelContent.class.getMethod("getChannelList",
877                                       new Class JavaDoc[] {CmsObject.class} ) , new Object JavaDoc[0]);
878             filterMethods.addElement(filterUp);
879         } catch (NoSuchMethodException JavaDoc nsm) {
880             // this exception should never occur because you know your filter methods.
881
}
882         return filterMethods;
883     }
884
885     /**
886      * Returns a vector of CD objects, sorted descending by channelname.
887      * This method is needed for the abstract backoffice class only.
888      * @param cms The CmsObject.
889      */

890     public static Vector JavaDoc getChannelList(CmsObject cms) throws CmsException {
891         Vector JavaDoc content = new Vector JavaDoc();
892         cms.getRequestContext().saveSiteRoot();
893         cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
894         try {
895             getAllResources(cms, "/", content);
896         } catch(CmsException e) {
897             // ignore the exception
898
if (CmsLog.getLog(CmsChannelContent.class).isWarnEnabled()) {
899                 CmsLog.getLog(CmsChannelContent.class).warn("Error while reading subfolders of cos root", e);
900             }
901         } finally {
902             cms.getRequestContext().restoreSiteRoot();
903         }
904         return content;
905     }
906     /**
907      * Helper for method getChannelList
908      */

909     private static void getAllResources(CmsObject cms, String JavaDoc rootFolder, Vector JavaDoc allFolders) throws CmsException {
910         // get folders of this rootFolder
911
Vector JavaDoc subFolders = new Vector JavaDoc();
912         try{
913             subFolders.addAll(cms.getResourcesInFolder(rootFolder, CmsResourceFilter.ONLY_VISIBLE));
914         } catch (CmsException e){
915             // if the folder could not be found it might be deleted, so don't throw this exception
916
if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() != CmsLegacyException.C_NOT_FOUND)) {
917                 throw e;
918             }
919         }
920         //copy the values into the allFolders Vector
921
for(int i = 0;i < subFolders.size();i++) {
922             CmsResource curFolder = (CmsResource)subFolders.elementAt(i);
923             CmsChannelContent curChannel = new CmsChannelContent(cms, curFolder);
924             allFolders.addElement(curChannel);
925             getAllResources(cms, cms.getSitePath(curFolder), allFolders);
926         }
927     }
928     /**
929      * Plauzibilization method.
930      * This method checks if all inputfields contain correct input data.
931      * If an input field has no correct data, a CmsPlausibilizationException is thrown.
932      * @throws Throws CmsPlausibilizationException containing a vector of error-codes.
933      */

934     public void check() throws CmsPlausibilizationException {
935         // define the vector which will hold all error codes
936
Vector JavaDoc errorCodes = new Vector JavaDoc();
937         //check the channelname
938
if (m_channelname == null || "".equals(m_channelname)) {
939             errorCodes.addElement(C_CHANNELNAME_ERRFIELD+com.opencms.core.I_CmsConstants.C_ERRSPERATOR+C_ERRCODE_EMPTY);
940         }
941         //check the parentchannel
942
if (m_parentchannel == null || "".equals(m_parentchannel)) {
943             errorCodes.addElement(C_PARENT_ERRFIELD+com.opencms.core.I_CmsConstants.C_ERRSPERATOR+C_ERRCODE_EMPTY);
944         }
945         // now test if there was an error message and throw an exception
946
if (errorCodes.size()>0) {
947             throw new CmsPlausibilizationException(errorCodes);
948         }
949     }
950 }
Popular Tags