📄 cmsmastercontent.java
字号:
/**
* import method
* to importthe current content of the content definition to the database.
* @param cms the CmsObject to use.
*/
public void importMaster(CmsObject cms) 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.
* @returns 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.
* @returns a int with the Id
*/
public int getId() {
return m_dataSet.m_masterId;
}
/**
* Gets the lockstate.
* @returns a int with the user who has locked the ressource.
*/
public int getLockstate() {
int retValue = -2; // no writeaccess for this user
try {
if(hasWriteAccess(m_cms)) {
retValue = m_dataSet.m_lockedBy;
}
} catch(CmsException exc) {
// ignore this exception - no writeaccess
}
return retValue;
}
/**
* Sets the lockstates
* @param the lockstate for the actual entry.
*/
public void setLockstate(int lockstate) {
m_lockstateWasChanged = true;
m_dataSet.m_lockedBy = lockstate;
}
/**
* Gets the owner of this contentdefinition.
*/
public int getOwner() {
return m_dataSet.m_userId;
}
/**
* Gets the ownername
*/
public String getOwnerName() {
String retValue = m_dataSet.m_userId + "";
if(m_dataSet.m_userName == null || "".equals(m_dataSet.m_userName.trim())) {
try { // to read the real name of this user
retValue = m_cms.readUser(m_dataSet.m_userId).getName();
} catch(CmsException exc) {
// ignore the exception - it was not possible to read the group
// instead return the groupid
}
} else {
// this is a history value - return it
retValue = m_dataSet.m_userName;
}
return retValue;
}
/**
* Sets the owner of this contentdefinition.
*/
public void setOwner(int id) {
m_dataSet.m_userId = id;
}
/**
* Gets the groupname
*/
public String getGroup() {
String retValue = m_dataSet.m_groupId + "";
if(m_dataSet.m_groupName == null || "".equals(m_dataSet.m_groupName.trim())) {
try { // to read the real name of this group
retValue = m_cms.readGroup(m_dataSet.m_groupId).getName();
} catch(CmsException exc) {
// ignore the exception - it was not possible to read the group
// instead return the groupid
}
} else {
// this is historical data - return it
retValue = m_dataSet.m_groupName;
}
return retValue;
}
/**
* Gets the groupid
*/
public int getGroupId() {
return m_dataSet.m_groupId;
}
/**
* Sets the group.
*/
public void setGroup(int id) {
m_dataSet.m_groupId = id;
}
/**
* Returns the projectId of the content definition.
* If the cd belongs to the current project the value
* is the id of the current project otherwise its
* the id of the online project
*
* @return int The project id
*/
public int getProjectId() {
return m_dataSet.m_projectId;
}
/**
* Returns the state of the content definition:
* unchanged, new, changed or deleted
*
* @return int The state of the cd
*/
public int getState() {
return m_dataSet.m_state;
}
/**
* Returns the projectId of the content definition
* that is stored in the cd table after the cd
* was locked
*
* @return int The id of the cd
*/
public int getLockedInProject() {
return m_dataSet.m_lockedInProject;
}
/**
* Returns the sub-id of this contentdefinition. You have to implement this
* method so it returns a unique sunb-id that describes the type of the
* contentdefinition. (E.g. article: sub-id=1; table: sub-id=2).
*/
abstract public int getSubId();
/**
* Returns a String representation of this instance.
* This can be used for debugging purposes.
*/
public String toString() {
StringBuffer returnValue = new StringBuffer();
returnValue.append(this.getClass().getName() + "{");
returnValue.append("UniqueId=" + getUniqueId(m_cms) + ";");
returnValue.append("Lockstate=" + getLockstate() + ";");
returnValue.append("AccessFlags=" + getAccessFlagsAsString() + ";");
returnValue.append(m_dataSet.toString() + "}");
return returnValue.toString();
}
/**
* set the accessFlag for the CD
* @param the accessFlag
*/
public void setAccessFlags(int accessFlags) {
m_dataSet.m_accessFlags = accessFlags;
}
/**
* get the accessFlag for the CD
* @returns the accessFlag
*/
public int getAccessFlags() {
return m_dataSet.m_accessFlags;
}
/**
* Convenience method to get the access-Flags as String representation.
* @return String of access rights
*/
public String getAccessFlagsAsString() {
int accessFlags = getAccessFlags();
String str = "";
str += ((accessFlags & I_CmsConstants.C_ACCESS_OWNER_READ)>0?"r":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_OWNER_WRITE)>0?"w":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_OWNER_VISIBLE)>0?"v":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_GROUP_READ)>0?"r":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_GROUP_WRITE)>0?"w":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_GROUP_VISIBLE)>0?"v":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_PUBLIC_READ)>0?"r":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_PUBLIC_WRITE)>0?"w":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE)>0?"v":"-");
str += ((accessFlags & I_CmsConstants.C_ACCESS_INTERNAL_READ)>0?"i":"-");
return str;
}
/**
* has the current user the right to view the CD
* @returns true if this cd is visible
*/
public boolean isVisible() {
CmsUser currentUser = m_cms.getRequestContext().currentUser();
try {
if(m_cms.isAdmin()) {
return true;
} else {
if ( !accessOther(C_ACCESS_PUBLIC_VISIBLE)
&& !accessOwner(m_cms, currentUser, C_ACCESS_OWNER_VISIBLE)
&& !accessGroup(m_cms, currentUser, C_ACCESS_GROUP_VISIBLE)) {
return false;
} else {
return true;
}
}
} catch(CmsException exc) {
// no access to cms -> not visible
return false;
}
}
/**
* returns true if the CD is readable for the current user
* @retruns true if the cd is readable
*/
public boolean isReadable() {
try {
if(m_cms.isAdmin()) {
return true;
} else {
return hasReadAccess(m_cms);
}
} catch(CmsException exc) {
// there was a cms-exception - no read-access!
return false;
}
}
/**
* returns true if the CD is writeable for the current user
* @retruns true if the cd is writeable
*/
public boolean isWriteable() {
try {
if(m_cms.isAdmin()) {
return true;
} else {
return this.hasWriteAccess(m_cms);
}
} catch(CmsException exc) {
// there was a cms-exception - no write-access!
return false;
}
}
/**
* Publishes the content definition directly
*
* @param cms The CmsObject
*/
public void publishResource(CmsObject cms) throws Exception {
Vector changedResources = new Vector();
Vector changedModuleData = new Vector();
int versionId = 0;
long publishDate = System.currentTimeMillis();
boolean enableHistory = cms.isHistoryEnabled();
if (enableHistory){
// Get the next version id
versionId = cms.getBackupVersionId();
// backup the current project
cms.backupProject(cms.getRequestContext().currentProject().getId(), versionId, publishDate);
}
// now publish the content definition
getDbAccessObject(getSubId()).publishResource(cms, m_dataSet, getSubId(), this.getClass().getName(),
enableHistory, versionId, publishDate, changedResources, changedModuleData);
// update the cache
cms.getOnlineElementCache().cleanupCache(changedResources, changedModuleData);
}
/**
* Undelete method
* for undelete instance of content definition
*
* @param cms The CmsObject
*/
public void undelete(CmsObject cms) throws Exception {
getDbAccessObject(getSubId()).undelete(m_cms, this, m_dataSet);
}
/**
* Publishes all modified content definitions for this project.
* @param cms The CmsObject
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -