Search in sources :

Example 1 with LogoPosition

use of org.openforis.collect.model.LogoPosition in project collect by openforis.

the class LogoController method downloadLogo.

@RequestMapping(value = "/downloadLogo.htm", method = RequestMethod.GET)
@ResponseBody
public void downloadLogo(HttpServletRequest request, HttpServletResponse response, @RequestParam String position) {
    LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
    Logo logo = logoManager.loadLogo(p);
    if (logo != null) {
        byte[] data = logo.getImage();
        ByteArrayInputStream is = new ByteArrayInputStream(data);
        try {
            String contentType = logo.getContentType();
            if (contentType == null) {
                contentType = "image/jpg";
            }
            // TODO get extension from db
            String extension = "jpg";
            Controllers.writeFileToResponse(response, is, "logo." + extension, contentType, data.length);
        } catch (IOException e) {
            log.error("Error writing logo in position: " + position, e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LogoPosition(org.openforis.collect.model.LogoPosition) IOException(java.io.IOException) Logo(org.openforis.collect.model.Logo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with LogoPosition

use of org.openforis.collect.model.LogoPosition in project collect by openforis.

the class LogoController method uploadLogo.

@RequestMapping(value = "/uploadLogo.htm", method = RequestMethod.POST)
@ResponseBody
public String uploadLogo(UploadItem uploadItem, BindingResult result, @RequestParam String position) throws IOException, SurveyImportException, IdmlParseException {
    CommonsMultipartFile fileData = uploadItem.getFileData();
    InputStream is = fileData.getInputStream();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    IOUtils.copy(is, output);
    byte[] byteArray = output.toByteArray();
    String contentType = fileData.getContentType();
    LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
    Logo logo = new Logo(p, byteArray, contentType);
    logoManager.save(logo);
    return "ok";
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) LogoPosition(org.openforis.collect.model.LogoPosition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) Logo(org.openforis.collect.model.Logo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 Logo (org.openforis.collect.model.Logo)2 LogoPosition (org.openforis.collect.model.LogoPosition)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)1