📄 cmsmastercontent.java
字号:
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 int getId() {
return m_dataSet.m_masterId;
}
/**
* Gets the lockstate.
* @return 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
* @return 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
* @return 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
* @return 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
* @return 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);
A_OpenCms.fireCmsEvent(cms, com.opencms.flex.I_CmsEventListener.EVENT_PUBLISH_BO_RESOURCE, new HashMap(0));
}
/**
* 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);
}
/**
* Overwrite this method in your subclasses to execute any tasks before the resources are published.
*/
public static boolean beforePublish( CmsObject cms, Boolean enableHistory,
Integer projectId, Integer versionId, Long publishingDate,
Vector changedRessources, Vector changedModuleData, CmsMasterDataSet dataset ) {
if (false && ((cms == null) && (enableHistory == null) && (projectId == null) &&
(versionId == null) && (publishingDate == null) && (changedRessources == null) &&
(changedModuleData == null) && (dataset == null))) {
// silly test so that eclipse does not complain about unused method parameters
}
return true;
}
/**
* Publishes all modified content definitions for this project.
* @param cms The CmsObject
* @param enableHistory set to true if backup tables should be filled.
* @param projectId the Project that should be published.
* @param versionId the versionId to save in the backup tables.
* @param publishingDate the date and time of this publishing process.
* @param subId the subId to publish cd's for.
* @param contentDefinitionClassName the name of cd-class.
* @param changedRessources a Vector of Ressources that were changed by this
* publishing process.
* @param changedModuleData a Vector of Ressource that were changed by this
* publishing process. New published data will be add to this Vector to
* return it.
*/
protected static void publishProject(CmsObject cms, boolean enableHistory,
int projectId, int versionId, long publishingDate, int subId,
String contentDefinitionClassName, Vector changedRessources,
Vector changedModuleData) throws CmsException {
// now publish the project
getDbAccessObject(subId).publishProject(cms, enableHistory, projectId,
versionId, publishingDate, subId, contentDefinitionClassName,
changedRessources, changedModuleData );
}
/**
* Returns a Vector with the datasets of the contentdefinitions in the given channel.
* @param subId the id-type of the contentdefinition.
* @param channelId the id of the channel.
* @return Vector the vector that includes the datasets
*/
protected static Vector readAllByChannel(CmsObject cms, int channelId, int subId) throws CmsException{
return getDbAccessObject(subId).readAllByChannel(cms, channelId, subId);
}
/**
* Returns the date of the last modification of the content definition
*
* @return long The date of the last modification
*/
public long getDateLastModified() {
return m_dataSet.m_dateLastModified;
}
/**
* Returns the date of the creation of the content definition
*
* @return long The date of the creation
*/
public long getDateCreated() {
return m_dataSet.m_dateCreated;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -