📄 cmswidgetdialog.java
字号:
protected String defaultActionHtmlStart() throws JspException {
StringBuffer result = new StringBuffer(2048);
result.append(htmlStart("administration/index.html"));
result.append("<script type=\"text/javascript\" src=\"").append(getResourceUri()).append(
"editors/xmlcontent/edit.js\"></script>\n");
result.append("<script type=\"text/javascript\" src=\"").append(getResourceUri()).append(
"editors/xmlcontent/help.js\"></script>\n");
result.append(getWidgetIncludes());
result.append("<script type=\"text/javascript\">\n<!--\n");
result.append("// flag indicating if form initialization is finished\n");
result.append("var initialized = false;\n");
result.append("// the OpenCms context path\n");
result.append("var contextPath = \"").append(OpenCms.getSystemInfo().getOpenCmsContext()).append("\";\n\n");
result.append("// action parameters of the form\n");
result.append("var actionAddElement = \"").append(EDITOR_ACTION_ELEMENT_ADD).append("\";\n");
result.append("var actionRemoveElement = \"").append(EDITOR_ACTION_ELEMENT_REMOVE).append("\";\n");
result.append("function init() {\n");
result.append(getWidgetInitCalls());
result.append("\tsetTimeout(\"scrollForm();\", 200);\n");
result.append("\tinitialized = true;\n");
result.append("}\n\n");
result.append("function exitEditor() {\n");
result.append("\ttry {\n");
result.append("\t\t// close file selector popup if present\n");
result.append("\t\tcloseTreeWin();\n");
result.append("\t} catch (e) {}\n");
result.append("}\n");
result.append(getWidgetInitMethods());
result.append("\n// -->\n</script>\n");
result.append(bodyStart(null, "onload='init();' onunload='exitEditor();'"));
result.append(dialogStart());
return result.toString();
}
/**
* Defines the list of parameters for this dialog.<p>
*/
protected abstract void defineWidgets();
/**
* Fills all widgets of this widget dialog with the values from the request parameters.<p>
*
* @param request the current HTTP servlet request
*/
protected void fillWidgetValues(HttpServletRequest request) {
Map parameters = request.getParameterMap();
Map processedParamters = new HashMap();
Iterator p = parameters.keySet().iterator();
// make sure all "hidden" widget parameters are decoded
while (p.hasNext()) {
String key = (String)p.next();
String[] values = (String[])parameters.get(key);
if (key.startsWith(HIDDEN_PARAM_PREFIX)) {
// this is an encoded hidden parameter
key = key.substring(HIDDEN_PARAM_PREFIX.length());
String[] newValues = new String[values.length];
for (int l = 0; l < values.length; l++) {
newValues[l] = CmsEncoder.decode(values[l], getCms().getRequestContext().getEncoding());
}
values = newValues;
}
processedParamters.put(key, values);
}
// now process the parameters
m_widgetParamValues = new HashMap();
Iterator i = getWidgets().iterator();
while (i.hasNext()) {
// check for all widget base parameters
CmsWidgetDialogParameter base = (CmsWidgetDialogParameter)i.next();
List params = new ArrayList();
int maxOccurs = base.getMaxOccurs();
boolean onPage = false;
if (base.isCollectionBase()) {
// for a collection base, check if we are on the page where the collection base is shown
if (CmsStringUtil.isNotEmpty(getParamAction()) && !DIALOG_INITIAL.equals(getParamAction())) {
// if no action set (usually for first display of dialog) make sure all values are shown
// DIALOG_INITIAL is a special value for the first display and must be handled the same way
String page = getParamPage();
// keep in mind that since the paramPage will be set AFTER the widget values are filled,
// so the first time this page is called from another page the following will result to "false",
// but for every "submit" on the page this will be "true"
onPage = CmsStringUtil.isEmpty(page)
|| CmsStringUtil.isEmpty(base.getDialogPage())
|| base.getDialogPage().equals(page);
}
}
for (int j = 0; j < maxOccurs; j++) {
// check for all possible values in the request parameters
String id = CmsWidgetDialogParameter.createId(base.getName(), j);
boolean required = (params.size() < base.getMinOccurs())
|| (processedParamters.get(id) != null)
|| (!onPage && base.hasValue(j));
if (required) {
CmsWidgetDialogParameter param = new CmsWidgetDialogParameter(base, params.size(), j);
param.setKeyPrefix(m_prefix);
base.getWidget().setEditorValue(getCms(), processedParamters, this, param);
params.add(param);
}
}
m_widgetParamValues.put(base.getName(), params);
}
}
/**
* Returns the title for this Dialog.<p>
*
* In the default implementation this method returns <code>null</code>.
* Override this if needed.<p>
*
* @return the title for this Dialog, or <code>null</code> if this dialog has no title
*/
protected String getDialogTitle() {
return null;
}
/**
* Returns the allowed pages for this dialog.<p>
*
* @return the allowed pages for this dialog
*/
protected abstract String[] getPageArray();
/**
* Returns the allowed pages for this dialog.<p>
*
* @return the allowed pages for this dialog
*/
protected List getPages() {
if (m_pages == null) {
m_pages = Arrays.asList(getPageArray());
}
return m_pages;
}
/**
* Returns the parameter widget definition for the given parameter name.<p>
*
* @param name the parameter name to get the definition for
*
* @return the parameter widget definition for the given parameter name
*/
protected CmsWidgetDialogParameter getParameterDefinition(String name) {
Iterator i = getWidgets().iterator();
while (i.hasNext()) {
// check for all widget parameters
CmsWidgetDialogParameter base = (CmsWidgetDialogParameter)i.next();
if (base.getName().equals(name)) {
return base;
}
}
return null;
}
/**
* Returns the map with the widget parameter values.<p>
*
* @return the map with the widget parameter values
*/
protected Map getParameters() {
return m_widgetParamValues;
}
/**
* Returns the validation errors for the dialog.<p>
*
* The method (@link CmsWidgetDialog#commitWidgetValues(String)) has to set this list.<p>
*
* @return the validation errors for the dialog
*/
protected List getValidationErrorList() {
return m_validationErrorList;
}
/**
* Returns the widget HTML code for the given parameter.<p>
*
* @param param the name (id) of the parameter to get the widget HTML for
*
* @return the widget HTML code for the given parameter
*/
protected String getWidget(CmsWidgetDialogParameter param) {
if (param != null) {
return param.getWidget().getDialogWidget(getCms(), this, param);
}
return null;
}
/**
* Returns the list of all widgets used on this widget dialog, the
* List must contain Objects of type <code>{@link CmsWidgetDialogParameter}</code>.<p>
*
* @return the list of all widgets used on this widget dialog
*/
protected List getWidgets() {
if (m_widgets == null) {
m_widgets = new ArrayList();
}
return m_widgets;
}
/**
* Returns <code>true</code> if the current dialog (page) has commit errors.<p>
*
* @return <code>true</code> if the current dialog (page) has commit errors
*/
protected boolean hasCommitErrors() {
return (m_commitErrors != null) && (m_commitErrors.size() > 0);
}
/**
* Returns <code>true</code> if the current dialog (page) has validation errors.<p>
*
* @return <code>true</code> if the current dialog (page) has validation errors
*/
protected boolean hasValidationErrors() {
return (m_validationErrorList != null) && (m_validationErrorList.size() > 0);
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// set the dialog type
setParamDialogtype(getClass().getName());
// fill the parameter values in the get/set methods
fillParamValues(request);
if (CmsStringUtil.isEmptyOrWhitespaceOnly(getParamPage()) || !getPages().contains(getParamPage())) {
// ensure a valid page is set
setParamPage((String)getPages().get(0));
}
// test the needed parameters
try {
validateParamaters();
} catch (Exception e) {
// close if parameters not available
setAction(ACTION_CANCEL);
try {
actionCloseDialog();
} catch (JspException e1) {
// noop
}
return;
}
// fill the widget map
defineWidgets();
fillWidgetValues(request);
// set the action for the JSP switch
if (DIALOG_SAVE.equals(getParamAction())) {
// ok button pressed, save
List errors = commitWidgetValues();
if (errors.size() > 0) {
setAction(ACTION_DEFAULT);
// found validation errors, redisplay page
return;
}
setAction(ACTION_SAVE);
} else if (DIALOG_OK.equals(getParamAction())) {
// ok button pressed
setAction(ACTION_CANCEL);
} else if (DIALOG_CANCEL.equals(getParamAction())) {
// cancel button pressed
setAction(ACTION_CANCEL);
} else if (EDITOR_ACTION_ELEMENT_ADD.equals(getParamAction())) {
// add optional input element
setAction(ACTION_ELEMENT_ADD);
actionToggleElement();
setAction(ACTION_DEFAULT);
} else if (EDITOR_ACTION_ELEMENT_REMOVE.equals(getParamAction())) {
// remove optional input element
setAction(ACTION_ELEMENT_REMOVE);
actionToggleElement();
setAction(ACTION_DEFAULT);
} else if (DIALOG_BACK.equals(getParamAction())) {
// go back one page
setAction(ACTION_DEFAULT);
List errors = commitWidgetValues(getParamPage());
if (errors.size() > 0) {
// found validation errors, redisplay page
return;
}
int pageIndex = getPages().indexOf(getParamPage()) - 1;
setParamPage((String)getPages().get(pageIndex));
} else if (DIALOG_CONTINUE.equals(getParamAction())) {
// go to next page
setAction(ACTION_DEFAULT);
List errors = commitWidgetValues(getParamPage());
if (errors.size() > 0) {
// found validation errors, redisplay page
return;
}
int pageIndex = getPages().indexOf(getParamPage()) + 1;
setParamPage((String)getPages().get(pageIndex));
} else {
// first dialog call, set the default action
setAction(ACTION_DEFAULT);
}
}
/**
* Sets the errors that are thrown by save actions or form generation.<p>
*
* @param errors the errors that are thrown by save actions or form generation
*/
protected void setCommitErrors(List errors) {
m_commitErrors = errors;
}
/**
* Sets an optional localized key prefix identificator for all widgets.<p>
*
* @param prefix the optional localized key prefix identificator for all widgets
*
* @see org.opencms.widgets.I_CmsWidgetParameter#setKeyPrefix(java.lang.String)
*/
protected void setKeyPrefix(String prefix) {
m_prefix = prefix;
}
/**
* Sets the allowed pages for this dialog.<p>
*
* @param pages the allowed pages for this dialog
*/
protected void setPages(List pages) {
m_pages = pages;
}
/**
* Sets the validation errors for the dialog.<p>
*
* Use this in the method (@link CmsWidgetDialog#commitWidgetValues(String)) to set the list.<p>
*
* @param errors the validation errors
*/
protected void setValidationErrorList(List errors) {
m_validationErrorList = errors;
}
/**
* Should be overriden for parameter validation.<p>
*
* The exception is never seen by the user, so it can be just a <code>new Exception()</code>.<p>
*
* @throws Exception if the parameters are not valid
*/
protected void validateParamaters() throws Exception {
// valid by default
}
/**
* Returns the (internal use only) map of dialog objects.<p>
*
* @return the (internal use only) map of dialog objects
*/
private Map getDialogObjectMap() {
Map objects = (Map)getSettings().getDialogObject();
if (objects == null) {
// using hashtable as most efficient version of a synchronized map
objects = new Hashtable();
getSettings().setDialogObject(objects);
}
return objects;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -