Esempio n. 1
0
 public static String getUserAvatar(String userName) throws Exception {
   String url = "";
   try {
     FAQService service = getFAQService();
     FileAttachment avatar = service.getUserAvatar(userName);
     if (avatar != null) {
       url = CommonUtils.getImageUrl(avatar.getPath()) + "?size=" + avatar.getSize();
     }
   } catch (Exception e) {
     log.debug("Failed to get user avatar of user: " + userName, e);
   }
   return (isFieldEmpty(url)) ? org.exoplatform.faq.service.Utils.DEFAULT_AVATAR_URL : url;
 }
Esempio n. 2
0
 public static String getFileSource(FileAttachment attachment) throws Exception {
   DownloadService dservice =
       (DownloadService) PortalContainer.getComponent(DownloadService.class);
   try {
     InputStream input = attachment.getInputStream();
     String fileName = attachment.getName();
     byte[] imageBytes = null;
     if (input != null) {
       imageBytes = new byte[input.available()];
       input.read(imageBytes);
       ByteArrayInputStream byteImage = new ByteArrayInputStream(imageBytes);
       InputStreamDownloadResource dresource = new InputStreamDownloadResource(byteImage, "image");
       dresource.setDownloadName(fileName);
       return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
     }
   } catch (Exception e) {
     log.error("Can not get File Source, exception: " + e.getMessage());
   }
   return "";
 }