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

The following examples show how to use org.alfresco.repo.content.MimetypeMap. These examples are extracted from open source projects. 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
private NodeRef createPdfDocumentAsCurrentlyAuthenticatedUser(final String nodeName)
{
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, nodeName);
    NodeRef result = nodeService.createNode(testFolder, 
                                            ContentModel.ASSOC_CONTAINS, 
                                            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), 
                                            ContentModel.TYPE_CONTENT,
                                            props).getChildRef();
    
    File file = loadQuickPdfFile();

    // Set the content
    ContentWriter writer = contentService.getWriter(result, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
    writer.setEncoding("UTF-8");
    
    writer.putContent(file);
    
    return result;
}
 
Example 2
private void checkTransformer()
{
    AuthenticationUtil.runAs(new RunAsWork<Void>()
    {
        @Override
        public Void doWork() throws Exception
        {
            if (!synchronousTransformClient.isSupported(MimetypeMap.MIMETYPE_IMAGE_JPEG, -1, null, MimetypeMap.MIMETYPE_IMAGE_PNG, Collections.emptyMap(), null, null
            ))
            {
                fail("Image transformer is not working.  Please check your image conversion command setup.");
            }

            return null;
        }
    }, AuthenticationUtil.getAdminUserName());
}
 
Example 3
/**
 * Ensures that the temp locations are cleaned out before the tests start
 */
@Override
public void setUp() throws Exception
{
    // Grab the context, which will normally have been
    //  cached by the ApplicationContextHelper
    ctx = MiscContextTestSuite.getMinimalContext();
    
    this.mimetypeMap = (MimetypeMap) ctx.getBean("mimetypeService");
    this.dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    
    // perform a little cleaning up
    long now = System.currentTimeMillis();
    TempFileProvider.TempFileCleanerJob.removeFiles(now);
    
    TimeZone tz = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(tz);
    // Joda time has already grabbed the JVM zone so re-set it here
    DateTimeZone.setDefault(DateTimeZone.forTimeZone(tz));
}
 
Example 4
/**
 * Ensure that upper and lowercase URLs don't clash
 * @throws Exception
 */
public void testEnsureCaseSensitiveStorage() throws Exception
{
    ContentData contentData = getContentData();
    String contentUrlUpper = contentData.getContentUrl().toUpperCase();
    ContentData contentDataUpper = new ContentData(
            contentUrlUpper, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "UTF-8", new Locale("FR"));
    String contentUrlLower = contentData.getContentUrl().toLowerCase();
    ContentData contentDataLower = new ContentData(
            contentUrlLower, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, "utf-8", new Locale("fr"));
    
    Pair<Long, ContentData> resultPairUpper = create(contentDataUpper);
    getAndCheck(resultPairUpper.getFirst(), contentDataUpper);
    
    Pair<Long, ContentData> resultPairLower = create(contentDataLower);
    getAndCheck(resultPairLower.getFirst(), contentDataLower);
}
 
Example 5
/**
 *  https://issues.alfresco.com/jira/browse/MNT-19682
 *  Test that mimetype is correctly set according to the content
 */
@Test
public void testWriteContentWithMimetypeAndWithoutFilename()
{
    createTestContent(true);
    ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY);
    scriptNode.setScope(getScope());

    ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT);

    InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
    InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8");

    scd.write(inputStreamContent, true, false);
    assertEquals(MimetypeMap.MIMETYPE_APPLICATION_PS, scriptNode.getMimetype());
}
 
Example 6
/**
 * Test transforming a valid eml with nested mimetype multipart/alternative to text
 */
