org.alfresco.repo.content.filestore.FileContentWriter Java Examples

The following examples show how to use org.alfresco.repo.content.filestore.FileContentWriter. 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: EMLTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test transforming a valid eml file to text
 */
public void testRFC822ToText() throws Exception
{
    File emlSourceFile = loadQuickTestFile("eml");
    File txtTargetFile = TempFileProvider.createTempFile("test", ".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);
    assertTrue(reader2.getContentString().contains(QUICK_EML_CONTENT));
}
 
Example #2
Source File: CompressingContentWriter.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
protected void cleanupTemporaryContent()
{
    // check if we can trigger eager clean up
    // (standard temp lifetime of between 1:00 and 1:59 hours just causes too much build-up)
    if (this.temporaryWriter instanceof FileContentWriter)
    {
        final File tempFile = ((FileContentWriter) this.temporaryWriter).getFile();
        if (tempFile.exists() && !tempFile.delete())
        {
            tempFile.deleteOnExit();
        }
    }
    else
    {
        try
        {
            this.temporaryContentStore.delete(this.temporaryWriter.getContentUrl());
        }
        catch (final UnsupportedOperationException uoe)
        {
            LOGGER.debug("Temporary content store does not support delete", uoe);
        }
    }
}
 
Example #3
Source File: DeduplicatingContentWriter.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
protected void cleanupTemporaryContent()
{
    // check if we can trigger eager clean up
    // (standard temp lifetime of between 1:00 and 1:59 hours just causes too much build-up)
    if (this.temporaryWriter instanceof FileContentWriter)
    {
        final File tempFile = ((FileContentWriter) this.temporaryWriter).getFile();
        if (tempFile.exists() && !tempFile.delete())
        {
            tempFile.deleteOnExit();
        }
    }
    else
    {
        try
        {
            this.temporaryContentStore.delete(this.temporaryWriter.getContentUrl());
        }
        catch (final UnsupportedOperationException uoe)
        {
            LOGGER.debug("Temporary content store does not support delete", uoe);
        }
    }
}
 
Example #4
Source File: XmlMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testDITAFileWithoutDoctype() throws Exception
{
    // Munge the file to skip the doctype
    ContentReader reader = getReader(FILE_DITA_FILE);
    assertTrue(reader.exists());
    String contents = reader.getContentString();
    String noDocType = contents.replaceAll("<!DOCTYPE.*?>", "");
    
    File tmp = File.createTempFile("alfresco", ".xml");
    tmp.deleteOnExit();
    ContentWriter w = new FileContentWriter(tmp);
    w.setEncoding(reader.getEncoding());
    w.setMimetype(reader.getMimetype());
    w.putContent(noDocType);
            
    // Now test extraction
    doTestDITAFile(w.getReader());
}
 
Example #5
Source File: AbstractMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testZeroLengthFile() throws Exception
{
    MetadataExtracter extractor = getExtracter();
    File file = TempFileProvider.createTempFile(getName(), ".bin");
    ContentWriter writer = new FileContentWriter(file);
    writer.getContentOutputStream().close();
    ContentReader reader = writer.getReader();
    // Try the zero length file against all supported mimetypes.
    // Note: Normally the reader would need to be fetched for each access, but we need to be sure
    // that the content is not accessed on the reader AT ALL.
    PropertyMap properties = new PropertyMap();
    List<String> mimetypes = mimetypeMap.getMimetypes();
    for (String mimetype : mimetypes)
    {
        if (!extractor.isSupported(mimetype))
        {
            // Not interested
            continue;
        }
        reader.setMimetype(mimetype);
        extractor.extract(reader, properties);
        assertEquals("There should not be any new properties", 0, properties.size());
    }
}
 
Example #6
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 a html part containing html special characters to text
 */
public void testHtmlSpecialCharsToText() throws Exception
{
    File emlSourceFile = loadQuickTestFile("htmlChars.eml");
    File txtTargetFile = TempFileProvider.createTempFile("test6", ".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(HTML_SPACE_SPECIAL_CHAR));
}
 
Example #7
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 #8
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 minetype multipart/alternative to text
 */
public void testRFC822AlternativeToText() throws Exception
{
    File emlSourceFile = loadQuickTestFile("alternative.eml");
    File txtTargetFile = TempFileProvider.createTempFile("test4", ".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_ALTERNATIVE_CONTENT));
}
 
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 an attachment to text; attachment should be ignored
 */
public void testRFC822WithAttachmentToText() throws Exception
{
    File emlSourceFile = loadQuickTestFile("attachment.eml");
    File txtTargetFile = TempFileProvider.createTempFile("test3", ".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_WITH_ATTACHMENT_CONTENT));
    assertTrue(!contentStr.contains(QUICK_EML_ATTACHMENT_CONTENT));
}
 
Example #10
Source File: EMLTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test transforming a non-ascii eml file to text
 */
public void testNonAsciiRFC822ToText() throws Exception
{
    File emlSourceFile = loadQuickTestFile("spanish.eml");
    File txtTargetFile = TempFileProvider.createTempFile("test2", ".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_CONTENT_SPANISH_UNICODE));
}
 
Example #11
Source File: MediaWikiContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testMediaWikiToHTML() throws Exception
{
   File input = TempFileProvider.createTempFile("mediaWikiTest", ".mw");
   FileOutputStream fos = new FileOutputStream(input);
   fos.write(WIKI_TEXT.getBytes());
   fos.close();
   
   File output = TempFileProvider.createTempFile("mediaWikiTest", ".htm");
   
   ContentReader contentReader = new FileContentReader(input);
   contentReader.setMimetype(MimetypeMap.MIMETYPE_TEXT_MEDIAWIKI);
   contentReader.setEncoding("UTF-8");
   
   ContentWriter contentWriter = new FileContentWriter(output);
   contentWriter.setMimetype(MimetypeMap.MIMETYPE_HTML);
   contentWriter.setEncoding("UTF-8");
   
   transformer.transform(contentReader, contentWriter);
   
   String line = null;
   BufferedReader reader = new BufferedReader(new FileReader(output));
   while ((line = reader.readLine()) != null) 
   {
       System.out.println(line);
   }
}
 
Example #12
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 #13
Source File: MailContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test transforming a valid unicode msg file to text
 */
public void testUnicodeMsgToText() throws Exception
{
    File msgSourceFile = loadQuickTestFile("unicode.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);
    assertTrue(reader2.getContentString().contains(QUICK_CONTENT));
}
 
Example #14
Source File: MailContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test transforming a valid msg file to text
 */
public void testMsgToText() throws Exception
{
    File msgSourceFile = loadQuickTestFile("msg");
    File txtTargetFile = TempFileProvider.createTempFile(getName() + "-target-1", ".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);
    assertTrue(reader2.getContentString().contains(QUICK_CONTENT));
}
 
Example #15
Source File: OpenOfficeContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test what is up with HTML to PDF
 */
public void testHtmlToPdf() throws Exception
{
    if (!isOpenOfficeWorkerAvailable())
    {
        // no connection
        System.err.println("ooWorker not available - skipping testHtmlToPdf !!");
        return;
    }
    File htmlSourceFile = loadQuickTestFile("html");
    File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf");
    ContentReader reader = new FileContentReader(htmlSourceFile);
    reader.setMimetype(MimetypeMap.MIMETYPE_HTML);
    ContentWriter writer = new FileContentWriter(pdfTargetFile);
    writer.setMimetype(MimetypeMap.MIMETYPE_PDF);

    transformer.transform(reader, writer);
}
 
Example #16
Source File: PoiHssfContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testCsvOutput() throws Exception
{
   File sourceFile = AbstractContentTransformerTest.loadQuickTestFile("xls");
   ContentReader sourceReader = new FileContentReader(sourceFile);

   File targetFile = TempFileProvider.createTempFile(
         getClass().getSimpleName() + "_" + getName() + "_xls_",
         ".csv");
   ContentWriter targetWriter = new FileContentWriter(targetFile);
   
   sourceReader.setMimetype(MimetypeMap.MIMETYPE_EXCEL);
   targetWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_CSV);
   transformer.transform(sourceReader, targetWriter);
   
   ContentReader targetReader = targetWriter.getReader();
   String checkContent = targetReader.getContentString();
   
   additionalContentCheck(
         MimetypeMap.MIMETYPE_EXCEL, 
         MimetypeMap.MIMETYPE_TEXT_CSV, 
         checkContent
   );
}
 
Example #17
Source File: RuntimeExecutableContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testCopyCommand() throws Exception
{
    String content = "<A><B></B></A>";
    // create the source
    File sourceFile = TempFileProvider.createTempFile(getName() + "_", ".txt");
    ContentWriter tempWriter = new FileContentWriter(sourceFile);
    tempWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    tempWriter.putContent(content);
    ContentReader reader = tempWriter.getReader(); 
    // create the target
    File targetFile = TempFileProvider.createTempFile(getName() + "_", ".xml");
    ContentWriter writer = new FileContentWriter(targetFile);
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    
    // do the transformation
    transformer.transform(reader, writer);   // no options on the copy
    
    // make sure that the content was copied over
    ContentReader checkReader = writer.getReader();
    String checkContent = checkReader.getContentString();
    assertEquals("Content not copied", content, checkContent);
}
 
Example #18
Source File: OpenOfficeContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * ALF-219. Transforamtion from .html to .pdf for empty file.
 * @throws Exception
 */
// The test was never run and fails on remote transformer
public void ignoreTestEmptyHtmlToEmptyPdf() throws Exception
{
    if (!isOpenOfficeWorkerAvailable())
    {
        // no connection
        System.err.println("ooWorker not available - skipping testEmptyHtmlToEmptyPdf !!");
        return;
    }
    URL url = this.getClass().getClassLoader().getResource("misc/empty.html");
    assertNotNull("URL was unexpectedly null", url);

    File htmlSourceFile = new File(url.getFile());
    assertTrue("Test file does not exist.", htmlSourceFile.exists());
    
    File pdfTargetFile = TempFileProvider.createTempFile(getName() + "-target-", ".pdf");
    
    ContentReader reader = new FileContentReader(htmlSourceFile);
    reader.setMimetype(MimetypeMap.MIMETYPE_HTML);
    ContentWriter writer = new FileContentWriter(pdfTargetFile);
    writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
    
    transformer.transform(reader, writer);
}
 
Example #19
Source File: StringExtractingContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    super.setUp();

    transformer = new StringExtractingContentTransformer();
    transformer.setMimetypeService(mimetypeService);
    transformer.setTransformerDebug(transformerDebug);
    transformer.setTransformerConfig(transformerConfig);
    targetWriter = new FileContentWriter(getTempFile());
    targetWriter.setMimetype("text/plain");
    targetWriter.setEncoding("UTF-8");
    transformer.afterPropertiesSet();
}
 
Example #20
Source File: AdminUiTransformerDebug.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String runWithinTransaction(String sourceExtension, String targetExtension)
{
    String targetMimetype = getMimetype(targetExtension, false);
    String sourceMimetype = getMimetype(sourceExtension, true);
    File tempFile = TempFileProvider.createTempFile(
            "TestTransform_" + sourceExtension + "_", "." + targetExtension);
    ContentWriter writer = new FileContentWriter(tempFile);
    writer.setMimetype(targetMimetype);

    NodeRef sourceNodeRef = null;
    StringBuilder sb = new StringBuilder();
    try
    {
        setStringBuilder(sb);
        sourceNodeRef = createSourceNode(sourceExtension, sourceMimetype);
        ContentReader reader = contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
        SynchronousTransformClient synchronousTransformClient = getSynchronousTransformClient();
        Map<String, String> actualOptions = Collections.emptyMap();
        synchronousTransformClient.transform(reader, writer, actualOptions, null, sourceNodeRef);
    }
    catch (Exception e)
    {
        logger.debug("Unexpected test transform error", e);
    }
    finally
    {
        setStringBuilder(null);
        deleteSourceNode(sourceNodeRef);
    }
    return sb.toString();
}
 
Example #21
Source File: EMLTransformer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Finds text on a given mail part. Accepted parts types are text/html and text/plain.
 * Attachments are ignored
 * 
 * @param part
 * @param sb
 * @throws IOException
 * @throws MessagingException
 */
private void processPart(Part part, StringBuilder sb) throws IOException, MessagingException
{
    boolean isAttachment = Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition());
    if (isAttachment)
    {
        return;
    }
    if (part.getContentType().contains(MimetypeMap.MIMETYPE_TEXT_PLAIN))
    {
        sb.append(part.getContent().toString());
    }
    else if (part.getContentType().contains(MimetypeMap.MIMETYPE_HTML))
    {
        String mailPartContent = part.getContent().toString();
        
        //create a temporary html file with same mail part content and encoding
        File tempHtmlFile = TempFileProvider.createTempFile("EMLTransformer_", ".html");
        ContentWriter contentWriter = new FileContentWriter(tempHtmlFile);
        contentWriter.setEncoding(getMailPartContentEncoding(part));
        contentWriter.setMimetype(MimetypeMap.MIMETYPE_HTML);
        contentWriter.putContent(mailPartContent);
        
        //transform html file's content to plain text
        EncodingAwareStringBean extractor = new EncodingAwareStringBean();
        extractor.setCollapse(false);
        extractor.setLinks(false);
        extractor.setReplaceNonBreakingSpaces(false);
        extractor.setURL(tempHtmlFile, contentWriter.getEncoding());
        sb.append(extractor.getStrings());
        
        tempHtmlFile.delete();
    }
}
 
Example #22
Source File: ContentWriterFacade.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
protected SpoofStreamListener(final ContentWriter actualWriter, final WritableByteChannel writableChannel,
        final FileContentWriter spoofWriter)
{
    this.actualWriter = actualWriter;
    this.writableChannel = writableChannel;
    this.spoofWriter = spoofWriter;
}
 
Example #23
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void DISABLED_testBasicFileOps()
{
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    // create folder
    Map<String,String> folderProps = new HashMap<String, String>();
    {
        folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate());
    }
    Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext());
    
    Map<String, String> fileProps = new HashMap<String, String>();
    {
        fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt"));
        writer.putContent("Ipsum and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    folder.createDocument(fileProps, fileContent, VersioningState.MAJOR);
}
 
Example #24
Source File: MappingMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see <a href="https://issues.alfresco.com/jira/browse/MNT-13919">MNT-13919</a>
 */
public void testEmbedSupportDifferentFromExtract()
{
    DummyMetadataEmbedder embedder = new DummyMetadataEmbedder();
    Map<QName, Serializable> propertiesToEmbed = new HashMap<QName, Serializable>();
    
    // make a writer for the target of the embed, we won't actually use it
    File targetFile = TempFileProvider.createTempFile(
            getClass().getSimpleName() + "_" + getName() + "_embed",
            ".txt");
    FileContentWriter writer = new FileContentWriter(targetFile);
    writer.setMimetype(DummyMetadataEmbedder.MIMETYPE_EMBEDDABLE);
    
    try
    {
        embedder.embed(propertiesToEmbed, reader, writer);
    }
    catch (AlfrescoRuntimeException e)
    {
        if (e.getMessage().contains("Metadata extracter does not support embedding mimetype"))
        {
            fail("Embed mimetype should not be tied to extracter's extract mimetypes");
        }
        else
        {
            fail(e.getMessage());
        }
    }
    finally
    {
        if (targetFile != null && targetFile.exists())
        {
            targetFile.delete();
        }
    }
}
 
Example #25
Source File: ContentStoreCleanerScalabilityRunner.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns a writer to a thread-unique file.  It's always the same file per thread so you must
 * use and close the writer before getting another.
 */
@Override
protected ContentWriter getWriterInternal(ContentReader existingContentReader, String newContentUrl)
{
    File file = hammeredFile.get();
    if (file == null)
    {
        file = TempFileProvider.createTempFile("NullContentStore", ".txt");
        hammeredFile.set(file);
    }
    return new FileContentWriter(file);
}
 
Example #26
Source File: ContentCacheImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void getWriter()
{
    final String url = "store://some/url.bin";
    
    FileContentWriter writer = (FileContentWriter) contentCache.getWriter(url);
    writer.putContent("Some test content for " + getClass().getName());
    
    assertEquals(url, writer.getContentUrl());
    // Check cached item is recorded properly in cache
    Mockito.verify(lookupTable).put(Key.forUrl(url), writer.getFile().getAbsolutePath());
    Mockito.verify(lookupTable).put(Key.forCacheFile(writer.getFile().getAbsolutePath()), url);
}
 
Example #27
Source File: TestCenteraLikeContentStore.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ContentWriter getWriterInternal(ContentReader existingContentReader, String newContentUrl)
{
    FileContentWriter fileContentWriter = (FileContentWriter)super.getWriterInternal(existingContentReader, newContentUrl);
    
    return new TestCenteraLikeContentWriter(fileContentWriter.getFile(), fileContentWriter.getContentUrl(), existingContentReader);
}
 
Example #28
Source File: StringExtractingContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Generate a large file and then transform it using the text extractor.
 * We are not creating super-large file (1GB) in order to test the transform
 * as it takes too long to create the file in the first place.  Rather,
 * this test can be used during profiling to ensure that memory is not
 * being consumed.
 */
public void testLargeFileStreaming() throws Exception
{
    File sourceFile = TempFileProvider.createTempFile(getName(), ".txt");

    int chars = 1000000;  // a million characters should do the trick
    Random random = new Random();

    Writer charWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(sourceFile)));
    for (int i = 0; i < chars; i++)
    {
        char next = (char)(random.nextDouble() * 93D + 32D);
        charWriter.write(next);
    }
    charWriter.close();

    // get a reader and a writer
    ContentReader reader = new FileContentReader(sourceFile);
    reader.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);

    File outputFile = TempFileProvider.createTempFile(getName(), ".txt");
    ContentWriter writer = new FileContentWriter(outputFile);
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);

    // transform
    transformer.transform(reader, writer);

    // delete files
    sourceFile.delete();
    outputFile.delete();
}
 
