📄 cmsdialog.java
字号:
* inserting a header with the content-type.<p>
*
* This overloads the default method of the parent class.<p>
*
* @param segment the HTML segment (START / END)
* @param helpUrl the url for the online help to include on the page
* @return the start html of the page
*/
public String pageHtml(int segment, String helpUrl) {
return pageHtml(segment, helpUrl, null);
}
/**
* Builds the start html of the page, including setting of DOCTYPE and
* inserting a header with the content-type.<p>
*
* This overloads the default method of the parent class.<p>
*
* @param segment the HTML segment (START / END)
* @param helpUrl the url for the online help to include on the page
* @param title the title for the page
* @return the start html of the page
*/
public String pageHtml(int segment, String helpUrl, String title) {
if (segment == HTML_START) {
String stylesheet = null;
if (isPopup() && !useNewStyle()) {
stylesheet = "popup.css";
}
StringBuffer result = new StringBuffer(pageHtmlStyle(segment, title, stylesheet));
if (getSettings().isViewExplorer()) {
result.append("<script type=\"text/javascript\" src=\"");
result.append(getSkinUri());
result.append("commons/explorer.js\"></script>\n");
}
result.append("<script type=\"text/javascript\">\n");
result.append(dialogScriptSubmit());
if (helpUrl != null) {
result.append("if (top.head && top.head.helpUrl) {\n");
result.append("\ttop.head.helpUrl=\"");
result.append(helpUrl + "\";\n");
result.append("}\n\n");
}
// the variable that may be set as path: if non-null this will be
// used as path for the online help window. This is needed because there are pages
// e.g. /administration/accounts/users/new that perform a jsp - forward while leaving the
// path param on the old page: no correct online help possible.
result.append("var onlineHelpUriCustom = ");
result.append(getOnlineHelpUriCustom());
result.append(";\n");
result.append("</script>\n");
return result.toString();
} else {
return super.pageHtml(segment, null);
}
}
/**
* Set the custom mapping for the online help. <p>
*
* This value will be set to a javascript variable called onlineHelpUriCustom.
* If it is set, the top.head javascript for the online help will use this value. <p>
*
* This method should be called from <code>{@link #initWorkplaceRequestValues(CmsWorkplaceSettings, HttpServletRequest)}</code>,
* <code>{@link CmsWorkplace#initWorkplaceMembers(CmsJspActionElement)}</code>
* or from the jsp if the dialog class is used for several actions.
* It should be used whenever the online help mapping does not work (due to jsp - forwards).<p>
*
* @param uri the left hand value in mapping.properties for the online help pages
*/
public void setOnlineHelpUriCustom(String uri) {
m_onlineHelpUriCustom = uri;
}
/**
* Sets the value of the action parameter.<p>
*
* @param value the value to set
*/
public void setParamAction(String value) {
m_paramAction = value;
}
/**
* Sets the value of the closelink parameter.<p>
*
* @param value the value to set
*/
public void setParamCloseLink(String value) {
// ensure decoded chars are re-encoded again properly
m_paramCloseLink = value;
}
/**
* Sets the value of the dialogtype parameter.<p>
*
* @param value the value to set
*/
public void setParamDialogtype(String value) {
m_paramDialogtype = value;
}
/**
* Sets the value of the frame name parameter.<p>
*
* @param value the value to set
*/
public void setParamFramename(String value) {
m_paramFrameName = value;
}
/**
* Sets the ispopup parameter.<p>
*
* @param value the ispopup parameter value
*/
public void setParamIsPopup(String value) {
m_paramIsPopup = value;
}
/**
* Sets the value of the message parameter.<p>
*
* @param value the value to set
*/
public void setParamMessage(String value) {
m_paramMessage = value;
}
/**
* Sets the value of the redirect flag parameter.<p>
*
* @param redirect the value of the redirect flag parameter
*/
public void setParamRedirect(String redirect) {
m_paramRedirect = redirect;
}
/**
* Sets the value of the file parameter.<p>
*
* @param value the value to set
*/
public void setParamResource(String value) {
m_paramResource = value;
}
/**
* Sets the value of the title parameter.<p>
*
* @param value the value to set
*/
public void setParamTitle(String value) {
m_paramTitle = value;
}
/**
* Appends a space char. between tag attribs.<p>
*
* @param attribute a tag attribute
* @return the tag attribute with a leading space char.
*/
protected String appendDelimiter(String attribute) {
if (CmsStringUtil.isNotEmpty(attribute)) {
if (!attribute.startsWith(" ")) {
// add a delimiter space between the beginning button HTML and the button tag attribs
return " " + attribute;
} else {
return attribute;
}
}
return "";
}
/**
* Checks if the permissions of the current user on the resource to use in the dialog are sufficient.<p>
*
* Automatically generates a CmsMessageContainer object with an error message and stores it in the users session.<p>
*
* @param required the required permissions for the dialog
* @param neededForFolder if true, the permissions are required for the parent folder of the resource (e.g. for editors)
* @return true if the permissions are sufficient, otherwise false
*/
protected boolean checkResourcePermissions(CmsPermissionSet required, boolean neededForFolder) {
return checkResourcePermissions(required, neededForFolder, Messages.get().container(
Messages.GUI_ERR_RESOURCE_PERMISSIONS_2,
getParamResource(),
required.getPermissionString()));
}
/**
* Checks if the permissions of the current user on the resource to use in the dialog are sufficient.<p>
*
* Automatically generates a CmsMessageContainer object with an error message and stores it in the users session.<p>
*
* @param required the required permissions for the dialog
* @param neededForFolder if true, the permissions are required for the parent folder of the resource (e.g. for editors)
* @param errorMessage the message container that is stored in the session in case the permissions are not sufficient
* @return true if the permissions are sufficient, otherwise false
*/
protected boolean checkResourcePermissions(
CmsPermissionSet required,
boolean neededForFolder,
CmsMessageContainer errorMessage) {
boolean hasPermissions = false;
try {
CmsResource res;
if (neededForFolder) {
// check permissions for the folder the resource is in
res = getCms().readResource(CmsResource.getParentFolder(getParamResource()), CmsResourceFilter.ALL);
} else {
res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
}
hasPermissions = getCms().hasPermissions(res, required, false, CmsResourceFilter.ALL);
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
if (!hasPermissions) {
// store the error message in the users session
getSettings().setErrorMessage(errorMessage);
}
return hasPermissions;
}
/**
* Renders the HTML for a single input button of a specified type.<p>
*
* @param result a string buffer where the rendered HTML gets appended to
* @param button a integer key to identify the button
* @param attribute an optional string with possible tag attributes, or null
*/
protected void dialogButtonsHtml(StringBuffer result, int button, String attribute) {
attribute = appendDelimiter(attribute);
switch (button) {
case BUTTON_OK:
result.append("<input name=\"ok\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_OK_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" type=\"submit\"");
} else {
result.append(" type=\"button\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_CANCEL:
result.append("<input name=\"cancel\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_CANCEL_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_EDIT:
result.append("<input name=\"ok\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_EDIT_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" type=\"submit\"");
} else {
result.append(" type=\"button\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_DISCARD:
result.append("<input name=\"cancel\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_DISCARD_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_CLOSE:
result.append("<input name=\"close\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_CLOSE_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_ADVANCED:
result.append("<input name=\"advanced\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_ADVANCED_0) + "\"");
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_SET:
result.append("<input name=\"set\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_SET_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" onclick=\"submitAction('" + DIALOG_SET + "', form);\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_BACK:
result.append("<input name=\"set\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_BACK_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" onclick=\"submitAction('" + DIALOG_BACK + "', form);\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_CONTINUE:
result.append("<input name=\"set\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_CONTINUE_0) + "\"");
if (attribute.toLowerCase().indexOf("onclick") == -1) {
result.append(" onclick=\"submitAction('" + DIALOG_CONTINUE + "', form);\"");
}
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
case BUTTON_DETAILS:
result.append("<input name=\"details\" type=\"button\" value=\"");
result.append(key(Messages.GUI_DIALOG_BUTTON_DETAIL_0) + "\"");
result.append(" class=\"dialogbutton\"");
result.append(attribute);
result.append(">\n");
break;
default:
// not a valid button code, just insert a warning in the HTML
result.append("<!-- invalid button code: ");
result.append(button);
result.append(" -->\n");
}
}
/**
* Returns the link URL to get back one folder in the administration view.<p>
*
* @return the link URL to get back one folder in the administration view
*/
protected String getAdministrationBackLink() {
return CmsWorkplace.VFS_PATH_WORKPLACE
+ "action/administration_content_top.html"
+ "?sender="
+ CmsResource.getParentFolder(getJsp().getRequestContext().getFolderUri());
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
fillParamValues(request);
if (DIALOG_CANCEL.equals(getParamAction())) {
setAction(ACTION_CANCEL);
}
}
/**
* Sets the action value.<p>
*
* @param value the action value
*/
protected void setAction(int value) {
m_action = value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -