Update content in Webscript
private void updateContent(NodeRef nodeRef, String path, String fileName, boolean newFile)
{
// Make versionable
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
// Update content
InputStream is = this.getClass().getClassLoader().getResourceAsStream(path + fileName);
if (is != null)
{
ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
if (newFile == true)
{
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentWriter.setEncoding("UTF-8");
}
contentWriter.putContent(is);
}
}
{
// Make versionable
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
// Update content
InputStream is = this.getClass().getClassLoader().getResourceAsStream(path + fileName);
if (is != null)
{
ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
if (newFile == true)
{
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentWriter.setEncoding("UTF-8");
}
contentWriter.putContent(is);
}
}
Comments
Post a Comment