Java Code Examples for org.eclipse.jetty.util.MultiMap#get()

The following examples show how to use org.eclipse.jetty.util.MultiMap#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhpFormProcessor.java    From TestingApp with Apache License 2.0 4 votes vote down vote up
public String post() {

        html = new StringBuilder();

        html.append("<html><head><title>Processed Form Details</title></head>");
        html.append("<body>");

        // for backwards compatibility with PHP we should process the form fields in the order they are submitted
        String[] paramKeys = req.body().split("&");
        Set<String> theParamKeys = new LinkedHashSet<>();
        int index=0;
        for(String paramKey : paramKeys){
            int trimFrom = paramKey.indexOf("=");
            paramKeys[index] = paramKey.substring(0,trimFrom).replace("%5B%5D","[]");
            if(!theParamKeys.contains(paramKeys[index])){
                theParamKeys.add(paramKeys[index]);
            }
            index++;
        }

        //now decode the form into its name value,value pairs
        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        if(params.get("submitbutton")==null) {
            addLine("<p id='_valuesubmitbutton'>You did not click the submit button</p>");
        }

        addLine("<p>Submitted Values</p>");

        for(String param : theParamKeys){
            if(params.get(param) == null) {
                addLine(String.format("<p><strong>No Value for %s</strong></p>", param));
            }else{

                List<String> value = params.get(param);

                if(value.size()==0 || value.get(0).length()==0){
                    addLine(String.format("<p><strong>No Value for %s</strong></p>", param));
                }else{

                    boolean paramIsArray = param.contains("[]");
                    String paramDisplayName = param.replace("[]","");

                    addLine(String.format("<div id='_%s'>",paramDisplayName));
                    addLine(String.format("<p name='_%s'><strong>%s</strong></p>", paramDisplayName, paramDisplayName));

                    addLine("<ul>");

                    if(paramIsArray) {
                        int count=0;
                        for (String aValue : value) {
                            addLine(String.format("<li id='_value%s%d'>%s</li>", paramDisplayName, count, aValue));
                            count++;
                        }
                    }else{
                        addLine(String.format("<li id='_value%s'>%s</li>",paramDisplayName, value.get(0)));
                    }
                    addLine("</ul>");

                    addLine("</div>");
                }
            }

        }

        if(params.get("checkboxes[]")==null) {
            addLine("<p><strong>No Value for checkboxes</strong></p>");
        }

        if(params.get("multipleselect[]")==null) {
            addLine("<p><strong>No Value for multipleselect</strong></p>");
        }

        if(params.get("filename")==null) {
            addLine("<p><strong>No Value for filename</strong></p>");
        }


        if(req.queryParams("ajax")!=null){
            addLine("<a href='basic_ajax.html' id='back_to_form'>Go back to the Ajax form</a>");
        }else{
            addLine("<a href='basic_html_form.html' id='back_to_form'>Go back to the main form</a>");
        }

        html.append("</body>");
        html.append("</html>");
        return html.toString();
    }
 
Example 2
Source File: PhpSearch.java    From TestingApp with Apache License 2.0 4 votes vote down vote up
public String post() {


        List<SearchUrl> urls = SearchUrls.get();


        this.html = new StringBuilder();

        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        List<SearchUrl> returnUrls = new ArrayList<>();

        String query = "";

        int urlsToReturn = 20;

        if (params.get("q") != null) {
            query = params.get("q").get(0);
        }

        // add the seleniumrc one to make sure that the exercises work
        SearchUrl seleniumrc = new SearchUrl("http://seleniumhq.org",
                "seleniumhq.org",
                "Selenium Remote-Control",
                "Selenium RC comes in two parts. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them. ...");

        if (query.equalsIgnoreCase("selenium-rc")) {
            returnUrls.add(seleniumrc);
            urlsToReturn--;
        }

        // try and find some matching in the list

        for (SearchUrl sUrl : urls) {
            boolean addThis = false;

            if (sUrl.description.contains(query)) {
                addThis = true;
            }

            if (sUrl.title.contains(query)) {
                addThis = true;
            }

            if (sUrl.displayUrl.contains(query)) {
                addThis = true;
            }

            if (addThis) {
                returnUrls.add(sUrl);
                urlsToReturn--;
            }

            if (urlsToReturn == 0) {
                break;
            }
        }


        if (urlsToReturn > 0) {
            // randomly choose some urls
            while (urlsToReturn > 0) {
                int totalUrls = urls.size();
                Random r = new Random();
                int Low = 0;
                int rand = r.nextInt(totalUrls - Low) + Low;
                returnUrls.add(urls.get(rand));
                urlsToReturn--;
            }
        }


        pageHtml(query, returnUrls);

        return html.toString();
    }
 
Example 3
Source File: PhpPrettySearch.java    From TestingApp with Apache License 2.0 4 votes vote down vote up
public String post() {


        List<SearchUrl> urls = SearchUrls.get();


        this.html = new StringBuilder();

        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        List<SearchUrl> returnUrls = new ArrayList<>();

        String query = "";

        int urlsToReturn = 20;

        if (params.get("q") != null) {
            query = params.get("q").get(0);
        }

        // add the seleniumrc one to make sure that the exercises work
        SearchUrl seleniumrc = new SearchUrl("http://seleniumhq.org",
                "seleniumhq.org",
                "Selenium Remote-Control",
                "Selenium RC comes in two parts. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them. ...");

        if (query.equalsIgnoreCase("selenium-rc")) {
            returnUrls.add(seleniumrc);
            urlsToReturn--;
        }

        // try and find some matching in the list

        for (SearchUrl sUrl : urls) {
            boolean addThis = false;

            if (sUrl.description.contains(query)) {
                addThis = true;
            }

            if (sUrl.title.contains(query)) {
                addThis = true;
            }

            if (sUrl.displayUrl.contains(query)) {
                addThis = true;
            }

            if (addThis) {
                returnUrls.add(sUrl);
                urlsToReturn--;
            }

            if (urlsToReturn == 0) {
                break;
            }
        }


        if (urlsToReturn > 0) {
            // randomly choose some urls
            while (urlsToReturn > 0) {
                int totalUrls = urls.size();
                Random r = new Random();
                int Low = 0;
                int rand = r.nextInt(totalUrls - Low) + Low;
                returnUrls.add(urls.get(rand));
                urlsToReturn--;
            }
        }


        return pageHtml(query, returnUrls);
    }