public void testRFC822NestedAlternativeToText() throws Exception
{
    File emlSourceFile = loadQuickTestFile("nested.alternative.eml");
    File txtTargetFile = TempFileProvider.createTempFile("test5", ".txt");
    ContentReader reader = new FileContentReader(emlSourceFile);
    reader.setMimetype(MimetypeMap.MIMETYPE_RFC822);
    ContentWriter writer = new FileContentWriter(txtTargetFile);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);

    transformer.transform(reader, writer);

    ContentReader reader2 = new FileContentReader(txtTargetFile);
    reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    String contentStr = reader2.getContentString();
    assertTrue(contentStr.contains(QUICK_EML_NESTED_ALTERNATIVE_CONTENT));
}
 
Example 7
@Test
public void testContentPropertyComparisons()
{
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    
    // What happens if you do this and the node has no content set yet !!
    
    // Add some content to the node reference
    ContentWriter contentWriter = this.contentService.getWriter(this.nodeRef, ContentModel.PROP_CONTENT, true);
    contentWriter.setEncoding("UTF-8");
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    contentWriter.putContent("This is some test content.");        
    
    // Test matching the mimetype
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_HTML);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));          
}
 
Example 8
@Override
public void setUp() throws Exception
{
    super.setUp();
    extracter = new SlowPdfBoxMetadataExtracter();
    extracter.setDictionaryService(dictionaryService);

    MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits();
    pdfLimit.setMaxConcurrentExtractionsCount(MAX_CONCURENT_EXTRACTIONS);
    pdfLimit.setMaxDocumentSizeMB(MAX_DOC_SIZE_MB);
    Map<String,MetadataExtracterLimits> limits = new HashMap<>();
    limits.put(MimetypeMap.MIMETYPE_PDF,pdfLimit);

    extracter.setMimetypeLimits(limits);
    extracter.setDelay(30*NUMBER_OF_CONCURRENT_THREADS);
    extracter.register();
}
 
Example 9
/**
 * Tests that delayed metadata extraction times out properly for mimetype-specific limits.
 *
 * @throws Exception
 */
@Test
public void testMimetypeSpecificTimeout() throws Exception
{
    long timeoutMs = 1000;

    MetadataExtracterLimits limits = new MetadataExtracterLimits();
    limits.setTimeoutMs(timeoutMs);
    HashMap<String, MetadataExtracterLimits> mimetypeLimits =
            new HashMap<String, MetadataExtracterLimits>(1);
    mimetypeLimits.put(MimetypeMap.MIMETYPE_TEXT_PLAIN, limits);
    ((MockDelayedMetadataExtracter) getExtracter()).setMimetypeLimits(mimetypeLimits);

    File file = AbstractContentTransformerTest.loadNamedQuickTestFile("quick.txt");

    long startTime = (new Date()).getTime();
    extractFromFile(file, MimetypeMap.MIMETYPE_TEXT_PLAIN);
    long extractionTime = (new Date()).getTime() - startTime;

    assertTrue("Metadata extraction took (" + extractionTime + "ms) " +
            "but should have failed with a timeout at " + timeoutMs + "ms",
            extractionTime < (timeoutMs + 50)); // bit of wiggle room for logging, cleanup, etc.
}
 
Example 10
/**
 * Test transforming a chinese non-unicode msg file to
 *  text
 */
public void testNonUnicodeChineseMsgToText() throws Exception
{
    File msgSourceFile = loadQuickTestFile("chinese.msg");
    File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-2", ".txt");
    ContentReader reader = new FileContentReader(msgSourceFile);
    reader.setMimetype(MimetypeMap.MIMETYPE_OUTLOOK_MSG);
    ContentWriter writer = new FileContentWriter(txtTargetFile);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    
    transformer.transform(reader, writer);
    
    ContentReader reader2 = new FileContentReader(txtTargetFile);
    reader2.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    
    // Check the quick text
    String text = reader2.getContentString();
    assertTrue(text.contains(QUICK_CONTENT));
    
    // Now check the non quick parts came out ok
    assertTrue(text.contains("(\u5f35\u6bd3\u502b)"));
    assertTrue(text.contains("\u683c\u5f0f\u6e2c\u8a66 )"));
}
 
