<commit_before>package nxt.http;

import nxt.util.Convert;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

public class APITestServlet extends HttpServlet {

    private static final String header1 =
            "<!DOCTYPE html>\n" +
            "<html>\n" +
            "<head>\n" +
            "    <meta charset=\"UTF-8\"/>\n" +
            "    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">" +
            "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + 
            "    <title>Nxt http API</title>\n" +
            "    <link href=\"css/bootstrap.min.css\" rel=\"stylesheet\" type=\"text/css\" />" +
            "    <style type=\"text/css\">\n" +
            "        table {border-collapse: collapse;}\n" +
            "        td {padding: 10px;}\n" +
            "        .result {white-space: pre; font-family: monospace; overflow: auto;}\n" +
            "    </style>\n" +
            "    <script type=\"text/javascript\">\n" +
            "        var apiCalls;\n" +
            "        function performSearch(searchStr) {\n" +
            "            $('.api-call-All').hide();\n" +
            "            $('.topic-link').css('font-weight', 'normal');\n" +
            "            for(var i=0; i<apiCalls.length; i++) {\n" +
            "                var apiCall = apiCalls[i];\n" +
            "                if (new RegExp(searchStr.toLowerCase()).test(apiCall.toLowerCase())) {\n" +
            "                    $('#api-call-' + apiCall).show();\n" +
            "                }\n" +
            "            }\n" +
            "        }\n" +
            "        function submitForm(form) {\n" +
            "            var url = '/nxt';\n" +
            "            var params = {};\n" +
            "            for (i = 0; i < form.elements.length; i++) {\n" +
            "                if (form.elements[i].type != 'button' && form.elements[i].value && form.elements[i].value != 'submit') {\n" +
            "                    params[form.elements[i].name] = form.elements[i].value;\n" +
            "                }\n" +
            "            }\n" +
            "            $.ajax({\n" +
            "                url: url,\n" +
            "                type: 'POST',\n" +
            "                data: params\n" +
            "            })\n" +
            "            .done(function(result) {\n" +
            "                var resultStr = JSON.stringify(JSON.parse(result), null, 4);\n" +
            "                form.getElementsByClassName(\"result\")[0].textContent = resultStr;\n" +
            "            })\n" +
            "            .error(function() {\n" +
            "                alert('API not available, check if Nxt Server is running!');\n" +
            "            });\n" +
            "            if ($(form).has('.uri-link').length > 0) {\n" + 
            "                  var uri = 'http://' + window.location.host + '/nxt?' + jQuery.param(params);\n" +
            "                  var html = '<a href=\"' + uri + '\" target=\"_blank\" style=\"font-size:12px;font-weight:normal;\">Open GET URL</a>';" +
            "                  form.getElementsByClassName(\"uri-link\")[0].innerHTML = html;\n" +
            "            }" +
            "            return false;\n" +
            "        }\n" +
            "    </script>\n" +
            "</head>\n" +
            "<body>\n" +
            "<div class=\"navbar navbar-default\" role=\"navigation\">" +
            "   <div class=\"container\">" + 
            "       <div class=\"navbar-header\">" +
            "           <a class=\"navbar-brand\" href=\"/test\">Nxt http API</a>" + 
            "       </div>" +
            "       <div class=\"navbar-collapse collapse\">" +
            "           <ul class=\"nav navbar-nav navbar-right\">" +
            "               <li><input type=\"text\" class=\"form-control\" id=\"search\" " + 
            "                    placeholder=\"Search\" style=\"margin-top:8px;\"></li>\n" +
            "               <li><a href=\"https://wiki.nxtcrypto.org/wiki/Nxt_API\" target=\"_blank\" style=\"margin-left:20px;\">Wiki Docs</a></li>" +
            "           </ul>" +
            "       </div>" +
            "   </div>" + 
            "</div>" +
            "<div class=\"container\">" +
            "<div class=\"row\">" + 
            "  <div class=\"col-xs-12\" style=\"margin-bottom:15px;\">" +
            "    <div class=\"pull-right\">" +
            "      <a href=\"#\" id=\"navi-show-open\">Show Open</a>" +
            "       | " +
            "      <a href=\"#\" id=\"navi-show-all\">Show All</a>" +
            "    </div>" +
            "  </div>" +
            "</div>" +
            "<div class=\"row\" style=\"margin-bottom:15px;\">" +
            "  <div class=\"col-xs-4 col-sm-3 col-md-2\">" +
            "    <ul class=\"nav nav-pills nav-stacked\">";
    private static final String header2 =
            "    </ul>" +
            "  </div> <!-- col -->" +
            "  <div  class=\"col-xs-8 col-sm-9 col-md-10\">" +
            "    <div class=\"panel-group\" id=\"accordion\">";

