📄 cmsmastercontent.java
字号:
* @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.
* @retruns 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;
}
/**
* 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
* @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();
try {
cms.setContextToCos();
//Vector subChannels = cms.getSubFolders(channel);
Vector subChannels = cms.getResourcesInFolder(channel);
for (int i=0; i < subChannels.size(); i++) {
String folder = ((CmsResource)subChannels.elementAt(i)).getAbsolutePath();
Vector v = getAllSubChannelsOf(cms, folder);
if (v.size() == 0) {
allChannels.addElement(folder);
}else {
for (int j=0; j < v.size(); j++) {
allChannels.addElement(v.elementAt(j));
}
}
}
} finally {
cms.setContextToVfs();
}
return allChannels;
}
/**
* Get all subchannels of the module root channel without the root channel in the channel names
* @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();
try {
cms.setContextToCos();
String rootChannel = getDbAccessObject(this.getSubId()).getRootChannel();
//Vector subChannels = cms.getSubFolders(rootChannel);
Vector subChannels = cms.getResourcesInFolder(rootChannel);
int offset = rootChannel.length()-1;
for (int i=0; i < subChannels.size(); i++) {
String folder = ((CmsResource)subChannels.elementAt(i)).getAbsolutePath();
Vector v = getAllSubChannelsOf(cms, folder);
if (v.size() == 0) {
allChannels.addElement(folder.substring(offset));
}else {
for (int j=0; j < v.size(); j++) {
allChannels.addElement(((String)v.elementAt(j)).substring(offset));
}
}
}
} finally {
cms.setContextToVfs();
}
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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -