response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request path, use: /wikiUserPortrait/[0-9]+/(l|s)");
return;
}
UserDAO userDAO = (UserDAO) Component.getInstance(UserDAO.class);
User user = userDAO.findUser(Long.valueOf(userId));
if (user == null || user.getProfile().getImageContentType() == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "User id not found or no portrait for user");
return;
}
byte[] image = imageSize.equals("l") ? user.getProfile().getImage() : user.getProfile().getSmallImage();
response.setContentType(user.getProfile().getImageContentType());
response.setContentLength(image.length);
response.getOutputStream().write(image);
response.getOutputStream().flush();
}