    private static final String footer1 =
            "    </div> <!-- panel-group -->" +
            "  </div> <!-- col -->" +
            "</div> <!-- row -->" +
            "</div> <!-- container -->" +
            "<script src=\"js/3rdparty/jquery.js\"></script>" +
            "<script src=\"js/3rdparty/bootstrap.js\" type=\"text/javascript\"></script>" +
            "<script>" + 
            "  $(document).ready(function() {" +
            "    apiCalls = [];\n";

    private static final String footer2 =
            "    $(\".collapse-link\").click(function(event) {" +
            "       event.preventDefault();" +    
            "    });" +
            "    $('#search').keyup(function(e) {\n" +
            "      if (e.keyCode == 13 && $(this).val().length > 0) {\n" +
            "        performSearch($(this).val());\n" +
            "      }\n" +
            "    });\n" +
            "    $('#navi-show-open').click(function(e) {" +
            "      $('.api-call-All').each(function() {" +
            "        if($(this).find('.panel-collapse.in').length != 0) {" +
            "          $(this).show();" +
            "        } else {" +
            "          $(this).hide();" +
            "        }" +
            "      });" +
            "      e.preventDefault();" +
            "    });" +
            "    $('#navi-show-all').click(function(e) {" +
            "      $('.api-call-All').show();" +
            "      e.preventDefault();" +
            "    });" +
            "  });" + 
            "</script>" +
            "</body>\n" +<commit_msg>Added indicator for active element for Show-Open/Show-All navi<commit_after>package nxt.http;

import nxt.util.Convert;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

public class APITestServlet extends HttpServlet {

