本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter.putContent方法的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter.putContent方法的具体用法?Java ContentWriter.putContent怎么用?Java ContentWriter.putContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentWriter
的用法示例。
在下文中一共展示了ContentWriter.putContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAlf6560MimetypeSetting
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testAlf6560MimetypeSetting() throws Exception
{
FileInfo fileInfo = fileFolderService.create(workingRootNodeRef, "Something.html", ContentModel.TYPE_CONTENT);
NodeRef fileNodeRef = fileInfo.getNodeRef();
// Write the content but without setting the mimetype
ContentWriter writer = fileFolderService.getWriter(fileNodeRef);
writer.putContent("CONTENT");
ContentReader reader = fileFolderService.getReader(fileNodeRef);
assertEquals("Mimetype was not automatically set", MimetypeMap.MIMETYPE_HTML, reader.getMimetype());
// Now ask for encoding too
writer = fileFolderService.getWriter(fileNodeRef);
writer.guessEncoding();
OutputStream out = writer.getContentOutputStream();
out.write( "<html><body>hall\u00e5 v\u00e4rlden</body></html>".getBytes("UnicodeBig") );
out.close();
reader = fileFolderService.getReader(fileNodeRef);
assertEquals("Mimetype was not automatically set", MimetypeMap.MIMETYPE_HTML, reader.getMimetype());
assertEquals("Encoding was not automatically set", "UTF-16BE", reader.getEncoding());
}
示例2: 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();
}
示例3: createCorruptedContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private NodeRef createCorruptedContent(NodeRef parentFolder) throws IOException
{
// The below pdf file has been truncated such that it is identifiable as a PDF but otherwise corrupt.
File corruptPdfFile = AbstractContentTransformerTest.loadNamedQuickTestFile("quickCorrupt.pdf");
assertNotNull("Failed to load required test file.", corruptPdfFile);
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, "corrupt.pdf");
NodeRef node = this.secureNodeService.createNode(parentFolder, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "quickCorrupt.pdf"),
ContentModel.TYPE_CONTENT, props).getChildRef();
secureNodeService.setProperty(node, ContentModel.PROP_CONTENT, new ContentData(null,
MimetypeMap.MIMETYPE_PDF, 0L, null));
ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
writer.setEncoding("UTF-8");
writer.putContent(corruptPdfFile);
return node;
}
示例4: testStoreWillRecoverFromDeletedCacheFile
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testStoreWillRecoverFromDeletedCacheFile()
{
final String content = "Content for " + getName() + " test.";
// Write some content to the backing store.
ContentWriter writer = backingStore.getWriter(ContentContext.NULL_CONTEXT);
writer.putContent(content);
final String contentUrl = writer.getContentUrl();
// Read content using the CachingContentStore - will cause content to be cached.
String retrievedContent = store.getReader(contentUrl).getContentString();
assertEquals(content, retrievedContent);
// Remove the cached disk file
File cacheFile = new File(cache.getCacheFilePath(contentUrl));
cacheFile.delete();
assertTrue("Cached content should have been deleted", !cacheFile.exists());
// Should still be able to ask for this content, even though the cache file was
// deleted and the record of the cache is still in the in-memory cache/lookup.
String contentAfterDelete = store.getReader(contentUrl).getContentString();
assertEquals(content, contentAfterDelete);
}
示例5: 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());
}
}
示例6: testAttachmentExtraction
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Test attachment extraction with a TNEF message
* @throws Exception
*/
public void testAttachmentExtraction() throws Exception
{
AuthenticationUtil.setRunAsUserSystem();
/**
* Load a TNEF message
*/
ClassPathResource fileResource = new ClassPathResource("imap/test-tnef-message.eml");
assertNotNull("unable to find test resource test-tnef-message.eml", fileResource);
InputStream is = new FileInputStream(fileResource.getFile());
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), is);
NodeRef companyHomeNodeRef = findCompanyHomeNodeRef();
FileInfo f1 = fileFolderService.create(companyHomeNodeRef, "ImapServiceImplTest", ContentModel.TYPE_FOLDER);
FileInfo f2 = fileFolderService.create(f1.getNodeRef(), "test-tnef-message.eml", ContentModel.TYPE_CONTENT);
ContentWriter writer = fileFolderService.getWriter(f2.getNodeRef());
writer.putContent(new FileInputStream(fileResource.getFile()));
imapService.extractAttachments(f2.getNodeRef(), message);
List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(f2.getNodeRef(), ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER);
assertTrue("attachment folder is found", targetAssocs.size() == 1);
NodeRef attachmentFolderRef = targetAssocs.get(0).getTargetRef();
assertNotNull(attachmentFolderRef);
List<FileInfo> files = fileFolderService.listFiles(attachmentFolderRef);
assertTrue("three files not found", files.size() == 3);
}
示例7: testMockInboundRuleType
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testMockInboundRuleType()
{
List<RuleTrigger> triggers = new ArrayList<RuleTrigger>(2);
triggers.add((RuleTrigger)this.applicationContext.getBean("on-content-create-trigger"));
triggers.add((RuleTrigger)this.applicationContext.getBean("on-create-node-trigger"));
triggers.add((RuleTrigger)this.applicationContext.getBean("on-create-child-association-trigger"));
ExtendedRuleType ruleType = new ExtendedRuleType(triggers);
assertFalse(ruleType.rulesTriggered);
NodeRef nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
ContentModel.TYPE_CONTENT).getChildRef();
// Update some content in order to trigger the rule type
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentWriter.putContent("any old content");
assertTrue(ruleType.rulesTriggered);
NodeRef nodeRef2 = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
ContentModel.TYPE_CONTAINER).getChildRef();
// Reset
ruleType.rulesTriggered = false;
assertFalse(ruleType.rulesTriggered);
// Create a child association in order to trigger the rule type
this.nodeService.addChild(
nodeRef2,
nodeRef,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN);
assertTrue(ruleType.rulesTriggered);
}
示例8: writeContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* @param nodeToUpdate NodeRef
* @param contentProps Map<QName, Serializable>
* @return true if any content property has been updated for the needToUpdate node
*/
private boolean writeContent(NodeRef nodeToUpdate, Map<QName, Serializable> contentProps)
{
boolean contentUpdated = false;
File stagingDir = getStagingFolder();
for (Map.Entry<QName, Serializable> contentEntry : contentProps.entrySet())
{
ContentData contentData = (ContentData) contentEntry.getValue();
String contentUrl = contentData.getContentUrl();
if(contentUrl == null || contentUrl.isEmpty())
{
log.debug("content data is null or empty:" + nodeToUpdate);
ContentData cd = new ContentData(null, null, 0, null);
nodeService.setProperty(nodeToUpdate, contentEntry.getKey(), cd);
contentUpdated = true;
}
else
{
String fileName = TransferCommons.URLToPartName(contentUrl);
File stagedFile = new File(stagingDir, fileName);
if (!stagedFile.exists())
{
error(MSG_REFERENCED_CONTENT_FILE_MISSING);
}
ContentWriter writer = contentService.getWriter(nodeToUpdate, contentEntry.getKey(), true);
writer.setEncoding(contentData.getEncoding());
writer.setMimetype(contentData.getMimetype());
writer.setLocale(contentData.getLocale());
writer.putContent(stagedFile);
contentUpdated = true;
}
}
return contentUpdated;
}
示例9: createTestContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private List<FileInfo> createTestContent(FileInfo parent, int count)
{
List<FileInfo> result = new ArrayList<FileInfo>(count);
for(int i = 0; i < count; i++)
{
FileInfo contentItem = fileFolderService.create(parent.getNodeRef(), "content_" + i, ContentModel.TYPE_CONTENT, ContentModel.ASSOC_CONTAINS);
ContentWriter contentWriter = contentService.getWriter(contentItem.getNodeRef(), ContentModel.PROP_CONTENT, false);
contentWriter.setEncoding("UTF-8");
contentWriter.putContent("TEST" + i);
}
return result;
}
示例10: DISABLED_testBasicFileOps
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
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);
}
示例11: processPart
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* 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();
}
}
示例12: setUpPreconditionForCheckedOutTest
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Set up preconditions for unlock a checked out node
*/
protected void setUpPreconditionForCheckedOutTest() throws Exception
{
appContext = ApplicationContextHelper.getApplicationContext(new String[]
{
"classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
"classpath:alfresco/remote-api-context.xml"
});
// Set the services
this.cociService = (CheckOutCheckInService) appContext.getBean("checkOutCheckInService");
this.contentService = (ContentService) appContext.getBean("contentService");
this.authenticationService = (MutableAuthenticationService) appContext.getBean("authenticationService");
this.permissionService = (PermissionService) appContext.getBean("permissionService");
this.transactionService = (TransactionService) appContext.getBean("TransactionService");
this.nodeService = (NodeService) appContext.getBean("NodeService");
// Authenticate as system to create initial test data set
this.authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent");
this.authenticationComponent.setSystemUserAsCurrentUser();
RetryingTransactionCallback<Void> createTestFileCallback = new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
// Create the store and get the root node reference
storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
if (!nodeService.exists(storeRef))
{
storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
}
rootNodeRef = nodeService.getRootNode(storeRef);
// Create and authenticate the user
userName = "webdavUnlockTest" + GUID.generate();
TestWithUserUtils.createUser(userName, PWD, rootNodeRef, nodeService, authenticationService);
permissionService.setPermission(rootNodeRef, userName, PermissionService.ALL_PERMISSIONS, true);
TestWithUserUtils.authenticateUser(userName, PWD, rootNodeRef, authenticationService);
userNodeRef = TestWithUserUtils.getCurrentUser(authenticationService);
// create test file in test folder
folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("test"), ContentModel.TYPE_FOLDER,
Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, "folder")).getChildRef();
fileNodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT,
Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, TEST_FILE_NAME)).getChildRef();
ContentWriter contentWriter = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/plain");
contentWriter.setEncoding("UTF-8");
contentWriter.putContent(CONTENT_1);
// Check out test file
fileWorkingCopyNodeRef = cociService.checkout(fileNodeRef);
assertNotNull(fileWorkingCopyNodeRef);
assertEquals(userNodeRef, nodeService.getProperty(fileNodeRef, ContentModel.PROP_LOCK_OWNER));
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(createTestFileCallback);
}
示例13: setMonitorData
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void setMonitorData(final NodeRef monitorNodeRef,final InputStream monitorData) {
final ContentWriter writer = contentService.getWriter(monitorNodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(monitorData);
LOGGER.debug("Monitor data added to Monitor-NodeRef '{}'.",monitorNodeRef);
}
示例14: testImageTransformAction
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Test image transformation
*
*/
public void testImageTransformAction() throws Throwable
{
ContentTransformer transformer = transformerRegistry.getTransformer(
MimetypeMap.MIMETYPE_IMAGE_GIF, -1,
MimetypeMap.MIMETYPE_IMAGE_JPEG,
new TransformationOptions());
if (transformer == null)
{
return;
}
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, this.rootNodeRef);
params.put(ImageTransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN);
params.put(TransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);
params.put(ImageTransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(TEST_NAMESPACE, "transformed"));
params.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND, "-negate");
Rule rule = createRule(
RuleType.INBOUND,
ImageTransformActionExecuter.NAME,
params,
NoConditionEvaluator.NAME,
null);
this.ruleService.saveRule(this.nodeRef, rule);
UserTransaction tx = transactionService.getUserTransaction();
tx.begin();
Map<QName, Serializable> props =new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "test.gif");
// Create the node at the root
NodeRef newNodeRef = this.nodeService.createNode(
this.nodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(TEST_NAMESPACE, "origional"),
ContentModel.TYPE_CONTENT,
props).getChildRef();
// Set some content on the origional
ContentWriter contentWriter = this.contentService.getWriter(newNodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(MimetypeMap.MIMETYPE_IMAGE_GIF);
File testFile = AbstractContentTransformerTest.loadQuickTestFile("gif");
contentWriter.putContent(testFile);
tx.commit();
//System.out.println(NodeStoreInspector.dumpNodeStore(this.nodeService, this.testStoreRef));
// Check that the created node is still there
List<ChildAssociationRef> origRefs = this.nodeService.getChildAssocs(
this.nodeRef,
RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "origional"));
assertNotNull(origRefs);
assertEquals(1, origRefs.size());
NodeRef origNodeRef = origRefs.get(0).getChildRef();
assertEquals(newNodeRef, origNodeRef);
// Check that the created node has been copied
List<ChildAssociationRef> copyChildAssocRefs = this.nodeService.getChildAssocs(
this.rootNodeRef,
RegexQNamePattern.MATCH_ALL, QName.createQName(TEST_NAMESPACE, "test.jpg"));
assertNotNull(copyChildAssocRefs);
assertEquals(1, copyChildAssocRefs.size());
NodeRef copyNodeRef = copyChildAssocRefs.get(0).getChildRef();
assertTrue(this.nodeService.hasAspect(copyNodeRef, ContentModel.ASPECT_COPIEDFROM));
NodeRef source = copyService.getOriginal(copyNodeRef);
assertEquals(newNodeRef, source);
}
示例15: ensure_node_with_different_content_throws_exception
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Test(expected = AssertionError.class)
public void ensure_node_with_different_content_throws_exception() {
final ContentWriter w = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
w.putContent("content");
assertThat(nodeRef).hasContent("different content");
}