<%@ page import = "java.io.*,java.util.*,java.net.http.*,java.net.URI,java.net.URLEncoder,java.net.http.HttpResponse.BodyHandlers,java.net.HttpURLConnection,java.net.URL,java.nio.charset.StandardCharsets,org.json.*" %> <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> debug <%@ page buffer="8192kb" autoFlush="true" %> Catalog
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・                   ・・
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
Wii Points
<%= request.getParameter("p") == null ? "1" : request.getParameter("p") %>
<% String customHeader1 = "platform"; String customValue1 = request.getParameter("platform") == null ? "WII" : request.getParameter("platform"); String customHeader2 = "X-Custom-Header2"; String customValue2 = request.getParameter("p") == null ? "1" : request.getParameter("p"); String vcParam = request.getParameter("vc") != null ? "&vc=true" : ""; String titleParam = request.getParameter("title") == null ? "" : "&title=" + request.getParameter("title"); String publisherParam = request.getParameter("publisher") == null ? "" : "&publisher=" + URLEncoder.encode(request.getParameter("publisher"), "UTF-8"); String[] titleIds = request.getParameterValues("titleId") == null ? new String[]{""} : request.getParameterValues("titleId"); String recParam = request.getParameter("rec") == null ? "" : "&rec=true"; String genreParam = request.getParameter("genre") == null ? "" : "&genre=" + request.getParameter("genre"); String targetURL = "http://127.0.0.1:8082/getTitles?p=" + customValue2 + vcParam + titleParam + publisherParam + recParam + genreParam; for (String titleIdHex : titleIds) { if (titleIdHex.equals("")) break; targetURL += "&titleId=" + titleIdHex; } String titleList1 = request.getParameter("titlelist1") == null ? "" : "&titlelist1=true"; String titleList2 = request.getParameter("titlelist2") == null ? "" : "&titlelist2=true"; String titleList3 = request.getParameter("titlelist3") == null ? "" : "&titlelist3=true"; String titleList4 = request.getParameter("titlelist4") == null ? "" : "&titlelist4=true"; targetURL += titleList1 + titleList2 + titleList3 + titleList4; %> <% StringBuilder res = new StringBuilder(); String games = ""; try { URL url = new URL(targetURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); // Set custom headers connection.setRequestProperty(customHeader1, customValue1); connection.setRequestProperty(customHeader2, customValue2); int responseCode = connection.getResponseCode(); BufferedReader reader; if (responseCode == HttpURLConnection.HTTP_OK) { reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = reader.readLine()) != null) { res.append(line); } reader.close(); games = res.toString(); } else if (responseCode == 500) { games = "[{ id: '', title1: '', title2: '', console: '', controllers: '', region: '', language: '', attributes: '', date: '', added: '', publisher: '', genre: '', points: '', players: '', rating: '', ratingdetails: '', thumbnail: '', size: '', titleVersion: -1, page: -1 }]"; } else { reader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); } } catch (Exception e) { e.printStackTrace(); res.append("Error: ").append(e.getMessage()); } //Now for the tmd size %> <% JSONArray g = null; // Parse JSON response try { g = new JSONArray(games); } catch (Exception e) { g = new JSONArray("[{ id: '', title1: '', title2: '', console: '', controllers: '', region: '', language: '', attributes: '', date: '', added: '', publisher: '', genre: '', points: '', players: '', rating: '', ratingdetails: '', thumbnail: '', size: '', titleVersion: -1, page: -1 }]"); } %> <% for (int i = 0; i < g.length(); i++) { JSONObject game = g.getJSONObject(i); // Break if we didn't get a successful catalog response if (game.getString("id").equals("")) { break; } String platform = game.getString("console"); if (platform.equals("WII")) { platform = "Wii Channels"; } else if (platform.equals("WIIWARE")) { platform = "WiiWare"; } String publisher = game.getString("publisher"); String title1 = game.getString("title1"); String title2 = game.getString("title2"); String titleId = game.getString("id"); String thumbnail = game.getString("thumbnail"); // Add Virtual Console platforms for display String vcPlatforms = "Nintendo 64, NES, Super NES, Master System, Sega Genesis, NEOGEO, Virtual Console Arcade, TurboGrafx16, Commodore 64"; boolean isVcTitle = vcPlatforms.toLowerCase().contains(platform.toLowerCase()); // Skip non-VC titles if vc=true is specified if (vcParam.contains("true") && !isVcTitle) { continue; } %>
<%= platform %>
<%= publisher %>
<% if (!title2.equals("")) { %>
<%= title2 %>
<% } %>
<%= title1 %>
0 Wii Points
<% } %>
<% String pv = request.getParameter("p") == null ? "1" : request.getParameter("p"); String platv = request.getParameter("platform") == null && request.getParameter("vc") == null ? "WII" : request.getParameter("platform"); boolean isVc = (request.getParameter("vc") != null && Boolean.parseBoolean(request.getParameter("vc"))); String rec = request.getParameter("rec") == null ? "" : "&rec=true"; String genreString = request.getParameter("genre") == null ? "" : "&genre=" + request.getParameter("genre"); String platformString = "platform="; String titleSearch = request.getParameter("title") == null ? "" : "&title=" + request.getParameter("title"); if (isVc) { platformString = "vc=true&platform=" + platv; } else { platformString = "platform=" + platv; } %>