1 package net.sf.cantina.system; 2 3 import net.sf.cantina.ListIterator; 4 import net.sf.cantina.SearchEngine; 5 import net.sf.cantina.webgui.StrutsAction; 6 import org.apache.log4j.Logger; 7 import org.apache.struts.action.*; 8 import org.apache.struts.validator.DynaValidatorActionForm; 9 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 /*** 14 * @author Stephane JAIS 15 */ 16 public class SearchDocumentContentAction 17 extends StrutsAction 18 { 19 private static final Logger logger = Logger.getLogger(SearchDocumentContentAction.class); 20 21 public ActionForward execute(ActionMapping mapping, 22 ActionForm form, 23 HttpServletRequest request, 24 HttpServletResponse response) 25 throws Exception 26 { 27 28 ActionMessages messages = new ActionMessages(); 29 DynaValidatorActionForm dynaform = (DynaValidatorActionForm)form; 30 ActionErrors errors = new ActionErrors(); 31 ListIterator result = SearchEngine.getInstance().searchDocuments( 32 constructQuery(dynaform) 33 ); 34 if (result.getSize() == 0) 35 { 36 messages.add("query",new ActionMessage("no.results")); 37 saveMessages(request,messages); 38 return mapping.findForward(MAPPING_INPUT); 39 } 40 saveInSession(request,result); 41 return mapping.findForward(MAPPING_SUCCESS); 42 } 43 44 public static String constructQuery(DynaValidatorActionForm form) 45 { 46 StringBuffer result = new StringBuffer(); 47 result.append(form.get("query")); 48 49 if (!nullOrEmpty((String)form.get("realmName"))) 50 result.append(" +realm:"+form.get("realmName")); 51 52 if (!nullOrEmpty((String)form.get("locale"))) 53 result.append(" +locale:"+form.get("locale")); 54 logger.debug("Generated query ["+result+"]"); 55 return result.toString(); 56 } 57 58 public static boolean nullOrEmpty(String s) 59 { 60 return (s == null) || (s.length()==0); 61 } 62 } 63