KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/master/CmsMasterContent.java,v $
3 * Date : $Date: 2005/07/13 09:23:21 $
4 * Version: $Revision: 1.6 $
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.CmsDbContext;
32 import org.opencms.db.CmsDbUtil;
33 import org.opencms.db.CmsPublishedResource;
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsProject;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.file.CmsUser;
39 import org.opencms.main.CmsEvent;
40 import org.opencms.main.CmsException;
41 import org.opencms.main.I_CmsEventListener;
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.I_CmsExtendedContentDefinition;
48 import com.opencms.defaults.master.genericsql.CmsDbAccess;
49 import com.opencms.legacy.CmsXmlTemplateLoader;
50
51 import java.util.HashMap JavaDoc;
52 import java.util.Map JavaDoc;
53 import java.util.StringTokenizer JavaDoc;
54 import java.util.Vector JavaDoc;
55
56 /**
57  * This class is the master of several Modules. It carries a lot of generic
58  * data-fileds which can be used for a special Module.
59  *
60  * The module creates a set of methods to support project-integration, history
61  * and import - export.
62  *
63  * @author A. Schouten $
64  * $Revision: 1.6 $
65  * $Date: 2005/07/13 09:23:21 $
66  *
67  * @deprecated Will not be supported past the OpenCms 6 release.
68  */

