⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmssearchwidgetdialog.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsSearchWidgetDialog.java,v $
 * Date   : $Date: 2006/03/28 19:15:20 $
 * Version: $Revision: 1.3 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 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.file.CmsRequestContext;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.search.CmsSearch;
import org.opencms.search.CmsSearchParameters;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.CmsCheckboxWidget;
import org.opencms.widgets.CmsDisplayWidget;
import org.opencms.widgets.CmsInputWidget;
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.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.3 $
 * 
 * @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_ADD}</code>) or removed 
     * 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();
    }

    /**
     * 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])) {

            // first block "Query for index...."
            result.append(dialogBlockStart(key(Messages.GUI_LABEL_SEARCHINDEX_BLOCK_SEARCH_QUERY_0)));
            result.append(createWidgetTableStart());
            result.append(createDialogRowsHtml(0, 5));
            result.append(createWidgetTableEnd());
            result.append(dialogBlockEnd());

            // 2nd block "Fields to search in"
            result.append(dialogBlockStart(key(Messages.GUI_LABEL_SEARCHINDEX_BLOCK_SEARCH_FIELDS_0)));
            result.append(createWidgetTableStart());
            result.append(createDialogRowsHtml(6, 10));
            result.append(createWidgetTableEnd());
            result.append(dialogBlockEnd());
        }

        result.append(createWidgetTableEnd());

        return result.toString();
    }

    /**
     * Returns the html code for the default action content.<p>
     * 
     * Overrides <code> {@link org.opencms.workplace.CmsWidgetDialog#defaultActionHtml()}</code> 
     * in order to put additional forms for page links and search results after OK - CANCEL buttons 
     * and outside the main form.<p>
     * 
     * @return html code
     */
    protected String defaultActionHtmlContent() {

        StringBuffer result = new StringBuffer(2048);
        result.append("<form name=\"EDITOR\" id=\"EDITOR\" method=\"post\" action=\"").append(getDialogUri());
        result.append("\" class=\"nomargin\" onsubmit=\"return submitAction('").append(DIALOG_OK).append(
            "', null, 'EDITOR');\">\n");
        result.append(dialogContentStart(null));
        result.append(buildDialogForm());
        result.append(dialogContentEnd());
        result.append(dialogButtonsCustom());
        result.append(paramsAsHidden());
        if (getParamFramename() == null) {
            result.append("\n<input type=\"hidden\" name=\"").append(PARAM_FRAMENAME).append("\" value=\"\">\n");
        }

        // add script for filtering categories 
        result.append(filterCategoryJS());
        result.append("</form>\n");

        // get search results if query was more than nothing
        // we have to retrieve them before category search results are available because 
        // those are collected as a side effect of search iteration.
        String searchResults = createSearchResults();

        // append category search results if there... 
        result.append(createCategorySearchResultHtml());
        result.append(searchResults);

        result.append(getWidgetHtmlEnd());
        // Normalize the previous encoded query value on client side 
        result.append(normalizePreviousQueryJS());

        return result.toString();
    }

    /**
     * 
     * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
     */
    protected void defineWidgets() {

        // initialization -> initUserObject

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -