1 31 package org.blojsom.plugin.search; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.blojsom.blog.Blog; 36 import org.blojsom.blog.Entry; 37 import org.blojsom.fetcher.Fetcher; 38 import org.blojsom.fetcher.FetcherException; 39 import org.blojsom.plugin.Plugin; 40 import org.blojsom.plugin.PluginException; 41 42 import javax.servlet.http.HttpServletRequest ; 43 import javax.servlet.http.HttpServletResponse ; 44 import java.util.Map ; 45 46 53 public class SimpleSearchPlugin implements Plugin { 54 55 private Log _logger = LogFactory.getLog(SimpleSearchPlugin.class); 56 57 60 protected static final String QUERY_PARAM = "query"; 61 62 private Fetcher _fetcher; 63 64 67 public SimpleSearchPlugin() { 68 } 69 70 75 public void setFetcher(Fetcher fetcher) { 76 _fetcher = fetcher; 77 } 78 79 84 public void init() throws PluginException { 85 } 86 87 98 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 99 String query = httpServletRequest.getParameter(QUERY_PARAM); 100 if (query == null) { 101 return entries; 102 } else { 103 query = query.toLowerCase(); 104 } 105 106 try { 107 return _fetcher.findEntries(blog, query); 108 } catch (FetcherException e) { 109 if (_logger.isErrorEnabled()) { 110 _logger.error(e); 111 } 112 113 return entries; 114 } 115 } 116 117 122 public void cleanup() throws PluginException { 123 } 124 125 130 public void destroy() throws PluginException { 131 } 132 } 133 | Popular Tags |