69 public abstract class CmsMasterContent
70     extends A_CmsContentDefinition
71     implements I_CmsExtendedContentDefinition {
72
73     /** The cms-object to get access to the cms-ressources */
74     protected CmsObject m_cms = null;
75
76     /** The dataset which holds all informations about this module */
77     protected CmsMasterDataSet m_dataSet = null;
78
79     /** Is set to true, if the lockstate changes */
80     protected boolean m_lockstateWasChanged = false;
81
82     /** A private HashMap to store all data access-objects. */
83     private static HashMap JavaDoc c_accessObjects = new HashMap JavaDoc();
84
85     /** Vector of currently selected channels */
86     protected Vector JavaDoc m_selectedChannels = null;
87
88     /** Vector of currently available channels */
89     protected Vector JavaDoc m_availableChannels = null;
90
91     /**
92      * Registers a database access object for the contentdefinition type.
93      * @param subId the id-type of the contentdefinition.
94      * @param dBAccessObject the dBAccessObject that should be used to access
95      * the databse.
96      */

97     protected static void registerDbAccessObject(int subId, CmsDbAccess dBAccessObject) {
98         c_accessObjects.put(new Integer JavaDoc(subId), dBAccessObject);
99     }
100
101     /**
102      * Returns a database access object for the contentdefinition type.
103      * @param subId the id-type of the contentdefinition.
104      * @return dBAccessObject the dBAccessObject that should be used to access
105      * the databse.
106      */

107     protected static CmsDbAccess getDbAccessObject(int subId) {
108         return (CmsDbAccess) c_accessObjects.get(new Integer JavaDoc(subId));
109     }
110
111     /**
112      * Constructor to create a new contentdefinition. You can set data with your
113      * set-Methods. After you have called the write-method this definition gets
114      * a unique id.
115      */

116     public CmsMasterContent(CmsObject cms) {
117         m_cms = cms;
118         initValues();
119     }
120
121     /**
122      * Constructor to create a new contentdefinition. You can set data with your
123      * set-Methods. After you have called the write-method this definition gets
124      * a unique id.
125      */

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

141     public CmsMasterContent(CmsObject cms, CmsUUID contentId) throws CmsException {
142         m_cms = cms;
143         initValues();
144         getDbAccessObject(getSubId()).read(m_cms, this, m_dataSet, contentId);
145     }
146     
147     /**
148      * TESTFIX New code:
149      * Empty constructor needed for instanciating CDs as JavaBeans on JSPs.
150      */

151     public CmsMasterContent() {}
152
153     /**
154      * This method initialises all needed members with default-values.
155      */

156     protected void initValues() {
157         m_dataSet = new CmsMasterDataSet();
158         m_dataSet.m_masterId = CmsUUID.getNullUUID();
159         m_dataSet.m_subId = CmsDbUtil.UNKNOWN_ID;
160         m_dataSet.m_lockedBy = CmsUUID.getNullUUID();
161         m_dataSet.m_versionId = CmsDbUtil.UNKNOWN_ID;
162         m_dataSet.m_userName = null;
163         m_dataSet.m_groupName = null;
164         m_dataSet.m_lastModifiedByName = null;
165         m_dataSet.m_userId = CmsUUID.getNullUUID();
166         setAccessFlags(com.opencms.core.I_CmsConstants.C_ACCESS_DEFAULT_FLAGS);
167     }
168
169     /**
170      * Returns the title of this cd
171      */

172     public String JavaDoc getTitle() {
173         return m_dataSet.m_title;
174     }
175
176     /**
177      * Sets title of this cd
178      */

179     public void setTitle(String JavaDoc title) {
180         m_dataSet.m_title = title;
181     }
182
183     /**
184      * Returns a Vector of media-objects for this master cd.
185      * @return a Vector of media-objects for this master cd.
186      * @throws CmsException if the media couldn't be read.
187      */

188     public Vector JavaDoc getMedia() throws CmsException {
189         if(m_dataSet.m_media == null) {
190             // the media was not read yet
191
// -> read them now from the db
192
m_dataSet.m_media = getDbAccessObject(getSubId()).readMedia(m_cms, this);
193         }
194         return m_dataSet.m_media;
195     }
196
197     /**
198      * Registers a new media, that should be written by calling write().
199      * @param media - The mediaobject to register for writing.
200      */

201     public void addMedia(CmsMasterMedia media) {
202         m_dataSet.m_mediaToAdd.add(media);
203     }
204
205     /**
206      * Registers a media for deletion.
207      * @param media - The mediaobject to register.
208      */

209     public void deleteMedia(CmsMasterMedia media) {
210         m_dataSet.m_mediaToDelete.add(media);
211     }
212
213     /**
214      * Registers a media for update
215      * @param media - The mediaobject to register.
216      */

217     public void updateMedia(CmsMasterMedia media) {
218         m_dataSet.m_mediaToUpdate.add(media);
219     }
220
221     /**
222      * Returns a Vector of channels for this master cd.
223      * @return a Vector of channel-names (String) for this master cd.
224      * @throws CmsException if the channel couldn't be read.
225      */

226     public Vector JavaDoc getChannels() throws CmsException {
227         if(m_dataSet.m_channel == null) {
228             // the channels was not read yet
229
// -> read them now from the db
230
m_dataSet.m_channel = getDbAccessObject(getSubId()).readChannels(m_cms, this);
231         }
232         return m_dataSet.m_channel;
233     }
234
235     /**
236      * Registers a new channel, that should be written by calling write().
237      * @param channels - The channel to register for writing.
238      */

239     public void addChannel(String JavaDoc channel) {
240         m_dataSet.m_channelToAdd.add(channel);
241     }
242
243     /**
244      * Registers a channel for deletion.
245      * @param channel - The channel to register for deleting.
246      */

247     public void deleteChannel(String JavaDoc channel) {
248         m_dataSet.m_channelToDelete.add(channel);
249     }
250
251     /**
252      * delete method
253      * for delete instance of content definition
254      * @param cms the CmsObject to use.
255      */

256     public void delete(CmsObject cms) throws Exception JavaDoc {
257         getDbAccessObject(getSubId()).delete(m_cms, this, m_dataSet);
258     }
259
260     /**
261      * change group method
262      * for the permissions of content definition
263      * @param cms the CmsObject to use.
264      * @param group the id of the new group.
265      */

266     public void chgrp(CmsObject cms, CmsUUID group) throws Exception JavaDoc {
267         m_dataSet.m_groupId = group;
268         getDbAccessObject(getSubId()).changePermissions(m_cms, this, m_dataSet);
269     }
270
271     /**
272      * change owner method
273      * for the permissions of content definition
274      * @param cms the CmsObject to use.
275      * @param owner the id of the new owner.
276      */

277     public void chown(CmsObject cms, CmsUUID owner) throws Exception JavaDoc {
278         m_dataSet.m_userId = owner;
279         getDbAccessObject(getSubId()).changePermissions(m_cms, this, m_dataSet);
280     }
281
282     /**
283      * change access flags method
284      * for the permissions of content definition
285      * @param cms the CmsObject to use.
286      * @param accessflags the new access flags.
287      */

288     public void chmod(CmsObject cms, int accessflags) throws Exception JavaDoc {
289         m_dataSet.m_accessFlags = accessflags;
290         getDbAccessObject(getSubId()).changePermissions(m_cms, this, m_dataSet);
291     }
292
293     /**
294      * copy method
295      *
296      * @param cms the CmsObject to use.
297      * @return int The id of the new content definition
298      */

299     public CmsUUID copy(CmsObject cms) throws Exception JavaDoc {
300         // insert the new cd with the copied dataset
301
return getDbAccessObject(getSubId()).copy(cms, this, (CmsMasterDataSet)m_dataSet.clone(), this.getMedia(), this.getChannels());
302     }
303
304     /**
305      * write method
306      * to write the current content of the content definition to the database.
307      * @param cms the CmsObject to use.
308      */

309     public void write(CmsObject cms) throws CmsException {
310         // add or delete channels according to current selection
311
updateChannels();
312         // is this a new row or an existing row?
313
if(m_dataSet.m_masterId.isNullUUID()) {
314             // this is a new row - call the create statement
315
getDbAccessObject(getSubId()).insert(m_cms, this, m_dataSet);
316         } else {
317             // this is a existing row - call the write statement
318
if(m_lockstateWasChanged) {
319                 // update the locksyte
320
getDbAccessObject(getSubId()).writeLockstate(m_cms, this, m_dataSet);
321             } else {
322                 // write the changes to the database
323
getDbAccessObject(getSubId()).write(m_cms, this, m_dataSet);
324             }
325         }
326         // everything is written - so lockstate was updated
327
m_lockstateWasChanged = false;
328         // for next access to the media - clean them so they must be read again
329
// from the db
330
m_dataSet.m_media = null;
331         m_dataSet.m_mediaToAdd = new Vector JavaDoc();
332         m_dataSet.m_mediaToDelete = new Vector JavaDoc();
333         m_dataSet.m_mediaToUpdate = new Vector JavaDoc();
334
335         // for next access to the channels - clean them so they must be read again
336
// from the db
337
m_dataSet.m_channel = null;
338         m_dataSet.m_channelToAdd = new Vector JavaDoc();
339         m_dataSet.m_channelToDelete = new Vector JavaDoc();
340     }
341
342     /**
343      * import method
344      * to import the current content of the content definition to the database.
345      */

346     public void importMaster() throws Exception JavaDoc {
347         getDbAccessObject(getSubId()).insert(m_cms, this, m_dataSet);
348         // everything is written - so lockstate was updated
349
m_lockstateWasChanged = false;
350         // for next access to the media - clean them so they must be read again
351
// from the db
352
m_dataSet.m_media = null;
353         m_dataSet.m_mediaToAdd = new Vector JavaDoc();
354         m_dataSet.m_mediaToDelete = new Vector JavaDoc();
355         m_dataSet.m_mediaToUpdate = new Vector JavaDoc();
356
357         // for next access to the channels - clean them so they must be read again
358
// from the db
359
m_dataSet.m_channel = null;
360         m_dataSet.m_channelToAdd = new Vector JavaDoc();
361         m_dataSet.m_channelToDelete = new Vector JavaDoc();
362     }
363
364     /**
365      * gets the unique Id of a content definition instance
366      * @param cms the CmsObject to use.
367      * @return a string with the Id
368      */

369     public String JavaDoc getUniqueId(CmsObject cms) {
370         return getId() + "";
371     }
372
373     /**
374      * gets the unique Id of a content definition instance
375      * @param cms the CmsObject to use.
376      * @return a int with the Id
377      */

378     public CmsUUID getId() {
379         return m_dataSet.m_masterId;
380     }
381
382     /**
383      * Gets the lockstate.
384      * @return a int with the user who has locked the ressource.
385      */

386     public CmsUUID getLockstate() {
387         /*
388         CmsUUID lockedByUserId = CmsUUID.getNullUUID();
389
390         try {
391             if (hasWriteAccess(m_cms)) {
392                 lockedByUserId = m_dataSet.m_lockedBy;
393             }
394         } catch (CmsException exc) {
395             // NOOP
396         }
397
398         return lockedByUserId;
399         */

400         
401         return m_dataSet.m_lockedBy;
402     }
403
404     /**
405      * Sets the lockstates
406      * @param the lockstate for the actual entry.
407      */

408     public void setLockstate(CmsUUID lockstate) {
409         m_lockstateWasChanged = true;
410         m_dataSet.m_lockedBy = lockstate;
411     }
412
413     /**
414      * Gets the owner of this contentdefinition.
415      */

416     public CmsUUID getOwner() {
417         return m_dataSet.m_userId;
418     }
419
420     /**
421      * Gets the ownername
422      */

423     public String JavaDoc getOwnerName() {
424
425         String JavaDoc retValue = m_dataSet.m_userId + "";
426         if ((m_dataSet.m_userName == null || "".equals(m_dataSet.m_userName.trim()))
427             && !CmsUUID.getNullUUID().equals(m_dataSet.m_userId)) {
428             try { // to read the real name of this user
429
retValue = m_cms.readUser(m_dataSet.m_userId).getName();
430             } catch (CmsException exc) {
431                 // ignore the exception - it was not possible to read the group
432
// instead return the groupid
433
}
434         } else {
435             // this is a history value - return it
436
retValue = m_dataSet.m_userName;
437         }
438         return retValue;
439     }
440
441     /**
442      * Sets the owner of this contentdefinition.
443      */

444     public void setOwner(CmsUUID id) {
445         m_dataSet.m_userId = id;
446     }
447
448     /**
449      * Gets the groupname
450      */

451     public String JavaDoc getGroup() {
452
453         String JavaDoc retValue = "";
454
455         if (m_dataSet.m_groupId != null) {
456             retValue = m_dataSet.m_groupId + "";
457         }
458
459         if ((m_dataSet.m_groupName == null || "".equals(m_dataSet.m_groupName.trim()))
460             && (m_dataSet.m_groupId != null && !CmsUUID.getNullUUID().equals(m_dataSet.m_groupId))) {
461             try {
462                 retValue = m_cms.readGroup(m_dataSet.m_groupId).getName();
463             } catch (CmsException exc) {
464                 // ignore the exception - it was not possible to read the group
465
// instead return the groupid
466
}
467         } else {
468             // this is historical data - return it
469
retValue = m_dataSet.m_groupName;
470         }
471
472         return retValue;
473     }
474
475     /**
476      * Gets the groupid
477      */

478     public CmsUUID getGroupId() {
479         return m_dataSet.m_groupId;
480     }
481
482     /**
483      * Sets the group.
484      */

485     public void setGroup(CmsUUID groupId) {
486         m_dataSet.m_groupId = groupId;
487     }
488
489     /**
490      * Returns the projectId of the content definition.
491      * If the cd belongs to the current project the value
492      * is the id of the current project otherwise its
493      * the id of the online project
494      *
495      * @return int The project id
496      */

497     public int getProjectId() {
498         return m_dataSet.m_projectId;
499     }
500
501     /**
502      * Returns the state of the content definition:
503      * unchanged, new, changed or deleted
504      *
505      * @return int The state of the cd
506      */

507     public int getState() {
508         return m_dataSet.m_state;
509     }
510
511     /**
512      * Returns the projectId of the content definition
513      * that is stored in the cd table after the cd
514      * was locked
515      *
516      * @return int The id of the cd
517      */

518     public int getLockedInProject() {
519         return m_dataSet.m_lockedInProject;
520     }
521
522     /**
523      * Returns the sub-id of this contentdefinition. You have to implement this
524      * method so it returns a unique sunb-id that describes the type of the
525      * contentdefinition. (E.g. article: sub-id=1; table: sub-id=2).
526      */

527     abstract public int getSubId();
528
529     /**
530      * Returns a String representation of this instance.
531      * This can be used for debugging purposes.
532      */

533     public String JavaDoc toString() {
534         StringBuffer JavaDoc returnValue = new StringBuffer JavaDoc();
535         returnValue.append(this.getClass().getName() + "{");
536         returnValue.append("UniqueId=" + getUniqueId(m_cms) + ";");
537         returnValue.append("Lockstate=" + getLockstate() + ";");
538         returnValue.append("AccessFlags=" + getAccessFlagsAsString() + ";");
539         returnValue.append(m_dataSet.toString() + "}");
540         return returnValue.toString();
541     }
542
543     /**
544      * set the accessFlag for the CD
545      * @param the accessFlag
546      */

547     public void setAccessFlags(int accessFlags) {
548         m_dataSet.m_accessFlags = accessFlags;
549     }
550
551     /**
552      * get the accessFlag for the CD
553      * @return the accessFlag
554      */

555     public int getAccessFlags() {
556         return m_dataSet.m_accessFlags;
557     }
558
559     /**
560      * Convenience method to get the access-Flags as String representation.
561      * @return String of access rights
562      */

563     public String JavaDoc getAccessFlagsAsString() {
564
565         int accessFlags = getAccessFlags();
566         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
567
568         buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_READ) > 0 ? "r" : "-"));
569         buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_WRITE) > 0 ? "w" : "-"));
570         buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_VIEW) > 0 ? "v" : "-"));
571         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_READ) > 0 ? "r" : "-"));
572         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_WRITE) > 0 ? "w" : "-"));
573         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_VISIBLE) > 0 ? "v" : "-"));
574         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_READ) > 0 ? "r" : "-"));
575         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_WRITE) > 0 ? "w" : "-"));
576         buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE) > 0 ? "v" : "-"));
577         buf.append(((accessFlags & CmsResource.FLAG_INTERNAL) > 0 ? "i" : "-"));
578
579         return buf.toString();
580     }
581
582     /**
583      * has the current user the right to view the CD
584      * @return true if this cd is visible
585      */

