@Override public String getMimetype() { return this.cacheWriter.getMimetype(); }
@Override public String getMimetype() { return this.cacheWriter.getMimetype(); }
@Override public String getMimetype() { return delegatee.getMimetype(); }
@Override public String getMimetype() { return delegatee.getMimetype(); }
/** * Checks if embedding for the mimetype is supported. * * @param writer the writer to check * @throws AlfrescoRuntimeException if embedding for the mimetype is not supported */ protected void checkIsEmbedSupported(ContentWriter writer) { String mimetype = writer.getMimetype(); if (!isEmbeddingSupported(mimetype)) { throw new AlfrescoRuntimeException( "Metadata extracter does not support embedding mimetype: \n" + " writer: " + writer + "\n" + " supported: " + supportedEmbedMimetypes + "\n" + " extracter: " + this); } }
/** * Checks if embedding for the mimetype is supported. * * @param writer the writer to check * @throws AlfrescoRuntimeException if embedding for the mimetype is not supported */ protected void checkIsEmbedSupported(ContentWriter writer) { String mimetype = writer.getMimetype(); if (!isEmbeddingSupported(mimetype)) { throw new AlfrescoRuntimeException( "Metadata extracter does not support embedding mimetype: \n" + " writer: " + writer + "\n" + " supported: " + supportedEmbedMimetypes + "\n" + " extracter: " + this); } }
/** * Returns max and limit values for time, size and pages for a specified source and * target mimetypes, combined with this Transformer's general limits and optionally * the supplied transformation option's limits. */ protected TransformationOptionLimits getLimits(ContentReader reader, ContentWriter writer, TransformationOptions options) { return (reader == null || writer == null) ? transformerConfig.getLimits(this, null, null, options.getUse()).combine(options.getLimits()) : getLimits(reader.getMimetype(), writer.getMimetype(), options); }
/** * Returns max and limit values for time, size and pages for a specified source and * target mimetypes, combined with this Transformer's general limits and optionally * the supplied transformation option's limits. */ protected TransformationOptionLimits getLimits(ContentReader reader, ContentWriter writer, TransformationOptions options) { return (reader == null || writer == null) ? transformerConfig.getLimits(this, null, null, options.getUse()).combine(options.getLimits()) : getLimits(reader.getMimetype(), writer.getMimetype(), options); }
@Test public void encodingAttrsCopiedToBackingStoreWriter() { cachingStore = new CachingContentStore(backingStore, cache, true); ContentContext ctx = ContentContext.NULL_CONTEXT; ContentWriter bsWriter = mock(ContentWriter.class); when(backingStore.getWriter(ctx)).thenReturn(bsWriter); when(bsWriter.getContentUrl()).thenReturn("url"); ContentWriter cacheWriter = mock(ContentWriter.class); when(cache.getWriter("url")).thenReturn(cacheWriter); ContentReader readerFromCacheWriter = mock(ContentReader.class); when(cacheWriter.getReader()).thenReturn(readerFromCacheWriter); when(cacheWriter.getEncoding()).thenReturn("UTF-8"); when(cacheWriter.getLocale()).thenReturn(Locale.UK); when(cacheWriter.getMimetype()).thenReturn("not/real/mimetype"); cachingStore.getWriter(ctx); // Get the stream listener and trigger it ArgumentCaptor<ContentStreamListener> arg = ArgumentCaptor.forClass(ContentStreamListener.class); verify(cacheWriter).addListener(arg.capture()); // Simulate a stream close arg.getValue().contentStreamClosed(); verify(bsWriter).setEncoding("UTF-8"); verify(bsWriter).setLocale(Locale.UK); verify(bsWriter).setMimetype("not/real/mimetype"); }
@Override public ContentWriter getWriter(NodeRef nodeRef) { FileInfo fileInfo = toFileInfo(nodeRef, false); if (fileInfo.isFolder()) { throw new InvalidTypeException("Unable to get a content writer for a folder: " + fileInfo); } final ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); // Ensure that a mimetype is set based on the filename (ALF-6560) // This has been removed from the create code in 3.4 to prevent insert-update behaviour // of the ContentData. if (writer.getMimetype() == null) { final String name = fileInfo.getName(); writer.guessMimetype(name); } // Done return writer; }
String targetMimetype = writer.getMimetype(); if (targetMimetype == null)
@Override public ContentWriter getWriter(NodeRef nodeRef) { FileInfo fileInfo = toFileInfo(nodeRef, false); if (fileInfo.isFolder()) { throw new InvalidTypeException("Unable to get a content writer for a folder: " + fileInfo); } final ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); // Ensure that a mimetype is set based on the filename (ALF-6560) // This has been removed from the create code in 3.4 to prevent insert-update behaviour // of the ContentData. if (writer.getMimetype() == null) { final String name = fileInfo.getName(); writer.guessMimetype(name); } // Done return writer; }
String targetMimetype = writer.getMimetype(); if (targetMimetype == null)
String targetMimetype = writer.getMimetype(); String targetEncoding = writer.getEncoding();
@Test public void canGuessMimeType() { AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); ContentService contentService = (ContentService) ctx.getBean("ContentService"); NodeService nodeService = (NodeService) ctx.getBean("NodeService"); StoreRef storeRef = nodeService.createStore("workspace", getClass().getName()+UUID.randomUUID()); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); NodeRef nodeRef = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getClass().getSimpleName()), ContentModel.TYPE_CONTENT).getChildRef(); ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); // Pre-condition of test is that we're testing with a potentially problematic BackingStoreAwareCacheWriter // rather than a FileContentWriter, which we would expect to work. assertTrue(writer instanceof BackingStoreAwareCacheWriter); String content = "This is some content"; writer.putContent(content); writer.guessMimetype("myfile.txt"); assertEquals("text/plain", writer.getMimetype()); }
public void testDirectTransform() throws Exception { ContentReader reader = writeContent("text/plain", "MacDingbat"); // check transformability assertTrue(transformer.isTransformable(reader.getMimetype(), -1, targetWriter.getMimetype(), new TransformationOptions())); // transform transformer.transform(reader, targetWriter); // get a reader onto the transformed content and check ContentReader checkReader = targetWriter.getReader(); String checkContent = checkReader.getContentString(); assertEquals("Content check failed", SOME_CONTENT, checkContent); }
public void testInterTextTransform() throws Exception { ContentReader reader = writeContent("text/xml", "MacDingbat"); // check transformability assertTrue(transformer.isTransformable(reader.getMimetype(), -1, targetWriter.getMimetype(), new TransformationOptions())); // transform transformer.transform(reader, targetWriter); // get a reader onto the transformed content and check ContentReader checkReader = targetWriter.getReader(); String checkContent = checkReader.getContentString(); assertEquals("Content check failed", SOME_CONTENT, checkContent); }
@Test public void testMimetypAndEncodingAndLocale() throws Exception { ContentWriter writer = getWriter(); // set mimetype and encoding writer.setMimetype("text/plain"); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); // create a UTF-16 string String content = "A little bit o' this and a little bit o' that"; byte[] bytesUtf16 = content.getBytes("UTF-16"); // write the bytes directly to the writer OutputStream os = writer.getContentOutputStream(); os.write(bytesUtf16); os.close(); // now get a reader from the writer ContentReader reader = writer.getReader(); assertEquals("Writer -> Reader content URL mismatch", writer.getContentUrl(), reader.getContentUrl()); assertEquals("Writer -> Reader mimetype mismatch", writer.getMimetype(), reader.getMimetype()); assertEquals("Writer -> Reader encoding mismatch", writer.getEncoding(), reader.getEncoding()); assertEquals("Writer -> Reader locale mismatch", writer.getLocale(), reader.getLocale()); // now get the string directly from the reader String contentCheck = reader.getContentString(); // internally it should have taken care of the encoding assertEquals("Encoding and decoding of strings failed", content, contentCheck); }
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, writer.getMimetype()); assertEquals("UTF-16", writer.getEncoding()); assertEquals(Locale.CHINESE, writer.getLocale()); assertNull(writer.getMimetype()); assertEquals("UTF-8", writer.getEncoding()); assertEquals(Locale.getDefault(), writer.getLocale());
assertNotNull("Writer should not be null", writer); assertNotNull("Content URL should not be null", writer.getContentUrl()); assertNotNull("Content mimetype should not be null", writer.getMimetype()); assertNotNull("Content encoding should not be null", writer.getEncoding()); assertNotNull("Content locale should not be null", writer.getLocale());