@POST @javax.ws.rs.Path("/svg") @Consumes("application/json;charset=UTF-8") @Produces("image/svg+xml") @GZIP @NoCache public Response createSvgForAton( @QueryParam("width") @DefaultValue("100") int width, @QueryParam("height") @DefaultValue("100") int height, @QueryParam("scale") @DefaultValue("0.4") double scale, AtonNodeVo aton) throws Exception { long t0 = System.currentTimeMillis(); ByteArrayOutputStream out = new ByteArrayOutputStream(); AtonIconRenderer.renderIcon( aton, "svg", out, width, // width height, // height width / 2, // x height / 2, // y scale // scale ); log.trace("Generated AtoN SVG in " + (System.currentTimeMillis() - t0) + " ms"); return Response.ok(out.toByteArray()).build(); }
@GET @javax.ws.rs.Path("/overview") @NoCache public Response getAtonOverviewIcon(@Context HttpServletRequest request) throws Exception { long t0 = System.currentTimeMillis(); String type = request.getParameter("seamark:type"); if (StringUtils.isBlank(type)) { return Response.temporaryRedirect(new URI("/img/aton/aton.png")).build(); } // Prepare an AtoN to use as a template for icon construction AtonNode aton = new AtonNode(); // Construct a repository path to the icon Path path = repositoryService.getRepoRoot().resolve(OVERVIEW_ICON_REPO); path = addParam(aton, path, request, "seamark:type"); path = addParam(aton, path, request, "seamark:" + type + ":category"); path = addParam(aton, path, request, "seamark:" + type + ":shape"); path = addParam(aton, path, request, "seamark:" + type + ":colour"); path = addParam(aton, path, request, "seamark:" + type + ":colour_pattern"); path = addParam(aton, path, request, "seamark:topmark:shape"); path = addParam(aton, path, request, "seamark:topmark:colour"); path = addParam(aton, path, request, "seamark:light:character"); path = addParam(aton, path, request, "seamark:light:colour"); // And the actual icon file path = path.resolve("aton_icon_" + OVERVIEW_ICON_WIDTH + "x" + OVERVIEW_ICON_HEIGHT + ".png"); if (!Files.isRegularFile(path)) { checkCreateParentDirs(path); try (FileOutputStream out = new FileOutputStream(path.toFile())) { AtonIconRenderer.renderIcon( aton.toVo(), "png", out, OVERVIEW_ICON_WIDTH, // width OVERVIEW_ICON_HEIGHT, // height OVERVIEW_ICON_WIDTH / 3, // x 2 * OVERVIEW_ICON_HEIGHT / 3, // y OVERVIEW_ICON_SCALE // scale ); log.trace( "Generated AtoN PNG " + path + " in " + (System.currentTimeMillis() - t0) + " ms"); } } // Redirect to the icon String iconUri = repositoryService.getRepoUri(path); return Response.temporaryRedirect(new URI("../" + iconUri)).build(); }