586     public boolean isVisible() {
587         CmsUser currentUser = m_cms.getRequestContext().currentUser();
588         try {
589             if(m_cms.isAdmin()) {
590                 return true;
591             } else {
592                 if ( !accessOther(com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE)
593                     && !accessOwner(m_cms, currentUser, CmsPermissionSet.PERMISSION_VIEW)
594                     && !accessGroup(m_cms, currentUser, com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_VISIBLE)) {
595                     return false;
596                 } else {
597                     return true;
598                 }
599             }
600         } catch(CmsException exc) {
601             // no access to cms -> not visible
602
return false;
603         }
604     }
605
606     /**
607      * returns true if the CD is readable for the current user
608      * @return true if the cd is readable
609      */

610     public boolean isReadable() {
611         try {
612             if(m_cms.isAdmin()) {
613                 return true;
614             } else {
615                 return hasReadAccess(m_cms);
616             }
617         } catch(CmsException exc) {
618             // there was a cms-exception - no read-access!
619
return false;
620         }
621     }
622
623     /**
624      * returns true if the CD is writeable for the current user
625      * @return true if the cd is writeable
626      */

627     public boolean isWriteable() {
628         try {
629             if(m_cms.isAdmin()) {
630                 return true;
631             } else {
632                 return this.hasWriteAccess(m_cms);
633             }
634         } catch(CmsException exc) {
635             // there was a cms-exception - no write-access!
636
return false;
637         }
638     }
639
640     /**
641      * Publishes the content definition directly
642      *
643      * @param cms The CmsObject
644      */

