12-21-2007 08:34 AM
12-21-2007 05:54 PM
ContentData content = ContentData.createContentProperty("My content.");
nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, content);
12-28-2007 05:55 PM
01-17-2008 08:39 AM
I need to modify the content (plain/text) of an existing node programatically. At first, I thought to use the ContentWriter class and its put() method.
I have to replace the content of a node entirely so I tried to get the ContentReader associated to the node, to store it into a String variable, to modify the string itself accordingly to my custom needs, then to write the new string to the ContentWriter. I noticed that the put() method does not replace the content but appends a new content to the old one, doesn't it?
How can I update the content of a node?
01-17-2008 08:57 AM
01-21-2009 09:24 AM
ContentService contentService = this.serviceRegistry.getContentService();
ContentWriter contentWriter = contentService.getWriter(nodeCurrentLogFile, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/plain");
OutputStream outputStream = contentWriter.getContentOutputStream();
PrintWriter printWriter = new PrintWriter(outputStream);
//printWriter.println(logLine); // Replaces the whole content with logLine.
//printWriter.append(logLine); // Replaces the whole content with logLine.
printWriter.write(logLine, (int) contentWriter.getSize(), logLine.length()); // Replaces the whole content with logLine.
printWriter.flush();
printWriter.close();
01-21-2009 11:55 AM
ContentWriter contentWriter = contentService.getWriter(nodeCurrentLogFile, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/plain");
FileChannel fileChannel = contentWriter.getFileChannel(false);
ByteBuffer bf = ByteBuffer.wrap(logLine.getBytes());
fileChannel.position(contentWriter.getSize());
fileChannel.write(bf);
fileChannel.force(false);
fileChannel.close();
06-05-2019 05:08 AM
I'm attempting to do this, but having tried both approaches shown above (FileChannel, PrintWriter), although the write appears to complete, I then get the following exception shown in the log, and no data is present in the file
2019-06-05 09:04:57,497 ERROR [extensions.webscripts.AbstractRuntime] [http-nio-8080-exec-7] Exception from executeScript: Transaction silently rolled back because it has been marked as rollback-only
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.