📄 cmschannelcontent.java
字号:
public String getLastModifiedByName(){
return "";
}
/**
* Gets the version id of version the channel
*/
public int getVersionId(){
return CmsDbUtil.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.
* @throws CmsException
*/
public Integer getGroups(CmsObject cms, Vector names, Vector values) throws CmsException {
// get all groups
List groups = cms.getGroups();
int retValue = -1;
String defaultGroup = OpenCms.getDefaultUsers().getGroupUsers();
// make sure the user has a session
CmsXmlTemplateLoader.getSession(cms.getRequestContext(), 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.get(z)).getProjectCoWorker()) {
String name = ((CmsGroup)groups.get(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 (CmsLog.getLog(this).isWarnEnabled() ) {
CmsLog.getLog(this).warn("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 (CmsLog.getLog(this).isWarnEnabled() ) {
CmsLog.getLog(this).warn("Channels have no history");
}
return null;
}
/**
* returns true if the CD is readable for the current user
* @return true
*/
public boolean isReadable() {
m_cms.getRequestContext().saveSiteRoot();
m_cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
try {
return m_cms.hasPermissions(m_channel, CmsPermissionSet.ACCESS_READ);
// TODO: remove this later
// m_cms.accessRead();
} catch(CmsException exc) {
// there was a cms-exception - no read-access!
return false;
} finally {
m_cms.getRequestContext().restoreSiteRoot();
}
}
/**
* returns true if the CD is writeable for the current user
* @return true
*/
public boolean isWriteable() {
m_cms.getRequestContext().saveSiteRoot();
m_cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
try {
// return m_cms.accessWrite(cms.readPath(m_channel));
return m_cms.hasPermissions(m_channel, CmsPermissionSet.ACCESS_WRITE);
} catch(CmsException exc) {
// there was a cms-exception - no write-access!
return false;
} finally {
m_cms.getRequestContext().restoreSiteRoot();
}
}
/**
* 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 = getAccessFlags();
StringBuffer buf = new StringBuffer();
buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_READ) > 0 ? "r" : "-"));
buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_WRITE) > 0 ? "w" : "-"));
buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_VIEW) > 0 ? "v" : "-"));
buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_READ) > 0 ? "r" : "-"));
buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_WRITE) > 0 ? "w" : "-"));
buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_VISIBLE) > 0 ? "v" : "-"));
buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_READ) > 0 ? "r" : "-"));
buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_WRITE) > 0 ? "w" : "-"));
buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE) > 0 ? "v" : "-"));
buf.append(((accessFlags & CmsResource.FLAG_INTERNAL) > 0 ? "i" : "-"));
return buf.toString();
}
/**
* 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 = org.opencms.db.CmsDbUtil.nextId(com.opencms.core.I_CmsConstants.C_TABLE_CHANNELID);
m_properties.put(CmsPropertyDefinition.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.
* @return 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.
* @return 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.getRequestContext().saveSiteRoot();
cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
try {
getAllResources(cms, "/", content);
} catch(CmsException e) {
// ignore the exception
if (CmsLog.getLog(CmsChannelContent.class).isWarnEnabled()) {
CmsLog.getLog(CmsChannelContent.class).warn("Error while reading subfolders of cos root", e);
}
} finally {
cms.getRequestContext().restoreSiteRoot();
}
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.addAll(cms.getResourcesInFolder(rootFolder, CmsResourceFilter.ONLY_VISIBLE));
} catch (CmsException e){
// if the folder could not be found it might be deleted, so don't throw this exception
if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() != CmsLegacyException.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, cms.getSitePath(curFolder), 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.
* @throws 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+com.opencms.core.I_CmsConstants.C_ERRSPERATOR+C_ERRCODE_EMPTY);
}
//check the parentchannel
if (m_parentchannel == null || "".equals(m_parentchannel)) {
errorCodes.addElement(C_PARENT_ERRFIELD+com.opencms.core.I_CmsConstants.C_ERRSPERATOR+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 + -