예제 #1
0
 public UIFormUploadInput(String name, String bindingExpression, int limit) {
   super(name, bindingExpression, String.class);
   uploadId_ = Integer.toString(Math.abs(hashCode()));
   UploadService service = getApplicationComponent(UploadService.class);
   service.addUploadLimit(uploadId_, Integer.valueOf(limit)); // Use the limit set by constructor.
   setComponentConfig(UIFormUploadInput.class, null);
 }
예제 #2
0
 public void decode(Object input, WebuiRequestContext context) throws Exception {
   uploadResource_ = null;
   boolean hasUpload = "true".equals(input);
   if (hasUpload) {
     UploadService service = getApplicationComponent(UploadService.class);
     uploadResource_ = service.getUploadResource(uploadId_);
   }
 }
예제 #3
0
 public UIFormUploadInput(String name, String bindingExpression, boolean isAutoUpload) {
   super(name, bindingExpression, String.class);
   uploadId_ = Integer.toString(Math.abs(hashCode()));
   this.isAutoUpload = isAutoUpload;
   UploadService service = getApplicationComponent(UploadService.class);
   service.addUploadLimit(uploadId_, null);
   setComponentConfig(UIFormUploadInput.class, null);
 }
예제 #4
0
    @Override
    public void execute(Event<UIAvatarUploader> event) throws Exception {
      WebuiRequestContext ctx = event.getRequestContext();
      UIApplication uiApplication = ctx.getUIApplication();
      UIAvatarUploader uiAvatarUploader = event.getSource();
      UIFormUploadInput uiAvatarUploadInput = uiAvatarUploader.getChild(UIFormUploadInput.class);
      UIPopupWindow uiPopup = uiAvatarUploader.getParent();
      InputStream uploadedStream = uiAvatarUploadInput.getUploadDataAsStream();

      if (uploadedStream == null) {
        uiApplication.addMessage(
            new ApplicationMessage(MSG_IMG_NOT_UPLOADED, null, ApplicationMessage.ERROR));
        ctx.addUIComponentToUpdateByAjax(uiAvatarUploader);
        return;
      }
      UploadResource uploadResource = uiAvatarUploadInput.getUploadResource();

      String mimeType = uploadResource.getMimeType();
      String uploadId = uiAvatarUploadInput.getUploadId();
      if (!uiAvatarUploader.isAcceptedMimeType(mimeType)) {
        UploadService uploadService =
            (UploadService) PortalContainer.getComponent(UploadService.class);
        uploadService.removeUploadResource(uploadId);
        uiApplication.addMessage(
            new ApplicationMessage(MSG_MIMETYPE_NOT_ACCEPTED, null, ApplicationMessage.ERROR));
        ctx.addUIComponentToUpdateByAjax(uiAvatarUploader);
      } else {
        MimeTypeResolver mimeTypeResolver = new MimeTypeResolver();
        String fileName = uploadResource.getFileName();

        // @since 1.1.3
        String extension = mimeTypeResolver.getExtension(mimeType);
        if ("".equals(extension)) {
          mimeType = uiAvatarUploader.getStandardMimeType(mimeType);
        }

        // Resize avatar to fixed width if can't(avatarAttachment == null) keep
        // origin avatar
        AvatarAttachment avatarAttachment =
            ImageUtils.createResizedAvatarAttachment(
                uploadedStream, WIDTH, 0, null, fileName, mimeType, null);
        if (avatarAttachment == null) {
          avatarAttachment =
              new AvatarAttachment(
                  null, fileName, mimeType, uploadedStream, null, System.currentTimeMillis());
        }

        UploadService uploadService =
            (UploadService) PortalContainer.getComponent(UploadService.class);
        uploadService.removeUploadResource(uploadId);
        UIAvatarUploadContent uiAvatarUploadContent =
            uiAvatarUploader.createUIComponent(UIAvatarUploadContent.class, null, null);
        uiAvatarUploadContent.setAvatarAttachment(avatarAttachment);
        uiPopup.setUIComponent(uiAvatarUploadContent);
        ctx.addUIComponentToUpdateByAjax(uiPopup);
      }
    }
예제 #5
0
 public UIFormUploadInput(String name, String bindingExpression) {
   super(name, bindingExpression, String.class);
   uploadId_ = Integer.toString(Math.abs(hashCode()));
   UploadService service = getApplicationComponent(UploadService.class);
   service.addUploadLimit(
       uploadId_,
       null); // Use the limit set by the service. Warning, the service can allow no size limit
              // (value to 0)
   setComponentConfig(UIFormUploadInput.class, null);
 }