@Test
  public void testAnyToPDFConverter() throws Exception {
    ConversionService cs = Framework.getLocalService(ConversionService.class);
    ConverterCheckResult check = cs.isConverterAvailable("any2pdf");
    assertNotNull(check);
    if (!check.isAvailable()) {
      log.warn("Skipping JOD based converter tests since OOo is not installed");
      log.warn("  converter check output : " + check.getInstallationMessage());
      log.warn("  converter check output : " + check.getErrorMessage());
      return;
    }

    doTestPDFConverter("text/html", "hello.html");
    //        doTestPDFConverter("text/xml", "hello.xml");
    doTestPDFConverter("application/vnd.ms-excel", "hello.xls");
    doTestPDFConverter("application/vnd.sun.xml.writer", "hello.sxw");
    doTestPDFConverter("application/vnd.oasis.opendocument.text", "hello.odt");
    doTestPDFConverter("application/vnd.sun.xml.calc", "hello.sxc");
    doTestPDFConverter("application/vnd.oasis.opendocument.spreadsheet", "hello.ods");
    doTestPDFConverter("application/vnd.sun.xml.impress", "hello.sxi");
    doTestPDFConverter("application/vnd.oasis.opendocument.presentation", "hello.odp");

    doTestPDFConverter(
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "hello.docx");
    doTestPDFConverter(
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "hello.xlsx");
    doTestPDFConverter(
        "application/vnd.openxmlformats-officedocument.presentationml.presentation", "hello.pptx");
  }
Пример #2
0
 @Override
 public ConverterCheckResult isConverterAvailable() {
   ConverterCheckResult result = new ConverterCheckResult();
   OOoManagerService oooManagerService = Framework.getService(OOoManagerService.class);
   if (!oooManagerService.isOOoManagerStarted()) {
     result.setAvailable(false);
   }
   return result;
 }
Пример #3
0
  @Test
  public void testChainConverterAvailability() throws Exception {
    deploy("OSGI-INF/converters-test-contrib3.xml");
    deploy("OSGI-INF/converters-test-contrib4.xml");
    deploy("OSGI-INF/converters-test-contrib5.xml");
    ConversionService cs = Framework.getLocalService(ConversionService.class);

    ConverterCheckResult result = cs.isConverterAvailable("chainAvailable");
    assertNotNull(result);
    assertTrue(result.isAvailable());

    result = cs.isConverterAvailable("chainNotAvailable");
    assertNotNull(result);
    assertFalse(result.isAvailable());
    assertNotNull(result.getErrorMessage());
    assertNotNull(result.getInstallationMessage());
  }
  protected String doTestPDFConverter(
      String srcMT, String fileName, boolean pdfa, boolean updateIndex) throws Exception {

    ConversionService cs = Framework.getLocalService(ConversionService.class);

    String converterName = cs.getConverterName(srcMT, "application/pdf");
    assertEquals("any2pdf", converterName);

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

    BlobHolder hg = getBlobFromPath("test-docs/" + fileName, srcMT);

    Map<String, Serializable> parameters = new HashMap<String, Serializable>();
    if (pdfa) {
      parameters.put(JODBasedConverter.PDFA1_PARAM, Boolean.TRUE);
    }
    if (updateIndex) {
      parameters.put(JODBasedConverter.UPDATE_INDEX_PARAM, Boolean.TRUE);
    }
    BlobHolder result = cs.convert(converterName, hg, parameters);
    assertNotNull(result);

    File pdfFile = File.createTempFile("testingPDFConverter", ".pdf");
    String text = null;
    try {
      result.getBlob().transferTo(pdfFile);
      text = readPdfText(pdfFile);
      assertTrue(text.contains("Hello") || text.contains("hello"));
      if (pdfa) {
        assertTrue("Output is not PDF/A", isPDFA(pdfFile));
      }
      return text;
    } finally {
      pdfFile.delete();
    }
  }
  @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"));
  }
  @Test
  public void testAnyToPDFConverterWithToc() throws Exception {
    ConversionService cs = Framework.getLocalService(ConversionService.class);
    ConverterCheckResult check = cs.isConverterAvailable("any2pdf");
    assertNotNull(check);
    if (!check.isAvailable()) {
      log.warn("Skipping JOD based converter tests since OOo is not installed");
      log.warn("  converter check output : " + check.getInstallationMessage());
      log.warn("  converter check output : " + check.getErrorMessage());
      return;
    }

    // generate without TOC
    String textContent =
        doTestPDFConverter("application/vnd.oasis.opendocument.text", "toc.odt", false, false);
    // check that there is no TOC generated
    assertFalse(textContent.contains("..........."));

    // generate with TOC
    textContent =
        doTestPDFConverter("application/vnd.oasis.opendocument.text", "toc.odt", false, true);
    assertTrue(textContent.contains("..........."));
  }
Пример #7
0
  @Test
  public void testAvailability() throws Exception {
    deploy("OSGI-INF/converters-test-contrib1.xml");
    deploy("OSGI-INF/converters-test-contrib2.xml");
    deploy("OSGI-INF/converters-test-contrib4.xml");
    ConversionService cs = Framework.getLocalService(ConversionService.class);

    ConverterCheckResult result = null;

    // ** not existing converter
    // check registration check
    boolean notRegistred = false;

    try {
      result = cs.isConverterAvailable("toto");
    } catch (ConverterNotRegistered e) {
      notRegistred = true;
    }
    assertTrue(notRegistred);

    // check call
    notRegistred = false;
    try {
      cs.convert("toto", new SimpleBlobHolder(new StringBlob("")), null);
    } catch (ConverterNotRegistered e) {
      notRegistred = true;
    }
    assertTrue(notRegistred);

    // not available converter
    notRegistred = false;
    try {
      result = cs.isConverterAvailable("NotAvailableConverter");
    } catch (ConverterNotRegistered e) {
      notRegistred = true;
    }
    assertFalse(notRegistred);
    assertFalse(result.isAvailable());
    assertNotNull(result.getErrorMessage());
    assertNotNull(result.getInstallationMessage());

    notRegistred = false;
    boolean notAvailable = false;
    try {
      cs.convert("NotAvailableConverter", new SimpleBlobHolder(new StringBlob("")), null);
    } catch (ConverterNotRegistered e) {
      notRegistred = true;
    } catch (ConverterNotAvailable e) {
      notAvailable = true;
    }
    assertFalse(notRegistred);
    assertTrue(notAvailable);

    // ** available converter
    notRegistred = false;
    notAvailable = false;
    try {
      result = cs.isConverterAvailable("dummy2");
    } catch (ConverterNotRegistered e) {
      notRegistred = true;
    }
    assertFalse(notRegistred);
    assertTrue(result.isAvailable());
    assertNull(result.getErrorMessage());
    assertNull(result.getInstallationMessage());
    assertSame(2, result.getSupportedInputMimeTypes().size());

    notRegistred = false;
    try {
      cs.convert("dummy2", new SimpleBlobHolder(new StringBlob("")), null);
    } catch (ConverterNotRegistered e) {
      notRegistred = true;
    } catch (ConverterNotAvailable e) {
      notAvailable = true;
    }
    assertFalse(notRegistred);
    assertFalse(notAvailable);
  }