Example #29
Source File: StringExtractingContentTransformerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes some content using the mimetype and encoding specified.
 *
 * @param mimetype String
 * @param encoding String
 * @return Returns a reader onto the newly written content
 */
private ContentReader writeContent(String mimetype, String encoding)
{
    ContentWriter writer = new FileContentWriter(getTempFile());
    writer.setMimetype(mimetype);
    writer.setEncoding(encoding);
    // put content
    writer.putContent(SOME_CONTENT);
    // return a reader onto the new content
    return writer.getReader();
}
 
Example #30
Source File: ScriptExecutorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void executeScriptUrl(Connection connection, String scriptUrl) throws Exception
{
    Dialect dialect = this.dialect;
    String dialectStr = dialect.getClass().getSimpleName();
    InputStream scriptInputStream = getScriptInputStream(dialect.getClass(), scriptUrl);
    // check that it exists
    if (scriptInputStream == null)
    {
        throw AlfrescoRuntimeException.create(ERR_SCRIPT_NOT_FOUND, scriptUrl);
    }
    // write the script to a temp location for future and failure reference
    File tempFile = null;
    try
    {
        tempFile = TempFileProvider.createTempFile("AlfrescoSchema-" + dialectStr + "-Update-", ".sql");
        ContentWriter writer = new FileContentWriter(tempFile);
        writer.putContent(scriptInputStream);
    }
    finally
    {
        try { scriptInputStream.close(); } catch (Throwable e) {}  // usually a duplicate close
    }
    // now execute it
    String dialectScriptUrl = scriptUrl.replaceAll(DialectUtil.PLACEHOLDER_DIALECT, dialect.getClass().getName());
    // Replace the script placeholders
    executeScriptFile(connection, tempFile, dialectScriptUrl);
}