Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/defaults/master/CmsChannelContent.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/defaults/master/CmsChannelContent.java,v $
3   * Date   : $Date: 2003/04/02 12:44:10 $
4   * Version: $Revision: 1.18 $
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 com.opencms.boot.I_CmsLogChannels;
32  import com.opencms.core.A_OpenCms;
33  import com.opencms.core.CmsException;
34  import com.opencms.core.I_CmsConstants;
35  import com.opencms.core.exceptions.CmsPlausibilizationException;
36  import com.opencms.defaults.A_CmsContentDefinition;
37  import com.opencms.defaults.CmsFilterMethod;
38  import com.opencms.defaults.I_CmsExtendedContentDefinition;
39  import com.opencms.file.CmsGroup;
40  import com.opencms.file.CmsObject;
41  import com.opencms.file.CmsResource;
42  import com.opencms.template.I_CmsContent;
43  
44  import java.util.Hashtable;
45  import java.util.Map;
46  import java.util.Vector;
47  
48  /**
49   * This class is the master of several Modules. It carries a lot of generic
50   * data-fileds which can be used for a special Module.
51   *
52   * The module creates a set of methods to support project-integration, history
53   * and import - export.
54   *
55   * @author E. Falkenhan $
56   * $Revision: 1.18 $
57   * $Date: 2003/04/02 12:44:10 $
58   */
59  public class CmsChannelContent extends A_CmsContentDefinition
60                                 implements I_CmsContent, I_CmsLogChannels, I_CmsExtendedContentDefinition{
61  
62      /**
63       * The name of the "tablekey" for the channel id
64       */
65      private static final String C_TABLE_CHANNELID = I_CmsConstants.C_TABLE_CHANNELID;
66  
67      // definition of the error codes used by this content defintion
68      private static String C_CHANNELNAME_ERRFIELD="channelname";
69      private static String C_PARENT_ERRFIELD="channelparent";
70      //error code for empty inputs
71      private static String C_ERRCODE_EMPTY="empty";
72      //error code for no text input
73  
74      /** The cms-object to get access to the cms-ressources */
75      protected CmsObject m_cms = null;
76  
77      /**
78       * The channel ID
79       */
80      private String m_channelId;
81  
82      /**
83       * The resource object that contains the information for the channel
84       */
85      private CmsResource m_channel;
86  
87      /**
88       * The name of the channel
89       */
90      private String m_channelname;
91  
92      /**
93       * The name of the parent channel
94       */
95      private String m_parentchannel;
96  
97      /**
98       * The properties of the channel
99       */
100     private Map m_properties;
101 
102     /**
103      * The groupid of the channel
104      */
105     private int m_groupid;
106 
107     /**
108      * The userid of the channel
109      */
110     private int m_userid;
111 
112     /**
113      * The accessflags of the channel
114      */
115     private int m_accessflags;
116 
117     /**
118      * Constructor to create a new contentdefinition. You can set data with your
119      * set-Methods. After you have called the write-method this definition gets
120      * a unique id.
121      */
122     public CmsChannelContent(CmsObject cms) {
123         m_cms = cms;
124         initValues();
125     }
126 
127     /**
128      * Constructor to read a existing contentdefinition from the database. The
129      * data read from the database will be filled into the member-variables.
130      * You can read them with the get- and modify them with the set-methods.
131      * Changes you have made must be written back to the database by calling
132      * the write-method.
133      * @param cms the cms-object for access to cms-resources.
134      * @param resourceid the resource id of the channel to read.
135      * @throws CmsException if the data couldn't be read from the database.
136      */
137     public CmsChannelContent(CmsObject cms, String resourceid) throws CmsException {
138         new CmsChannelContent(cms, new Integer(resourceid));
139     }
140     /**
141      * Constructor to read a existing contentdefinition from the database. The
142      * data read from the database will be filled into the member-variables.
143      * You can read them with the get- and modify them with the set-methods.
144      * Changes you have made must be written back to the database by calling
145      * the write-method.
146      * @param cms the cms-object for access to cms-resources.
147      * @param channelname the name of the channel to read.
148      * @throws CmsException if the data couldn't be read from the database.
149      */
150     public CmsChannelContent(CmsObject cms, Integer resourceid) throws CmsException {
151         m_cms = cms;
152         initValues();
153         m_cms.setContextToCos();
154         try{
155             m_channel = (CmsResource) m_cms.readFolder(resourceid.intValue(), true);
156             m_channelname = m_channel.getName();
157             m_parentchannel = m_channel.getParent();
158             m_groupid = m_channel.getGroupId();
159             m_userid = m_channel.getOwnerId();
160             m_accessflags = m_channel.getAccessFlags();
161             m_properties = m_cms.readProperties(m_channel.getAbsolutePath());
162             m_channelId = (String)m_properties.get(I_CmsConstants.C_PROPERTY_CHANNELID);
163         } catch (CmsException exc){
164             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
165                 A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not get channel "+resourceid);
166             }
167         } finally {
168             m_cms.setContextToVfs();
169         }
170     }
171 
172     /**
173      * Constructor to create a new contentdefinition. You can set data with your
174      * set-Methods. After you have called the write-method this definition gets
175      * a unique id.
176      */
177     public CmsChannelContent(CmsObject cms, CmsResource resource) {
178         String channelId = C_UNKNOWN_ID+"";
179         m_cms = cms;
180         m_channel = resource;
181         m_channelname = resource.getName();
182         m_parentchannel = resource.getParent();
183         m_groupid = resource.getGroupId();
184         m_userid = resource.getOwnerId();
185         m_accessflags = resource.getAccessFlags();
186         try{
187             m_properties = cms.readProperties(resource.getAbsolutePath());
188             channelId = (String)m_properties.get(I_CmsConstants.C_PROPERTY_CHANNELID);
189         } catch (CmsException exc){
190             m_properties = new Hashtable();
191             m_properties.put(I_CmsConstants.C_PROPERTY_CHANNELID, C_UNKNOWN_ID+"");
192         } finally {
193             if(channelId == null || "".equals(channelId)){
194                 channelId = C_UNKNOWN_ID+"";
195             }
196             m_channelId = channelId;
197         }
198     }
199 
200     /**
201      * This method initialises all needed members with default-values.
202      */
203     protected void initValues() {
204         m_channelId = I_CmsConstants.C_UNKNOWN_ID+"";
205         m_channelname = "";
206         m_parentchannel = "";
207         m_groupid = m_cms.getRequestContext().currentGroup().getId();
208         m_userid = m_cms.getRequestContext().currentUser().getId();
209         m_accessflags = I_CmsConstants.C_ACCESS_DEFAULT_FLAGS;
210         // create the resource object for the channel:
211         // int resourceId, int parentId, int fileId, String resourceName, int resourceType,
212         // int resourceFlags, int user, int group, int projectId, int accessFlags, int state,
213         // int lockedBy, int launcherType, String launcherClassname, long dateCreated,
214         // long dateLastModified, int resourceLastModifiedBy,int size, int lockedInProject
215         m_channel = new CmsResource(I_CmsConstants.C_UNKNOWN_ID, I_CmsConstants.C_UNKNOWN_ID,
216                                      I_CmsConstants.C_UNKNOWN_ID, "", I_CmsConstants.C_TYPE_FOLDER, 0,
217                                      m_cms.getRequestContext().currentUser().getId(),
218                                      m_cms.getRequestContext().currentGroup().getId(),
219                                      m_cms.getRequestContext().currentProject().getId(),
220                                      I_CmsConstants.C_ACCESS_DEFAULT_FLAGS, 1,
221                                      m_cms.getRequestContext().currentUser().getId(),
222                                      I_CmsConstants.C_UNKNOWN_ID, "",
223                                      System.currentTimeMillis(), System.currentTimeMillis(),
224                                      m_cms.getRequestContext().currentUser().getId(), 0,
225                                      m_cms.getRequestContext().currentProject().getId());
226         m_properties = new Hashtable();
227     }
228 
229     /**
230      * delete method
231      * for delete instance of content definition
232      * @param cms the CmsObject to use.
233      */
234     public void delete(CmsObject cms) throws Exception {
235         cms.setContextToCos();
236         try{
237             cms.deleteResource(m_channel.getAbsolutePath());
238         } catch (CmsException exc){
239             throw exc;
240             /*
241             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
242                 A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not delete channel "+m_channel.getAbsolutePath());
243             }
244             */
245         } finally {
246             cms.setContextToVfs();
247         }
248     }
249 
250     /**
251      * undelete method
252      * for undelete instance of content definition
253      * @param cms the CmsObject to use.
254      */
255     public void undelete(CmsObject cms) throws Exception {
256         cms.setContextToCos();
257         try{
258             cms.undeleteResource(m_channel.getAbsolutePath());
259         } catch (CmsException exc){
260             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
261                 A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not undelete channel "+m_channel.getAbsolutePath());
262             }
263         } finally {
264             cms.setContextToVfs();
265         }
266     }
267 
268     /**
269      * publish method
270      * for publish instance of content definition
271      * @param cms the CmsObject to use.
272      */
273     public void publishResource(CmsObject cms) {
274         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
275             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels can't be published directly!");
276         }
277     }
278 
279     /**
280      * restore method
281      * for restore instance of content definition from history
282      * @param cms the CmsObject to use.
283      * @param versionId The id of the version to restore
284      */
285     public void restore(CmsObject cms, int versionId) {
286         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
287             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels can't be restored from history!");
288         }
289     }
290 
291     /**
292      * Change owner method
293      * for changing permissions of content definition
294      * @param cms the CmsObject to use.
295      * @param owner the new owner of the cd.
296      */
297     public void chown(CmsObject cms, int owner) {
298         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
299             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Permissions of Channels can be changed only in EditBackoffice!");
300         }
301     }
302 
303     /**
304      * Change group method
305      * for changing permissions of content definition
306      * @param cms the CmsObject to use.
307      * @param group the new group of the cd.
308      */
309     public void chgrp(CmsObject cms, int group) {
310         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
311             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Permissions of Channels can be changed only in EditBackoffice!");
312         }
313     }
314 
315     /**
316      * Change access flags method
317      * for changing permissions of content definition
318      * @param cms the CmsObject to use.
319      * @param accessflags the new access flags of the cd.
320      */
321     public void chmod(CmsObject cms, int accessflags) {
322         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
323             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Permissions of Channels can be changed only in EditBackoffice!");
324         }
325     }
326     /**
327      * Copy method
328      * for copying content definition
329      * @param cms the CmsObject to use.
330      * @return int The id of the new content definition
331      */
332     public int copy(CmsObject cms) {
333         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
334             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels can be copied!");
335         }
336         return -1;
337     }
338 
339     /**
340      * write method
341      * to write the current content of the content definition to the database.
342      * @param cms the CmsObject to use.
343      */
344     public void write(CmsObject cms) throws Exception {
345         CmsResource newChannel = null;
346         // is this a new row or an existing row?
347         cms.setContextToCos();
348         try{
349             if((I_CmsConstants.C_UNKNOWN_ID+"").equals(m_channelId)) {
350                 // this is a new row - call the create statement
351                 // first set the new channelId
352                 setNewChannelId();
353                 newChannel = cms.createResource(m_parentchannel, m_channelname, I_CmsConstants.C_TYPE_FOLDER_NAME, m_properties);
354                 cms.lockResource(newChannel.getAbsolutePath(), true);
355             } else {
356                 if (!"".equals(m_channel.getResourceName())) {
357                     newChannel = cms.readFolder(m_channel.getAbsolutePath());
358                 }
359                 
360                 if (newChannel!=null && !newChannel.getAbsolutePath().equals(m_parentchannel+m_channelname+"/")){
361                     // the parent and/or the channelname has changed,
362                     // so move or rename the channel
363                     if(!newChannel.getParent().equals(m_parentchannel)){
364                         // move the channel to the new parent channel
365                         cms.moveResource(newChannel.getAbsolutePath(), m_parentchannel+m_channelname);
366                     } else if (!newChannel.getName().equals(m_channelname)){
367                         // only rename the channel, the parent has not changed
368                         cms.renameResource(newChannel.getAbsolutePath(), m_channelname);
369                     }
370                 }
371                 // read the changed channel
372                 newChannel =  cms.readFolder(m_parentchannel+m_channelname+"/");
373                 // update the title of the channel
374                 String propTitle = cms.readProperty(newChannel.getAbsolutePath(), I_CmsConstants.C_PROPERTY_TITLE);
375                 if (propTitle == null){
376                     propTitle = "";
377                 }
378                 if (!propTitle.equals(this.getTitle())){
379                     cms.writeProperty(newChannel.getAbsolutePath(), I_CmsConstants.C_PROPERTY_TITLE, this.getTitle());
380                 }
381                 // check if the lockstate has changed
382                 if(newChannel.isLockedBy() != this.getLockstate() ||
383                     newChannel.getLockedInProject() != cms.getRequestContext().currentProject().getId()){
384                     if(this.getLockstate() == I_CmsConstants.C_UNKNOWN_ID){
385                         // unlock the channel
386                         cms.unlockResource(newChannel.getAbsolutePath());
387                     } else {
388                         // lock the channel
389                         cms.lockResource(newChannel.getAbsolutePath(), true);
390                     }
391                 };
392             }
393             // check if the owner has changed
394             if(newChannel.getOwnerId() != this.getOwner()){
395                 cms.chown(newChannel.getAbsolutePath(), this.getOwnerName());
396             };
397             // check if the group has changed
398             if(newChannel.getGroupId() != this.getGroupId()){
399                 cms.chgrp(newChannel.getAbsolutePath(), this.getGroup());
400             };
401             // check if the accessflags has changed
402             if(newChannel.getAccessFlags() != this.getAccessFlags()){
403                 cms.chmod(newChannel.getAbsolutePath(), this.getAccessFlags());
404             };
405             m_channel = cms.readFolder(newChannel.getAbsolutePath());
406         } catch (CmsException exc){
407             throw exc;
408             /*
409             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
410                 A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not write channel "+m_channel.getAbsolutePath());
411             }
412             */
413         } finally {
414             cms.setContextToVfs();
415         }
416     }
417 
418     /**
419      * gets the unique Id of a content definition instance
420      * @param cms the CmsObject to use.
421      * @return a string with the Id
422      */
423     public String getUniqueId(CmsObject cms) {
424         return m_channel.getResourceId() + "";
425     }
426 
427     /**
428      * gets the unique Id of a content definition instance
429      *
430      * @return int The unique id
431      */
432     public int getId() {
433         return m_channel.getResourceId();
434     }
435 
436     /**
437      * Gets the projectId where the CD belongs to.
438      * This method is required for the use of the abstract backoffice.
439      * @return int with the projectId.
440      */
441     public int getLockedInProject() {
442         return m_channel.getLockedInProject();
443     }
444 
445     /**
446      * Gets the state of a CD.
447      * This method is required for the use of the abstract backoffice.
448      * @return int with the state.
449      */
450     public int getState() {
451         return m_channel.getState();
452     }
453 
454     /**
455      * Gets the projectId of a CD.
456      * This method is required for the use of the abstract backoffice.
457      * @return int with the projectId.
458      */
459     public int getProjectId() {
460         return m_channel.getProjectId();
461     }
462 
463     /**
464      * gets the unique channel Id of a content definition instance
465      * @return a string with the Id
466      */
467     public String getChannelId() {
468         return m_channelId;
469     }
470 
471     /**
472      * sets the unique channel Id of a content definition instance
473      */
474     public void setChannelId(String id) {
475         m_properties.put(I_CmsConstants.C_PROPERTY_CHANNELID, id);
476         m_channelId = id;
477     }
478 
479     /**
480      * Gets the title of the channel
481      */
482     public String getTitle(){
483         String title = (String)m_properties.get(I_CmsConstants.C_PROPERTY_TITLE);
484         if (title == null){
485             title = "";
486         }
487         return title;
488     }
489 
490     /**
491      * sets the title of a content definition instance
492      */
493     public void setTitle(String title) {
494         m_properties.put(I_CmsConstants.C_PROPERTY_TITLE, title);
495     }
496 
497     /**
498      * Gets the lockstate.
499      * @return a int with the user who has locked the ressource.
500      */
501     public int getLockstate() {
502         return m_channel.isLockedBy();
503     }
504 
505     /**
506      * Sets the lockstates
507      * @param the lockstate for the actual entry.
508      */
509     public void setLockstate(int lockstate) {
510         m_channel.setLocked(lockstate);
511     }
512 
513     /**
514      * Gets the ownername of this contentdefinition.
515      */
516     public String getOwnerName() {
517         String ownername = "";
518         try{
519             ownername = m_cms.readUser(getOwner()).getName();
520         } catch (CmsException exc){
521             //nothing to do, return empty string
522         }
523         return ownername;
524     }
525 
526     /**
527      * Gets the owner of this contentdefinition.
528      */
529     public int getOwner() {
530         return m_userid;
531     }
532 
533     /**
534      * Sets the owner of this contentdefinition.
535      */
536     public void setOwner(int id) {
537         m_userid = id;
538     }
539 
540     /**
541      * Gets the groupname
542      */
543     public String getGroup() {
544         String groupname = "";
545         try{
546             groupname = m_cms.readGroup(this.getGroupId()).getName();
547         } catch (CmsException exc){
548             // nothing to do, return empty string
549         }
550         return groupname;
551     }
552 
553     /**
554      * Gets the groupid
555      */
556     public int getGroupId() {
557         return m_groupid;
558     }
559 
560     /**
561      * Sets the group.
562      */
563     public void setGroup(int id) {
564         m_groupid = id;
565     }
566 
567     /**
568      * Gets the channelname
569      */
570     public String getChannelPath() {
571         return m_channel.getParent()+m_channel.getName();
572     }
573 
574     /**
575      * Gets the channelname
576      */
577     public String getChannelName() {
578         return m_channelname;
579     }
580 
581     /**
582      * Sets the channelname.
583      */
584     public void setChannelName(String name) {
585         m_channelname = name;
586     }
587 
588     /**
589      * Sets the parentname of the channel.
590      */
591     public void setParentName(String name) {
592         m_parentchannel = name;
593     }
594 
595     /**
596      * Gets the name of the parent channel
597      */
598     public String getParentName() {
599         return m_parentchannel;
600     }
601 
602     /**
603      * Sets the accessflags of the channel.
604      */
605     public void setAccessFlags(int flags) {
606         m_accessflags = flags;
607     }
608 
609     /**
610      * Gets the accessflags of the channel
611      */
612     public int getAccessFlags() {
613         return m_accessflags;
614     }
615 
616     /**
617      * Gets the date of the last modification of the channel
618      */
619     public long getDateLastModified(){
620         return m_channel.getDateLastModified();
621     }
622 
623     /**
624      * Gets the date of the creation of the channel
625      */
626     public long getDateCreated(){
627         return m_channel.getDateCreated();
628     }
629 
630     /**
631      * Gets the id of the user who has modified the channel
632      */
633     public int getLastModifiedBy(){
634         return m_channel.getResourceLastModifiedBy();
635     }
636 
637     /**
638      * Gets the name of the user who has modified the channel
639      */
640     public String getLastModifiedByName(){
641         return "";
642     }
643 
644     /**
645      * Gets the version id of version the channel
646      */
647     public int getVersionId(){
648         return C_UNKNOWN_ID;
649     }
650 
651     /**
652      * Gets all groups, that may work for a project.
653      * <P>
654      * The given vectors <code>names</code> and <code>values</code> will
655      * be filled with the appropriate information to be used for building
656      * a select box.
657      *
658      * @param cms CmsObject Object for accessing system resources.
659      * @param names Vector to be filled with the appropriate values in this method.
660      * @param values Vector to be filled with the appropriate values in this method.
661      * @return Index representing the current value in the vectors.
662      * @throws CmsException
663      */
664 
665     public Integer getGroups(CmsObject cms, Vector names, Vector values) throws CmsException {
666 
667         // get all groups
668         Vector groups = cms.getGroups();
669         int retValue = -1;
670         String defaultGroup = C_GROUP_USERS;
671         // make sure the user has a session
672         cms.getRequestContext().getSession(true);
673         String enteredGroup = this.getGroup();
674         if(enteredGroup != null && !enteredGroup.equals("")) {
675 
676             // if an error has occurred before, take the previous entry of the user
677             defaultGroup = enteredGroup;
678         }
679 
680         // fill the names and values
681         int n = 0;
682         for(int z = 0;z < groups.size();z++) {
683             if(((CmsGroup)groups.elementAt(z)).getProjectCoWorker()) {
684                 String name = ((CmsGroup)groups.elementAt(z)).getName();
685                 if(defaultGroup.equals(name)) {
686                     retValue = n;
687                 }
688                 names.addElement(name);
689                 values.addElement(name);
690                 n++; // count the number of ProjectCoWorkers
691             }
692         }
693         return new Integer(retValue);
694     }
695 
696     /**
697      * history method
698      * returns the history of content definition
699      * @param cms the CmsObject to use.
700      * @return Vector The history of a cd
701      */
702     public Vector getHistory(CmsObject cms) {
703         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
704             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels have no history!");
705         }
706         return null;
707     }
708 
709     /**
710      * History method
711      * returns the cd of the version with the given versionId
712      *
713      * @param cms The CmsObject
714      * @param versionId The version id
715      * @return Object The object with the version of the cd
716      */
717     public Object getVersionFromHistory(CmsObject cms, int versionId){
718         if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
719             A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels have no history!");
720         }
721         return null;
722     };
723     /**
724      * returns true if the CD is readable for the current user
725      * @return true
726      */
727     public boolean isReadable() {
728         m_cms.setContextToCos();
729         try {
730             return m_cms.accessRead(m_channel.getAbsolutePath());
731         } catch(CmsException exc) {
732             // there was a cms-exception - no read-access!
733             return false;
734         } finally {
735             m_cms.setContextToVfs();
736         }
737     }
738 
739     /**
740      * returns true if the CD is writeable for the current user
741      * @return true
742      */
743     public boolean isWriteable() {
744         m_cms.setContextToCos();
745         try {
746             return m_cms.accessWrite(m_channel.getAbsolutePath());
747         } catch(CmsException exc) {
748             // there was a cms-exception - no write-access!
749             return false;
750         } finally {
751             m_cms.setContextToVfs();
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 toString() {
767         StringBuffer returnValue = new StringBuffer();
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 getAccessFlagsAsString() {
782         int accessFlags = m_channel.getAccessFlags();
783         String str = "";
784         str += ((accessFlags & I_CmsConstants.C_ACCESS_OWNER_READ)>0?"r":"-");
785         str += ((accessFlags & I_CmsConstants.C_ACCESS_OWNER_WRITE)>0?"w":"-");
786         str += ((accessFlags & I_CmsConstants.C_ACCESS_OWNER_VISIBLE)>0?"v":"-");
787         str += ((accessFlags & I_CmsConstants.C_ACCESS_GROUP_READ)>0?"r":"-");
788         str += ((accessFlags & I_CmsConstants.C_ACCESS_GROUP_WRITE)>0?"w":"-");
789         str += ((accessFlags & I_CmsConstants.C_ACCESS_GROUP_VISIBLE)>0?"v":"-");
790         str += ((accessFlags & I_CmsConstants.C_ACCESS_PUBLIC_READ)>0?"r":"-");
791         str += ((accessFlags & I_CmsConstants.C_ACCESS_PUBLIC_WRITE)>0?"w":"-");
792         str += ((accessFlags & I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE)>0?"v":"-");
793         str += ((accessFlags & I_CmsConstants.C_ACCESS_INTERNAL_READ)>0?"i":"-");
794         return str;
795     }
796 
797     /**
798      * Get the permissions of Channel
799      */
800     public void setAccessFlagsAsString(String permissions){
801         //change direction
802         String perm=permissions;
803         permissions="";
804         for(int x=9;x >= 0;x--) {
805             char temp=perm.charAt(x);
806             permissions+=temp;
807         }
808         setAccessFlags(Integer.parseInt(permissions,2));
809     }
810 
811     /**
812      * Sets the channelId of a new channel
813      */
814     private void setNewChannelId() throws CmsException{
815         int newChannelId = com.opencms.dbpool.CmsIdGenerator.nextId(C_TABLE_CHANNELID);
816         m_properties.put(I_CmsConstants.C_PROPERTY_CHANNELID, newChannelId+"");
817         m_channelId = newChannelId+"";
818     }
819 
820     /**
821      * This content definition is lockable. This class overwrited the isLockable method of the abstract
822      * backoffice to flag that this content definition uses the lock feature of the backoffice.  *
823      */
824     public static boolean isLockable() {
825         return true;
826     }
827 
828     /**
829      * Gets the names of the table columns displayed in the backoffice filelist.
830      * This method is needed for the abstract backoffice class only.
831      * @return Vector containing the columnnames.
832      */
833     public static Vector getFieldNames(CmsObject cms) {
834         Vector names = new Vector();
835         names.addElement("channelId");
836         names.addElement("channelPath");
837         names.addElement("title");
838         names.addElement("ownerName");
839         names.addElement("group");
840         names.addElement("accessFlagsAsString");
841         return names;
842     }
843 
844     /**
845      * Gets the methods used to display the dava values in the backoffice filelist.
846      * This method is needed for the abstract backoffice class only.
847      * @return Vector with the nescessary get methods
848      */
849     public static Vector getFieldMethods(CmsObject cms) {
850         Vector methods = new Vector();
851         try {
852             methods.addElement(CmsChannelContent.class.getMethod("getChannelId", new Class[0]));
853             methods.addElement(CmsChannelContent.class.getMethod("getChannelPath", new Class[0]));
854             methods.addElement(CmsChannelContent.class.getMethod("getTitle", new Class[0]));
855             methods.addElement(CmsChannelContent.class.getMethod("getOwnerName", new Class[0]));
856             methods.addElement(CmsChannelContent.class.getMethod("getGroup", new Class[0]));
857             methods.addElement(CmsChannelContent.class.getMethod("getAccessFlagsAsString", new Class[0]));
858         } catch(NoSuchMethodException exc) {
859             // this exception should never occur. You know your own methods in this cd
860         }
861         return methods;
862     }
863 
864     /**
865      * Gets the filter methods
866      * This method is needed for the abstract backoffice class only.
867      * @return a method array containing the methods
868      */
869     public static Vector getFilterMethods(CmsObject cms) {
870         Vector filterMethods = new Vector();
871         try {
872             CmsFilterMethod filterUp = new CmsFilterMethod("All Channels",
873                                       CmsChannelContent.class.getMethod("getChannelList",
874                                       new Class[] {CmsObject.class} ) , new Object[0]);
875             filterMethods.addElement(filterUp);
876         } catch (NoSuchMethodException nsm) {
877             // this exception should never occur because you know your filter methods.
878         }
879         return filterMethods;
880     }
881 
882     /**
883      * Returns a vector of CD objects, sorted descending by channelname.
884      * This method is needed for the abstract backoffice class only.
885      * @param cms The CmsObject.
886      */
887     public static Vector getChannelList(CmsObject cms) throws CmsException {
888         Vector content = new Vector();
889         cms.setContextToCos();
890         try {
891             getAllResources(cms, "/", content);
892         } catch(CmsException e) {
893             // ignore the exception
894             if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
895                 A_OpenCms.log(A_OpenCms.C_MODULE_INFO, "[CmsChannelContent]: error when reading subfolders of cos root: "+e.getMessage());
896             }
897         } finally {
898             cms.setContextToVfs();
899         }
900         return content;
901     }
902     /**
903      * Helper for method getChannelList
904      */
905     private static void getAllResources(CmsObject cms, String rootFolder, Vector allFolders) throws CmsException {
906         // get folders of this rootFolder
907         Vector subFolders = new Vector();
908         try{
909             subFolders = cms.getResourcesInFolder(rootFolder);
910         } catch (CmsException e){
911             // if the folder could not be found it might be deleted, so don't throw this exception
912             if(e.getType() != CmsException.C_NOT_FOUND){
913                 throw e;
914             }
915         }
916         //copy the values into the allFolders Vector
917         for(int i = 0;i < subFolders.size();i++) {
918             CmsResource curFolder = (CmsResource)subFolders.elementAt(i);
919             CmsChannelContent curChannel = new CmsChannelContent(cms, curFolder);
920             allFolders.addElement(curChannel);
921             getAllResources(cms, curFolder.getAbsolutePath(), allFolders);
922         }
923     }
924     /**
925      * Plauzibilization method.
926      * This method checks if all inputfields contain correct input data.
927      * If an input field has no correct data, a CmsPlausibilizationException is thrown.
928      * @throws Throws CmsPlausibilizationException containing a vector of error-codes.
929      */
930     public void check() throws CmsPlausibilizationException {
931         // define the vector which will hold all error codes
932         Vector errorCodes = new Vector();
933         //check the channelname
934         if (m_channelname == null || "".equals(m_channelname)) {
935             errorCodes.addElement(C_CHANNELNAME_ERRFIELD+C_ERRSPERATOR+C_ERRCODE_EMPTY);
936         }
937         //check the parentchannel
938         if (m_parentchannel == null || "".equals(m_parentchannel)) {
939             errorCodes.addElement(C_PARENT_ERRFIELD+C_ERRSPERATOR+C_ERRCODE_EMPTY);
940         }
941         // now test if there was an error message and throw an exception
942         if (errorCodes.size()>0) {
943             throw new CmsPlausibilizationException(errorCodes);
944         }
945     }
946 }