645     public void publishResource(CmsObject cms) throws Exception JavaDoc {
646         Vector JavaDoc changedResources = new Vector JavaDoc();
647         Vector JavaDoc changedModuleData = new Vector JavaDoc();
648         int versionId = 0;
649         long publishDate = System.currentTimeMillis();
650         boolean historyEnabled = OpenCms.getSystemInfo().isVersionHistoryEnabled();
651         CmsUUID publishHistoryId = new CmsUUID();
652
653         try {
654             if (historyEnabled) {
655                 // Get the next version id
656
versionId = cms.getBackupTagId();
657                 // backup the current project
658
cms.backupProject(versionId, publishDate);
659             }
660             
661             // now publish the content definition
662
getDbAccessObject(getSubId()).publishResource(cms, publishHistoryId, m_dataSet, getSubId(), this.getClass().getName(), historyEnabled, versionId, publishDate, changedResources, changedModuleData);
663             
664             // update the cache
665
if (CmsXmlTemplateLoader.isElementCacheEnabled()) {
666                 CmsXmlTemplateLoader.getOnlineElementCache().cleanupCache(changedResources, changedModuleData);
667             }
668         } finally {
669             
670             // a "directly" published COS resource can be handled totally equal to a published project
671
Map JavaDoc eventData = new HashMap JavaDoc();
672             eventData.put(I_CmsEventListener.KEY_PUBLISHID, publishHistoryId.toString());
673             eventData.put(I_CmsEventListener.KEY_PROJECTID, new Integer JavaDoc(cms.getRequestContext().currentProject().getId()));
674             eventData.put(I_CmsEventListener.KEY_DBCONTEXT, new CmsDbContext(cms.getRequestContext()));
675             OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PUBLISH_PROJECT, eventData));
676         }
677     }
678     
679     /**
680      * Writes an entry to the publish history for a published COS resource.<p>
681      *
682      * @param project the current project
683      * @param publishedBoResource the CmsPublishedResource onject representing the published COS resource
684      * @param publishId unique int ID to identify each publish task in the publish history
685      * @param tagId the backup tag revision
686      *
687      * @throws CmsException if something goes wrong
688      */

