cmssearchwidgetdialog.java
来自「找了很久才找到到源代码」· Java 代码 · 共 704 行 · 第 1/2 页
JAVA
704 行
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsSearchWidgetDialog.java,v $
* Date : $Date: 2007-08-23 15:45:38 $
* Version: $Revision: 1.10 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.workplace.tools.searchindex;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsIllegalStateException;
import org.opencms.main.OpenCms;
import org.opencms.search.CmsSearch;
import org.opencms.search.CmsSearchIndex;
import org.opencms.search.CmsSearchParameters;
import org.opencms.search.fields.CmsSearchField;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.CmsCalendarWidget;
import org.opencms.widgets.CmsCheckboxWidget;
import org.opencms.widgets.CmsDisplayWidget;
import org.opencms.widgets.CmsInputWidget;
import org.opencms.widgets.CmsMultiSelectWidget;
import org.opencms.widgets.CmsSelectWidget;
import org.opencms.widgets.CmsSelectWidgetOption;
import org.opencms.widgets.CmsVfsFileWidget;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWidgetDialogParameter;
import org.opencms.workplace.CmsWorkplaceSettings;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
/**
* A <code>{@link org.opencms.workplace.CmsWidgetDialog}</code> that performs a
* search on the <code>{@link org.opencms.search.CmsSearchIndex}</code> identified
* by request parameter
* <code>{@link org.opencms.workplace.tools.searchindex.A_CmsEditSearchIndexDialog#PARAM_INDEXNAME}</code>
* using an instance of <code>{@link org.opencms.search.CmsSearchParameters}</code>
* as widget object to fill.
* <p>
*
* @author Achim Westermann
*
* @version $Revision: 1.10 $
*
* @since 6.0.0
*/
public class CmsSearchWidgetDialog extends A_CmsEditSearchIndexDialog {
/** The request parameter for the search object. **/
public static final String PARAM_SEARCH_OBJECT = "searchobject";
/** The request parameter for the search parameters. **/
public static final String PARAM_SEARCH_PARAMS = "searchparams";
/** The search instance used with the search parameters. **/
protected CmsSearch m_search;
/** The search parameter instance used for storing widget values and performing search. */
protected CmsSearchParameters m_searchParams;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsSearchWidgetDialog(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsSearchWidgetDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Overrides this action that is performed in case an element
* has been added to a widget parameter
* (<code>{@link org.opencms.workplace.CmsWidgetDialog#ACTION_ELEMENT_ADD}</code>)
* or removed
* (<code>{@link org.opencms.workplace.CmsWidgetDialog#ACTION_ELEMENT_REMOVE}</code>)
* from a widget parameter to additionally commit these values to the
* underlying lists.<p>
*
* This is necessary because this dialog performs a search for every request
* (not only if OK is pressed, also if a category or field is added/removed).
* The search directly uses the underlying Lists of categories, fields,... .
* More precise: The very same lists that are in the search parameter instance used
* for search are contained as base collections of the widget parameters.
* Therefore before every search the changes of categories, fields,... have to
* be committed here.<p>
*
* @see org.opencms.workplace.CmsWidgetDialog#actionToggleElement()
*/
public void actionToggleElement() {
super.actionToggleElement();
commitWidgetValues();
}
/**
* Builds the standard javascript for submitting the dialog.<p>
*
* Overridden to allow additional validation and encoding of the
* search query. <p>
*
* @return the standard javascript for submitting the dialog
*/
public String dialogScriptSubmit() {
StringBuffer html = new StringBuffer(512);
html.append(submitJS());
html.append("function submitAction(actionValue, theForm, formName) {\n");
html.append("\tif (theForm == null) {\n");
html.append("\t\ttheForm = document.forms[formName];\n");
html.append("\t}\n");
html.append("\tvar queryOK = validateQuery();\n");
html.append("\ttheForm." + CmsDialog.PARAM_FRAMENAME + ".value = window.name;\n");
html.append("\tif (queryOK) {\n");
html.append("\t\tif (actionValue == '" + CmsDialog.DIALOG_OK + "') {\n");
// html.append("\t\t\talert('action :'+actionValue);\n");
html.append("\t\t\tloadingOn();\n");
html.append("\t\t\treturn queryOK;\n");
html.append("\t\t}\n");
html.append("\t\ttheForm." + CmsDialog.PARAM_ACTION + ".value = actionValue;\n");
html.append("\t\tsubmitForm(theForm);\n");
html.append("\t}\n");
html.append("\treturn queryOK;\n");
html.append("}\n");
return html.toString();
}
/**
* Returns the fields parameter value.<p>
*
* @return the fields parameter value
*/
public String getFields() {
return CmsStringUtil.collectionAsString(m_searchParams.getFields(), ",");
}
/**
* Returns the creation date the resources have to have as maximum.<p>
*
* @return the creation date the resources have to have as maximum
*/
public String getMaxDateCreated() {
if (m_searchParams.getMaxDateCreated() == Long.MAX_VALUE) {
return "";
}
return Long.toString(m_searchParams.getMaxDateCreated());
}
/**
* Returns the last modification date the resources have to have as maximum.<p>
*
* @return the last modification date the resources have to have as maximum
*/
public String getMaxDateLastModified() {
if (m_searchParams.getMaxDateLastModified() == Long.MAX_VALUE) {
return "";
}
return Long.toString(m_searchParams.getMaxDateLastModified());
}
/**
* Returns the creation date the resources have to have as minimum.<p>
*
* @return the creation date the resources have to have as minimum
*/
public String getMinDateCreated() {
if (m_searchParams.getMinDateCreated() == Long.MIN_VALUE) {
return "";
}
return Long.toString(m_searchParams.getMinDateCreated());
}
/**
* Returns the last modification date the resources have to have as minimum.<p>
*
* @return the last modification date the resources have to have as minimum
*/
public String getMinDateLastModified() {
if (m_searchParams.getMinDateLastModified() == Long.MIN_VALUE) {
return "";
}
return Long.toString(m_searchParams.getMinDateLastModified());
}
/**
* Returns the list of searchable fields used in the workplace search index.<p>
*
* @return the list of searchable fields used in the workplace search index
*/
public List getSearchFields() {
CmsSearchIndex index = OpenCms.getSearchManager().getIndex(getParamIndexName());
List result = new ArrayList();
Iterator i = index.getFieldConfiguration().getFields().iterator();
while (i.hasNext()) {
CmsSearchField field = (CmsSearchField)i.next();
if (field.isIndexed() && field.isDisplayed()) {
// only include indexed (ie. searchable) fields
result.add(field);
}
}
return result;
}
/**
* Sets the fields parameter value.<p>
*
* @param fields the fields parameter value to set
*/
public void setFields(String fields) {
if (CmsStringUtil.isEmptyOrWhitespaceOnly(fields)) {
throw new CmsIllegalStateException(org.opencms.workplace.search.Messages.get().container(
org.opencms.workplace.search.Messages.ERR_VALIDATE_SEARCH_PARAMS_0));
}
m_searchParams.setFields(CmsStringUtil.splitAsList(fields, ","));
}
/**
* Sets the creation date the resources have to have as maximum.<p>
*
* @param maxCreationDate the creation date the resources have to have as maximum to set
*/
public void setMaxDateCreated(String maxCreationDate) {
if ((CmsStringUtil.isNotEmptyOrWhitespaceOnly(maxCreationDate)) && (!maxCreationDate.equals("0"))) {
m_searchParams.setMaxDateCreated(Long.parseLong(maxCreationDate));
} else {
m_searchParams.setMaxDateCreated(Long.MAX_VALUE);
}
}
/**
* Sets the last modification date the resources have to have as maximum.<p>
*
* @param maxDateLastModified the last modification date the resources have to have as maximum to set
*/
public void setMaxDateLastModified(String maxDateLastModified) {
if ((CmsStringUtil.isNotEmptyOrWhitespaceOnly(maxDateLastModified)) && (!maxDateLastModified.equals("0"))) {
m_searchParams.setMaxDateLastModified(Long.parseLong(maxDateLastModified));
} else {
m_searchParams.setMaxDateLastModified(Long.MAX_VALUE);
}
}
/**
* Sets the creation date the resources have to have as minimum.<p>
*
* @param minCreationDate the creation date the resources have to have as minimum to set
*/
public void setMinDateCreated(String minCreationDate) {
if ((CmsStringUtil.isNotEmptyOrWhitespaceOnly(minCreationDate)) && (!minCreationDate.equals("0"))) {
m_searchParams.setMinDateCreated(Long.parseLong(minCreationDate));
} else {
m_searchParams.setMinDateCreated(Long.MIN_VALUE);
}
}
/**
* Sets the last modification date the resources have to have as minimum.<p>
*
* @param minDateLastModified the last modification date the resources have to have as minimum to set
*/
public void setMinDateLastModified(String minDateLastModified) {
if ((CmsStringUtil.isNotEmptyOrWhitespaceOnly(minDateLastModified)) && (!minDateLastModified.equals("0"))) {
m_searchParams.setMinDateLastModified(Long.parseLong(minDateLastModified));
} else {
m_searchParams.setMinDateLastModified(Long.MIN_VALUE);
}
}
/**
* This dialog does not return on commit but stay for many search requests until it is
* exited with cancel or up in the workplace. <p>
*
* @return false always to ensure the dialog is not left
*
* @see org.opencms.workplace.CmsWidgetDialog#closeDialogOnCommit()
*/
protected boolean closeDialogOnCommit() {
return false;
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
*/
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])) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?