Example 11
/**
 * Create a compound set of data representing a single instance of <i>content</i>.
 * <p>
 * In order to ensure data integrity, the {@link #getMimetype() mimetype}
 * must be set if the {@link #getContentUrl() content URL} is set.
 * 
 * @param contentUrl the content URL.  If this value is non-null, then the
 *      <b>mimetype</b> must be supplied.
 * @param mimetype the content mimetype.  This is mandatory if the <b>contentUrl</b> is specified.
 * @param size the content size.
 * @param encoding the content encoding.  This is mandatory if the <b>contentUrl</b> is specified.
 * @param locale the locale of the content (may be <tt>null</tt>).  If <tt>null</tt>, the
 *      {@link I18NUtil#getLocale() default locale} will be used.
 */
public ContentData(String contentUrl, String mimetype, long size, String encoding, Locale locale)
{
    if (contentUrl != null && (mimetype == null || mimetype.length() == 0))
    {
        mimetype = MimetypeMap.MIMETYPE_BINARY;
    }
    checkContentUrl(contentUrl, mimetype, encoding);
    this.contentUrl = contentUrl;
    this.mimetype = mimetype;
    this.size = size;
    this.encoding = encoding;
    if (locale == null)
    {
        locale = I18NUtil.getLocale();
    }
    this.locale = locale;
}
 
Example 12
@Override
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
{
    if (!isAvailable())
    {
        return false;
    }

    // Add limited support (so lots of other transforms are not supported)
    // for PDF to PNG.
    if ((MimetypeMap.MIMETYPE_PDF.equals(sourceMimetype) || MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR.equals(sourceMimetype)) &&
        MimetypeMap.MIMETYPE_IMAGE_PNG.equals(targetMimetype))
    {
        return true;
    }

    return false;
}
 
Example 13
/**
 * This test method ensures that all the 'built-in' renditionDefinitions are
 * available after startup and that their configuration is correct.
 * 
 * @throws Exception
 */
@Test
public void testBuiltinRenditionDefinitions() throws Exception
{
    final RenditionDefinition mediumRenditionDef = loadAndValidateRenditionDefinition("medium");
    final RenditionDefinition doclibRenditionDef = loadAndValidateRenditionDefinition("doclib");
    final RenditionDefinition imgpreviewRenditionDef = loadAndValidateRenditionDefinition("imgpreview");
    final RenditionDefinition webpreviewRenditionDef = loadAndValidateRenditionDefinition("webpreview");
    final RenditionDefinition avatarRenditionDef = loadAndValidateRenditionDefinition("avatar");

    assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, mediumRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, doclibRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_JPEG, imgpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_FLASH, webpreviewRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, avatarRenditionDef.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE));
}
 
Example 14
/**
 *  https://issues.alfresco.com/jira/browse/MNT-19682
 *  Test that mimetype is correctly set according to the filename
 */
@Test
public void testWriteContentWithMimetypeAndFilename()
{
    createTestContent(true);
    ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY);
    scriptNode.setScope(getScope());

    ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT);

    InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
    InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8");

    scd.write(inputStreamContent, true, false, "test.ai");
    assertEquals(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR, scriptNode.getMimetype());
}
 
Example 15
private NodeRef createActiveModel(String contentFile)
{
    PropertyMap properties = new PropertyMap(1);
    properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
    NodeRef modelNode = this.nodeService.createNode(
             this.rootNodeRef,
             ContentModel.ASSOC_CHILDREN,
             QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"),
             ContentModel.TYPE_DICTIONARY_MODEL,
             properties).getChildRef();
     assertNotNull(modelNode);

     ContentWriter contentWriter = this.contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true);
     contentWriter.setEncoding("UTF-8");
     contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
     contentWriter.putContent(Thread.currentThread().getContextClassLoader().getResourceAsStream(contentFile));
     return modelNode;
}
 
