@Override public void setLocale(Locale locale) { delegatee.setLocale(locale); }
@Override public void setLocale(Locale locale) { this.cacheWriter.setLocale(locale); }
@Override public void setLocale(Locale locale) { this.cacheWriter.setLocale(locale); }
@Override public void setLocale(Locale locale) { delegatee.setLocale(locale); }
writer.setLocale(Locale.getDefault()); writer.setMimetype(MimetypeMap.MIMETYPE_XML); writer.setEncoding(DEFAULT_ENCODING);
@Override public Void execute() throws Throwable { ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); return null; } };
@Override public Void execute() throws Throwable { ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_UPDATE_STRING); return null; } };
@Override public Void execute() throws Throwable { ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.setEncoding(CONTENT_ENCODING); writer.putContent(testContext.contentString); return null; } };
@Override public Void execute() throws Throwable { Serializable modifiedDate = nodeService.getProperty(testContext.contentNodeRef, ContentModel.PROP_MODIFIED); if(modifiedDate instanceof Date) { logger.debug("srcModified: " + SDF.format(modifiedDate)); } ContentWriter writer = contentService.getWriter(testContext.contentNodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.setEncoding(CONTENT_ENCODING); writer.putContent(CONTENT_STRING); return null; } };
@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 void contentStreamClosed() throws ContentIOException { // Finished writing to the cache, so copy to the backing store - // ensuring that the encoding attributes are set to the same as for the cache writer. bsWriter.setEncoding(cacheWriter.getEncoding()); bsWriter.setLocale(cacheWriter.getLocale()); bsWriter.setMimetype(cacheWriter.getMimetype()); bsWriter.putContent(cacheWriter.getReader()); boolean contentUrlChanged = !url.equals(bsWriter.getContentUrl()); // MNT-11758 fix, re-cache files for which content url has changed after write to backing store (e.g. XAM, Centera) if (!quota.afterWritingCacheFile(cacheWriter.getSize()) || contentUrlChanged) { if (contentUrlChanged) { // MNT-11758 fix, cache file with new and correct contentUrl after write operation to backing store completed cache.put(bsWriter.getContentUrl(), cacheWriter.getReader()); } // Quota manager has requested that the new cache file is not kept. cache.deleteFile(url); cache.remove(url); } } });
@Override public void contentStreamClosed() throws ContentIOException { // Finished writing to the cache, so copy to the backing store - // ensuring that the encoding attributes are set to the same as for the cache writer. bsWriter.setEncoding(cacheWriter.getEncoding()); bsWriter.setLocale(cacheWriter.getLocale()); bsWriter.setMimetype(cacheWriter.getMimetype()); bsWriter.putContent(cacheWriter.getReader()); boolean contentUrlChanged = !url.equals(bsWriter.getContentUrl()); // MNT-11758 fix, re-cache files for which content url has changed after write to backing store (e.g. XAM, Centera) if (!quota.afterWritingCacheFile(cacheWriter.getSize()) || contentUrlChanged) { if (contentUrlChanged) { // MNT-11758 fix, cache file with new and correct contentUrl after write operation to backing store completed cache.put(bsWriter.getContentUrl(), cacheWriter.getReader()); } // Quota manager has requested that the new cache file is not kept. cache.deleteFile(url); cache.remove(url); } } });
@Override public Void execute() throws Throwable { for(int i = 0; i < 100; i++) { ChildAssociationRef child = nodeService.createNode(testContext.nodeABA, ContentModel.ASSOC_CONTAINS, QName.createQName(GUID.generate() + i), ContentModel.TYPE_CONTENT); NodeRef nodeX = child.getChildRef(); nodeService.setProperty(nodeX , ContentModel.PROP_TITLE, CONTENT_TITLE + i); nodeService.setProperty(nodeX , ContentModel.PROP_NAME, CONTENT_NAME +i); nodes.add(nodeX); ContentWriter writer = contentService.getWriter(nodeX, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING + i); } return null; } };
@Override public Void execute() throws Throwable { ChildAssociationRef child = nodeService.createNode(testData.A1NodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("A3"), ContentModel.TYPE_CONTENT); testData.A3NodeRef = child.getChildRef(); nodeService.setProperty(testData.A3NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.A3NodeRef, ContentModel.PROP_NAME, "A3"); ContentWriter writer = contentService.getWriter(testData.A3NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); return null; } });
@Override public Void execute() throws Throwable { testData.destNodeRef = testNodeFactory.getMappedNodeRef(testData.A1NodeRef); ChildAssociationRef child = nodeService.createNode(testData.destNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("B9"), ContentModel.TYPE_CONTENT); testData.B9NodeRef = child.getChildRef(); nodeService.setProperty(testData.B9NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.B9NodeRef, ContentModel.PROP_NAME, "B9"); ContentWriter writer = contentService.getWriter(testData.B9NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); return null; } });
@Override public Void execute() throws Throwable { testData.destNodeRef = testNodeFactory.getMappedNodeRef(testData.A6NodeRef); ChildAssociationRef child = nodeService.createNode(testData.destNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("B13"), ContentModel.TYPE_CONTENT); testData.B13NodeRef = child.getChildRef(); nodeService.setProperty(testData.B13NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.B13NodeRef, ContentModel.PROP_NAME, "B13"); ContentWriter writer = contentService.getWriter(testData.B13NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); return null; } });
@Override public Void execute() throws Throwable { testData.destNodeRef = testNodeFactory.getMappedNodeRef(testData.A2NodeRef); ChildAssociationRef child = nodeService.createNode(testData.destNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("B10"), ContentModel.TYPE_CONTENT); testData.B10NodeRef = child.getChildRef(); nodeService.setProperty(testData.B10NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.B10NodeRef, ContentModel.PROP_NAME, "B10"); ContentWriter writer = contentService.getWriter(testData.B10NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); return null; } });
@Override public Void execute() throws Throwable { testData.destNodeRef = testNodeFactory.getMappedNodeRef(testData.A4NodeRef); ChildAssociationRef child = nodeService.createNode(testData.destNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("B11"), ContentModel.TYPE_CONTENT); testData.B11NodeRef = child.getChildRef(); nodeService.setProperty(testData.B11NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.B11NodeRef, ContentModel.PROP_NAME, "B11"); ContentWriter writer = contentService.getWriter(testData.B11NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); nodeService.deleteNode(testData.A2NodeRef); return null; } });
@Override public Void execute() throws Throwable { testData.destNodeRef = testNodeFactory.getMappedNodeRef(testData.A1NodeRef); ChildAssociationRef child = nodeService.createNode(testData.destNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("B9"), ContentModel.TYPE_CONTENT); testData.B9NodeRef = child.getChildRef(); nodeService.setProperty(testData.B9NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.B9NodeRef, ContentModel.PROP_NAME, "B9"); ContentWriter writer = contentService.getWriter(testData.B9NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); testData.destNodeRef = testNodeFactory.getMappedNodeRef(testData.A2NodeRef); child = nodeService.createNode(testData.destNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("B10"), ContentModel.TYPE_CONTENT); testData.B10NodeRef = child.getChildRef(); nodeService.setProperty(testData.B10NodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE); nodeService.setProperty(testData.B10NodeRef, ContentModel.PROP_NAME, "B10"); writer = contentService.getWriter(testData.B10NodeRef, ContentModel.PROP_CONTENT, true); writer.setLocale(CONTENT_LOCALE); writer.putContent(CONTENT_STRING); return null; } });
/** * Check that a valid writer into the content store can be retrieved and used. */ public void testSimpleNonTempWriter() throws Exception { ContentWriter writer = contentService.getWriter(null, null, false); assertNotNull("Writer should not be null", writer); assertNotNull("Content URL should not be null", writer.getContentUrl()); // write some content writer.putContent(SOME_CONTENT); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-16"); writer.setLocale(Locale.CHINESE); // set the content property manually nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, writer.getContentData()); // get the reader ContentReader reader = contentService.getReader(contentNodeRef, ContentModel.PROP_CONTENT); assertNotNull("Reader should not be null", reader); assertNotNull("Content URL should not be null", reader.getContentUrl()); assertEquals("Content Encoding was not set", "UTF-16", reader.getEncoding()); assertEquals("Content Locale was not set", Locale.CHINESE, reader.getLocale()); }