1 23 24 package org.apache.slide.search; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import org.apache.slide.common.Namespace; 30 import org.apache.slide.common.NamespaceConfig; 31 import org.apache.slide.common.ServiceAccessException; 32 import org.apache.slide.common.SlideToken; 33 import org.apache.slide.content.Content; 34 import org.apache.slide.search.basic.BasicSearchLanguage; 35 import org.apache.slide.structure.Structure; 36 import org.apache.slide.event.VetoException; 37 import org.apache.slide.event.EventDispatcher; 38 import org.apache.slide.event.SearchEvent; 39 import org.jdom.Element; 40 41 46 public final class SearchImpl implements Search { 47 48 50 51 57 public SearchImpl(Namespace namespace, 58 NamespaceConfig namespaceConfig, 59 Structure structureHelper, 60 Content contentHelper) { 61 this.namespace = namespace; 62 this.namespaceConfig = namespaceConfig; 63 this.structureHelper = structureHelper; 64 this.contentHelper = contentHelper; 65 } 66 67 68 70 private static final SearchLanguage [] SEARCH_LANGUAGES = { 72 new BasicSearchLanguage () 73 }; 74 75 76 private static final Map GRAMMAR_BY_URI = new HashMap (); 77 static { 78 for (int i = 0; i < SEARCH_LANGUAGES.length; i++) 79 GRAMMAR_BY_URI.put (SEARCH_LANGUAGES [i].getGrammarUri(), 80 SEARCH_LANGUAGES [i]); 81 } 82 83 86 private final static String LOG_CHANNEL = SearchImpl.class.getName(); 87 88 89 92 private Namespace namespace; 93 94 97 private Structure structureHelper; 98 99 100 103 private NamespaceConfig namespaceConfig; 104 105 108 private Content contentHelper; 109 110 111 113 114 121 public SearchQueryResult search (SlideToken token, SearchQuery query) 122 throws ServiceAccessException, VetoException { 123 124 if ( SearchEvent.SEARCH.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(SearchEvent.SEARCH, new SearchEvent(this, token, namespace, query)); 126 127 return query.execute (); 128 } 129 130 131 134 public SearchLanguage[] getSupportedLanguages () { 135 return SEARCH_LANGUAGES; 136 } 137 138 139 149 public SearchLanguage getLanguage (String grammarUri) 150 throws BadQueryException 151 { 152 SearchLanguage result =(SearchLanguage) GRAMMAR_BY_URI.get (grammarUri); 153 if (result == null) 154 throw new BadQueryException ("grammar not found: " + grammarUri); 155 156 return result; 157 } 158 159 160 161 162 175 public SearchQuery createSearchQuery (String grammarUri, 176 Element queryElement, 177 SlideToken token, 178 int maxDepth) 179 throws BadQueryException 180 { 181 return createSearchQuery (grammarUri, queryElement, token, maxDepth, (PropertyProvider)null); 182 } 183 184 198 public SearchQuery createSearchQuery (String grammarUri, 199 Element searchRequestElement, 200 SlideToken token, 201 int maxDepth, 202 PropertyProvider propertyProvider) 203 throws BadQueryException 204 { 205 return createSearchQuery (grammarUri, searchRequestElement, token, maxDepth, propertyProvider, null); 206 } 207 208 221 public SearchQuery createSearchQuery (String grammarUri, 222 Element queryElement, 223 SlideToken token, 224 int maxDepth, 225 String requestUri) 226 throws BadQueryException 227 { 228 return createSearchQuery (grammarUri, queryElement, token, maxDepth, null, requestUri); 229 } 230 231 246 public SearchQuery createSearchQuery (String grammarUri, 247 Element searchRequestElement, 248 SlideToken token, 249 int maxDepth, 250 PropertyProvider propertyProvider, 251 String requestUri) 252 throws BadQueryException 253 { 254 SearchQuery result = null; 255 SearchToken searchToken = 257 SearchToken.createSearchToken (token, contentHelper, 258 structureHelper, maxDepth, 259 requestUri, namespace); 260 261 SearchLanguage language = getLanguage (grammarUri); 262 result = language.parseQuery (searchRequestElement, searchToken, propertyProvider); 263 264 return result; 265 } 266 } 267 268 | Popular Tags |