01: package com.flexive.war.javascript;
02:
03: import com.flexive.shared.EJBLookup;
04: import com.flexive.shared.search.AdminResultLocations;
05: import static com.flexive.shared.search.AdminResultLocations.ADMIN;
06: import com.flexive.war.JsonWriter;
07:
08: import java.io.Serializable;
09: import java.io.StringWriter;
10: import java.util.ArrayList;
11: import java.util.Collections;
12: import java.util.List;
13:
14: /**
15: * Implements JSON/RPC methods for the search query panel.
16: *
17: * @author Daniel Lichtenberger, UCS
18: * @version $Rev$
19: */
20: public class SearchQueryEditor implements Serializable {
21: private static final long serialVersionUID = -1665068866212914870L;
22:
23: /**
24: * Renders all stored search queries of the calling user.
25: *
26: * @return all search queries of the calling user (in JSON format).
27: * @throws Exception on server-side errors
28: */
29: public String renderSearchQueries() throws Exception {
30: final StringWriter out = new StringWriter();
31: final JsonWriter writer = new JsonWriter(out);
32: writer.startArray();
33: final List<String> names = new ArrayList<String>(EJBLookup
34: .getSearchEngine().loadNames(ADMIN));
35: Collections.sort(names);
36: for (String name : names) {
37: writer.startMap();
38: writer.writeAttribute("name", name);
39: writer.closeMap();
40: }
41: writer.closeArray().finishResponse();
42: return out.toString();
43: }
44:
45: /**
46: * Remove an admin search query definition.
47: *
48: * @param name the query name
49: * @return nothing
50: * @throws Exception if the query was not found or could not be deleted
51: */
52: public String remove(String name) throws Exception {
53: EJBLookup.getSearchEngine().remove(ADMIN, name);
54: return "[]";
55: }
56: }
|