📄 cmsmastercontent.java
字号:
}
/**
* Returns the id of the user who has modified the content definition
*
* @return int The id of the user who has modified the cd
*/
public int getLastModifiedBy() {
return m_dataSet.m_lastModifiedBy;
}
/**
* Returns the name of the user who has modified the content definition
*
* @return String The name of the user who has modified the cd
*/
public String getLastModifiedByName() {
String retValue = m_dataSet.m_lastModifiedBy + "";;
if(m_dataSet.m_lastModifiedByName == null) {
try {
retValue = m_cms.readUser(m_dataSet.m_lastModifiedBy).getName();
} catch(CmsException exc) {
// ignore this exception, return the id instead
}
} else {
retValue = m_dataSet.m_lastModifiedByName;
}
return retValue;
}
/**
* Returns the id of the version in the history of the content definition
*
* @return int The id of the version, or -1 if there is no version-info
*/
public int getVersionId() {
return m_dataSet.m_versionId;
}
/**
* Restore method
* for restore instance of content definition from the history
*
* @param cms The CmsObject
* @param versionId The id of the version to restore
*/
public void restore(CmsObject cms, int versionId) throws Exception {
getDbAccessObject(this.getSubId()).restore(cms, this, m_dataSet, versionId);
}
/**
* History method
* returns the vector of the versions of content definition in the history
*
* @param cms The CmsObject
* @return Vector The versions of the cd in the history
*/
public Vector getHistory(CmsObject cms) throws Exception {
return getDbAccessObject(this.getSubId()).getHistory(cms, this.getClass(), m_dataSet.m_masterId, this.getSubId());
}
/**
* History method
* returns the cd of the version with the given versionId
*
* @param cms The CmsObject
* @param versionId The version id
* @return Object The object with the version of the cd
*/
public Object getVersionFromHistory(CmsObject cms, int versionId) throws Exception{
return getDbAccessObject(this.getSubId()).getVersionFromHistory(cms, this.getClass(), m_dataSet.m_masterId, this.getSubId(), versionId);
}
/**
* Get all currently selected channels
* @return Vector of all currently selected channels
*/
public Vector getSelectedChannels() throws CmsException{
if (m_selectedChannels == null) {
Vector dbChannels = getChannels();
m_selectedChannels = new Vector();
String rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
int offset = rootChannel.length()-1;
for (int i=0; i< dbChannels.size(); i++) {
// remove the root channel name from the channel's name
// and add to new Vector
m_selectedChannels.add(((String)dbChannels.elementAt(i)).substring(offset));
}
}
return m_selectedChannels;
}
/**
* set Selected Channels
* @param channels a String containing the channels names as a comma separated list
*/
public void setSelectedChannels(String channels) {
StringTokenizer tk = new StringTokenizer(channels, ",");
Vector v = new Vector();
int tokens = tk.countTokens();
if (channels != null && channels.equals("empty")) {
m_selectedChannels = v;
}else if (tokens > 0) {
for (int i=0; i<tokens; i++) {
v.addElement(tk.nextToken());
}
m_selectedChannels = v;
}
}
/**
* Get all currently available channels
* Note: the root channel of the module is not included in the returned
* channelnames. For example if the root channel is /Jobs/ and a channel's
* name is /Jobs/Education/Cologne/ the returned name for this channel will
* be /Education/Cologne/.
* @param cms object to access system resources
* @return a Vector of all channels that can be selected
*/
public Vector getAvailableChannels(CmsObject cms) throws CmsException {
if (m_availableChannels == null) {
Vector selectedChannels = getSelectedChannels();
Vector subChannels = getAllSubChannelsOfRootChannel(cms);
for (int i=0; i<subChannels.size(); i++) {
for (int j=0; j<selectedChannels.size(); j++) {
if (subChannels.elementAt(i).equals(selectedChannels.elementAt(j))) {
subChannels.removeElementAt(i);
i--;
break;
}
}
}
m_availableChannels = subChannels;
}
return m_availableChannels;
}
/**
* Set the Available Channels
* @param channels a String containing the channels to add as a comma separated list
*/
public void setAvailableChannels(String channels) {
StringTokenizer tk = new StringTokenizer(channels, ",");
Vector v = new Vector();
int tokens = tk.countTokens();
if (channels != null && channels.equals("empty")) {
m_availableChannels = v;
} else if (tokens > 0) {
for (int i=0; i<tokens; i++) {
v.addElement(tk.nextToken());
}
m_availableChannels = v;
}
}
/**
* Get all subchannels of a channel.
* Method returns only channels that doesn't have further subchannels because
* it is it not intended to add contentdefinitions to channels that are not
* endpoints of the channel folder structure. If different functionality
* is needed this method has to be overridden in derived
* contentdefinition classes.
* @param cms object to access system resources
* @param channel channel to be searched for subchannels
* @return Vector with names of all subchannels
* @throws com.opencms.core.CmsException in case of unrecoverable errors
*/
public static Vector getAllSubChannelsOf (CmsObject cms, String channel)
throws CmsException {
Vector allChannels = new Vector();
Vector subChannels = cms.getResourcesInFolder("//cos" + channel);
for (int i=0; i < subChannels.size(); i++) {
CmsResource resource = (CmsResource)subChannels.get(i);
if (resource.getState() != CmsResource.C_STATE_DELETED) {
String folder = resource.getAbsolutePath();
Vector v = getAllSubChannelsOf(cms, folder);
if (v.size() == 0 && hasWriteAccess(cms, resource)) {
allChannels.add(folder);
}else {
for (int j=0; j < v.size(); j++) {
allChannels.add(v.get(j));
}
}
}
}
return allChannels;
}
/**
* Get all subchannels of the module root channel without the root channel in the channel names
* Method returns only channels that doesn't have further subchannels because
* it is it not intended to add contentdefinitions to channels that are not
* endpoints in the channel folder structure. If different functionality
* is needed this method has to be overridden in derived
* contentdefinition classes.
* @param cms object to access system resources
* @param channel channel to be searched for subchannels
* @return Vector with names of all subchannels
* @throws com.opencms.core.CmsException in case of unrecoverable errors
*/
public Vector getAllSubChannelsOfRootChannel (CmsObject cms)
throws CmsException {
Vector allChannels = new Vector();
String rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
Vector subChannels = cms.getResourcesInFolder("//cos" + rootChannel);
int offset = rootChannel.length()-1;
for (int i=0; i < subChannels.size(); i++) {
CmsResource resource = (CmsResource)subChannels.get(i);
if (resource.getState() != CmsResource.C_STATE_DELETED) {
String folder = resource.getAbsolutePath();
Vector v = getAllSubChannelsOf(cms, folder);
if (v.size() == 0 && hasWriteAccess(cms, resource)) {
allChannels.add(folder.substring(offset));
} else {
for (int j=0; j < v.size(); j++) {
allChannels.add(((String)v.get(j)).substring(offset));
}
}
}
}
return allChannels;
}
/**
* Add or remove channels
* compares the currently selected channels with the selected
* channels stored in the database and adds or deletes channels if necessary
*/
protected void updateChannels() throws CmsException{
Vector dbChannels = getChannels();
Vector selectedChannels = getSelectedChannels();
String rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
String prefix = rootChannel.substring(0, rootChannel.length()-1);
// mark all channels to be deleted if not existing in m_selectedChannels but in datatabase
for (int i=0; i < dbChannels.size(); i++) {
boolean found = false;
for (int j=0; j < selectedChannels.size(); j++) {
if (dbChannels.elementAt(i).equals(prefix + ((String)selectedChannels.elementAt(j)))) {
found = true;
break;
}
}
if (!found) {
deleteChannel((String)dbChannels.elementAt(i));
}
}
// mark all channels to be added if existing in m_selectedChannels but not in database
for (int i=0; i < selectedChannels.size(); i++) {
boolean found = false;
for (int j=0; j < dbChannels.size(); j++) {
if ((prefix + ((String)selectedChannels.elementAt(i))).equals(dbChannels.elementAt(j))) {
found = true;
break;
}
}
if (!found) {
addChannel(prefix + (String)selectedChannels.elementAt(i));
}
}
}
/**
* Get the root channel of the module
* @return the root channel of the module
*/
public String getRootChannel() {
return getDbAccessObject(this.getSubId()).getRootChannel();
}
/**
* has the current user the right to write the resource
* @return a boolean
*/
protected static boolean hasWriteAccess(CmsObject cms, CmsResource resource) throws CmsException {
CmsUser currentUser = cms.getRequestContext().currentUser();
// check the rights for the current resource
if( ! ( accessOther(C_ACCESS_PUBLIC_WRITE, resource) ||
accessOwner(cms, currentUser, C_ACCESS_OWNER_WRITE, resource) ||
accessGroup(cms, currentUser, C_ACCESS_GROUP_WRITE, resource) ) ) {
// no write access to this resource!
return false;
}
return true;
}
/**
* Checks, if the owner may access this resource.
*
* @param cms the cmsObject
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param flags The flags to check.
*
* @return wether the user has access, or not.
*/
protected static boolean accessOwner(CmsObject cms, CmsUser currentUser,
int flags, CmsResource resource) throws CmsException {
// The Admin has always access
if( cms.isAdmin() ) {
return(true);
}
// is the resource owned by this user?
if(resource.getOwnerId() == currentUser.getId()) {
if( (resource.getAccessFlags() & flags) == flags ) {
return true ;
}
}
// the resource isn't accesible by the user.
return false;
}
/**
* Checks, if the group may access this resource.
*
* @param cms the cmsObject
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param flags The flags to check.
*
* @return wether the user has access, or not.
*/
protected static boolean accessGroup(CmsObject cms, CmsUser currentUser,
int flags, CmsResource resource) throws CmsException {
// is the user in the group for the resource?
if(cms.userInGroup(currentUser.getName(), cms.readGroup(resource.getGroupId()).getName())) {
if( (resource.getAccessFlags() & flags) == flags ) {
return true;
}
}
// the resource isn't accesible by the user.
return false;
}
/**
* Checks, if others may access this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param flags The flags to check.
*
* @return wether the user has access, or not.
*/
protected static boolean accessOther( int flags, CmsResource resource) throws CmsException {
if ((resource.getAccessFlags() & flags) == flags) {
return true;
} else {
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -