本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter类的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter类的具体用法?Java ContentWriter怎么用?Java ContentWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContentWriter类属于org.alfresco.service.cmr.repository包,在下文中一共展示了ContentWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canGuessMimeType
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
@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());
}
示例2: testSimpleNonTempWriter
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
/**
* 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());
}
示例3: testReadAndWriteStreamByPull
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
@Test
public void testReadAndWriteStreamByPull() throws Exception
{
ContentWriter writer = getWriter();
String content = "ABC";
// put the content using a stream
InputStream is = new ByteArrayInputStream(content.getBytes());
writer.putContent(is);
assertTrue("Stream close not detected", writer.isClosed());
// get the content using a stream
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
ContentReader reader = writer.getReader();
reader.getContent(os);
byte[] bytes = os.toByteArray();
String check = new String(bytes);
assertEquals("Write out and read in using streams failed", content, check);
}
示例4: testGeneralUse
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
@Test
public void testGeneralUse()
{
for (int i = 0 ; i < 20; i++)
{
ContentContext contentContext = new ContentContext(null, null);
ContentWriter writer = routingStore.getWriter(contentContext);
String content = "This was generated by " + this.getClass().getName() + "#testGeneralUse number " + i;
writer.putContent(content);
// Check that it exists
String contentUrl = writer.getContentUrl();
checkForContent(contentUrl, content);
// Now go direct to the routing store and check that it is able to find the appropriate URLs
ContentReader reader = routingStore.getReader(contentUrl);
assertNotNull("Null reader returned", reader);
assertTrue("Reader should be onto live content", reader.exists());
}
}
示例5: addTextContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
private NodeRef addTextContent(NodeRef folderRef, String name, String textData, boolean custom)
{
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, name);
ChildAssociationRef association = nodeService.createNode(folderRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
(custom == true ? customType: ContentModel.TYPE_CONTENT),
contentProps);
NodeRef content = association.getChildRef();
nodesToDelete.add(content);
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(textData);
return content;
}
示例6: test09OnContentUpdate
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
@Test
public final void test09OnContentUpdate() throws Exception
{
ContentWriter writer = serviceRegistry.getContentService().getWriter(content1, ContentModel.TYPE_CONTENT, true);
writer.putContent("The cow jumped over the moon.");
txn.commit();
txn = null;
assertEquals(1, auditMapList.size());
Map<String, Serializable> auditMap = auditMapList.get(0);
assertEquals("UPDATE CONTENT", auditMap.get("action")); // TODO Should be UPDATE CONTENT
assertContains("updateContent", auditMap.get("sub-actions"));
assertContains("updateNodeProperties", auditMap.get("sub-actions"));
assertEquals("/cm:homeFolder/cm:folder1/cm:content1", auditMap.get("path"));
assertEquals("cm:content", auditMap.get("type"));
}
示例7: testStringTruncation
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
@Test
public void testStringTruncation() throws Exception
{
String content = "1234567890";
ContentWriter writer = getWriter();
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8"); // shorter format i.t.o. bytes used
// write the content
writer.putContent(content);
// get a reader - get it in a larger format i.t.o. bytes
ContentReader reader = writer.getReader();
String checkContent = reader.getContentString(5);
assertEquals("Truncated strings don't match", "12345", checkContent);
}
示例8: getExistingContentUrl
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>
* This implementation creates some content in the store and returns the new content URL.
*/
protected String getExistingContentUrl()
{
ContentWriter writer = getWriter();
writer.putContent("Content for getExistingContentUrl");
return writer.getContentUrl();
}
示例9: testGetWriter
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
/**
* Test getWriter
*/
public void testGetWriter()
{
// Create a new versionable node
NodeRef versionableNode = createNewVersionableNode();
// Create a new version
Version version = createVersion(versionableNode, this.versionProperties);
// Get writer is not supported by the version content service
try
{
ContentWriter contentWriter = this.contentService.getWriter(
version.getFrozenStateNodeRef(),
ContentModel.PROP_CONTENT,
true);
contentWriter.putContent("bobbins");
fail("This operation is not supported.");
}
catch (Exception exception)
{
// An exception should be raised
}
}
示例10: testMediaWikiToHTML
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
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);
}
}
示例11: loadAndAddQuickFileAsManager
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
private File loadAndAddQuickFileAsManager(final NodeRef nodeRef, final String quickFileName, final String mimeType)
throws IOException
{
final File file = AbstractContentTransformerTest.loadNamedQuickTestFile(quickFileName);
if (file == null) { return null; }
// Set authentication to SiteManager and add a file
AuthenticationUtil.setFullyAuthenticatedUser(testSiteAndMemberInfo.siteManager);
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, quickFileName);
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimeType);
writer.setEncoding("UTF-8");
writer.putContent(file);
return null;
}
});
return file;
}
示例12: checkTransformable
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
/**
* Convenience method to check the transformability of a transformation
*
* @param reader content reader
* @param writer content writer
* @param options transformation options
* @throws AlfrescoRuntimeException if the the transformation isn't supported
*/
protected void checkTransformable(ContentReader reader, ContentWriter writer, TransformationOptions options)
{
String sourceMimetype = getMimetype(reader);
String targetMimetype = getMimetype(writer);
long sourceSize = reader.getSize();
boolean transformable = isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
if (transformable == false)
{
// This method is only called once a transformer has been selected, so it should be able to
// handle the mimetypes but might not be able to handle all the limits as it might be part of
// of a complex (compound) transformer. So report the max size if set.
long maxSourceSizeKBytes = getMaxSourceSizeKBytes(sourceMimetype, targetMimetype, options);
boolean sizeOkay = maxSourceSizeKBytes < 0 || (maxSourceSizeKBytes > 0 && sourceSize <= maxSourceSizeKBytes*1024);
AlfrescoRuntimeException e = new UnsupportedTransformationException("Unsupported transformation: " +
getBeanName()+' '+sourceMimetype+" to "+targetMimetype+' '+
(sizeOkay
? ""
: transformerDebug.fileSize(sourceSize)+" > "+ transformerDebug.fileSize(maxSourceSizeKBytes*1024)));
throw transformerDebug.setCause(e);
}
// it all checks out OK
}
示例13: createContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
protected ChildAssociationRef createContent(NodeRef parent, final String name, String contentString,
String mimeType, String encoding)
{
ChildAssociationRef nodeAssoc = createTypedNode(parent,
name,
ContentModel.TYPE_CONTENT);
NodeRef child = nodeAssoc.getChildRef();
ContentWriter writer = contentService.getWriter(child,
ContentModel.PROP_CONTENT,
true);
writer.setMimetype(mimeType);
writer.setEncoding(encoding);
writer.putContent(contentString);
return nodeAssoc;
}
示例14: testRFC822AlternativeToText
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
/**
* 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));
}
示例15: writeToCacheWithExistingReader
import org.alfresco.service.cmr.repository.ContentWriter; //导入依赖的package包/类
@Test
public void writeToCacheWithExistingReader()
{
ContentWriter oldWriter = store.getWriter(ContentContext.NULL_CONTEXT);
oldWriter.putContent("Old content for " + getClass().getSimpleName());
ContentReader existingReader = oldWriter.getReader();
// Write through the caching content store - cache during the process.
final String proposedUrl = FileContentStore.createNewFileStoreUrl();
ContentWriter writer = store.getWriter(new ContentContext(existingReader, proposedUrl));
final String content = makeContent();
writer.putContent(content);
assertEquals("Writer should have correct URL", proposedUrl, writer.getContentUrl());
assertFalse("Old and new writers must have different URLs",
oldWriter.getContentUrl().equals(writer.getContentUrl()));
ContentReader reader = store.getReader(writer.getContentUrl());
assertEquals("Reader and writer should have same URLs", writer.getContentUrl(), reader.getContentUrl());
assertEquals("Reader should get correct content", content, reader.getContentString());
}