📄 cmsadmingroups.java
字号:
// add a new user to selectedUsers
String username = (String)parameters.get("NOTSELECTEDUSERS");
if(username != null) {
selectedUsers.addElement(username);
notSelectedUsers.removeElement(username);
}
}
else {
if(parameters.get("REMOVE") != null) {
// delete a group from selectedUsers
// and move it to notSelectedUsers
String username = (String)parameters.get("SELECTEDUSERS");
if(username != null) {
notSelectedUsers.addElement(username);
selectedUsers.removeElement(username);
}
}
else {
if(parameters.get("OK") != null) {
// form submitted, try to change the group data
try {
CmsGroup theGroup = cms.readGroup(groupname);
if("".equals(supergroup) || supergroup.equals(C_NO_SUPERGROUP_SELECTED)) {
cms.setParentGroup(groupname, null);
}
else {
cms.setParentGroup(groupname, supergroup);
}
theGroup = cms.readGroup(groupname);
theGroup.setDescription(description);
theGroup.setProjectManager(projectManager);
theGroup.setProjectCoWorker(projectCoWorker);
theGroup.setRole(role);
cms.writeGroup(theGroup);
theGroup = cms.readGroup(groupname);
// now change the list of users of this group but take into account that
// the default group of a user can't be removed
List allUsers = cms.getUsersOfGroup(groupname);
boolean defaultProblem = false;
Vector falseUsers = new Vector();
for(int z = 0;z < allUsers.size();z++) {
String theUserName = ((CmsUser)allUsers.get(z)).getName();
if(!selectedUsers.contains(theUserName)) {
cms.removeUserFromGroup(theUserName, groupname);
}
}
for(int z = 0;z < selectedUsers.size();z++) {
cms.addUserToGroup((String)selectedUsers.elementAt(z), groupname);
}
cms.writeGroup(theGroup);
session.removeValue("selectedUsers");
session.removeValue("notSelectedUsers");
session.removeValue("PROJECTMANAGER");
session.removeValue("PROJECTCOWORKER");
session.removeValue("ROLE");
session.removeValue("ERROR");
if(defaultProblem) {
xmlTemplateDocument.setData("RMDEFAULTDETAIL", "The following users which were to be removed had " + groupname + " as default group: " + falseUsers);
templateSelector = "errorremovedefault";
}
else {
templateSelector = ""; //successful
}
}
catch(CmsException e) {
// remeber that an error has occurred
session.putValue("ERROR", new String("yes"));
session.putValue("GROUPDESC", description);
session.putValue("SUPERGROUP", supergroup);
if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_GROUP)) {
templateSelector = "errornogroup2";
}
else {
if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_USER && e.getMessage().equals("user data missing"))) {
templateSelector = "errordatamissing2";
}
else {
throw e; // hand the exception down
}
}
} // catch
} // else if 'OK'
}
}
} // groupYetChanged
session.putValue("selectedUsers", selectedUsers);
session.putValue("notSelectedUsers", notSelectedUsers);
session.putValue("SUPERGROUP", supergroup);
}
// again common part for 'newgroup' and 'changegroup':
// set the variables for display in the document
if(groupname == null) {
groupname = "";
}
if(description == null) {
description = "";
}
if(supergroup == null) {
supergroup = "";
}
xmlTemplateDocument.setData("GROUPNAME", groupname);
xmlTemplateDocument.setData("GROUPDESC", description);
xmlTemplateDocument.setData("SUPERGROUP", supergroup);
xmlTemplateDocument.setData("PCWCHECKED", projectCoWorker ? "checked" : "");
xmlTemplateDocument.setData("PMCHECKED", projectManager ? "checked" : "");
xmlTemplateDocument.setData("PRCHECKED", role ? "checked" : "");
} // belongs to: 'if perspective is newgroup or changegroup'
else {
if(perspective.equals("deletegroup")) {
String groupname = (String)parameters.get("GROUPNAME");
xmlTemplateDocument.setData("GROUPNAME", groupname);
templateSelector = "RUsureDelete";
}
else {
if(perspective.equals("reallydeletegroup")) {
// deleting the group
try {
String groupname = (String)parameters.get("GROUPNAME");
cms.deleteGroup(groupname);
templateSelector = "";
}
catch(Exception e) {
// groupname == null or delete failed
xmlTemplateDocument.setData("DELETEDETAILS", CmsException.getStackTraceAsString(e));
templateSelector = "deleteerror";
}
}
}
}
// Now load the template file and start the processing
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
}
/**
* Gets all groups for a select box
* <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.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the current value in the vectors.
* @throws CmsException
*/
public Integer getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
Vector values, Hashtable parameters) throws CmsException {
// get all groups
List groups = cms.getGroups();
int retValue = 0;
// fill the names and values
for(int z = 0;z < groups.size();z++) {
String name = ((CmsGroup)groups.get(z)).getName();
names.addElement(name);
values.addElement(name);
}
return new Integer(retValue);
}
/**
* Gets all users, that have not yet been selected for the group
* <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.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the current value in the vectors.
* @throws CmsException
*/
public Integer getNotSelectedUsers(CmsObject cms, CmsXmlLanguageFile lang,
Vector names, Vector values, Hashtable parameters) throws CmsException {
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
Vector notSelectedUsers = (Vector)session.getValue("notSelectedUsers");
if(notSelectedUsers != null) {
for(int z = 0;z < notSelectedUsers.size();z++) {
String name = (String)notSelectedUsers.elementAt(z);
names.addElement(name);
values.addElement(name);
}
}
return new Integer(-1); // nothing preselected
}
/**
* Gets all users that have been selected to be in the group
* <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.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the default Group of the user
* @throws CmsException
*/
public Integer getSelectedUsers(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
Vector values, Hashtable parameters) throws CmsException {
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
Vector selectedUsers = (Vector)session.getValue("selectedUsers");
if(selectedUsers != null) {
for(int z = 0;z < selectedUsers.size();z++) {
String name = (String)selectedUsers.elementAt(z);
names.addElement(name);
values.addElement(name);
}
}
else {
selectedUsers = new Vector();
}
return new Integer(-1);
}
/**
* Gets all supergroups of the actual group (in session or in form data) for a selectbox
* <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.
* @param parameters Hashtable containing all user parameters.
* @return Index representing the current value in the vectors.
* @throws CmsException
*/
public Integer getSuperGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
Vector values, Hashtable parameters) throws CmsException {
int retValue = -1;
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
String actualGroup = (String)session.getValue("GROUPNAME");
String temp = (String)parameters.get("GROUPNAME");
if(temp != null) {
actualGroup = temp;
}
if(parameters.get("NEW") != null) {
// user pressed the NEW-button so we dont need the actual Group
actualGroup = "";
}
String supergroup = (String)session.getValue("SUPERGROUP");
temp = (String)parameters.get("SUPERGROUP");
if(temp != null) {
supergroup = temp;
}
if(supergroup == null) {
supergroup = "";
}
names.addElement(lang.getLanguageValue("input.none"));
values.addElement(C_NO_SUPERGROUP_SELECTED);
List groups = cms.getGroups();
int selectedGroup = 0;
for(int z = 0;z < groups.size();z++) {
String name = ((CmsGroup)groups.get(z)).getName();
if(name.equals(supergroup)) {
retValue = selectedGroup;
}
if(!name.equals(actualGroup)) {
names.addElement(name);
values.addElement(name);
selectedGroup++;
}
}
return new Integer(retValue + 1);
}
/**
* Determines if the group icon is shown in the administration view depending on the property value of the key "workplace.administration.showusergroupicon".<p>
*
* @param cms the CmsObject
* @param lang the workplace language file
* @param parameters the parameters
* @return Boolean to determine if group icon is shown in the administration view
*/
public Boolean isVisible(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) {
return new Boolean(OpenCms.getWorkplaceManager().showUserGroupIcon());
}
/**
* Indicates if the results of this class are cacheable.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
*/
public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
Hashtable parameters, String templateSelector) {
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -