本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentWriter.setMimetype方法的典型用法代码示例。如果您正苦于以下问题:Java ContentWriter.setMimetype方法的具体用法?Java ContentWriter.setMimetype怎么用?Java ContentWriter.setMimetype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentWriter
的用法示例。
在下文中一共展示了ContentWriter.setMimetype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNonAsciiRFC822ToText
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* 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));
}
示例2: testMsgToText
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* 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));
}
示例3: testEmptyHtmlToEmptyPdf
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* ALF-219. Transforamtion from .html to .pdf for empty file.
* @throws Exception
*/
public void testEmptyHtmlToEmptyPdf() 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);
}
示例4: writeContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Write content to the node from InputStream.
*
* @param nodeRef Target node.
* @param content Content stream.
* @param mimetype MIME content type.
* @param encoding Encoding. Can be null for text based content, n which case the best guess.
*/
protected void writeContent(NodeRef nodeRef, InputStream content, String mimetype, String encoding)
{
InputStream bis = new BufferedInputStream(content, 4092);
// Only guess the encoding if it has not been supplied
if (encoding == null)
{
if (mimetypeService.isText(mimetype))
{
ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
encoding = charsetFinder.getCharset(bis, mimetype).name();
}
else
{
encoding = "UTF-8";
}
}
if (log.isDebugEnabled())
{
log.debug("Write content (MimeType=\"" + mimetype + "\", Encoding=\"" + encoding + "\"");
}
ContentService contentService = getContentService();
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype);
writer.setEncoding(encoding);
writer.putContent(bis);
}
示例5: makeCopy
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void makeCopy(NodeRef nodeRef)
{
InputStream resource = getClass().getClassLoader().getResourceAsStream(fileName);
if (resource != null)
{
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.setMimetype(TEXT_CONTENT_MIMETYPE);
writer.putContent(resource);
}
else throw new PatchException("Resource '"+fileName+"' not found");
}
示例6: setContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* Set the content stream
*
* @param content Content string to set
*/
public void setContent(String content)
{
ContentService contentService = services.getContentService();
ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
writer.setMimetype(getMimetype()); // use existing mimetype value
writer.putContent(content);
// update cached variables after putContent()
updateContentData(true);
}
示例7: addComment
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private NodeRef addComment(NodeRef nr, String comment, boolean suppressRollups)
{
// There is no CommentService, so we have to create the node structure by hand.
// This is what happens within e.g. comment.put.json.js when comments are submitted via the REST API.
if (!nodeService.hasAspect(nr, ForumModel.ASPECT_DISCUSSABLE))
{
nodeService.addAspect(nr, ForumModel.ASPECT_DISCUSSABLE, null);
}
if (!nodeService.hasAspect(nr, ForumModel.ASPECT_COMMENTS_ROLLUP) && !suppressRollups)
{
nodeService.addAspect(nr, ForumModel.ASPECT_COMMENTS_ROLLUP, null);
}
// Forum node is created automatically by DiscussableAspect behaviour.
NodeRef forumNode = nodeService.getChildAssocs(nr, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef();
final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"));
NodeRef topicNode = null;
if (existingTopics.isEmpty())
{
topicNode = nodeService.createNode(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"), ForumModel.TYPE_TOPIC).getChildRef();
}
else
{
topicNode = existingTopics.get(0).getChildRef();
}
NodeRef postNode = nodeService.createNode(topicNode, ContentModel.ASSOC_CONTAINS, QName.createQName("comment" + System.currentTimeMillis()), ForumModel.TYPE_POST).getChildRef();
nodeService.setProperty(postNode, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
ContentWriter writer = contentService.getWriter(postNode, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(comment);
return postNode;
}
示例8: writeDestinationReport
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public NodeRef writeDestinationReport(String transferName,
TransferTarget target,
File tempFile)
{
String title = transferName + "_destination";
String description = "Transfer Destination Report - target: " + target.getName();
String name = title + ".xml";
logger.debug("writing destination transfer report " + title);
logger.debug("parent node ref " + target.getNodeRef());
Map<QName, Serializable> properties = new HashMap<QName, Serializable> ();
properties.put(ContentModel.PROP_NAME, name);
properties.put(ContentModel.PROP_TITLE, title);
properties.put(ContentModel.PROP_DESCRIPTION, description);
ChildAssociationRef ref = nodeService.createNode(target.getNodeRef(),
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
TransferModel.TYPE_TRANSFER_REPORT_DEST,
properties);
ContentWriter writer = contentService.getWriter(ref.getChildRef(),
ContentModel.PROP_CONTENT, true);
writer.setLocale(Locale.getDefault());
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding(DEFAULT_ENCODING);
writer.putContent(tempFile);
logger.debug("written " + name + ", " + ref.getChildRef());
return ref.getChildRef();
}
示例9: testUpdateContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testUpdateContent() throws Exception
{
NodeRef pivot = createContent();
NodeRef empty = null;
multilingualContentService.makeTranslation(pivot, Locale.FRENCH);
empty = multilingualContentService.addEmptyTranslation(pivot, "empty_" + System.currentTimeMillis(), Locale.CHINESE);
// update the empty translation content
ContentWriter writer = contentService.getWriter(empty, ContentModel.PROP_CONTENT, true);
writer.setMimetype("text/plain");
writer.putContent("ANY_CONTENT");
// Ensure that the URL property of the empty translation content is not null
assertNotNull("The url of an updated (ex)empty transation can't be null", ((ContentData) nodeService.getProperty(empty, ContentModel.PROP_CONTENT)).getContentUrl());
// Ensure that the mlEmptyTranslation aspect is removed
assertFalse("The " + ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION + " aspect of an updated (ex)empty translation must be removed", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
// Ensure that the mlDocument aspect is not removed
assertTrue("The " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " aspect of an updated (ex)empty translation must be keeped", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
// Ensure that the content is written
assertEquals("The content of the (ex)empty translation is not correct",
fileFolderService.getReader(empty).getContentString(),
"ANY_CONTENT");
// Ensure that the content is different that the content of the pivot
assertNotSame("The content of the (ex)empty translation is not updated and is the same as the content of the pivot",
fileFolderService.getReader(empty).getContentString(),
fileFolderService.getReader(pivot).getContentString());
}
示例10: onSetUpInTransaction
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
this.mimetypeService = (MimetypeService) this.applicationContext.getBean("mimetypeService");
this.metadataExtracterRegistry = (MetadataExtracterRegistry) this.applicationContext.getBean("metadataExtracterRegistry");
AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Setup the content from the PDF test data
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_PDF);
cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf"));
// Get the executer instance
this.executer = new ContentMetadataEmbedder();
this.executer.setNodeService(nodeService);
this.executer.setContentService(contentService);
this.executer.setMetadataExtracterRegistry(metadataExtracterRegistry);
this.executer.setApplicableTypes(new String[] { ContentModel.TYPE_CONTENT.toString() });
}
示例11: setImageContentOnNode
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
private void setImageContentOnNode(NodeRef nodeWithImage, String mimetypeImage, File imageFile)
{
assertTrue(imageFile.exists());
nodeService.setProperty(nodeWithImage, ContentModel.PROP_CONTENT, new ContentData(null,
mimetypeImage, 0L, null));
ContentWriter writer = contentService.getWriter(nodeWithImage, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetypeImage);
writer.setEncoding("UTF-8");
writer.putContent(imageFile);
}
示例12: addTextContent
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
protected NodeRef addTextContent(String siteId, String name)
{
String textData = name;
String mimeType = MimetypeMap.MIMETYPE_TEXT_PLAIN;
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, name);
// ensure that the Document Library folder is pre-created so that test code can start creating content straight away.
// At the time of writing V4.1 does not create this folder automatically, but Thor does
NodeRef parentRef = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
if (parentRef == null)
{
parentRef = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
}
ChildAssociationRef association = nodeService.createNode(parentRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
ContentModel.TYPE_CONTENT,
contentProps);
NodeRef content = association.getChildRef();
// add titled aspect (for Web Client display)
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
titledProps.put(ContentModel.PROP_TITLE, name);
titledProps.put(ContentModel.PROP_DESCRIPTION, name);
nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimeType);
writer.setEncoding("UTF-8");
writer.putContent(textData);
activityService.postActivity("org.alfresco.documentlibrary.file-added", siteId, "documentlibrary", content, name, ContentModel.PROP_CONTENT, parentRef);
return content;
}
示例13: createComment
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
/**
* This method was taken from the CommmentServiceImpl on the cloud branch
*
* TODO: When this is merged to HEAD, please remove this method and use the one in CommmentServiceImpl
*/
private NodeRef createComment(final NodeRef discussableNode, String title, String comment, boolean suppressRollups)
{
if(comment == null)
{
throw new IllegalArgumentException("Must provide a non-null comment");
}
// There is no CommentService, so we have to create the node structure by hand.
// This is what happens within e.g. comment.put.json.js when comments are submitted via the REST API.
if (!nodeService.hasAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE))
{
nodeService.addAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE, null);
}
if (!nodeService.hasAspect(discussableNode, ForumModel.ASPECT_COMMENTS_ROLLUP) && !suppressRollups)
{
nodeService.addAspect(discussableNode, ForumModel.ASPECT_COMMENTS_ROLLUP, null);
}
// Forum node is created automatically by DiscussableAspect behaviour.
NodeRef forumNode = nodeService.getChildAssocs(discussableNode, ForumModel.ASSOC_DISCUSSION, QName.createQName(NamespaceService.FORUMS_MODEL_1_0_URI, "discussion")).get(0).getChildRef();
final List<ChildAssociationRef> existingTopics = nodeService.getChildAssocs(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"));
NodeRef topicNode = null;
if (existingTopics.isEmpty())
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
props.put(ContentModel.PROP_NAME, "Comments");
topicNode = nodeService.createNode(forumNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Comments"), ForumModel.TYPE_TOPIC, props).getChildRef();
}
else
{
topicNode = existingTopics.get(0).getChildRef();
}
NodeRef postNode = nodeService.createNode(topicNode, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS, ForumModel.TYPE_POST).getChildRef();
nodeService.setProperty(postNode, ContentModel.PROP_CONTENT, new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
nodeService.setProperty(postNode, ContentModel.PROP_TITLE, title);
ContentWriter writer = contentService.getWriter(postNode, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
writer.setEncoding("UTF-8");
writer.putContent(comment);
return postNode;
}
示例14: testAsyncExecutionWithPotentialLoop
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
public void testAsyncExecutionWithPotentialLoop()
{
if (this.transformerRegistry.getTransformer(MimetypeMap.MIMETYPE_EXCEL, -1, MimetypeMap.MIMETYPE_TEXT_PLAIN, new TransformationOptions()) != null)
{
try
{
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(TransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
params.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, this.nodeRef);
params.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS);
params.put(TransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(TEST_NAMESPACE, "transformed"));
Rule rule = createRule(
RuleType.INBOUND,
TransformActionExecuter.NAME,
params,
NoConditionEvaluator.NAME,
null);
rule.setExecuteAsynchronously(true);
rule.setTitle("Transform document to text");
UserTransaction tx0 = transactionService.getUserTransaction();
tx0.begin();
this.ruleService.saveRule(this.nodeRef, rule);
tx0.commit();
UserTransaction tx = transactionService.getUserTransaction();
tx.begin();
Map<QName, Serializable> props =new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "test.xls");
// 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_EXCEL);
File testFile = AbstractContentTransformerTest.loadQuickTestFile("xls");
contentWriter.putContent(testFile);
tx.commit();
// Sleep to ensure work is done b4 execution is canceled
Thread.sleep(10000);
}
catch (Exception exception)
{
throw new RuntimeException(exception);
}
}
}
示例15: createPost
import org.alfresco.service.cmr.repository.ContentWriter; //导入方法依赖的package包/类
@Override
public PostInfo createPost(TopicInfo topic, String contents)
{
// Sanity check what we were given
if (topic.getNodeRef() == null)
{
throw new IllegalArgumentException("Can't create posts for a topic that was never persisted!");
}
// Are we going to be the primary post?
boolean isPrimary = false;
if (getPrimaryPost(topic) == null)
{
isPrimary = true;
}
// Decide on the name. If this is the first post in a topic,
// it should share the topic's name, otherwise needs a new one
String name = generateName();
if (isPrimary)
{
name = topic.getSystemName();
}
// Create the properties for the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, name);
// TODO Remove this shortly, when the webscripts have been
// fixed up to avoid their current broken-ness
props.put(ContentModel.PROP_PUBLISHED, new Date());
// Do we want a title? By default, primary posts share a title
// with the topic, but replies are title-free
if (isPrimary)
{
props.put(ContentModel.PROP_TITLE, topic.getTitle());
}
// Build the node
NodeRef nodeRef = nodeService.createNode(
topic.getNodeRef(),
ContentModel.ASSOC_CONTAINS,
QName.createQName(name),
ForumModel.TYPE_POST,
props
).getChildRef();
// Store the content
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_HTML);
writer.putContent(contents);
// Generate the wrapping object for it
// Build it that way, so creator and created date come through
return buildPost(nodeRef, topic, name, contents);
}