    private static final String header1 =
            "<!DOCTYPE html>\n" +
            "<html>\n" +
            "<head>\n" +
            "    <meta charset=\"UTF-8\"/>\n" +
            "    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">" +
            "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + 
            "    <title>Nxt http API</title>\n" +
            "    <link href=\"css/bootstrap.min.css\" rel=\"stylesheet\" type=\"text/css\" />" +
            "    <style type=\"text/css\">\n" +
            "        table {border-collapse: collapse;}\n" +
            "        td {padding: 10px;}\n" +
            "        .result {white-space: pre; font-family: monospace; overflow: auto;}\n" +
            "    </style>\n" +
            "    <script type=\"text/javascript\">\n" +
            "        var apiCalls;\n" +
            "        function performSearch(searchStr) {\n" +
            "            $('.api-call-All').hide();\n" +
            "            $('.topic-link').css('font-weight', 'normal');\n" +
            "            for(var i=0; i<apiCalls.length; i++) {\n" +
            "                var apiCall = apiCalls[i];\n" +
            "                if (new RegExp(searchStr.toLowerCase()).test(apiCall.toLowerCase())) {\n" +
            "                    $('#api-call-' + apiCall).show();\n" +
            "                }\n" +
            "            }\n" +
            "        }\n" +
            "        function submitForm(form) {\n" +
            "            var url = '/nxt';\n" +
            "            var params = {};\n" +
            "            for (i = 0; i < form.elements.length; i++) {\n" +
            "                if (form.elements[i].type != 'button' && form.elements[i].value && form.elements[i].value != 'submit') {\n" +
            "                    params[form.elements[i].name] = form.elements[i].value;\n" +
            "                }\n" +
            "            }\n" +
            "            $.ajax({\n" +
            "                url: url,\n" +
            "                type: 'POST',\n" +
            "                data: params\n" +
            "            })\n" +
            "            .done(function(result) {\n" +
            "                var resultStr = JSON.stringify(JSON.parse(result), null, 4);\n" +
            "                form.getElementsByClassName(\"result\")[0].textContent = resultStr;\n" +
            "            })\n" +
            "            .error(function() {\n" +
            "                alert('API not available, check if Nxt Server is running!');\n" +
            "            });\n" +
            "            if ($(form).has('.uri-link').length > 0) {\n" + 
            "                  var uri = 'http://' + window.location.host + '/nxt?' + jQuery.param(params);\n" +
            "                  var html = '<a href=\"' + uri + '\" target=\"_blank\" style=\"font-size:12px;font-weight:normal;\">Open GET URL</a>';" +
            "                  form.getElementsByClassName(\"uri-link\")[0].innerHTML = html;\n" +
            "            }" +
            "            return false;\n" +
            "        }\n" +
            "    </script>\n" +
            "</head>\n" +
            "<body>\n" +
            "<div class=\"navbar navbar-default\" role=\"navigation\">" +
            "   <div class=\"container\">" + 
            "       <div class=\"navbar-header\">" +
            "           <a class=\"navbar-brand\" href=\"/test\">Nxt http API</a>" + 
            "       </div>" +
            "       <div class=\"navbar-collapse collapse\">" +
            "           <ul class=\"nav navbar-nav navbar-right\">" +
            "               <li><input type=\"text\" class=\"form-control\" id=\"search\" " + 
            "                    placeholder=\"Search\" style=\"margin-top:8px;\"></li>\n" +
            "               <li><a href=\"https://wiki.nxtcrypto.org/wiki/Nxt_API\" target=\"_blank\" style=\"margin-left:20px;\">Wiki Docs</a></li>" +
            "           </ul>" +
            "       </div>" +
            "   </div>" + 
            "</div>" +
            "<div class=\"container\">" +
            "<div class=\"row\">" + 
            "  <div class=\"col-xs-12\" style=\"margin-bottom:15px;\">" +
            "    <div class=\"pull-right\">" +
            "      <a href=\"#\" id=\"navi-show-open\">Show Open</a>" +
            "       | " +
            "      <a href=\"#\" id=\"navi-show-all\" style=\"font-weight:bold;\">Show All</a>" +
            "    </div>" +
            "  </div>" +
            "</div>" +
            "<div class=\"row\" style=\"margin-bottom:15px;\">" +
            "  <div class=\"col-xs-4 col-sm-3 col-md-2\">" +
            "    <ul class=\"nav nav-pills nav-stacked\">";
    private static final String header2 =
            "    </ul>" +
            "  </div> <!-- col -->" +
            "  <div  class=\"col-xs-8 col-sm-9 col-md-10\">" +
            "    <div class=\"panel-group\" id=\"accordion\">";

    private static final String footer1 =
            "    </div> <!-- panel-group -->" +
            "  </div> <!-- col -->" +
            "</div> <!-- row -->" +
            "</div> <!-- container -->" +
            "<script src=\"js/3rdparty/jquery.js\"></script>" +
            "<script src=\"js/3rdparty/bootstrap.js\" type=\"text/javascript\"></script>" +
            "<script>" + 
            "  $(document).ready(function() {" +
            "    apiCalls = [];\n";

    private static final String footer2 =
            "    $(\".collapse-link\").click(function(event) {" +
            "       event.preventDefault();" +    
            "    });" +
            "    $('#search').keyup(function(e) {\n" +
            "      if (e.keyCode == 13 && $(this).val().length > 0) {\n" +
            "        performSearch($(this).val());\n" +
            "      }\n" +
            "    });\n" +
            "    $('#navi-show-open').click(function(e) {" +
            "      $('.api-call-All').each(function() {" +
            "        if($(this).find('.panel-collapse.in').length != 0) {" +
            "          $(this).show();" +
            "        } else {" +
            "          $(this).hide();" +
            "        }" +
            "      });" +
            "      $('#navi-show-all').css('font-weight', 'normal');" +
            "      $(this).css('font-weight', 'bold');" +
            "      e.preventDefault();" +
            "    });" +
            "    $('#navi-show-all').click(function(e) {" +
            "      $('.api-call-All').show();" +
            "      $('#navi-show-open').css('font-weight', 'normal');" +
            "      $(this).css('font-weight', 'bold');" +
            "      e.preventDefault();" +
            "    });" +
            "  });" + 
            "</script>" +
            "</body>\n" +
{'fraction_non_alphanumeric': 0.2030570652173913, 'fraction_numerical': 0.005163043478260869, 'mean_word_length': 1.2193577566711895, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 0, '>': 147, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7573414', 'n_tokens_mistral': 4374, 'n_tokens_neox': 4306, 'n_words': 668}