@Override
 public List<String> update(
     List<FileItem> items, T field, FieldTemplate template, PagesContext pageContext)
     throws FormException {
   String fieldName = Util.getFieldOccurrenceName(template.getFieldName(), field.getOccurrence());
   String value = FileUploadUtil.getParameter(items, fieldName, null, pageContext.getEncoding());
   if (pageContext.getUpdatePolicy() == PagesContext.ON_UPDATE_IGNORE_EMPTY_VALUES
       && !StringUtil.isDefined(value)) {
     return new ArrayList<>(0);
   }
   return update(value, field, template, pageContext);
 }
  public static boolean processThumbnail(ForeignPK pk, String objectType, List<FileItem> parameters)
      throws Exception {
    boolean thumbnailChanged = false;
    String mimeType = null;
    String physicalName = null;
    FileItem uploadedFile = FileUploadUtil.getFile(parameters, "WAIMGVAR0");
    if (uploadedFile != null) {
      String logicalName = uploadedFile.getName().replace('\\', '/');
      if (StringUtil.isDefined(logicalName)) {
        logicalName = FilenameUtils.getName(logicalName);
        mimeType = FileUtil.getMimeType(logicalName);
        String type = FileRepositoryManager.getFileExtension(logicalName);
        if (FileUtil.isImage(logicalName)) {
          physicalName = String.valueOf(System.currentTimeMillis()) + '.' + type;
          SilverpeasFileDescriptor descriptor =
              new SilverpeasFileDescriptor(pk.getInstanceId())
                  .mimeType(mimeType)
                  .parentDirectory(publicationSettings.getString("imagesSubDirectory"))
                  .fileName(physicalName);
          SilverpeasFile target = SilverpeasFileProvider.newFile(descriptor);
          target.writeFrom(uploadedFile.getInputStream());
        } else {
          throw new ThumbnailRuntimeException(
              "ThumbnailController.processThumbnail()",
              SilverpeasRuntimeException.ERROR,
              "thumbnail_EX_MSG_WRONG_TYPE_ERROR");
        }
      }
    }

    // If no image have been uploaded, check if one have been picked up from a gallery
    if (physicalName == null) {
      // on a pas d'image, regarder s'il y a une provenant de la galerie
      String nameImageFromGallery = FileUploadUtil.getParameter(parameters, "valueImageGallery");
      if (StringUtil.isDefined(nameImageFromGallery)) {
        physicalName = nameImageFromGallery;
        mimeType = "image/jpeg";
      }
    }

    // If one image is defined, save it through Thumbnail service
    if (StringUtil.isDefined(physicalName)) {
      ThumbnailDetail detail =
          new ThumbnailDetail(
              pk.getInstanceId(),
              Integer.parseInt(pk.getId()),
              ThumbnailDetail.THUMBNAIL_OBJECTTYPE_PUBLICATION_VIGNETTE);
      detail.setOriginalFileName(physicalName);
      detail.setMimeType(mimeType);
      try {
        ThumbnailController.updateThumbnail(detail);
        thumbnailChanged = true;
      } catch (ThumbnailRuntimeException e) {
        SilverTrace.error(
            "thumbnail",
            "KmeliaRequestRouter.processVignette",
            "thumbnail_MSG_UPDATE_THUMBNAIL_KO",
            e);
        try {
          ThumbnailController.deleteThumbnail(detail);
        } catch (Exception exp) {

        }
      }
    }
    return thumbnailChanged;
  }