source: vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/pages/HtmlFormCreator.java @ 2568

Last change on this file since 2568 was 2568, checked in by keeloo, 11 years ago

created branch for parameterized vlo

  • Property svn:mime-type set to text/plain
File size: 1.8 KB
Line 
1package eu.clarin.cmdi.vlo.pages;
2
3import java.io.UnsupportedEncodingException;
4import java.util.Iterator;
5import java.util.List;
6import java.util.Map;
7
8import net.sf.json.JSONArray;
9import net.sf.json.JSONObject;
10import eu.clarin.cmdi.vlo.Configuration;
11import 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 */
19public 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}
Note: See TracBrowser for help on using the repository browser.