cmsedituseraddinfodialog.java
来自「找了很久才找到到源代码」· Java 代码 · 共 530 行 · 第 1/2 页
JAVA
530 行
*/
public void setParamEditall(String editAll) {
m_paramEditall = editAll;
}
/**
* Sets the user id parameter value.<p>
*
* @param userId the user id parameter value to set
*/
public void setParamUserid(String userId) {
m_paramUserid = userId;
}
/**
* Sets the read only add info.<p>
*
* @param addInfoReadOnly the read only add info to set
*/
public void setReadonly(SortedMap addInfoReadOnly) {
m_addInfoReadOnly = addInfoReadOnly;
}
/**
* Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
*
* This overwrites the method from the super class to create a layout variation for the widgets.<p>
*
* @param dialog the dialog (page) to get the HTML for
*
* @return the dialog HTML for all defined widgets of the named dialog (page)
*/
protected String createDialogHtml(String dialog) {
StringBuffer result = new StringBuffer(1024);
result.append(createWidgetTableStart());
// show error header once if there were validation errors
result.append(createWidgetErrorHeader());
if (dialog.equals(PAGES[0])) {
if (!Boolean.valueOf(getParamEditall()).booleanValue()) {
int pos = 0;
Iterator it = OpenCms.getWorkplaceManager().getUserInfoManager().getBlocks().iterator();
while (it.hasNext()) {
CmsWorkplaceUserInfoBlock block = (CmsWorkplaceUserInfoBlock)it.next();
result.append(dialogBlockStart(key(block.getTitle())));
result.append(createWidgetTableStart());
result.append(createDialogRowsHtml(pos, pos - 1 + block.getEntries().size()));
result.append(createWidgetTableEnd());
result.append(dialogBlockEnd());
pos += block.getEntries().size();
}
} else {
result.append(createWidgetBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_ADDITIONALINFO_BLOCK_0)));
result.append(createDialogRowsHtml(0, 0));
result.append(createWidgetBlockEnd());
result.append(createWidgetBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_READONLY_BLOCK_0)));
result.append(createDialogRowsHtml(1, 1));
result.append(createWidgetBlockEnd());
}
}
result.append(createWidgetTableEnd());
return result.toString();
}
/**
* @see org.opencms.workplace.tools.accounts.A_CmsEditUserDialog#defineWidgets()
*/
protected void defineWidgets() {
// initialize the user object to use for the dialog
initUserObject();
setKeyPrefix(KEY_PREFIX);
int count = 0;
if (!Boolean.valueOf(getParamEditall()).booleanValue()) {
// widgets to display
Iterator itBlocks = OpenCms.getWorkplaceManager().getUserInfoManager().getBlocks().iterator();
while (itBlocks.hasNext()) {
CmsWorkplaceUserInfoBlock block = (CmsWorkplaceUserInfoBlock)itBlocks.next();
Iterator itEntries = block.getEntries().iterator();
while (itEntries.hasNext()) {
CmsWorkplaceUserInfoEntry entry = (CmsWorkplaceUserInfoEntry)itEntries.next();
int min = entry.isOptional() ? 0 : 1;
I_CmsWidget widget = entry.getWidgetObject();
addWidget(new CmsWidgetDialogParameter(
m_addInfoList.get(count),
"value",
entry.getKey(),
"",
PAGES[0],
widget,
min,
1));
count++;
}
}
} else {
addWidget(new CmsWidgetDialogParameter(this, "info", PAGES[0], new CmsInputWidget()));
addWidget(new CmsWidgetDialogParameter(this, "readonly", PAGES[0], new CmsDisplayWidget()));
}
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
*/
protected String[] getPageArray() {
return PAGES;
}
/**
* @see org.opencms.workplace.CmsWorkplace#initMessages()
*/
protected void initMessages() {
// add specific dialog resource bundle
addMessages(Messages.get().getBundleName());
// add default resource bundles
super.initMessages();
}
/**
* Initializes the additional info bean to work with, depending on the dialog state and request parameters.<p>
*/
protected void initUserObject() {
try {
if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
// edit an existing user, get the user object from db
m_user = getCms().readUser(new CmsUUID(getParamUserid()));
if (!Boolean.valueOf(getParamEditall()).booleanValue()) {
m_addInfoList = createAddInfoList(m_user);
} else {
setAddInfoMaps();
}
return;
} else {
// this is not the initial call, get the user object from session
m_user = getCms().readUser(new CmsUUID(getParamUserid()));
if (!Boolean.valueOf(getParamEditall()).booleanValue()) {
m_addInfoList = (List)getDialogObject();
} else {
Map dObj = (Map)getDialogObject();
m_addInfoEditable = (SortedMap)dObj.get("editable");
m_addInfoReadOnly = (SortedMap)dObj.get("readonly");
}
return;
}
} catch (Exception e) {
// noop
}
// create a new user object
try {
m_user = getCms().readUser(new CmsUUID(getParamUserid()));
} catch (CmsException e) {
// ignore
}
if (!Boolean.valueOf(getParamEditall()).booleanValue()) {
m_addInfoList = createAddInfoList(m_user);
} else {
setAddInfoMaps();
}
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// initialize parameters and dialog actions in super implementation
super.initWorkplaceRequestValues(settings, request);
// save the current state (may be changed because of the widget values)
if (!Boolean.valueOf(getParamEditall()).booleanValue()) {
setDialogObject(m_addInfoList);
} else {
Map dObj = new HashMap();
dObj.put("editable", m_addInfoEditable);
dObj.put("readonly", m_addInfoReadOnly);
setDialogObject(dObj);
}
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
*/
protected void validateParamaters() throws Exception {
// test the needed parameters
String ou = getCms().readUser(new CmsUUID(getParamUserid())).getOuFqn();
OpenCms.getRoleManager().checkRole(getCms(), CmsRole.ACCOUNT_MANAGER.forOrgUnit(ou));
}
/**
* Creates a new additional information bean object.<p>
*
* @param user the user to create the bean for
*
* @return a new additional information bean object
*/
private List createAddInfoList(CmsUser user) {
List addInfoList = new ArrayList();
// add beans
Iterator itBlocks = OpenCms.getWorkplaceManager().getUserInfoManager().getBlocks().iterator();
while (itBlocks.hasNext()) {
CmsWorkplaceUserInfoBlock block = (CmsWorkplaceUserInfoBlock)itBlocks.next();
Iterator itEntries = block.getEntries().iterator();
while (itEntries.hasNext()) {
CmsWorkplaceUserInfoEntry entry = (CmsWorkplaceUserInfoEntry)itEntries.next();
Object value = user.getAdditionalInfo(entry.getKey());
if (value == null) {
value = "";
}
addInfoList.add(new CmsUserAddInfoBean(entry.getKey(), value.toString(), entry.getClassType()));
}
}
return addInfoList;
}
/**
* Builds the additional info maps.<p>
*/
private void setAddInfoMaps() {
m_addInfoEditable = new TreeMap();
m_addInfoReadOnly = new TreeMap();
Iterator itEntries = m_user.getAdditionalInfo().entrySet().iterator();
while (itEntries.hasNext()) {
Map.Entry entry = (Map.Entry)itEntries.next();
String key = entry.getKey().toString();
if ((entry.getValue() == null) || CmsStringUtil.isEmptyOrWhitespaceOnly(entry.getValue().toString())) {
// skip empty entries
continue;
}
if (!entry.getValue().getClass().equals(String.class)) {
// only show type different to string
key += "@" + entry.getValue().getClass().getName();
}
if (CmsDataTypeUtil.isParseable(entry.getValue().getClass())) {
m_addInfoEditable.put(key, entry.getValue());
} else {
String value = entry.getValue().toString();
if (value.length() > (75 - key.length())) {
if ((75 - key.length()) > 5) {
value = value.substring(0, (75 - key.length())) + " ...";
} else {
value = "...";
}
}
m_addInfoReadOnly.put(key, value);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?