📄 cmschannelcontent.java
字号:
}
/**
* Gets the name of the user who has modified the channel
*/
public String getLastModifiedByName(){
return "";
}
/**
* Gets the version id of version the channel
*/
public int getVersionId(){
return C_UNKNOWN_ID;
}
/**
* Gets all groups, that may work for a project.
* <P>
* The given vectors <code>names</code> and <code>values</code> will
* be filled with the appropriate information to be used for building
* a select box.
*
* @param cms CmsObject Object for accessing system resources.
* @param names Vector to be filled with the appropriate values in this method.
* @param values Vector to be filled with the appropriate values in this method.
* @return Index representing the current value in the vectors.
* @exception CmsException
*/
public Integer getGroups(CmsObject cms, Vector names, Vector values) throws CmsException {
// get all groups
Vector groups = cms.getGroups();
int retValue = -1;
String defaultGroup = C_GROUP_USERS;
I_CmsSession session = cms.getRequestContext().getSession(true);
String enteredGroup = this.getGroup();
if(enteredGroup != null && !enteredGroup.equals("")) {
// if an error has occurred before, take the previous entry of the user
defaultGroup = enteredGroup;
}
// fill the names and values
int n = 0;
for(int z = 0;z < groups.size();z++) {
if(((CmsGroup)groups.elementAt(z)).getProjectCoWorker()) {
String name = ((CmsGroup)groups.elementAt(z)).getName();
if(defaultGroup.equals(name)) {
retValue = n;
}
names.addElement(name);
values.addElement(name);
n++; // count the number of ProjectCoWorkers
}
}
return new Integer(retValue);
}
/**
* history method
* returns the history of content definition
* @param cms the CmsObject to use.
* @return Vector The history of a cd
*/
public Vector getHistory(CmsObject cms) {
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels have no history!");
}
return null;
}
/**
* 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){
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Channels have no history!");
}
return null;
};
/**
* returns true if the CD is readable for the current user
* @retruns true
*/
public boolean isReadable() {
m_cms.setContextToCos();
try {
return m_cms.accessRead(m_channel.getAbsolutePath());
} catch(CmsException exc) {
// there was a cms-exception - no read-access!
return false;
} finally {
m_cms.setContextToVfs();
}
}
/**
* returns true if the CD is writeable for the current user
* @retruns true
*/
public boolean isWriteable() {
m_cms.setContextToCos();
try {
return m_cms.accessWrite(m_channel.getAbsolutePath());
} catch(CmsException exc) {
// there was a cms-exception - no write-access!
return false;
} finally {
m_cms.setContextToVfs();
}
}
/**
* 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("ChannelId=" + getChannelId() + ";");
returnValue.append("ChannelName=" + getChannelPath() + ";");
returnValue.append("Lockstate=" + getLockstate() + ";");
returnValue.append("AccessFlags=" + getAccessFlagsAsString() + ";");
returnValue.append(m_channel.toString() + "}");
return returnValue.toString();
}
/**
* Convenience method to get the access-Flags as String representation.
* @return String of access rights
*/
public String getAccessFlagsAsString() {
int accessFlags = m_channel.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;
}
/**
* Get the permissions of Channel
*/
public void setAccessFlagsAsString(String permissions){
//change direction
String perm=permissions;
permissions="";
for(int x=9;x >= 0;x--) {
char temp=perm.charAt(x);
permissions+=temp;
}
setAccessFlags(Integer.parseInt(permissions,2));
}
/**
* Sets the channelId of a new channel
*/
private void setNewChannelId() throws CmsException{
int newChannelId = com.opencms.dbpool.CmsIdGenerator.nextId(this.C_TABLE_CHANNELID);
m_properties.put(I_CmsConstants.C_PROPERTY_CHANNELID, newChannelId+"");
m_channelId = newChannelId+"";
}
/**
* This content definition is lockable. This class overwrited the isLockable method of the abstract
* backoffice to flag that this content definition uses the lock feature of the backoffice. *
*/
public static boolean isLockable() {
return true;
}
/**
* Gets the names of the table columns displayed in the backoffice filelist.
* This method is needed for the abstract backoffice class only.
* @return Vector containing the columnnames.
*/
public static Vector getFieldNames(CmsObject cms) {
Vector names = new Vector();
names.addElement("channelId");
names.addElement("channelPath");
names.addElement("title");
names.addElement("ownerName");
names.addElement("group");
names.addElement("accessFlagsAsString");
return names;
}
/**
* Gets the methods used to display the dava values in the backoffice filelist.
* This method is needed for the abstract backoffice class only.
* @returns Vector with the nescessary get methods
*/
public static Vector getFieldMethods(CmsObject cms) {
Vector methods = new Vector();
try {
methods.addElement(CmsChannelContent.class.getMethod("getChannelId", new Class[0]));
methods.addElement(CmsChannelContent.class.getMethod("getChannelPath", new Class[0]));
methods.addElement(CmsChannelContent.class.getMethod("getTitle", new Class[0]));
methods.addElement(CmsChannelContent.class.getMethod("getOwnerName", new Class[0]));
methods.addElement(CmsChannelContent.class.getMethod("getGroup", new Class[0]));
methods.addElement(CmsChannelContent.class.getMethod("getAccessFlagsAsString", new Class[0]));
} catch(NoSuchMethodException exc) {
// this exception should never occur. You know your own methods in this cd
}
return methods;
}
/**
* Gets the filter methods
* This method is needed for the abstract backoffice class only.
* @returns a method array containing the methods
*/
public static Vector getFilterMethods(CmsObject cms) {
Vector filterMethods = new Vector();
try {
CmsFilterMethod filterUp = new CmsFilterMethod("All Channels",
CmsChannelContent.class.getMethod("getChannelList",
new Class[] {CmsObject.class} ) , new Object[0]);
filterMethods.addElement(filterUp);
} catch (NoSuchMethodException nsm) {
// this exception should never occur because you know your filter methods.
}
return filterMethods;
}
/**
* Returns a vector of CD objects, sorted descending by channelname.
* This method is needed for the abstract backoffice class only.
* @param cms The CmsObject.
*/
public static Vector getChannelList(CmsObject cms) throws CmsException {
Vector content = new Vector();
cms.setContextToCos();
try {
getAllResources(cms, "/", content);
} catch(CmsException e) {
// ignore the exception
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(A_OpenCms.C_MODULE_INFO, "[CmsChannelContent]: error when reading subfolders of cos root: "+e.getMessage());
}
} finally {
cms.setContextToVfs();
}
return content;
}
/**
* Helper for method getChannelList
*/
private static void getAllResources(CmsObject cms, String rootFolder, Vector allFolders) throws CmsException {
// get folders of this rootFolder
Vector subFolders = new Vector();
try{
subFolders = cms.getResourcesInFolder(rootFolder);
} catch (CmsException e){
// if the folder could not be found it might be deleted, so don't throw this exception
if(e.getType() != CmsException.C_NOT_FOUND){
throw e;
}
}
//copy the values into the allFolders Vector
for(int i = 0;i < subFolders.size();i++) {
CmsResource curFolder = (CmsResource)subFolders.elementAt(i);
CmsChannelContent curChannel = new CmsChannelContent(cms, curFolder);
allFolders.addElement(curChannel);
getAllResources(cms, curFolder.getAbsolutePath(), allFolders);
}
}
/**
* Plauzibilization method.
* This method checks if all inputfields contain correct input data.
* If an input field has no correct data, a CmsPlausibilizationException is thrown.
* @exception Throws CmsPlausibilizationException containing a vector of error-codes.
*/
public void check() throws CmsPlausibilizationException {
// define the vector which will hold all error codes
Vector errorCodes = new Vector();
//check the channelname
if (m_channelname == null || "".equals(m_channelname)) {
errorCodes.addElement(C_CHANNELNAME_ERRFIELD+C_ERRSPERATOR+this.C_ERRCODE_EMPTY);
}
//check the parentchannel
if (m_parentchannel == null || "".equals(m_parentchannel)) {
errorCodes.addElement(C_PARENT_ERRFIELD+C_ERRSPERATOR+this.C_ERRCODE_EMPTY);
}
// now test if there was an error message and throw an exception
if (errorCodes.size()>0) {
throw new CmsPlausibilizationException(errorCodes);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -