org.alfresco.repo.content.MimetypeMap Java Examples

The following examples show how to use org.alfresco.repo.content.MimetypeMap. 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: ScriptNodeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 7 votes vote down vote up
@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 #2
Source File: CompareMimeTypeEvaluatorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: ScriptNodeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *  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 #4
Source File: ThumbnailServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: PagedSourceOptions.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #6
Source File: ContentDataDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #7
Source File: ConcurrencyPdfBoxMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: MetadataExtracterLimitsTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #9
Source File: EMLTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #10
Source File: AbstractMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #11
Source File: MailContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #12
Source File: QuickShareRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #13
Source File: PoiMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #14
Source File: MultiUserRenditionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #15
Source File: AlfrescoPdfRendererContentTransformerWorker.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #16
Source File: ContentData.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #17
Source File: RenditionServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #18
Source File: ScriptNodeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *  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 #19
Source File: SerializeTests.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #20
Source File: DictionaryModelTypeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #21
Source File: CompressingContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
@Test
public void mimetypeRestrictedCompression() throws Exception
{
    final DictionaryService dictionaryService = EasyMock.mock(DictionaryService.class);

    final CompressingContentStore compressingContentStore = new CompressingContentStore();
    compressingContentStore.setNamespaceService(PREFIX_RESOLVER);
    compressingContentStore.setDictionaryService(dictionaryService);
    compressingContentStore.setMimetypesToCompress(Arrays.asList(MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_XML));

    final FileContentStore fileContentStore = new FileContentStore();
    fileContentStore.setRootDirectory(backingStoreFolder.getAbsolutePath());
    fileContentStore.setProtocol("store");
    compressingContentStore.setBackingStore(fileContentStore);

    final FileContentStore temporaryContentStore = new FileContentStore();
    temporaryContentStore.setRootDirectory(temporaryStoreFolder.getAbsolutePath());
    temporaryContentStore.setProtocol("store");
    compressingContentStore.setTemporaryStore(temporaryContentStore);

    fileContentStore.afterPropertiesSet();
    temporaryContentStore.afterPropertiesSet();
    compressingContentStore.afterPropertiesSet();

    testCompressableMimetype(compressingContentStore, fileContentStore, MimetypeMap.MIMETYPE_TEXT_PLAIN, CompressorStreamFactory.GZIP);
    testCompressableMimetype(compressingContentStore, fileContentStore, MimetypeMap.MIMETYPE_XML, CompressorStreamFactory.GZIP);
    testUncompressableMimetype(compressingContentStore, fileContentStore, MimetypeMap.MIMETYPE_PDF);
}
 
Example #22
Source File: DifferrentMimeTypeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testDetectedInWhiteList() throws IOException
{
    // The transformer can read the file as a pdf and does not know the node had the wrong mimetype.
    testTransformToJPeg("quickCS5.ai",
        MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR,
        MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR,
        MimetypeMap.MIMETYPE_PDF,
        NEITHER, SUCCESS);
}
 
Example #23
Source File: JodMetadataExtractorOOoTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Map<QName, Serializable> extractFromMimetype() throws Exception
{
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    
    // attempt to get a source file for each mimetype
    File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("doc");
    if (sourceFile == null)
    {
        throw new FileNotFoundException("No quick.doc file found for test");
    }

    // construct a reader onto the source file
    ContentReader sourceReader = new FileContentReader(sourceFile);
    sourceReader.setMimetype(MimetypeMap.MIMETYPE_WORD);
    
    OpenOfficeMetadataWorker worker = (OpenOfficeMetadataWorker) ctx.getBean("extracter.worker.JodConverter");
    
    Set<String> supportedTypes = new HashSet<String>();
    supportedTypes.add(MimetypeMap.MIMETYPE_WORD);
    JodConverterMetadataExtracter extracter = new JodConverterMetadataExtracter(supportedTypes);
    extracter.setMimetypeService(serviceRegistry.getMimetypeService());
    extracter.setDictionaryService(serviceRegistry.getDictionaryService());
    extracter.setWorker(worker);

    extracter.init();

    extracter.extract(sourceReader, properties);
    return properties;
}
 