Example 16
@Test
public void testInvokeMultiPartEntity() throws IOException
{
    ResourceWithMetadata entityResource = locator.locateEntityResource(api,"multiparttest", HttpMethod.POST);
    assertNotNull(entityResource);
    MultiPartResourceAction.Create<?> resource = (MultiPartResourceAction.Create<?>) entityResource.getResource();

    File file = TempFileProvider.createTempFile("ParamsExtractorTests-", ".txt");
    PrintWriter writer = new PrintWriter(file);
    writer.println("Multipart Mock test2.");
    writer.close();

    MultiPartRequest reqBody = MultiPartBuilder.create()
                .setFileData(new FileData(file.getName(), file, MimetypeMap.MIMETYPE_TEXT_PLAIN))
                .build();

    MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", "");
    mockRequest.setContent(reqBody.getBody());
    mockRequest.setContentType(reqBody.getContentType());

    String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api,null, NOT_USED, resource.create(new FormData(mockRequest), NOT_USED, callBack)));
    assertTrue("There must be json output", StringUtils.startsWith(out, "{\"entry\":"));
}
 
Example 17
@Test
public void testDuplicationNames() throws Exception
{
    checkTransformer();

    NodeRef jpgOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
    ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
    imageResizeOptions.setWidth(64);
    imageResizeOptions.setHeight(64);
    imageResizeOptions.setResizeToThumbnail(true);
    ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions();
    imageTransformationOptions.setResizeOptions(imageResizeOptions);
    // ThumbnailDetails createOptions = new ThumbnailDetails();
    NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT,
                MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "small");
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, 
    		Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "small", 1)));
    checkRendition("small", thumbnail1);

    // the origional thumbnail is returned if we are attempting to create a duplicate
    NodeRef duplicate = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
                    imageTransformationOptions, "small");
    assertNotNull(duplicate);
    assertEquals(duplicate, thumbnail1);
}
 
Example 18
protected static List<String> getDefaultApplicableMimetypes()
{
    List<String> defaults = new ArrayList<String>(17);
    defaults.add(MimetypeMap.MIMETYPE_PDF);
    defaults.add(MimetypeMap.MIMETYPE_WORD);
    defaults.add(MimetypeMap.MIMETYPE_PPT);
    defaults.add(MimetypeMap.MIMETYPE_IMAGE_TIFF);
    defaults.add(MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION);
    defaults.add(MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE);
    defaults.add(MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE);
    defaults.add(MimetypeMap.MIMETYPE_OPENOFFICE1_WRITER);
    defaults.add(MimetypeMap.MIMETYPE_OPENOFFICE1_IMPRESS);
    defaults.add(MimetypeMap.MIMETYPE_OPENXML_PRESENTATION);
    defaults.add(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
    defaults.add(MimetypeMap.MIMETYPE_STAROFFICE5_IMPRESS);
    defaults.add(MimetypeMap.MIMETYPE_STAROFFICE5_IMPRESS_PACKED);
    defaults.add(MimetypeMap.MIMETYPE_STAROFFICE5_WRITER);
    defaults.add(MimetypeMap.MIMETYPE_STAROFFICE5_WRITER_GLOBAL);
    defaults.add(MimetypeMap.MIMETYPE_IWORK_KEYNOTE);
    defaults.add(MimetypeMap.MIMETYPE_IWORK_PAGES);
    defaults.add(MimetypeMap.MIMETYPE_WORDPERFECT);
    return defaults;
}
 
Example 19
@BeforeClass public static void initStaticData() throws Exception
{
    CONTENT_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("ContentService", ContentService.class);
    NODE_SERVICE          = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
    SERVICE_REGISTRY      = APP_CONTEXT_INIT.getApplicationContext().getBean("ServiceRegistry", ServiceRegistry.class);
    TRANSACTION_HELPER    = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    PERMISSION_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("permissionService", PermissionServiceSPI.class);
    SEARCH_SCRIPT         = APP_CONTEXT_INIT.getApplicationContext().getBean("searchScript", Search.class);
    VERSIONABLE_ASPECT    = APP_CONTEXT_INIT.getApplicationContext().getBean("versionableAspect", VersionableAspect.class);
    VERSION_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("VersionService", VersionService.class);
    DICTIONARY_SERVICE    = APP_CONTEXT_INIT.getApplicationContext().getBean("DictionaryService", DictionaryService.class);       
    NAMESPACE_SERVICE     = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
    DICTIONARY_DAO        = APP_CONTEXT_INIT.getApplicationContext().getBean("dictionaryDAO", DictionaryDAO.class);
    TENANT_ADMIN_SERVICE  = APP_CONTEXT_INIT.getApplicationContext().getBean("tenantAdminService", TenantAdminService.class);
    MESSAGE_SERVICE       = APP_CONTEXT_INIT.getApplicationContext().getBean("messageService", MessageService.class);
    TRANSACTION_SERVICE   = APP_CONTEXT_INIT.getApplicationContext().getBean("transactionComponent", TransactionService.class);
    POLICY_COMPONENT      = APP_CONTEXT_INIT.getApplicationContext().getBean("policyComponent", PolicyComponent.class);

    USER_ONES_TEST_SITE = STATIC_TEST_SITES.createTestSiteWithUserPerRole(GUID.generate(), "sitePreset", SiteVisibility.PRIVATE, USER_ONE_NAME);
    USER_ONES_TEST_FILE = STATIC_TEST_NODES.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, USER_ONES_TEST_SITE.doclib, "test.txt", USER_ONE_NAME);		
}
 