689     public void writePublishHistory(CmsProject project, CmsPublishedResource publishedBoResource, CmsUUID publishId, int tagId) throws CmsException {
690
691         getDbAccessObject(getSubId()).writePublishHistory(
692             project,
693             publishId,
694             tagId,
695             // content definition name
696
publishedBoResource.getRootPath(),
697             // master id
698
publishedBoResource.getResourceId(),
699             // sub ID
700
publishedBoResource.getType(), // state
701
publishedBoResource.getState());
702         
703     }
704
705     /**
706      * Undelete method
707      * for undelete instance of content definition
708      *
709      * @param cms The CmsObject
710      */

711     public void undelete(CmsObject cms) throws Exception JavaDoc {
712         getDbAccessObject(getSubId()).undelete(m_cms, this, m_dataSet);
713     }
714     
715     /**
716      * Overwrite this method in your subclasses to execute any tasks before the resources are published.
717      */

718     public static boolean beforePublish( CmsObject cms, Boolean JavaDoc enableHistory,
719         Integer JavaDoc projectId, Integer JavaDoc versionId, Long JavaDoc publishingDate,
720         Vector JavaDoc changedRessources, Vector JavaDoc changedModuleData, CmsMasterDataSet dataset ) {
721         
722         if (false && ((cms == null) && (enableHistory == null) && (projectId == null) &&
723             (versionId == null) && (publishingDate == null) && (changedRessources == null) &&
724             (changedModuleData == null) && (dataset == null))) {
725             // silly test so that eclipse does not complain about unused method parameters
726
}
727         
728         return true;
729     }
730
731     /**
732      * Publishes all modified content definitions for this project.<p>
733      *
734      * @param cms The CmsObject
735      * @param publishHistoryId the ID of the current publish task
736      * @param enableHistory set to true if backup tables should be filled.
737      * @param projectId the Project that should be published.
738      * @param versionId the versionId to save in the backup tables.
739      * @param publishingDate the date and time of this publishing process.
740      * @param subId the subId to publish cd's for.
741      * @param contentDefinitionClassName the name of cd-class.
742      * @param changedRessources a Vector of Ressources that were changed by this
743      * publishing process.
744      * @param changedModuleData a Vector of Ressource that were changed by this
745      * publishing process. New published data will be add to this Vector to
746      * return it.
747      */

748     protected static void publishProject(CmsObject cms, CmsUUID publishHistoryId,
749         boolean enableHistory, int projectId, int versionId, long publishingDate,
750         int subId, String JavaDoc contentDefinitionClassName,
751         Vector JavaDoc changedRessources, Vector JavaDoc changedModuleData) throws CmsException {
752
753          // now publish the project
754
getDbAccessObject(subId).publishProject(cms, publishHistoryId, enableHistory,
755              projectId, versionId, publishingDate, subId,
756              contentDefinitionClassName, changedRessources, changedModuleData );
757     }
758
759     /**
760      * Returns a Vector with the datasets of the contentdefinitions in the given channel.
761      * @param subId the id-type of the contentdefinition.
762      * @param channelId the id of the channel.
763      * @return Vector the vector that includes the datasets
764      */

