Java Code Examples for org.alfresco.repo.content.MimetypeMap#MIMETYPE_PDF

The following examples show how to use org.alfresco.repo.content.MimetypeMap#MIMETYPE_PDF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThumbnailServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testCreateRenditionThumbnailFromPdfPage2() throws Exception
{
    ImageTransformationOptions options = new ImageTransformationOptions();
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(new Integer(2));
    pagedSourceOptions.setEndPageNumber(new Integer(2));
    options.addSourceOptions(pagedSourceOptions);
    
    ThumbnailDefinition thumbnailDefinition = new ThumbnailDefinition(MimetypeMap.MIMETYPE_PDF, options, "doclib_2");
    thumbnailService.getThumbnailRegistry().addThumbnailDefinition(thumbnailDefinition);

    checkTransformer();

    NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);

    NodeRef thumbnail0 = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT,
                MimetypeMap.MIMETYPE_IMAGE_JPEG, thumbnailDefinition.getTransformationOptions(), "doclib_2");
    assertNotNull(thumbnail0);
    checkRenditioned(pdfOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "doclib_2", 1)));
    checkRendition("doclib_2", thumbnail0);
    
    // Check the length
    File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", ".jpg");
    ContentReader reader = this.contentService.getReader(thumbnail0, ContentModel.PROP_CONTENT);
    
    long size = reader.getSize();
    reader.getContent(tempFile);
    assertTrue("Page 2 should be blank and less than 4500 bytes. It was "+size+" bytes. tempFile="+tempFile.getPath(), size < 4500);
}
 
Example 2
Source File: PdfBoxContentTransformer.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PdfBoxContentTransformer() {
   super(new String[] {
         MimetypeMap.MIMETYPE_PDF
   });
}
 
Example 3
Source File: ArchiveContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testArchiveToPdf() throws Exception
{
    String sourceMimetype = MimetypeMap.MIMETYPE_ZIP;
    String targetMimetype = MimetypeMap.MIMETYPE_PDF;

    // force Transformers subsystem to start (this will also load the ContentTransformerRegistry - including complex/dynamic pipelines)
    // note: a call to contentService.getTransformer would also do this .. even if transformer cannot be found (returned as null)
    ChildApplicationContextFactory transformersSubsystem = (ChildApplicationContextFactory) ctx.getBean("Transformers");
    transformersSubsystem.start();

    assertNotNull(registry.getTransformer("transformer.complex.ArchiveToPdf"));

    // note: txt -> pdf currently uses OpenOffice/LibreOffice
    if (! isOpenOfficeWorkerAvailable())
    {
        // no connection
        System.err.println("ooWorker not available - skipping testArchiveToPdf !!");
        return;
    }

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    ContentTransformer transformer = serviceRegistry.getContentService().getTransformer(sourceMimetype, targetMimetype);
    assertNotNull(transformer);

    String sourceExtension = mimetypeService.getExtension(sourceMimetype);
    String targetExtension = mimetypeService.getExtension(targetMimetype);

    File zipSourceFile = loadQuickTestFile("zip");
    ContentReader sourceReader = new FileContentReader(zipSourceFile);

    // make a writer for the target file
    File targetFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_"
            + getName() + "_" + sourceExtension + "_", "." + targetExtension);
    ContentWriter targetWriter = new FileContentWriter(targetFile);

    // do the transformation
    sourceReader.setMimetype(sourceMimetype);
    targetWriter.setMimetype(targetMimetype);
    transformer.transform(sourceReader.getReader(), targetWriter);

    ContentReader targetReader = new FileContentReader(targetFile);
    assertTrue(targetReader.getSize() > 0);
}
 
Example 4
Source File: EMLTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test transforming a valid eml file to pdf using complex transformer ("Rfc822ToPdf") - eg. for HTML5 preview
 */
public void testRFC822ToPdf() throws Exception
{
    String sourceMimetype = MimetypeMap.MIMETYPE_RFC822;
    String targetMimetype = MimetypeMap.MIMETYPE_PDF;

    // force Transformers subsystem to start (this will also load the ContentTransformerRegistry - including complex/dynamic pipelines)
    // note: a call to contentService.getTransformer would also do this .. even if transformer cannot be found (returned as null)
    ChildApplicationContextFactory transformersSubsystem = (ChildApplicationContextFactory) ctx.getBean("Transformers");
    transformersSubsystem.start();

    assertNotNull(registry.getTransformer("transformer.complex.Rfc822ToPdf"));

    // note: txt -> pdf currently uses OpenOffice/LibreOffice
    if (! isOpenOfficeWorkerAvailable())
    {
        // no connection
        System.err.println("ooWorker available - skipping testRFC822ToPdf !!");
        return;
    }

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    assertTrue(synchronousTransformClient.isSupported(sourceMimetype, -1, null, targetMimetype, Collections.emptyMap(), null, null));

    String sourceExtension = mimetypeService.getExtension(sourceMimetype);
    String targetExtension = mimetypeService.getExtension(targetMimetype);

    File emlSourceFile = loadQuickTestFile("eml");
    ContentReader sourceReader = new FileContentReader(emlSourceFile);

    // make a writer for the target file
    File targetFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_"
            + getName() + "_" + sourceExtension + "_", "." + targetExtension);
    ContentWriter targetWriter = new FileContentWriter(targetFile);

    // do the transformation
    sourceReader.setMimetype(sourceMimetype);
    targetWriter.setMimetype(targetMimetype);
    synchronousTransformClient.transform(sourceReader, targetWriter, Collections.emptyMap(), null, null);

    ContentReader targetReader = new FileContentReader(targetFile);
    assertTrue(targetReader.getSize() > 0);
}
 
Example 5
Source File: PdfBoxContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Added to test a single transform that appeared to have problems.
 * Commented out once issue was fixed, but left in the code to help with
 * future issues.
 * @throws Exception
 */
public void testPdfToTextConversions() throws Exception
{
    final String sourceMimetype = MimetypeMap.MIMETYPE_PDF;
    final String targetMimetype = MimetypeMap.MIMETYPE_TEXT_PLAIN;
    int transforms = 100;
    final String filename = "svn-book.pdf";
    
    final CountDownLatch doneSignal = new CountDownLatch(transforms);
    
    int threadCount = 8;
    final ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
    long time = System.currentTimeMillis();
    for (int i=0; i<transforms; i++)
        
    {
        threadPool.submit(new Runnable() {
            public void run()
            {
                try
                {
                    pdfToTextTransform(filename, sourceMimetype, targetMimetype);
                    doneSignal.countDown();
                }
                catch (IOException e)
                {
                    threadPool.shutdown();
                    e.printStackTrace();
                }
            }});
        if (i < threadCount)
        {
            Thread.sleep(1000);
        }
    }
    boolean okay = doneSignal.await(100, TimeUnit.SECONDS);
    
    time = System.currentTimeMillis() - time;
    transforms = transforms - (int)doneSignal.getCount();
    String message = "Total time "+time+" ms   "+(transforms > 0 ? "average="+(time/transforms)+" ms" : "")+"  threads="+threadCount+"  transforms="+transforms;
    System.out.println(message);
    
    if (!okay)
    {
        // Before the changes to PDFBox, this would fail having only done about 50 transforms.
        // After the change, this takes about 55 seconds
        fail("********** Transforms did not finish ********** "+message);
    }
}
 
Example 6
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testAspectWithChildAssociationsCreationAndRetrieval() throws Exception
{
    // Create a folder.  This is like the user's home folder, say.
    NodeRef folderNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(BaseNodeServiceTest.NAMESPACE, "UserX-" + GUID.generate()),
            ContentModel.TYPE_FOLDER).getChildRef();
    // Create a document.  This is the actual document uploaded by the user.
    NodeRef fileNodeRef = nodeService.createNode(
            folderNodeRef,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(BaseNodeServiceTest.NAMESPACE, "Uploaded.pdf"),
            ContentModel.TYPE_FOLDER).getChildRef();
    // So, thus far, this is exactly what you have.  Now for the bit to add some renditions.
    // First, we can make some content data pages - spoofed, of course
    List<ContentData> renditionContentPages = new ArrayList<ContentData>(20);
    // This loop is where you will, outside of the transaction, push the page content into the repo
    for(int i = 0; i < 100; i++)
    {
        ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_PDF, 10245, "UTF-8");
        renditionContentPages.add(contentData);
    }
    
    nodeService.addAspect(fileNodeRef, ASPECT_QNAME_TEST_RENDERED, null);
    int pageNumber = 0;
    for (int i = 0; i < 100; i++)
    {
        pageNumber++;
        QName renditionQName = makePageAssocName(pageNumber);
        NodeRef nodeRef = nodeService.createNode(
                fileNodeRef,
                ASSOC_TYPE_QNAME_TEST_RENDITION,
                renditionQName,
                TYPE_QNAME_TEST_RENDITION_PAGE).getChildRef();
        ContentWriter writer = contentService.getWriter(nodeRef, PROP_QNAME_TEST_RENDITION_PAGE_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
        writer.setEncoding("UTF-8");
        writer.putContent("Some content");
    }
    
    // That's it for uploading.  Now we retrieve them.
    if (!nodeService.hasAspect(fileNodeRef, ASPECT_QNAME_TEST_RENDERED))
    {
        // Jump to the original rendition retrieval code
        return;
    }
    // It has the aspect, so it's the new model
    List<ChildAssociationRef> fetchedRenditionChildAssocs = nodeService.getChildAssocs(
            fileNodeRef,
            ASSOC_TYPE_QNAME_TEST_RENDITION,
            RegexQNamePattern.MATCH_ALL);
    assertEquals(
            "We didn't get the correct number of pages back",
            renditionContentPages.size(),
            fetchedRenditionChildAssocs.size());
    // Get page ... 5.  This is to prove that they are ordered.
    ChildAssociationRef fetchedRenditionChildAssoc5 = fetchedRenditionChildAssocs.get(4);
    QName page5QName = makePageAssocName(5);
    assertEquals(
            "Local name of page 5 assoc is not correct",
            page5QName,
            fetchedRenditionChildAssoc5.getQName());
    // Now retrieve page 5 using the NodeService
    List<ChildAssociationRef> fetchedRenditionChildAssocsPage5 = nodeService.getChildAssocs(
            fileNodeRef,
            ASSOC_TYPE_QNAME_TEST_RENDITION,
            page5QName);
    assertEquals("Expected exactly one result", 1, fetchedRenditionChildAssocsPage5.size());
    assertEquals("Targeted page retrieval was not correct",
            page5QName,
            fetchedRenditionChildAssocsPage5.get(0).getQName());
}