@Override
  public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters)
      throws ConversionException {
    try {
      // Make sure the toThumbnail command is available
      CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class);
      CommandAvailability commandAvailability = cles.getCommandAvailability(THUMBNAIL_COMMAND);
      if (!commandAvailability.isAvailable()) {
        return null;
      }
      // get the input and output of the command
      Blob blob = blobHolder.getBlob();
      File inputFile = null;
      if (blob instanceof FileBlob) {
        inputFile = ((FileBlob) blob).getFile();
      } else if (blob instanceof SQLBlob) {
        StreamSource source = ((SQLBlob) blob).getBinary().getStreamSource();
        inputFile = ((FileSource) source).getFile();
      } else if (blob instanceof StreamingBlob) {
        StreamingBlob streamingBlob = ((StreamingBlob) blob);
        if (!streamingBlob.isPersistent()) {
          streamingBlob.persist();
        }
        StreamSource source = streamingBlob.getStreamSource();
        inputFile = ((FileSource) source).getFile();
      }
      if (inputFile == null) {
        return null;
      }
      CmdParameters params = new CmdParameters();
      File outputFile = File.createTempFile("nuxeoImageTarget", "." + "png");
      String size = THUMBNAIL_DEFAULT_SIZE;
      if (parameters != null) {
        if (parameters.containsKey(THUMBNAIL_SIZE_PARAMETER_NAME)) {
          size = (String) parameters.get(THUMBNAIL_SIZE_PARAMETER_NAME);
        }
      }
      params.addNamedParameter(THUMBNAIL_SIZE_PARAMETER_NAME, size);
      params.addNamedParameter("inputFilePath", inputFile);
      params.addNamedParameter("outputFilePath", outputFile);

      ExecResult res = cles.execCommand(THUMBNAIL_COMMAND, params);
      if (!res.isSuccessful()) {
        throw res.getError();
      }
      Blob targetBlob = new FileBlob(outputFile);
      Framework.trackFile(outputFile, targetBlob);
      return new SimpleCachableBlobHolder(targetBlob);
    } catch (CommandNotAvailable | IOException | ClientException | CommandException e) {
      throw new ConversionException("Thumbnail conversion failed", e);
    }
  }
  @Test
  public void testHTMLConverter() throws Exception {
    String converterName = cs.getConverterName("application/vnd.apple.pages", "text/html");
    assertEquals("iwork2html", converterName);

    CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class);
    assertNotNull(cles);

    ConverterCheckResult check = cs.isConverterAvailable(converterName);
    assertNotNull(check);
    if (!check.isAvailable()) {
      log.warn("Skipping PDF2Html tests since commandLine is not installed");
      log.warn(" converter check output : " + check.getInstallationMessage());
      log.warn(" converter check output : " + check.getErrorMessage());
      return;
    }

    CommandAvailability ca = cles.getCommandAvailability("pdftohtml");

    if (!ca.isAvailable()) {
      log.warn("pdftohtml command is not available, skipping test");
      return;
    }

    BlobHolder pagesBH = getBlobFromPath("test-docs/hello.pages");
    pagesBH.getBlob().setMimeType("application/vnd.apple.pages");
    BlobHolder result = cs.convert(converterName, pagesBH, null);
    assertNotNull(result);

    List<Blob> blobs = result.getBlobs();
    assertNotNull(blobs);
    assertEquals(2, blobs.size());

    Blob mainBlob = result.getBlob();
    assertEquals("index.html", mainBlob.getFilename());

    Blob subBlob = blobs.get(1);
    assertTrue(subBlob.getFilename().startsWith("index001"));

    String htmlContent = mainBlob.getString();
    assertTrue(htmlContent.contains("hello"));
  }
  @Override
  public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters)
      throws ConversionException {
    try {
      // Make sure the toThumbnail command is available
      CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class);
      CommandAvailability commandAvailability = cles.getCommandAvailability(THUMBNAIL_COMMAND);
      if (!commandAvailability.isAvailable()) {
        return null;
      }
      // get the input and output of the command
      Blob blob = blobHolder.getBlob();

      Blob targetBlob = Blobs.createBlobWithExtension(".png");
      targetBlob.setMimeType("image/png");
      try (CloseableFile source = blob.getCloseableFile()) {
        CmdParameters params = new CmdParameters();
        String size;
        if (parameters != null && parameters.containsKey(THUMBNAIL_SIZE_PARAMETER_NAME)) {
          size = (String) parameters.get(THUMBNAIL_SIZE_PARAMETER_NAME);
        } else {
          size = THUMBNAIL_DEFAULT_SIZE;
        }
        params.addNamedParameter(THUMBNAIL_SIZE_PARAMETER_NAME, size);
        params.addNamedParameter("inputFilePath", source.getFile());
        params.addNamedParameter("outputFilePath", targetBlob.getFile());

        ExecResult res = cles.execCommand(THUMBNAIL_COMMAND, params);
        if (!res.isSuccessful()) {
          throw res.getError();
        }
      }
      return new SimpleCachableBlobHolder(targetBlob);
    } catch (CommandNotAvailable | IOException | ClientException | CommandException e) {
      throw new ConversionException("Thumbnail conversion failed", e);
    }
  }