765     protected static Vector JavaDoc readAllByChannel(CmsObject cms, String JavaDoc channelId, int subId) throws CmsException{
766         return getDbAccessObject(subId).readAllByChannel(cms, channelId, subId);
767     }
768
769     /**
770      * Returns the date of the last modification of the content definition
771      *
772      * @return long The date of the last modification
773      */

774     public long getDateLastModified() {
775         return m_dataSet.m_dateLastModified;
776     }
777
778     /**
779      * Returns the date of the creation of the content definition
780      *
781      * @return long The date of the creation
782      */

783     public long getDateCreated() {
784         return m_dataSet.m_dateCreated;
785     }
786
787     /**
788      * Returns the id of the user who has modified the content definition
789      *
790      * @return int The id of the user who has modified the cd
791      */

792     public CmsUUID getLastModifiedBy() {
793         return m_dataSet.m_lastModifiedBy;
794     }
795
796     /**
797      * Returns the name of the user who has modified the content definition
798      *
799      * @return String The name of the user who has modified the cd
800      */

801     public String JavaDoc getLastModifiedByName() {
802
803         String JavaDoc retValue = "";
804         if (m_dataSet.m_lastModifiedBy != null) {
805             retValue = m_dataSet.m_lastModifiedBy + "";
806         }
807         if (m_dataSet.m_lastModifiedByName == null && m_dataSet.m_lastModifiedBy != null) {
808             try {
809                 retValue = m_cms.readUser(m_dataSet.m_lastModifiedBy).getName();
810             } catch (CmsException exc) {
811                 // ignore this exception, return the id instead
812
}
813         } else {
814             retValue = m_dataSet.m_lastModifiedByName;
815         }
816         return retValue;
817     }
818
819     /**
820      * Returns the id of the version in the history of the content definition
821      *
822      * @return int The id of the version, or -1 if there is no version-info
823      */

824     public int getVersionId() {
825         return m_dataSet.m_versionId;
826     }
827
828     /**
829      * Restore method
830      * for restore instance of content definition from the history
831      *
832      * @param cms The CmsObject
833      * @param versionId The id of the version to restore
834      */

835     public void restore(CmsObject cms, int versionId) throws Exception JavaDoc {
836         getDbAccessObject(this.getSubId()).restore(cms, this, m_dataSet, versionId);
837     }
838
839     /**
840      * History method
841      * returns the vector of the versions of content definition in the history
842      *
843      * @param cms The CmsObject
844      * @return Vector The versions of the cd in the history
845      */

846     public Vector JavaDoc getHistory(CmsObject cms) throws Exception JavaDoc {
847         return getDbAccessObject(this.getSubId()).getHistory(cms, this.getClass(), m_dataSet.m_masterId, this.getSubId());
848     }
849
850     /**
851      * History method
852      * returns the cd of the version with the given versionId
853      *
854      * @param cms The CmsObject
855      * @param versionId The version id
856      * @return Object The object with the version of the cd
857      */

858     public Object JavaDoc getVersionFromHistory(CmsObject cms, int versionId) throws Exception JavaDoc{
859         return getDbAccessObject(this.getSubId()).getVersionFromHistory(cms, this.getClass(), m_dataSet.m_masterId, this.getSubId(), versionId);
860     }
861
862
863     /**
864      * Get all currently selected channels
865      * @return Vector of all currently selected channels
866      */

867      public Vector JavaDoc getSelectedChannels() throws CmsException{
868         if (m_selectedChannels == null) {
869             Vector JavaDoc dbChannels = getChannels();
870             m_selectedChannels = new Vector JavaDoc();
871             String JavaDoc rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
872             int offset = rootChannel.length()-1;
873             for (int i=0; i< dbChannels.size(); i++) {
874                 // remove the root channel name from the channel's name
875
// and add to new Vector
876
m_selectedChannels.add(((String JavaDoc)dbChannels.elementAt(i)).substring(offset));
877             }
878         }
879         return m_selectedChannels;
880      }
881
882      /**
883      * set Selected Channels
884      * @param channels a String containing the channels names as a comma separated list
885      */

886     public void setSelectedChannels(String JavaDoc channels) {
887         StringTokenizer JavaDoc tk = new StringTokenizer JavaDoc(channels, ",");
888         Vector JavaDoc v = new Vector JavaDoc();
889         int tokens = tk.countTokens();
890         if (channels != null && channels.equals("empty")) {
891             m_selectedChannels = v;
892         }else if (tokens > 0) {
893             for (int i=0; i<tokens; i++) {
894                 v.addElement(tk.nextToken());
895             }
896             m_selectedChannels = v;
897         }
898     }
899
900      /**
901       * Get all currently available channels
902       * Note: the root channel of the module is not included in the returned
903       * channelnames. For example if the root channel is /Jobs/ and a channel's
904       * name is /Jobs/Education/Cologne/ the returned name for this channel will
905       * be /Education/Cologne/.
906       * @param cms object to access system resources
907       * @return a Vector of all channels that can be selected
908       */

909       public Vector JavaDoc getAvailableChannels(CmsObject cms) throws CmsException {
910         if (m_availableChannels == null) {
911             Vector JavaDoc selectedChannels = getSelectedChannels();
912             Vector JavaDoc subChannels = getAllSubChannelsOfRootChannel(cms);
913             for (int i=0; i<subChannels.size(); i++) {
914                 for (int j=0; j<selectedChannels.size(); j++) {
915                     if (subChannels.elementAt(i).equals(selectedChannels.elementAt(j))) {
916                         subChannels.removeElementAt(i);
917                         i--;
918                         break;
919                     }
920                 }
921             }
922             m_availableChannels = subChannels;
923         }
924         return m_availableChannels;
925       }
926
927     /**
928      * Set the Available Channels
929      * @param channels a String containing the channels to add as a comma separated list
930      */

931     public void setAvailableChannels(String JavaDoc channels) {
932         StringTokenizer JavaDoc tk = new StringTokenizer JavaDoc(channels, ",");
933         Vector JavaDoc v = new Vector JavaDoc();
934         int tokens = tk.countTokens();
935         if (channels != null && channels.equals("empty")) {
936             m_availableChannels = v;
937         } else if (tokens > 0) {
938             for (int i=0; i<tokens; i++) {
939                 v.addElement(tk.nextToken());
940             }
941             m_availableChannels = v;
942         }
943     }
944
945     /**
946      * Get all subchannels of a channel.
947      * Method returns only channels that doesn't have further subchannels because
948      * it is it not intended to add contentdefinitions to channels that are not
949      * endpoints of the channel folder structure. If different functionality
950      * is needed this method has to be overridden in derived
951      * contentdefinition classes.
952      * @param cms object to access system resources
953      * @param channel channel to be searched for subchannels
954      * @return Vector with names of all subchannels
955      * @throws org.opencms.main.CmsException in case of unrecoverable errors
956      */

957     public static Vector JavaDoc getAllSubChannelsOf (CmsObject cms, String JavaDoc channel)
958             throws CmsException {
959         Vector JavaDoc allChannels = new Vector JavaDoc();
960         Vector JavaDoc subChannels = new Vector JavaDoc();
961         String JavaDoc siteRoot = cms.getRequestContext().getSiteRoot();
962         try {
963             cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
964             subChannels.addAll(cms.getResourcesInFolder(channel, CmsResourceFilter.ONLY_VISIBLE));
965
966             for (int i=0; i < subChannels.size(); i++) {
967                 CmsResource resource = (CmsResource)subChannels.get(i);
968                 if (resource.getState() != CmsResource.STATE_DELETED) {
969                     String JavaDoc folder = cms.getSitePath(resource);
970                     Vector JavaDoc v = getAllSubChannelsOf(cms, folder);
971                     if (v.size() == 0) {
972                         allChannels.add(folder);
973                     }else {
974                         for (int j=0; j < v.size(); j++) {
975                             allChannels.add(v.get(j));
976                         }
977                     }
978                 }
979             }
980
981         } catch (CmsException e) {
982             // the channel is not present, so return empty Vector.
983
} finally {
984             cms.getRequestContext().setSiteRoot(siteRoot);
985         }
986         
987         return allChannels;
988     }
989
990
991     /**
992      * Get all subchannels of the module root channel without the root channel in the channel names
993      * Method returns only channels that doesn't have further subchannels because
994      * it is it not intended to add contentdefinitions to channels that are not
995      * endpoints in the channel folder structure. If different functionality
996      * is needed this method has to be overridden in derived
997      * contentdefinition classes.
998      * @param cms object to access system resources
999      * @param channel channel to be searched for subchannels
1000     * @return Vector with names of all subchannels
1001     * @throws org.opencms.main.CmsException in case of unrecoverable errors
1002     */

