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

📄 cmshelpsearchresultview.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/help/CmsHelpSearchResultView.java,v $
 * Date   : $Date: 2006/03/27 14:53:04 $
 * Version: $Revision: 1.6 $
 *
 * 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.help;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.search.CmsSearch;
import org.opencms.search.CmsSearchResult;
import org.opencms.util.CmsStringUtil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

/**
 * Displays the result of a <code>{@link org.opencms.search.CmsSearch}</code>.<p>
 * 
 * Requires the following request parameters (see constructor): 
 * <ul>
 *  <li>
 *  index:<br>the String identifying the required search index. 
 *  <li>
 *  query:<br>the search query to run.
 * </ul>
 * <p>
 * 
 * @author Achim Westermann
 * 
 * @version $Revision: 1.6 $
 * 
 * @since 6.0.0
 */
public class CmsHelpSearchResultView {

    /** The project that forces evaluation of all dynamic content. */
    protected CmsProject m_offlineProject;

    /** The project that allows static export. */
    protected CmsProject m_onlineProject;

    /** The flag that decides wethter links to search result point to their exported version or not. */
    private boolean m_exportLinks = false;

    /**
     * A small cache for the forms generated by <code>{@link #toPostParameters(String)}</code> during a request. <p>
     * 
     * Avoids duplicate forms.</p>  
     * 
     */
    private SortedMap m_formCache;

    /** The CmsJspActionElement to use. **/
    private CmsJspActionElement m_jsp;

    /** The url to a proprietary search url (different from m_jsp.getRequestContext().getUri). **/
    private String m_searchRessourceUrl;

    /**
     * Constructor with the action element to use. <p>
     * 
     * @param action the action element to use
     */
    public CmsHelpSearchResultView(CmsJspActionElement action) {

        m_jsp = action;
        this.m_formCache = new TreeMap();
        try {
            m_onlineProject = m_jsp.getCmsObject().readProject(CmsProject.ONLINE_PROJECT_ID);
            m_offlineProject = m_jsp.getRequestContext().currentProject();
        } catch (CmsException e) {
            // failed to get online project, at least avoid NPE
            m_onlineProject = m_offlineProject;
        }

    }

    /**
     * Constructor with arguments for construction of a <code>{@link CmsJspActionElement}</code>. <p>
     * 
     * @param pageContext the page context to use 
     * @param request the current request
     * @param response the current response
     */
    public CmsHelpSearchResultView(PageContext pageContext, HttpServletRequest request, HttpServletResponse response) {

        this(new CmsJspActionElement(pageContext, request, response));

    }

    /**
     * Returns the formatted search results.<p>
     * 
     * @param search the preconfigured search bean 
     * @return the formatted search results
     */
    public String displaySearchResult(CmsSearch search) {

        initSearch(search);
        StringBuffer result = new StringBuffer(800);
        CmsMessages messages = org.opencms.search.Messages.get().getBundle(m_jsp.getRequestContext().getLocale());

        result.append("<h1>\n");
        result.append(messages.key(org.opencms.search.Messages.GUI_HELP_SEARCH_RESULT_TITLE_0));
        result.append("\n</h1>\n");
        List searchResult;
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(search.getQuery())) {
            search.setQuery("");
            searchResult = new ArrayList();
        } else {
            searchResult = search.getSearchResult();
        }

        HttpServletRequest request = m_jsp.getRequest();
        // get the action to perform from the request
        String action = request.getParameter("action");

        if (action != null && searchResult == null) {
            result.append("<p class=\"formerror\">\n");
            if (search.getLastException() != null) {

                result.append(messages.key(org.opencms.search.Messages.GUI_HELP_SEARCH_UNAVAILABLE_0));
                result.append("\n<!-- ").append(search.getLastException().toString());
                result.append(" //-->\n");
            } else {
                result.append(messages.key(org.opencms.search.Messages.GUI_HELP_SEARCH_NOMATCH_1, search.getQuery()));
                result.append("\n");
            }
            result.append("</p>\n");
        } else if (action != null && searchResult.size() <= 0) {
            result.append("<p class=\"formerror\">\n");
            result.append(messages.key(org.opencms.search.Messages.GUI_HELP_SEARCH_NOMATCH_1, search.getQuery()));
            result.append("\n");
            result.append("</p>\n");
        } else if (action != null && searchResult.size() > 0) {
            result.append("<p>\n");
            result.append(messages.key(org.opencms.search.Messages.GUI_HELP_SEARCH_RESULT_START_0));
            result.append("\n");
            result.append("</p>\n<p>\n");

            Iterator iterator = searchResult.iterator();

            try {
                if (m_exportLinks) {
                    m_jsp.getRequestContext().setCurrentProject(m_onlineProject);
                }

                while (iterator.hasNext()) {
                    CmsSearchResult entry = (CmsSearchResult)iterator.next();
                    result.append("\n<div class=\"searchResult\"><a class=\"navhelp\" href=\"");

                    result.append(m_jsp.link(new StringBuffer(
                        "/system/modules/org.opencms.workplace.help/jsptemplates/help_body.jsp?helpresource=").append(
                        m_jsp.getRequestContext().removeSiteRoot(entry.getPath())).append("&").append(
                        CmsLocaleManager.PARAMETER_LOCALE).append("=").append(m_jsp.getRequestContext().getLocale()).toString()));
                    result.append("\">\n");
                    result.append(entry.getTitle());
                    result.append("</a>");
                    result.append("&nbsp;(").append(entry.getScore()).append("&nbsp;%)\n");

⌨️ 快捷键说明

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