本文整理汇总了Java中org.alfresco.service.cmr.repository.ContentService.getWriter方法的典型用法代码示例。如果您正苦于以下问题:Java ContentService.getWriter方法的具体用法?Java ContentService.getWriter怎么用?Java ContentService.getWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.service.cmr.repository.ContentService
的用法示例。
在下文中一共展示了ContentService.getWriter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canGuessMimeType
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的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: copyContentOnly
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
private void copyContentOnly(FileInfo sourceFileInfo, FileInfo destFileInfo, FileFolderService fileFolderService) throws WebDAVServerException
{
ContentService contentService = getContentService();
ContentReader reader = contentService.getReader(sourceFileInfo.getNodeRef(), ContentModel.PROP_CONTENT);
if (reader == null)
{
// There is no content for the node if it is a folder
if (!sourceFileInfo.isFolder())
{
// Non-folders should have content available.
logger.error("Unable to get ContentReader for source node " + sourceFileInfo.getNodeRef());
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
}
else
{
ContentWriter contentWriter = contentService.getWriter(destFileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
contentWriter.putContent(reader);
}
}
示例3: delete
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
/**
* Delete the content stream
*/
public void delete()
{
ContentService contentService = services.getContentService();
ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
OutputStream output = writer.getContentOutputStream();
try
{
output.close();
}
catch (IOException e)
{
// NOTE: fall-through
}
writer.setMimetype(null);
writer.setEncoding(null);
// update cached variables after putContent()
updateContentData(true);
}
示例4: writeContent
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的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: writeSpace
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
/**
* This method writes space as a content. We need this space because rules doesn't proceed documents with empty content. We need rule processing for command email messages with
* empty body.
*
* @param nodeRef Reference to the parent node
*/
private void writeSpace(NodeRef nodeRef)
{
if (log.isDebugEnabled())
{
log.debug("Write space string");
}
ContentService contentService = getContentService();
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(" ");
}
示例6: transformNode
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
/**
* Generic method to transform Node content from one mimetype to another.
*
* @param transformer The Transformer delegate supplying the transformation logic
* @param mimetype Mimetype of the destination content
* @param destination Destination folder location for the resulting document
*
* @return Node representing the transformed content - or null if the transform failed
*/
private ScriptNode transformNode(Transformer transformer, String mimetype, NodeRef destination)
{
ScriptNode transformedNode = null;
// get the content reader
ContentService contentService = this.services.getContentService();
ContentReader reader = contentService.getReader(this.nodeRef, ContentModel.PROP_CONTENT);
// only perform the transformation if some content is available
if (reader != null)
{
// Copy the content node to a new node
String copyName = TransformActionExecuter.transformName(this.services.getMimetypeService(), getName(),
mimetype, true);
NodeRef copyNodeRef = this.services.getCopyService().copy(this.nodeRef, destination,
ContentModel.ASSOC_CONTAINS,
QName.createQName(ContentModel.PROP_CONTENT.getNamespaceURI(), QName.createValidLocalName(copyName)),
false);
// modify the name of the copy to reflect the new mimetype
this.nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, copyName);
// get the writer and set it up
ContentWriter writer = contentService.getWriter(copyNodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype); // new mimetype
writer.setEncoding(reader.getEncoding()); // original encoding
// Try and transform the content using the supplied delegate
transformedNode = transformer.transform(contentService, copyNodeRef, reader, writer);
}
return transformedNode;
}
示例7: setContent
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的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);
}
示例8: write
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
/**
* Set the content stream from another content object.
*
* @param content ScriptContent to set
*/
public void write(Content content)
{
ContentService contentService = services.getContentService();
ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
writer.setMimetype(content.getMimetype());
writer.setEncoding(content.getEncoding());
writer.putContent(content.getInputStream());
// update cached variables after putContent()
updateContentData(true);
}
示例9: createAvatarDirect
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile)
{
// create new avatar node
nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(
personRef,
ContentModel.ASSOC_PREFERENCE_IMAGE,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"),
ContentModel.TYPE_CONTENT);
final NodeRef avatarRef = assoc.getChildRef();
// JSF client compatibility?
nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
// upload the avatar content
ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
writer.guessMimetype(avatarFile.getName());
writer.putContent(avatarFile);
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
renditions.createRendition(avatarRef.getId(), avatarR, false, null);
return avatarRef;
}
示例10: testLifecycleOfXmlMetadataExtraction
import org.alfresco.service.cmr.repository.ContentService; //导入方法依赖的package包/类
/**
* Tests metadata extraction using an action with an EAGER MetadataExtracter for XML.
*/
public void testLifecycleOfXmlMetadataExtraction() throws Exception
{
NodeService nodeService = serviceRegistry.getNodeService();
ContentService contentService = serviceRegistry.getContentService();
ActionExecuter executer = (ActionExecuter) ctx.getBean("extract-metadata");
Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, null);
StoreRef storeRef = new StoreRef("test", getName());
NodeRef rootNodeRef = null;
if (nodeService.exists(storeRef))
{
rootNodeRef = nodeService.getRootNode(storeRef);
}
else
{
nodeService.createStore("test", getName());
rootNodeRef = nodeService.getRootNode(storeRef);
}
// Set up some properties
PropertyMap properties = new PropertyMap();
properties.put(ContentModel.PROP_TITLE, "My title");
properties.put(ContentModel.PROP_DESCRIPTION, "My description");
NodeRef contentNodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()),
ContentModel.TYPE_CONTENT,
properties).getChildRef();
// Add some content
ContentReader alfrescoModelReader = getReader(FILE_ALFRESCO_MODEL);
assertTrue(alfrescoModelReader.exists());
ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.putContent(alfrescoModelReader);
// Execute the action
executer.execute(action, contentNodeRef);
// Check the node's properties. The EAGER overwrite policy should have replaced the required
// properties.
String checkTitle = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_TITLE);
String checkDescription = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_DESCRIPTION);
assertEquals("fm:forummodel", checkTitle);
assertEquals("Forum Model", checkDescription);
}