1003    public Vector JavaDoc getAllSubChannelsOfRootChannel (CmsObject cms)
1004            throws CmsException {
1005        Vector JavaDoc allChannels = new Vector JavaDoc();
1006        cms.getRequestContext().saveSiteRoot();
1007        try {
1008            String JavaDoc rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
1009            cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
1010            //Vector subChannels = cms.getResourcesInFolder(I_CmsConstants.VFS_FOLDER_COS + rootChannel);
1011
Vector JavaDoc subChannels = new Vector JavaDoc(cms.getResourcesInFolder(rootChannel, CmsResourceFilter.ONLY_VISIBLE));
1012            int offset = rootChannel.length()-1;
1013            for (int i=0; i < subChannels.size(); i++) {
1014                CmsResource resource = (CmsResource)subChannels.get(i);
1015                if (resource.getState() != CmsResource.STATE_DELETED) {
1016                    String JavaDoc folder = cms.getSitePath(resource);
1017                    Vector JavaDoc v = getAllSubChannelsOf(cms, folder);
1018                    if (v.size() == 0 && cms.hasPermissions(resource, CmsPermissionSet.ACCESS_VIEW)) {
1019                        allChannels.add(folder.substring(offset));
1020                    } else {
1021                        for (int j=0; j < v.size(); j++) {
1022                            allChannels.add(((String JavaDoc)v.get(j)).substring(offset));
1023                        }
1024                    }
1025                }
1026            }
1027        } finally {
1028            cms.getRequestContext().restoreSiteRoot();
1029        }
1030        return allChannels;
1031    }
1032
1033    /**
1034     * Add or remove channels
1035     * compares the currently selected channels with the selected
1036     * channels stored in the database and adds or deletes channels if necessary
1037     */

1038    protected void updateChannels() throws CmsException{
1039        Vector JavaDoc dbChannels = getChannels();
1040        Vector JavaDoc selectedChannels = getSelectedChannels();
1041        String JavaDoc rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
1042        String JavaDoc prefix = rootChannel.substring(0, rootChannel.length()-1);
1043        // mark all channels to be deleted if not existing in m_selectedChannels but in datatabase
1044
for (int i=0; i < dbChannels.size(); i++) {
1045            boolean found = false;
1046            for (int j=0; j < selectedChannels.size(); j++) {
1047                if (dbChannels.elementAt(i).equals(prefix + ((String JavaDoc)selectedChannels.elementAt(j)))) {
1048                    found = true;
1049                    break;
1050                }
1051            }
1052            if (!found) {
1053                deleteChannel((String JavaDoc)dbChannels.elementAt(i));
1054            }
1055        }
1056        // mark all channels to be added if existing in m_selectedChannels but not in database
1057
for (int i=0; i < selectedChannels.size(); i++) {
1058            boolean found = false;
1059            for (int j=0; j < dbChannels.size(); j++) {
1060                if ((prefix + ((String JavaDoc)selectedChannels.elementAt(i))).equals(dbChannels.elementAt(j))) {
1061                    found = true;
1062                    break;
1063                }
1064            }
1065            if (!found) {
1066                addChannel(prefix + (String JavaDoc)selectedChannels.elementAt(i));
1067            }
1068        }
1069    }
1070
1071    /**
1072     * Get the root channel of the module
1073     * @return the root channel of the module
1074     */

1075     public String JavaDoc getRootChannel() {
1076        return getDbAccessObject(this.getSubId()).getRootChannel();
1077     }
1078
1079    /**
1080     * Checks, if the owner may access this resource.
1081     *
1082     * @param cms the cmsObject
1083     * @param currentUser The user who requested this method.
1084     * @param currentProject The current project of the user.
1085     * @param flags The flags to check.
1086     *
1087     * @return wether the user has access, or not.
1088     */
/*
1089    protected static boolean accessOwner(CmsObject cms, CmsUser currentUser,
1090                                    int flags, CmsResource resource) throws CmsException {
1091        // The Admin has always access
1092        if( cms.isAdmin() ) {
1093            return(true);
1094        }
1095        // is the resource owned by this user?
1096        if(resource.getOwnerId().equals(currentUser.getId())) {
1097            if( (resource.getAccessFlags() & flags) == flags ) {
1098                return true ;
1099            }
1100        }
1101        // the resource isn't accesible by the user.
1102        return false;
1103    } */

1104
1105    /**
1106     * Checks, if the group may access this resource.
1107     *
1108     * @param cms the cmsObject
1109     * @param currentUser The user who requested this method.
1110     * @param currentProject The current project of the user.
1111     * @param flags The flags to check.
1112     *
1113     * @return wether the user has access, or not.
1114     */
/*
1115    protected static boolean accessGroup(CmsObject cms, CmsUser currentUser,
1116                                  int flags, CmsResource resource) throws CmsException {
1117        return cms.
1118        // is the user in the group for the resource?
1119        // if(cms.userInGroup(currentUser.getName(), cms.readGroup(resource.getGroupId()).getName())) {
1120        // if( (resource.getAccessFlags() & flags) == flags ) {
1121        // return true;
1122        // }
1123        //}
1124        // the resource isn't accesible by the user.
1125        // return false;
1126    }*/

1127
1128    /**
1129     * Checks, if others may access this resource.
1130     *
1131     * @param currentUser The user who requested this method.
1132     * @param currentProject The current project of the user.
1133     * @param flags The flags to check.
1134     *
1135     * @return wether the user has access, or not.
1136     */
/*
1137    protected static boolean accessOther( int flags, CmsResource resource) throws CmsException {
1138        if ((resource.getAccessFlags() & flags) == flags) {
1139            return true;
1140        } else {
1141            return false;
1142        }
1143    }*/

1144}
Popular Tags