From 57019c8898f9928bc995a82e017cc5827693bc05 Mon Sep 17 00:00:00 2001 From: "marcin.sciesinski" Date: Fri, 16 Aug 2019 13:21:17 -0700 Subject: [PATCH] Game history is displayed as HTML in /gameHistory/list/html --- .../handler/GameHistoryRequestHandler.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameHistoryRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameHistoryRequestHandler.java index 2b8254eb4..2ed82276b 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameHistoryRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/GameHistoryRequestHandler.java @@ -86,6 +86,41 @@ public class GameHistoryRequestHandler extends LotroServerRequestHandler impleme } else if (uri.equals("/list") && request.getMethod() == HttpMethod.GET) { final List playerGameHistory = _gameHistoryService.getTrackableGames(100); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + Document doc = documentBuilder.newDocument(); + Element gameHistory = doc.createElement("gameHistory"); + + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (GameHistoryEntry gameHistoryEntry : playerGameHistory) { + Element historyEntry = doc.createElement("historyEntry"); + historyEntry.setAttribute("winner", gameHistoryEntry.getWinner()); + historyEntry.setAttribute("loser", gameHistoryEntry.getLoser()); + + historyEntry.setAttribute("winReason", gameHistoryEntry.getWinReason()); + historyEntry.setAttribute("loseReason", gameHistoryEntry.getLoseReason()); + + historyEntry.setAttribute("formatName", gameHistoryEntry.getFormatName()); + + historyEntry.setAttribute("winnerRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.getWinner()+"$"+gameHistoryEntry.getWinnerRecording()); + historyEntry.setAttribute("winnerDeckName", gameHistoryEntry.getWinnerDeckName()); + + historyEntry.setAttribute("loserRecordingLink", "http://www.gempukku.com/gemp-lotr/game.html?replayId="+gameHistoryEntry.getLoser()+"$"+gameHistoryEntry.getLoserRecording()); + historyEntry.setAttribute("loserDeckName", gameHistoryEntry.getLoserDeckName()); + + historyEntry.setAttribute("startTime", dateFormat.format(new Date(gameHistoryEntry.getStartTime().getTime()))); + historyEntry.setAttribute("endTime", dateFormat.format(new Date(gameHistoryEntry.getEndTime().getTime()))); + + gameHistory.appendChild(historyEntry); + } + + doc.appendChild(gameHistory); + + responseWriter.writeXmlResponse(doc); + } else if (uri.equals("/list/html") && request.getMethod() == HttpMethod.GET) { + final List playerGameHistory = _gameHistoryService.getTrackableGames(100); + StringBuilder sb = new StringBuilder(); sb.append("");