📄 cmswidgetdialog.java
字号:
case ACTION_DEFAULT:
default:
// ACTION: show dialog (default)
if (!writeLater) {
writeDialog();
}
}
}
/**
* @see org.opencms.widgets.I_CmsWidgetDialog#getButtonStyle()
*/
public int getButtonStyle() {
return getSettings().getUserSettings().getEditorButtonStyle();
}
/**
* Returns the errors that are thrown by save actions or form generation.<p>
*
* @return the errors that are thrown by save actions or form generation
*/
public List getCommitErrors() {
return m_commitErrors;
}
/**
* Returns the dialog object for this widget dialog, or <code>null</code>
* if no dialog object has been set.<p>
*
* @return the dialog object for this widget dialog, or <code>null</code>
*/
public Object getDialogObject() {
if (m_dialogObject == null) {
m_dialogObject = getDialogObjectMap().get(getClass().getName());
}
return m_dialogObject;
}
/**
* @see org.opencms.widgets.I_CmsWidgetDialog#getHelpMessageIds()
*/
public Set getHelpMessageIds() {
if (m_helpMessageIds == null) {
m_helpMessageIds = new HashSet();
}
return m_helpMessageIds;
}
/**
* Returns the index of the element to add or remove.<p>
*
* @return the index of the element to add or remove
*/
public String getParamElementIndex() {
return m_paramElementIndex;
}
/**
* Returns the name of the element to add or remove.<p>
*
* @return the name of the element to add or remove
*/
public String getParamElementName() {
return m_paramElementName;
}
/**
* Returns the page parameter.<p>
*
* @return the page parameter
*/
public String getParamPage() {
return m_paramPage;
}
/**
* Returns the value of the widget parameter with the given name, or <code>null</code>
* if no such widget parameter is available.<p>
*
* @param name the widget parameter name to get the value for
*
* @return the value of the widget parameter with the given name
*/
public String getParamValue(String name) {
return getParamValue(name, 0);
}
/**
* Returns the value of the widget parameter with the given name and index, or <code>null</code>
* if no such widget parameter is available.<p>
*
* @param name the widget parameter name to get the value for
* @param index the widget parameter index
*
* @return the value of the widget parameter with the given name and index
*/
public String getParamValue(String name, int index) {
List params = (List)m_widgetParamValues.get(name);
if (params != null) {
if ((index >= 0) && (index < params.size())) {
CmsWidgetDialogParameter param = (CmsWidgetDialogParameter)params.get(index);
if (param.getId().equals(CmsWidgetDialogParameter.createId(name, index))) {
return param.getStringValue(getCms());
}
}
}
return null;
}
/**
* @see org.opencms.widgets.I_CmsWidgetDialog#getUserAgent()
*/
public String getUserAgent() {
return getJsp().getRequest().getHeader(CmsRequestUtil.HEADER_USER_AGENT);
}
/**
* Generates the HTML for the end of the widget dialog.<p>
*
* This HTML includes additional components, for example the <div>
* tags containing the help texts.<p>
*
* @return the HTML for the end of the widget dialog
*/
public String getWidgetHtmlEnd() {
StringBuffer result = new StringBuffer(32);
// iterate over unique widgets from collector
Iterator i = getWidgets().iterator();
while (i.hasNext()) {
CmsWidgetDialogParameter param = (CmsWidgetDialogParameter)i.next();
result.append(param.getWidget().getDialogHtmlEnd(getCms(), this, param));
}
return result.toString();
}
/**
* Generates the HTML include tags for external JavaScripts files of the used widgets.<p>
*
* @return the HTML include tags for external JavaScripts files of the used widgets
*
* @throws JspException if an error occurs during JavaScript generation
*/
public String getWidgetIncludes() throws JspException {
StringBuffer result = new StringBuffer(32);
try {
// iterate over unique widgets from collector
Iterator i = getWidgets().iterator();
Set set = new HashSet();
while (i.hasNext()) {
I_CmsWidget widget = ((CmsWidgetDialogParameter)i.next()).getWidget();
if (!set.contains(widget)) {
result.append(widget.getDialogIncludes(getCms(), this));
result.append('\n');
set.add(widget);
}
}
} catch (Throwable e) {
includeErrorpage(this, e);
}
return result.toString();
}
/**
* Generates the JavaScript init calls for the used widgets.<p>
*
* @return the JavaScript init calls for the used widgets
*
* @throws JspException the JavaScript init calls for the used widgets
*/
public String getWidgetInitCalls() throws JspException {
StringBuffer result = new StringBuffer(32);
try {
// iterate over unique widgets from collector
Iterator i = getWidgets().iterator();
Set set = new HashSet();
while (i.hasNext()) {
I_CmsWidget widget = ((CmsWidgetDialogParameter)i.next()).getWidget();
if (!set.contains(widget)) {
result.append(widget.getDialogInitCall(getCms(), this));
set.add(widget);
}
}
} catch (Throwable e) {
includeErrorpage(this, e);
}
return result.toString();
}
/**
* Generates the JavaScript initialization methods for the used widgets.<p>
*
* @return the JavaScript initialization methods for the used widgets
*
* @throws JspException if an error occurs during JavaScript generation
*/
public String getWidgetInitMethods() throws JspException {
StringBuffer result = new StringBuffer(32);
try {
// iterate over unique widgets from collector
Iterator i = getWidgets().iterator();
Set set = new HashSet();
while (i.hasNext()) {
I_CmsWidget widget = ((CmsWidgetDialogParameter)i.next()).getWidget();
if (!set.contains(widget)) {
result.append(widget.getDialogInitMethod(getCms(), this));
set.add(widget);
}
}
} catch (Throwable e) {
includeErrorpage(this, e);
}
return result.toString();
}
/**
* @see org.opencms.workplace.CmsWorkplace#paramsAsHidden()
*/
public String paramsAsHidden() {
if (getAction() != ACTION_ERROR) {
return super.paramsAsHidden();
}
// on an error page, also output the widget parameters
StringBuffer result = new StringBuffer();
result.append(super.paramsAsHidden());
result.append('\n');
result.append(widgetParamsAsHidden());
return result.toString();
}
/**
* Stores the given object as "dialog object" for this widget dialog in the current users session.<p>
*
* @param dialogObject the object to store
*/
public void setDialogObject(Object dialogObject) {
m_dialogObject = dialogObject;
if (dialogObject == null) {
// null object: remove the entry from the map
getDialogObjectMap().remove(getClass().getName());
} else {
getDialogObjectMap().put(getClass().getName(), dialogObject);
}
}
/**
* Sets the index of the element to add or remove.<p>
*
* @param elementIndex the index of the element to add or remove
*/
public void setParamElementIndex(String elementIndex) {
m_paramElementIndex = elementIndex;
}
/**
* Sets the name of the element to add or remove.<p>
*
* @param elementName the name of the element to add or remove
*/
public void setParamElementName(String elementName) {
m_paramElementName = elementName;
}
/**
* Sets the page parameter.<p>
*
* @param paramPage the page parameter to set
*/
public void setParamPage(String paramPage) {
m_paramPage = paramPage;
}
/**
* Returns the values of all widget parameters of this dialog as HTML hidden fields.<p>
*
* @return the values of all widget parameters of this dialog as HTML hidden fields
*
* @see org.opencms.workplace.CmsWorkplace#paramsAsHidden()
*/
public String widgetParamsAsHidden() {
return widgetParamsAsHidden(null);
}
/**
* Returns the values of all widget parameters of this dialog as HTML hidden fields,
* excluding the widget values that are on the given dialog page.<p>
*
* This can be used to create multi-page dialogs where the values are passed from
* one page to another before everyting is submitted. If a widget A is used on page X,
* there should be no "hidden" HTML field for A since otherwise A would have 2 values when
* submitting the dialog page: The one from the widget itself and the one from the hidden
* field. This may lead to undefined results when processing the submitted values.<p>
*
* @param excludeDialogPage the dialog page to exclude the values for
*
* @return the values of all widget parameters of this dialog as HTML hidden fields,
* excluding the widget values that are on the given dialog page
*
* @see org.opencms.workplace.CmsWorkplace#paramsAsHidden()
*/
public String widgetParamsAsHidden(String excludeDialogPage) {
StringBuffer result = new StringBuffer();
Iterator i = m_widgetParamValues.keySet().iterator();
while (i.hasNext()) {
List params = (List)m_widgetParamValues.get(i.next());
Iterator j = params.iterator();
while (j.hasNext()) {
CmsWidgetDialogParameter param = (CmsWidgetDialogParameter)j.next();
String value = param.getStringValue(getCms());
if (CmsStringUtil.isNotEmpty(value)
&& ((excludeDialogPage == null) || (!param.getDialogPage().equals(excludeDialogPage)))) {
result.append("<input type=\"hidden\" name=\"");
result.append(HIDDEN_PARAM_PREFIX);
result.append(param.getId());
result.append("\" value=\"");
String encoded = CmsEncoder.encode(value, getCms().getRequestContext().getEncoding());
result.append(encoded);
result.append("\">\n");
}
}
}
return result.toString();
}
/**
* Writes the dialog html code, only if the <code>{@link #ACTION_DEFAULT}</code> is set.<p>
*
* @throws JspException if dialog actions fail
* @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
*/
public void writeDialog() throws IOException, JspException {
if (isForwarded()) {
return;
}
switch (getAction()) {
case ACTION_CANCEL:
case ACTION_ERROR:
case ACTION_SAVE:
break;
case ACTION_DEFAULT:
default:
// ACTION: show dialog (default)
setParamAction(DIALOG_SAVE);
JspWriter out = getJsp().getJspContext().getOut();
out.print(defaultActionHtml());
}
}
/**
* Adds the given error to the list of errors that are thrown by save actions or form generation.<p>
*
* If the error list has not been initilaized yet, this is done automatically.<p>
*
* @param error the errors to add
*/
protected void addCommitError(Exception error) {
if (m_commitErrors == null) {
m_commitErrors = new ArrayList();
}
m_commitErrors.add(error);
}
/**
* Adds a new widget parameter definition to the list of all widgets of this dialog.<p>
*
* @param param the widget parameter definition to add
*/
protected void addWidget(CmsWidgetDialogParameter param) {
if (m_widgets == null) {
m_widgets = new ArrayList();
}
param.setKeyPrefix(m_prefix);
m_widgets.add(param);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -