1 | package eu.clarin.cmdi.vlo.pages; |
---|
2 | |
---|
3 | import java.io.UnsupportedEncodingException; |
---|
4 | import java.util.Iterator; |
---|
5 | import java.util.List; |
---|
6 | import java.util.Map; |
---|
7 | |
---|
8 | import net.sf.json.JSONArray; |
---|
9 | import net.sf.json.JSONObject; |
---|
10 | import eu.clarin.cmdi.vlo.Configuration; |
---|
11 | import eu.clarin.cmdi.vlo.config.WebAppConfig; |
---|
12 | |
---|
13 | /** |
---|
14 | * Little helper class that creates HTML forms as String |
---|
15 | * |
---|
16 | * @author Thomas Eckart |
---|
17 | * |
---|
18 | */ |
---|
19 | public class HtmlFormCreator { |
---|
20 | /** |
---|
21 | * Creates an HTML form for the content search (FCS). |
---|
22 | * @param aggregationContextMap Mapping CQL endpoint -> List of resource IDs |
---|
23 | * @return HTML content search form as String |
---|
24 | * @throws UnsupportedEncodingException |
---|
25 | */ |
---|
26 | public static String getContentSearchForm(Map<String, List<String>> aggregationContextMap) throws UnsupportedEncodingException { |
---|
27 | JSONObject aggregationJson = new JSONObject(); |
---|
28 | Iterator<String> aggregationContextIter = aggregationContextMap.keySet().iterator(); |
---|
29 | while(aggregationContextIter.hasNext()) { |
---|
30 | String endpoint = aggregationContextIter.next(); |
---|
31 | JSONArray idArray = new JSONArray(); |
---|
32 | for(String id : aggregationContextMap.get(endpoint)) { |
---|
33 | idArray.add(id); |
---|
34 | } |
---|
35 | aggregationJson.put(endpoint, idArray); |
---|
36 | } |
---|
37 | |
---|
38 | String form = "<form method=\"post\" action=\""+WebAppConfig.get().getFederatedContentSearchUrl()+"\"> \n" |
---|
39 | + "<fieldset style=\"border:0px;\"> \n" |
---|
40 | + "\t <label for=\"query\">CQL query:</label> \n" |
---|
41 | + "\t <input id=\"query\" type=\"text\" name=\"query\" size=\"30\" /> \n" |
---|
42 | + "\t <input type=\"hidden\" name=\"x-aggregation-context\" value=\'"+aggregationJson.toString(2)+"\' /> \n" |
---|
43 | + "\t <input type=\"hidden\" name=\"operation\" value=\"searchRetrieve\" /> \n" |
---|
44 | + "\t <input type=\"hidden\" name=\"version\" value=\"1.2\" /> \n" |
---|
45 | + "\t <input type=\"submit\" value=\"Send query\" /> \n" |
---|
46 | + "</fieldset> \n" |
---|
47 | + "</form> \n"; |
---|
48 | return form; |
---|
49 | } |
---|
50 | } |
---|