Example 20
/**
 * Test for MNT-577: Alfresco is running 100% CPU for over 10 minutes while extracting metadata for Word office document
 * 
 * @throws Exception
 */
public void testFootnotesLimitParameterUsingDefault() throws Exception
{
    PoiMetadataExtracter extractor = (PoiMetadataExtracter) getExtracter();

    File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(PROBLEM_FOOTNOTES_DOCUMENT_NAME);
    ContentReader sourceReader = new FileContentReader(sourceFile);
    sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);

    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    long startTime = System.currentTimeMillis();
    extractor.extract(sourceReader, properties);
    extractionTimeWithDefaultFootnotesLimit = System.currentTimeMillis() - startTime;

    assertExtractedProperties(properties);
    if (extractionTimeWithLargeFootnotesLimit != null)
    {
        assertTrue("The second metadata extraction operation must be longer!", extractionTimeWithLargeFootnotesLimit > extractionTimeWithDefaultFootnotesLimit);
    }
}
 
Example 21
@Override
protected void additionalContentCheck(String sourceMimetype,
     String targetMimetype, String contents) {
   if(targetMimetype.equals(MimetypeMap.MIMETYPE_TEXT_CSV)) {
      assertTrue(
            "Content not properly CSV'd",
            contents.contains("1,2,2")
      );
      assertTrue(
            "Content not properly CSV'd",
            contents.contains("\"The\",\"quick\",\"brown\",\"fox\"")
      );
   } else if(targetMimetype.equals(MimetypeMap.MIMETYPE_XML)) {
      // First check we got the usual bits
      super.additionalContentCheck(sourceMimetype, targetMimetype, contents);
      
      // Now check tables came out correctly
      assertTrue(
            "Content lacks XHTML table tags:\n" + contents,
            contents.contains("<table>")
      );
      assertTrue(
            "Content lacks XHTML table tags:\n" + contents,
            contents.contains("<tr>")
      );
      assertTrue(
            "Content lacks XHTML table tags:\n" + contents,
            contents.contains("<td>1</td>")
      );
      assertTrue(
            "Content lacks XHTML table tags:\n" + contents,
            contents.contains("<td>The</td>")
      );
   } else {
      super.additionalContentCheck(sourceMimetype, targetMimetype, contents);
   }
}
 
Example 22
/**
 * See REPO-2257, MNT-17661
 */
@Test
public void testLastThumbnailModificationDataContentCopy() throws Exception
{
    final NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
    QName qname = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "doclib");

    ThumbnailDefinition details = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(qname.getLocalName());
    NodeRef thumbnail = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
            details.getTransformationOptions(), "doclib");
    assertNotNull(thumbnail);

    TestTransaction.flagForCommit();
    TestTransaction.end();

    Thread.sleep(1000);

    // Get initial value of property "Last thumbnail modification data"
    List<String>lastThumbnailData = (List<String>)this.secureNodeService.getProperty(pdfOrig, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA);
    assertNotNull(lastThumbnailData);
    assertEquals(1, lastThumbnailData.size());
    assertTrue(lastThumbnailData.get(0).contains("doclib:"));

    final NodeRef pdfCopy = copyService.copy(pdfOrig, this.folder, ContentModel.ASSOC_CONTAINS, QName.createQName("copyOfOriginal"));
    List<String> lastThumbnailDataCopy = (List<String>)this.secureNodeService.getProperty(pdfCopy, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA);
    assertNull(lastThumbnailDataCopy);
}
 
Example 23
/**
 * Tests that source nodes with a suitable marker aspect on them are not renditioned.
 * 
 * @since 4.0.1
 */
@Test
public void testSuitablyMarkedNodesDoNotGetRenditioned() throws Exception
{
    this.renditionNode = transactionHelper
        .doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
        {
            public NodeRef execute() throws Throwable
            {
                // Initially the node that provides the content
                // should not have the rn:renditioned aspect on it.
                assertFalse("Source node has unexpected renditioned aspect.", nodeService.hasAspect(
                            nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
                
                //Add the marker aspect to prevent rendition
                nodeService.addAspect(nodeWithImageContent, RenditionModel.ASPECT_PREVENT_RENDITIONS, null);

                RenditionDefinition action = makeReformatAction(null, MimetypeMap.MIMETYPE_TEXT_PLAIN);
                action.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);

                ChildAssociationRef renditionAssoc = null;
                boolean expectedExceptionThrown = false;
                try
                {
                    renditionAssoc = renditionService.render(nodeWithImageContent, action);
                } catch (RenditionServiceException expected)
                {
                    expectedExceptionThrown = true;
                }
                assertTrue("Expected exception was not thrown.", expectedExceptionThrown);
                
                return renditionAssoc == null ? null : renditionAssoc.getChildRef();
            }
        });
}
 
Example 24
public void testDetectedNotInWhiteListRetry() throws IOException
{
    // The retry fails without soffice (which is not available on Bamboo)
    testTransformToJPeg("quick.doc",
        MimetypeMap.MIMETYPE_WORD,
        MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR,
        MimetypeMap.MIMETYPE_WORD,
        RETRY, FAILURE);
}
 
Example 25
public void testIsTransformable() throws Exception
{
    assertFalse(transformer.isTransformable(MimetypeMap.MIMETYPE_TEXT_PLAIN, -1, MimetypeMap.MIMETYPE_PDF, new TransformationOptions()));
    assertTrue(transformer.isTransformable(MimetypeMap.MIMETYPE_PDF, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions()));
    assertTrue(transformer.isTransformable(MimetypeMap.MIMETYPE_PDF, -1, MimetypeMap.MIMETYPE_HTML, new TransformationOptions()));
    assertTrue(transformer.isTransformable(MimetypeMap.MIMETYPE_PDF, -1, MimetypeMap.MIMETYPE_XML, new TransformationOptions()));
}
 
