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