freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
changeset 100 8b899ed24f9f
parent 99 fed05535725f
child 101 c7244cdd143e
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Sat Sep 19 12:51:50 2009 +0200
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Sat Sep 19 14:38:29 2009 +0200
     1.3 @@ -140,20 +140,34 @@
     1.4      }
     1.5  
     1.6      private Viewable board(String id) {
     1.7 -        return board(id, "");
     1.8 +        return board(id, "", null);
     1.9      }
    1.10      @GET
    1.11      @Path("games/{id}/")
    1.12      @Produces(MediaType.TEXT_HTML)
    1.13 -    public Viewable board(@PathParam("id") String id, @QueryParam("format") @DefaultValue("") String format) {
    1.14 -        return board(id, null, format);
    1.15 +    public Viewable board(
    1.16 +        @PathParam("id") String id,
    1.17 +        @QueryParam("format") @DefaultValue("") String format,
    1.18 +        @QueryParam("move") @DefaultValue("-1") String move
    1.19 +    ) {
    1.20 +        return board(id, null, format, move);
    1.21      }
    1.22 -    private Viewable board(@PathParam("id") String id, String msg, String format) {
    1.23 +    private Viewable board(@PathParam("id") String id, String msg, String format, String m) {
    1.24          Viewable v = checkLogin();
    1.25          if (v != null) {
    1.26              return v;
    1.27          }
    1.28 -        Document doc = base.path("games").path(id).accept(MediaType.TEXT_XML).get(Document.class);
    1.29 +        int move;
    1.30 +        try {
    1.31 +            move = Integer.parseInt(m);
    1.32 +        } catch (NumberFormatException ex) {
    1.33 +            move = -1;
    1.34 +        }
    1.35 +        WebResource url = base.path("games").path(id);
    1.36 +        if (move >= 0) {
    1.37 +            url = url.queryParam("move", "" + move);
    1.38 +        }
    1.39 +        Document doc = url.accept(MediaType.TEXT_XML).get(Document.class);
    1.40          Board b;
    1.41          try {
    1.42              b = Board.valueOf(doc.getElementsByTagName("board").item(0).getTextContent());
    1.43 @@ -196,7 +210,7 @@
    1.44                  return board(id);
    1.45              }
    1.46          } catch (UniformInterfaceException ex) {
    1.47 -            return board(id, "WRONG_MOVE");
    1.48 +            return board(id, "WRONG_MOVE", "-1");
    1.49          }
    1.50          return board(id);
    1.51      }