Example 26
public void test20_ALF_12732()
{
    final String tenantDomain1 = TEST_RUN+".one.alf12732";
    
    createTenant(tenantDomain1);
    
    String tenantAdminName = tenantService.getDomainUser(AuthenticationUtil.getAdminUserName(), tenantDomain1);
    
    try
    {
        AuthenticationUtil.setFullyAuthenticatedUser(tenantAdminName); // note: since SiteServiceImpl.setupSitePermissions currently uses getCurrentUserName (rather than runAs)
        
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Object>()
        {
            public Object doWork() throws Exception
            {
                createSite("site1");
                
                NodeRef docLib1Ref = siteService.getContainer("site1", SiteService.DOCUMENT_LIBRARY);
                NodeRef contentRef = addContent(docLib1Ref, "tqbfjotld.txt", "The quick brown fox jumps over the lazy dog", MimetypeMap.MIMETYPE_TEXT_PLAIN);
                
                createSite("site2");
                
                NodeRef docLib2Ref = siteService.getContainer("site2", SiteService.DOCUMENT_LIBRARY);
                
                nodeService.moveNode(contentRef, docLib2Ref, ContentModel.ASSOC_CONTAINS, QName.createQName("tqbfjotld.txt"));
                
                // for Share, called via "move-to.post.json.js" -> ScriptSiteService.cleanSitePermissions
                siteService.cleanSitePermissions(contentRef, null);
                
                return null;
            }
        }, tenantAdminName, tenantDomain1);
    }
    finally
    {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
Example 27
public void testWrongExtensionRetry() throws IOException
{
    testTransformToJPeg("quick-differentMimetype.docx",
        MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING,
        MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING,
        MimetypeMap.MIMETYPE_IMAGE_PNG,
        RETRY, SUCCESS);
}
 
Example 28
public NodeRef writeDestinationReport(String transferName,
        TransferTarget target,
        File tempFile)
{
   
    String title = transferName + "_destination";
    String description = "Transfer Destination Report - target: " + target.getName();
    String name = title + ".xml";
    
    logger.debug("writing destination transfer report " + title);
    logger.debug("parent node ref " + target.getNodeRef());
    
    Map<QName, Serializable> properties = new HashMap<QName, Serializable> ();
    properties.put(ContentModel.PROP_NAME, name);
    properties.put(ContentModel.PROP_TITLE, title);
    properties.put(ContentModel.PROP_DESCRIPTION, description);
    ChildAssociationRef ref = nodeService.createNode(target.getNodeRef(), 
            ContentModel.ASSOC_CONTAINS, 
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), 
            TransferModel.TYPE_TRANSFER_REPORT_DEST, 
            properties);
    
    ContentWriter writer = contentService.getWriter(ref.getChildRef(), 
            ContentModel.PROP_CONTENT, true);
    writer.setLocale(Locale.getDefault());
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    writer.setEncoding(DEFAULT_ENCODING);
    writer.putContent(tempFile);
    
    logger.debug("written " + name + ", " + ref.getChildRef());
    
    return ref.getChildRef();
}
 
Example 29
public void testReliability() throws Exception
{
    if (!this.transformer.getWorker().isAvailable())
    {
        return;
    }
    boolean reliability = transformer.isTransformable(
            MimetypeMap.MIMETYPE_IMAGE_GIF, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions());
    assertEquals("Mimetype should not be supported", false, reliability);
    reliability = transformer.isTransformable(
            MimetypeMap.MIMETYPE_IMAGE_GIF, -1, MimetypeMap.MIMETYPE_IMAGE_JPEG, new TransformationOptions());
    assertEquals("Mimetype should be supported", true, reliability);
}
 
Example 30
public void testIsTransformable() throws Exception
{
    TransformationOptions options = new TransformationOptions();
    boolean reliability = false;
    
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_TEXT_PLAIN, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, options);
    assertFalse("Mimetype should not be supported", reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_XML, -1, MimetypeMap.MIMETYPE_XML, options);
    assertFalse("Mimetype should not be supported", reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_WORD, -1, MimetypeMap.MIMETYPE_WORD, options);
    assertTrue("Mimetype should be supported", reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_EXCEL, -1, MimetypeMap.MIMETYPE_EXCEL, options);
    assertTrue("Mimetype should be supported", reliability);
}