Example #24
Source File: ComplexContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testReliability() throws Exception
{
    if (!isAvailable)
    {
        return;
    }
    boolean reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_PPT, -1, MimetypeMap.MIMETYPE_PDF, new TransformationOptions());
    assertEquals("Mimetype should not be supported", false, reliability);
    reliability = transformer.isTransformable(MimetypeMap.MIMETYPE_PPT, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions());
    assertEquals("Mimetype should be supported", true, reliability);
}
 
Example #25
Source File: DifferrentMimeTypeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testWrongExtensionStrict() throws IOException
{
    testTransformToJPeg("quick-differentMimetype.docx",
        MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING,
        MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING,
        MimetypeMap.MIMETYPE_IMAGE_PNG,
        STRICT, FAILURE);
}
 
Example #26
Source File: EMLTransformer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Finds the suitable part from an multipart/alternative and appends it's text content to StringBuilder sb
 * 
 * @param multipart
 * @param sb
 * @throws IOException
 * @throws MessagingException
 */
private void processAlternativeMultipart(Multipart multipart, StringBuilder sb) throws IOException, MessagingException
{
    Part partToUse = null;
    for (int i = 0, n = multipart.getCount(); i < n; i++)
    {
        Part part = multipart.getBodyPart(i);
        if (part.getContentType().contains(MimetypeMap.MIMETYPE_TEXT_PLAIN))
        {
            partToUse = part;
            break;
        }
        else if  (part.getContentType().contains(MimetypeMap.MIMETYPE_HTML))
        {
            partToUse = part;
        } 
        else if (part.getContentType().contains(MimetypeMap.MIMETYPE_MULTIPART_ALTERNATIVE))
        {
            if (part.getContent() instanceof Multipart)
            {
                processAlternativeMultipart((Multipart) part.getContent(), sb);
            }
        }
    }
    if (partToUse != null)
    {
        processPart(partToUse, sb);
    }
}
 
Example #27
Source File: MetadataExtracterLimitsTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Tests that delayed metadata extraction completes properly for unlimited timeout.
 *
 * @throws Exception
 */
@Test
public void testUnlimitedTimeout() throws Exception
{
    File file = AbstractContentTransformerTest.loadNamedQuickTestFile("quick.txt");

    Map<QName, Serializable> properties = extractFromFile(file, MimetypeMap.MIMETYPE_TEXT_PLAIN);

    assertEquals("value1", properties.get(QName.createQName("http://DummyMappingMetadataExtracter", "a1")));
}
 
Example #28
Source File: ScriptNodeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create test content, can be versionable.
 * @param versionable boolean
 */
private void createTestContent(boolean versionable)
{
    Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    NodeRef companyHome = repositoryHelper.getCompanyHome();
     
    // Create some test content
    testNode = testNodes.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, companyHome, "userOnesDoc", TEST_USER1.getUsername(), versionable);
}
 
Example #29
Source File: LocalPassThroughTransform.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean isToText(String sourceMimetype, String targetMimetype)
{
    return (targetMimetype.equals(MimetypeMap.MIMETYPE_TEXT_PLAIN) &&
            sourceMimetype.startsWith(MimetypeMap.PREFIX_TEXT)) ||
            sourceMimetype.equals(MimetypeMap.MIMETYPE_JAVASCRIPT) ||
            sourceMimetype.equals(MimetypeMap.MIMETYPE_DITA);
}
 
Example #30
Source File: LocalPassThroughTransform.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Transformer getConfig(List<String> mimetypes)
{
    Set<SupportedSourceAndTarget> supportedSourceAndTargetList = new HashSet();
    for (String mimetype: mimetypes)
    {
        supportedSourceAndTargetList.add(new SupportedSourceAndTarget(mimetype, mimetype, -1, 20));
        if (isToText(mimetype, mimetype))
        {
            supportedSourceAndTargetList.add(new SupportedSourceAndTarget(mimetype, MimetypeMap.MIMETYPE_TEXT_PLAIN, -1, 20));
        }
    }
    return Transformer.builder().withTransformerName(LocalPassThroughTransform.NAME).
            withSupportedSourceAndTargetList(supportedSourceAndTargetList).build();
}