001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.webapp.search; 018 019import java.io.Serializable; 020import java.util.List; 021import java.util.Map; 022 023import javax.faces.application.FacesMessage; 024import javax.faces.component.UIComponent; 025import javax.faces.context.FacesContext; 026import javax.faces.validator.ValidatorException; 027 028import org.apache.commons.lang.StringUtils; 029import org.jboss.seam.ScopeType; 030import org.jboss.seam.annotations.Name; 031import org.jboss.seam.annotations.Observer; 032import org.jboss.seam.annotations.Scope; 033import org.jboss.seam.annotations.intercept.BypassInterceptors; 034import org.nuxeo.ecm.core.api.SortInfo; 035import org.nuxeo.ecm.platform.ui.web.util.ComponentUtils; 036import org.nuxeo.ecm.webapp.helpers.EventNames; 037 038/** 039 * Handles search parameters needed for simple and advanced and administrator searches. 040 * <p> 041 * Search parameters are referenced in the content views used on search form and result pages. 042 * 043 * @author Anahide Tchertchian 044 * @since 5.4 045 * @deprecated since 6.0. Not used anymore, see NXP-14992. 046 */ 047@Deprecated 048@Name("documentSearchActions") 049@Scope(ScopeType.CONVERSATION) 050public class DocumentSearchActions implements Serializable { 051 052 private static final long serialVersionUID = 1L; 053 054 /** 055 * Query parameter string used to perform full text search on all documents 056 */ 057 protected String simpleSearchKeywords = ""; 058 059 protected String nxqlQuery = ""; 060 061 protected List<String> selectedLayoutColumns; 062 063 protected List<SortInfo> searchSortInfos; 064 065 public String getSimpleSearchKeywords() { 066 return simpleSearchKeywords; 067 } 068 069 public void setSimpleSearchKeywords(String simpleSearchKeywords) { 070 this.simpleSearchKeywords = simpleSearchKeywords; 071 } 072 073 public void validateSimpleSearchKeywords(FacesContext context, UIComponent component, Object value) { 074 if (!(value instanceof String) || StringUtils.isEmpty(((String) value).trim())) { 075 FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ComponentUtils.translate(context, 076 "feedback.search.noKeywords"), null); 077 // also add global message 078 context.addMessage(null, message); 079 throw new ValidatorException(message); 080 } 081 String[] keywords = ((String) value).trim().split(" "); 082 for (String keyword : keywords) { 083 if (keyword.startsWith("*")) { 084 // Can't begin search with * character 085 FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ComponentUtils.translate(context, 086 "feedback.search.star"), null); 087 // also add global message 088 context.addMessage(null, message); 089 throw new ValidatorException(message); 090 } 091 } 092 } 093 094 public String getNxqlQuery() { 095 return nxqlQuery; 096 } 097 098 public void setNxqlQuery(String nxqlQuery) { 099 this.nxqlQuery = nxqlQuery; 100 } 101 102 public List<String> getSelectedLayoutColumns() { 103 return selectedLayoutColumns; 104 } 105 106 public void setSelectedLayoutColumns(List<String> selectedLayoutColumns) { 107 this.selectedLayoutColumns = selectedLayoutColumns; 108 } 109 110 public void resetSelectedLayoutColumns() { 111 setSelectedLayoutColumns(null); 112 } 113 114 public List<SortInfo> getSearchSortInfos() { 115 return searchSortInfos; 116 } 117 118 public void setSearchSortInfos(List<SortInfo> searchSortInfos) { 119 this.searchSortInfos = searchSortInfos; 120 } 121 122 public SortInfo getNewSortInfo() { 123 return new SortInfo("", true); 124 } 125 126 public Map<String, Serializable> getNewSortInfoMap() { 127 SortInfo sortInfo = getNewSortInfo(); 128 return SortInfo.asMap(sortInfo); 129 } 130 131 @BypassInterceptors 132 public void resetSearches() { 133 simpleSearchKeywords = ""; 134 nxqlQuery = ""; 135 } 136 137 /** 138 * Resets cached selected columns/sort infos on hot reload when dev mode is set. 139 * 140 * @since 5.9.4 141 */ 142 @Observer(value = { EventNames.FLUSH_EVENT }, create = false) 143 @BypassInterceptors 144 public void onHotReloadFlush() { 145 selectedLayoutColumns = null; 146 searchSortInfos = null; 147 } 148 149}