@@ -0,0 +1,1798 @@
+/**%0A * @license%0A * Copyright 2019 The FOAM Authors. All Rights Reserved.%0A * http://www.apache.org/licenses/LICENSE-2.0%0A */%0A%0Apackage foam.nanos.servlet;%0A%0Aimport foam.util.SafetyUtil;%0Aimport org.apache.commons.io.FilenameUtils;%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.apache.commons.text.StringEscapeUtils;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.BufferedInputStream;%0Aimport java.io.InputStream;%0Aimport java.io.IOException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class ResourceImageServlet%0A  extends ImageServlet%0A%7B%0A  @Override%0A  protected void service(HttpServletRequest req, HttpServletResponse resp)%0A    throws ServletException, IOException%0A  %7B%0A    System.out.println(%22ResourceImageServlet.service uri: %22+req.getRequestURI());%0A    String request = req.getRequestURI().replaceFirst(%22/?images/?%22, %22/%22);%0A    System.out.println(%22ResourceImageServlet.service request: %22+request);%0A    // tried a few prefixes, /images, /webapp/images, images/, %0A    InputStream is = getClass().getResourceAsStream(%22images/%22+request);%0A    if ( is != null ) %7B%0A      String ext = EXTS.get(request.substring(request.lastIndexOf('.') +1));%0A      try ( BufferedInputStream bis = new BufferedInputStream(is) ) %7B%0A        resp.setContentType(!SafetyUtil.isEmpty(ext) ? ext : DEFAULT_EXT);%0A        resp.setHeader(%22Content-Disposition%22, %22filename=%5C%22%22 + StringEscapeUtils.escapeHtml4(request) + %22%5C%22%22);%0A        //resp.setContentLengthLong(src.length());%0A%0A        IOUtils.copy(bis, resp.getOutputStream());%0A        return;%0A      %7D%0A    %7D else %7B%0A      System.out.println(%22ResourceImageServlet.service is: null%22);%0A    %7D%0A    resp.sendError(resp.SC_NOT_FOUND);%0A  %7D%0A%7D%0A

Support loading images from jar resource.