Package com.highcharts.export.util

Examples of com.highcharts.export.util.MimeType


      }

      String filename = getFilename(getParameter(request, "filename",
          multi));
      Float width = getWidth(getParameter(request, "width", multi));
      MimeType mime = getMime(getParameter(request, "type", multi));

      ExportController.writeFileContentToHttpResponse(svg, filename,
          width, mime, response);

    } catch (IOException ioe) {
View Full Code Here


    }
    return null;
  }

  private static MimeType getMime(String mime) {
    MimeType type = MimeType.get(mime);
    if (type != null) {
      return type;
    }
    return MimeType.PNG;
  }
View Full Code Here

      }

      String filename = getFilename(getParameter(request, "filename",
          multi));
      Float width = getWidth(getParameter(request, "width", multi));
      MimeType mime = getMime(getParameter(request, "type", multi));

      ExportController.writeFileContentToHttpResponse(svg, filename,
          width, mime, response);

    } catch (IOException ioe) {
View Full Code Here

    }
    return null;
  }

  private static MimeType getMime(String mime) {
    MimeType type = MimeType.get(mime);
    if (type != null) {
      return type;
    }
    return MimeType.PNG;
  }
View Full Code Here

      @RequestParam(value = "constr", required = false) String constructor,
      @RequestParam(value = "callback", required = false) String callback)
      throws ServletException, IOException, InterruptedException,
      TimeoutException {

    MimeType mime = getMime(type);
    filename = getFilename(filename);
    Float parsedWidth = widthToFloat(width);
    Float parsedScale = scaleToFloat(scale);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
View Full Code Here

  private String getFilename(String name) {
    return (name != null) ? name : "chart";
  }

  private static MimeType getMime(String mime) {
    MimeType type = MimeType.get(mime);
    if (type != null) {
      return type;
    }
    return MimeType.PNG;
  }
View Full Code Here

      HttpServletResponse response, HttpServletRequest request)
      throws ServletException, IOException, InterruptedException, SVGConverterException, NoSuchElementException, PoolException, TimeoutException {

    long start1 = System.currentTimeMillis();

    MimeType mime = getMime(type);
    filename = getFilename(filename);
    Float parsedWidth = widthToFloat(width);
    Float parsedScale = scaleToFloat(scale);
    options = sanitize(options);
    String input;

    boolean convertSvg = false;

    if (options != null) {
      // create a svg file out of the options
      input = options;
      callback = sanitize(callback);
    } else {
      // assume SVG conversion
      if (svg == null) {
        throw new ServletException(
            "The manadatory svg POST parameter is undefined.");
      } else {
        svg = sanitize(svg);
        if (svg == null) {
          throw new ServletException(
              "The manadatory svg POST parameter is undefined.");
        }
        convertSvg = true;
        input = svg;
      }
    }

    ByteArrayOutputStream stream = null;
    if (convertSvg && mime.equals(MimeType.SVG)) {
      // send this to the client, without converting.
      stream = new ByteArrayOutputStream();
                        // add XML Doctype for svg
                        input = SVG_DOCTYPE + input;
      stream.write(input.getBytes());
    } else {
      //stream = SVGCreator.getInstance().convert(input, mime, constructor, callback, parsedWidth, parsedScale);
      stream = converter.convert(input, mime, constructor, callback, parsedWidth, parsedScale);
    }

    if (stream == null) {
      throw new ServletException("Error while converting");
    }

    logger.debug(request.getHeader("referer") + " Total time: " + (System.currentTimeMillis() - start1));

    response.reset();
    response.setCharacterEncoding("utf-8");
    response.setContentLength(stream.size());
    response.setStatus(HttpStatus.OK.value());
    response.setHeader("Content-disposition", "attachment; filename=\""
        + filename + "." + mime.name().toLowerCase() + "\"");

    IOUtils.write(stream.toByteArray(), response.getOutputStream());
    response.flushBuffer();
  }
View Full Code Here

    name = sanitize(name);
    return (name != null) ? name : "chart";
  }

  private static MimeType getMime(String mime) {
    MimeType type = MimeType.get(mime);
    if (type != null) {
      return type;
    }
    return MimeType.PNG;
  }
View Full Code Here

    @RequestParam(value = "callback", required = false) String callback,
    @RequestParam(value = "async", required = false, defaultValue = "false"Boolean async,
    HttpServletRequest request,
    HttpSession session) throws ServletException, InterruptedException, SVGConverterException, NoSuchElementException, PoolException, TimeoutException, IOException {

    MimeType mime = getMime(type);
    String tempFilename = null;

    boolean isAndroid = request.getHeader("user-agent") != null && request.getHeader("user-agent").contains("Android");

    if (isAndroid || MimeType.PDF.equals(mime) || async) {
      tempFilename = createUniqueFileName(mime.name().toLowerCase());
    }

    String output = processRequest(svg, mime, width, scale, options, constructor, callback, tempFilename);
    ByteArrayOutputStream stream;

    if (async) {
      String link = TempDir.getDownloadLink(tempFilename);
      // write to stream
      stream = new ByteArrayOutputStream();
      stream.write(link.getBytes("utf-8"));
    } else {
      stream = ouputToStream(output, mime, tempFilename);
    }

    /* If tempFilename is not null, then we want to save the filename in session, in case of GET is used later on*/
    if (isAndroid) {
      session.setAttribute("tempFile", FilenameUtils.getName(tempFilename));
    }

    filename = getFilename(filename);

      HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", mime.getType() + "; charset=utf-8");
    headers.add("Content-Disposition",
                   "attachment; filename=" + filename.replace(" ", "_") + "." + mime.name().toLowerCase());
    headers.setContentLength(stream.size());

    return new HttpEntity<byte[]>(stream.toByteArray(), headers);
  }
View Full Code Here

    } catch (IOException ioex) {
      logger.error("Tried to read file from filesystem: " + ioex.getMessage());
      throw new SVGConverterException("IOException: cannot find your file to download...");
    }

    MimeType mime = MimeType.valueOf(ext.toUpperCase());

    response.reset();
    response.setCharacterEncoding("utf-8");
    response.setContentLength(stream.size());
    response.setContentType(mime.getType());
    response.setStatus(HttpStatus.OK.value());
    IOUtils.write(stream.toByteArray(), response.getOutputStream());
    response.flushBuffer();

  }
View Full Code Here

TOP

Related Classes of com.highcharts.export.util.MimeType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.