📄 cmsmastercontent.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/defaults/master/CmsMasterContent.java,v $
* Date : $Date: 2005/07/13 09:23:21 $
* Version: $Revision: 1.6 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.defaults.master;
import org.opencms.db.CmsDbContext;
import org.opencms.db.CmsDbUtil;
import org.opencms.db.CmsPublishedResource;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.CmsUser;
import org.opencms.main.CmsEvent;
import org.opencms.main.CmsException;
import org.opencms.main.I_CmsEventListener;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.util.CmsUUID;
import com.opencms.defaults.A_CmsContentDefinition;
import com.opencms.defaults.I_CmsExtendedContentDefinition;
import com.opencms.defaults.master.genericsql.CmsDbAccess;
import com.opencms.legacy.CmsXmlTemplateLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* This class is the master of several Modules. It carries a lot of generic
* data-fileds which can be used for a special Module.
*
* The module creates a set of methods to support project-integration, history
* and import - export.
*
* @author A. Schouten $
* $Revision: 1.6 $
* $Date: 2005/07/13 09:23:21 $
*
* @deprecated Will not be supported past the OpenCms 6 release.
*/
public abstract class CmsMasterContent
extends A_CmsContentDefinition
implements I_CmsExtendedContentDefinition {
/** The cms-object to get access to the cms-ressources */
protected CmsObject m_cms = null;
/** The dataset which holds all informations about this module */
protected CmsMasterDataSet m_dataSet = null;
/** Is set to true, if the lockstate changes */
protected boolean m_lockstateWasChanged = false;
/** A private HashMap to store all data access-objects. */
private static HashMap c_accessObjects = new HashMap();
/** Vector of currently selected channels */
protected Vector m_selectedChannels = null;
/** Vector of currently available channels */
protected Vector m_availableChannels = null;
/**
* Registers a database access object for the contentdefinition type.
* @param subId the id-type of the contentdefinition.
* @param dBAccessObject the dBAccessObject that should be used to access
* the databse.
*/
protected static void registerDbAccessObject(int subId, CmsDbAccess dBAccessObject) {
c_accessObjects.put(new Integer(subId), dBAccessObject);
}
/**
* Returns a database access object for the contentdefinition type.
* @param subId the id-type of the contentdefinition.
* @return dBAccessObject the dBAccessObject that should be used to access
* the databse.
*/
protected static CmsDbAccess getDbAccessObject(int subId) {
return (CmsDbAccess) c_accessObjects.get(new Integer(subId));
}
/**
* Constructor to create a new contentdefinition. You can set data with your
* set-Methods. After you have called the write-method this definition gets
* a unique id.
*/
public CmsMasterContent(CmsObject cms) {
m_cms = cms;
initValues();
}
/**
* Constructor to create a new contentdefinition. You can set data with your
* set-Methods. After you have called the write-method this definition gets
* a unique id.
*/
public CmsMasterContent(CmsObject cms, CmsMasterDataSet dataset) {
this(cms);
m_dataSet = dataset;
}
/**
* Constructor to read a existing contentdefinition from the database. The
* data read from the databse will be filled into the member-variables.
* You can read them with the get- and modify them with the ser-methods.
* Changes you have made must be written back to the database by calling
* the write-method.
* @param cms the cms-object for access to cms-resources.
* @param id the master-id of the dataset to read.
* @throws CmsException if the data couldn't be read from the database.
*/
public CmsMasterContent(CmsObject cms, CmsUUID contentId) throws CmsException {
m_cms = cms;
initValues();
getDbAccessObject(getSubId()).read(m_cms, this, m_dataSet, contentId);
}
/**
* TESTFIX New code:
* Empty constructor needed for instanciating CDs as JavaBeans on JSPs.
*/
public CmsMasterContent() {}
/**
* This method initialises all needed members with default-values.
*/
protected void initValues() {
m_dataSet = new CmsMasterDataSet();
m_dataSet.m_masterId = CmsUUID.getNullUUID();
m_dataSet.m_subId = CmsDbUtil.UNKNOWN_ID;
m_dataSet.m_lockedBy = CmsUUID.getNullUUID();
m_dataSet.m_versionId = CmsDbUtil.UNKNOWN_ID;
m_dataSet.m_userName = null;
m_dataSet.m_groupName = null;
m_dataSet.m_lastModifiedByName = null;
m_dataSet.m_userId = CmsUUID.getNullUUID();
setAccessFlags(com.opencms.core.I_CmsConstants.C_ACCESS_DEFAULT_FLAGS);
}
/**
* Returns the title of this cd
*/
public String getTitle() {
return m_dataSet.m_title;
}
/**
* Sets title of this cd
*/
public void setTitle(String title) {
m_dataSet.m_title = title;
}
/**
* Returns a Vector of media-objects for this master cd.
* @return a Vector of media-objects for this master cd.
* @throws CmsException if the media couldn't be read.
*/
public Vector getMedia() throws CmsException {
if(m_dataSet.m_media == null) {
// the media was not read yet
// -> read them now from the db
m_dataSet.m_media = getDbAccessObject(getSubId()).readMedia(m_cms, this);
}
return m_dataSet.m_media;
}
/**
* Registers a new media, that should be written by calling write().
* @param media - The mediaobject to register for writing.
*/
public void addMedia(CmsMasterMedia media) {
m_dataSet.m_mediaToAdd.add(media);
}
/**
* Registers a media for deletion.
* @param media - The mediaobject to register.
*/
public void deleteMedia(CmsMasterMedia media) {
m_dataSet.m_mediaToDelete.add(media);
}
/**
* Registers a media for update
* @param media - The mediaobject to register.
*/
public void updateMedia(CmsMasterMedia media) {
m_dataSet.m_mediaToUpdate.add(media);
}
/**
* Returns a Vector of channels for this master cd.
* @return a Vector of channel-names (String) for this master cd.
* @throws CmsException if the channel couldn't be read.
*/
public Vector getChannels() throws CmsException {
if(m_dataSet.m_channel == null) {
// the channels was not read yet
// -> read them now from the db
m_dataSet.m_channel = getDbAccessObject(getSubId()).readChannels(m_cms, this);
}
return m_dataSet.m_channel;
}
/**
* Registers a new channel, that should be written by calling write().
* @param channels - The channel to register for writing.
*/
public void addChannel(String channel) {
m_dataSet.m_channelToAdd.add(channel);
}
/**
* Registers a channel for deletion.
* @param channel - The channel to register for deleting.
*/
public void deleteChannel(String channel) {
m_dataSet.m_channelToDelete.add(channel);
}
/**
* delete method
* for delete instance of content definition
* @param cms the CmsObject to use.
*/
public void delete(CmsObject cms) throws Exception {
getDbAccessObject(getSubId()).delete(m_cms, this, m_dataSet);
}
/**
* change group method
* for the permissions of content definition
* @param cms the CmsObject to use.
* @param group the id of the new group.
*/
public void chgrp(CmsObject cms, CmsUUID group) throws Exception {
m_dataSet.m_groupId = group;
getDbAccessObject(getSubId()).changePermissions(m_cms, this, m_dataSet);
}
/**
* change owner method
* for the permissions of content definition
* @param cms the CmsObject to use.
* @param owner the id of the new owner.
*/
public void chown(CmsObject cms, CmsUUID owner) throws Exception {
m_dataSet.m_userId = owner;
getDbAccessObject(getSubId()).changePermissions(m_cms, this, m_dataSet);
}
/**
* change access flags method
* for the permissions of content definition
* @param cms the CmsObject to use.
* @param accessflags the new access flags.
*/
public void chmod(CmsObject cms, int accessflags) throws Exception {
m_dataSet.m_accessFlags = accessflags;
getDbAccessObject(getSubId()).changePermissions(m_cms, this, m_dataSet);
}
/**
* copy method
*
* @param cms the CmsObject to use.
* @return int The id of the new content definition
*/
public CmsUUID copy(CmsObject cms) throws Exception {
// insert the new cd with the copied dataset
return getDbAccessObject(getSubId()).copy(cms, this, (CmsMasterDataSet)m_dataSet.clone(), this.getMedia(), this.getChannels());
}
/**
* write method
* to write the current content of the content definition to the database.
* @param cms the CmsObject to use.
*/
public void write(CmsObject cms) throws CmsException {
// add or delete channels according to current selection
updateChannels();
// is this a new row or an existing row?
if(m_dataSet.m_masterId.isNullUUID()) {
// this is a new row - call the create statement
getDbAccessObject(getSubId()).insert(m_cms, this, m_dataSet);
} else {
// this is a existing row - call the write statement
if(m_lockstateWasChanged) {
// update the locksyte
getDbAccessObject(getSubId()).writeLockstate(m_cms, this, m_dataSet);
} else {
// write the changes to the database
getDbAccessObject(getSubId()).write(m_cms, this, m_dataSet);
}
}
// everything is written - so lockstate was updated
m_lockstateWasChanged = false;
// for next access to the media - clean them so they must be read again
// from the db
m_dataSet.m_media = null;
m_dataSet.m_mediaToAdd = new Vector();
m_dataSet.m_mediaToDelete = new Vector();
m_dataSet.m_mediaToUpdate = new Vector();
// for next access to the channels - clean them so they must be read again
// from the db
m_dataSet.m_channel = null;
m_dataSet.m_channelToAdd = new Vector();
m_dataSet.m_channelToDelete = new Vector();
}
/**
* import method
* to import the current content of the content definition to the database.
*/
public void importMaster() throws Exception {
getDbAccessObject(getSubId()).insert(m_cms, this, m_dataSet);
// everything is written - so lockstate was updated
m_lockstateWasChanged = false;
// for next access to the media - clean them so they must be read again
// from the db
m_dataSet.m_media = null;
m_dataSet.m_mediaToAdd = new Vector();
m_dataSet.m_mediaToDelete = new Vector();
m_dataSet.m_mediaToUpdate = new Vector();
// for next access to the channels - clean them so they must be read again
// from the db
m_dataSet.m_channel = null;
m_dataSet.m_channelToAdd = new Vector();
m_dataSet.m_channelToDelete = new Vector();
}
/**
* gets the unique Id of a content definition instance
* @param cms the CmsObject to use.
* @return a string with the Id
*/
public String getUniqueId(CmsObject cms) {
return getId() + "";
}
/**
* gets the unique Id of a content definition instance
* @param cms the CmsObject to use.
* @return a int with the Id
*/
public CmsUUID getId() {
return m_dataSet.m_masterId;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -