/** * Initialization method. * * @param sSearchTerms The search term string. It is internally separated into multiple tokens * by using a "\s+" regular expression. * @return this */ @Nonnull protected Finder initialize(@Nonnull @Nonempty final String sSearchTerms) { if (StringHelper.hasNoTextAfterTrim(sSearchTerms)) throw new IllegalArgumentException("SearchTerms"); // Split search terms by white spaces m_aSearchTerms = RegExHelper.getSplitToArray(sSearchTerms.trim(), "\\s+"); if (m_aSearchTerms.length == 0) throw new IllegalStateException( "Weird - splitting of '" + sSearchTerms.trim() + "' failed!"); for (final String sSearchTerm : m_aSearchTerms) if (sSearchTerm.length() == 0) throw new IllegalArgumentException("Weird - empty search term present!"); return this; }
@Override @Nonnull protected final IAjaxResponse mainHandleRequest(@Nonnull final LECTYPE aLEC) throws Exception { final String sOriginalQuery = getQueryString(aLEC); if (StringHelper.hasNoTextAfterTrim(sOriginalQuery)) { // May happen when the user enters " " (only spaces) return AjaxDefaultResponse.createSuccess(aLEC.getRequestScope(), new JsonObject()); } // Create the main Finder object final Finder aFinder = createFinder(sOriginalQuery, aLEC); // Map from ID to name final List<? extends TypeaheadDatum> aMatchingDatums = getAllMatchingDatums(aFinder, aLEC); // Convert to JSON, sorted by display name using the current display locale final JsonArray ret = new JsonArray(); for (final TypeaheadDatum aDatum : aMatchingDatums) ret.add(aDatum.getAsJson()); // Use the simple response, because the response layout is predefined! return new AjaxSimpleResponse(true, ret); }